faiface / pixel

A hand-crafted 2D game library in Go
MIT License
4.46k stars 246 forks source link

#244 GLTriangle's fragment shader is used when rendered by the Canvas. #246

Closed dusk125 closed 3 years ago

dusk125 commented 4 years ago

Allows for custom fragment shaders to be used with canvas.MakeTriangles.

Usage:

shader := pixelgl.NewGLShader(shaderText)
...
tris := pixel.MakeTrianglesData(5)
// fill triangles...
shaderTris := pixelgl.NewGLTriangles(shader, tris)
win.Canvas().MakeTriangles(shaderTris).Draw()
dusk125 commented 4 years ago

My use case for this feature is that in the Pixleui project, imgui returns a list of draw data; part of this draw data is a list of triangles. I need to draw these triangles using a specific fragment shader and I don't want to change the windows (canvas's) fragment shader since that will change it globally (and cause a shader rebuild every frame).

If this is not accepted, I can create my own canvas in pixelui with the fragment shader and just render that canvas ontop the window canvas, at the cost of some performance.

delp commented 4 years ago

I want to play around with this some more

dusk125 commented 4 years ago

Fixed the conflict generated by my other PR.

dusk125 commented 4 years ago

@delp here is a link to how I'm using the triangles in pixelui. Let me know if any explanation is needed.

delp commented 3 years ago

This PR will be better now that its been allowed to age like a fine wine :P