Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KHA FEATURE THOUGHT] replace graphics.fillRect with graphics.fill #214

Open
lewislepton opened this issue Jan 16, 2016 · 18 comments
Open

Comments

@lewislepton
Copy link
Contributor

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

graphics.color = Color.Black;
graphics.fill();
graphics.drawRect(x, y, w, h);

so rather than having this

graphics.color = Color.Black;
graphics.fillRect(x, y, w, h);

or having this

graphics.color = Color.Black;
graphics.drawRect(x, y, w, h);

so in essence we only use 1 for drawing rectangle technique

anyhow, hope that load of typing made sense ;)

@wighawag
Copy link
Contributor

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, ...)

@RobDangerous
Copy link
Member

I would also prefer the skia api. Plus it's easier to implement.

@RafaelOliveira
Copy link
Contributor

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.

@lewislepton
Copy link
Contributor Author

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 ;)

@RobDangerous
Copy link
Member

Well, are you ok with the skia method of doing that?

@lewislepton
Copy link
Contributor Author

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 ;)

@RobDangerous
Copy link
Member

Oki, the skia method does that too, so I'll go for that.

@lewislepton
Copy link
Contributor Author

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' ;)

@RobDangerous
Copy link
Member

Always trying to do simplicity ala http://www.infoq.com/presentations/Simple-Made-Easy ;)

@Justinfront
Copy link

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.

@hammeron-art
Copy link
Contributor

hammeron-art commented Aug 13, 2016

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.

@RafaelOliveira
Copy link
Contributor

@hammeron-art don't forget the rounded rectangles :) This will be open source? Kha needs a good drawing lib like flash graphics.

@hammeron-art
Copy link
Contributor

@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.

@RobDangerous
Copy link
Member

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.

@hammeron-art
Copy link
Contributor

hammeron-art commented Aug 14, 2016

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.

@RobDangerous
Copy link
Member

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.

@RobDangerous
Copy link
Member

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 . There are no systems which provide 3D apis in that style as their lowest level graphics api so no need for Kha to do anything like that.

@hammeron-art
Copy link
Contributor

hammeron-art commented Aug 14, 2016

Oh, I see. I was thinking in a primitive drawing thing but the goal is a 3D api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants