Open lewislepton opened 8 years ago
I like skia (https://skia.org/) api : https://skia.org/user/api every draw command accept a paint param that contains all the setting (fill, color, ...)
I would also prefer the skia api. Plus it's easier to implement.
Having drawings functions like the skia would be nice in Kha. But I think Kha could put this (and other features like creative coding as in #212) in separate repos, like "official kha extensions", to mantain the main repo small.
but if you get what i mean. whilst having a function that does a lot is alright to some degree. but if you can esily just say put in
graphics.fill();
rather than
graphics.drawRect(x,y,w,h,fill,strencth);
just that it has this extesibility too it. plus easily for implementing changes with having to damage other code. if you get me? ;)
UPDATE unless it is that you are all agreeing with me and im just talking for a weird reason ;)
Well, are you ok with the skia method of doing that?
aye. i guess so. mainly its to split up certain things but to also get rid of certain things also, that i care about. because there is no point in having 2 draw rectangle functions. as long as its stream lined, then im all for it really ;)
Oki, the skia method does that too, so I'll go for that.
its 'simplicity with power' that i think would be good. because even though kha can make really awesome things, its making it approachable to new users.
so they can look at something and understand it well
actually, that could be the slogan - 'simplicity with power' ;)
Always trying to do simplicity ala http://www.infoq.com/presentations/Simple-Made-Easy ;)
lewislepton might want to experiment with GraphicsKha experiments of mine on github it has quite a bit of drawing stuff but it's still experimental.
This is the design of what I'm implementing in the Graphics2 api:
var g = framebuffer.g2;
g.begin(true);
// Applied when style is not specified
g.style.fill = true;
g.style.fillColor = Color.fromFloats(r, g, b, a);
g.style.stroke = true;
g.style.strokeColor = Color.Black;
g.style.strokeWeight = 1.0;
//...
var style = new Style();
// Drawing
g.rect(x, y, width, width);
g.push();
g.translate(x, y);
g.arc(x, y, width, height, startAngle, endAngle, style);
var transform = g.pop();
g.scale(3.0, 3.0);
g.translate(32, 0);
g.ellipse(x, y, width, height);
g.setTransform(transform);
g.ellipse(x, y, width, height, style);
g.setTransform(transform);
g.rotate(Math.PI);
g.triangle(x1, y1, x2, y2, x3, y3);
g.resetTransform();
g.beginShape(TRIANGLES);
g.vertex(x1, y1);
g.vertex(x2, y2);
g.vertex(x3, y3);
g.vertex(x4, y4);
g.vertex(x5, y5);
g.vertex(x6, y6);
g.endShape();
g.line(x1, y1, x2, y2);
g.quad(x1, y1, x2, y2, x3, y3, x4, y4);
g.end();
It's begin easy to implement for all targets because I made the underling code more generic. It's already working for OpenGL targets and html5 canvas.
@hammeron-art don't forget the rounded rectangles :) This will be open source? Kha needs a good drawing lib like flash graphics.
@RafaelOliveira It's for Kha itself. It isn't a full featured lib but shape drawing like html5 canvas. The current g2 plus GraphicsExtension can do most of it but I'm simplifying the interface and adding features like style parameters, fill and stroke. Improving vertex batching too. Currently, it switches buffers depending on the shape for the same shader type. I'm rewriting it to use a single buffer per shader and a single draw call. These changes will make it easy to implement a Graphics3 for 3D shape drawing.
Ah, with style objects, looks good.
PS: Graphics3 will be an OpenGL 1 style api to support 3D on older systems. No relation to Graphics2.
I'm not sure how OpenGL 1 worked but as I see it the only difference between 2d and 3d drawing is that the latter takes z positions. Internally the transformation matrix, vertex buffer building, shaders, etc, is the same as Graphics2.
Graphics2 has no vertex buffers - only internally when implemented on top of Graphics4. Graphics3 will have them, will be like Graphics4 minus shaders plus more state.
To get more into the thinking behind that: Kha is a hardware/software abstraction library, the only reason for graphics2 to exist is to abstract away typical 2D apis like
Oh, I see. I was thinking in a primitive drawing thing but the goal is a 3D api.
so i was just thinking about the api/code for kha, things that could be made more simpler. and one that points out to me is the use of 2 rectangle drawing function.
whilst i know that drawRect has a strength, thats fine. but it would be good to have just a fill function, that will replace the fillRect. so like the .color. we only have to put up above the code
so rather than having this
or having this
so in essence we only use 1 for drawing rectangle technique
anyhow, hope that load of typing made sense ;)