RafaelOliveira / KhaGfx

2 stars 0 forks source link

Bresenham - partially ported and tested on hxDeadalus ( wings.pixel.Plot ) #1

Closed Justinfront closed 8 years ago

Justinfront commented 8 years ago

RafaelOliveria - We have already done quite a bit of work on "http://members.chello.at/~easyfilter/bresenham.html"
https://github.com/hxDaedalus/hxDaedalus/blob/master/src/wings/pixel/Plot.hx
It might be worth joining some efforts? I ported them and then Azarfe7 fixed them up some, I think there is work still to do. I was just using them for pixel drawing to say png's. I thought it might be nice to generate gif animations on server for targets that could not render paths. but as you may know my github profile is not really active anymore, but feel free to contact me off list.

Justinfront commented 8 years ago

You can see specific limited use here: https://github.com/hxDaedalus/hxDaedalus-simpledrawing/blob/master/formatCompile.hxml https://github.com/hxDaedalus/hxDaedalus-simpledrawing/blob/master/src/TestGraphics.hx#L75 https://cloud.githubusercontent.com/assets/489459/8213460/e0bb6944-1519-11e5-9070-d00f1c173c37.png

RafaelOliveira commented 8 years ago

I think would be great to add kha to your library, but I need to study it to see how this could be done. I'm seeing the class hxPixels/Pixels.hx writing directly the pixels, where kha does this already. But TPixels uses a typedef to reference it, so this could be used in some way to integrate Kha. And would be cool to integrate all the hxDaedalus functionality.

About using g1 in my functions instead of g2, its because the simplest function in g2 is for drawing lines, so I don't know if for drawing single pixels is fast enough. And many functions draws curves, that need single pixels.

I'd like this to be more flexible, like draw others things like images in the place of the pixels, and have a variation that could only return the points, where we can use in others forms of drawing, like drawing text aligned along a path.

nanjizal commented 8 years ago

I just wondered if your Kha we could put this code into a pixel shader some how. For html target the pixel class abstracts over canvas, you could draw to canvas and transfer the canvas to shader I don't know if that might be fast? Try out hxDaedalus and get a feel it would be great to have a Kha target but not much use if it was slower than openfl one. Any comments left on hxDaedalus will get input from Azarfe7 who has lots of algorithm knowledge and may have some good ideas. So perhaps after having a look leave an issue over there.

RafaelOliveira commented 8 years ago

From what I know, Kha already uses webgl for 2d drawing where it is available. But I can implement a version where the functions returns the points that could be used to fill a vertex buffer, then the user can use with shaders the way he want. Is this correctly? I'm still learning shaders.

Justinfront commented 8 years ago

I suspect the processing cost is often on putting them on screen. So drawing to canvas ( but not putting canvas on screen ) and then passing image to the vertex shader may work ok or drawing on a bitmap and similar. https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial/Using_textures_in_WebGL

RafaelOliveira commented 8 years ago

I'm planning 4 versions of the algorithms, this way the developer can choose the best way to use. 1 - pixel with g1. 2 - pixel with g2 using drawLine. 3 - passing a function to render outside. 4 - just return the points.

Justinfront commented 8 years ago

if you separate it properly then you can have one library that wraps it for use with Kha and more generic one that allows hooking upto other stuff like luxe.

RafaelOliveira commented 8 years ago

I found a bezier render that was much smaller than the bresenham version, and sent a pr to Kha. You can see here: https://github.com/KTXSoftware/Kha/blob/master/Sources/kha/graphics2/GraphicsExtension.hx#L121 After that I decided to remove the bresenham methods, and I'm looking for algorithms based on a total of segments where I can draw with a line. I don't have strong arguments, but that seems faster than draw pixel by pixel. The loop will depended on total of segments chosen.

RafaelOliveira commented 8 years ago

@Justinfront The problem is that I don't want a generic implementation that interfere on the speed of the algorithms (but I'm opened for ideas). And I don't know if this is easy to do, because Kha works in a different level than the other haxe frameworks. I tried to make hxPixels to work with Kha, but didn't work. But I can try again another time.

@nanjizal I want to include a shader version in the future, but I'm still studying shaders. I want to see if I can compute the algorithms directly on a shader.