I want to create my own 2D graphics library using signed distance functions where everything is drawn on the GPU. Browsing the web I quickly found Inigo Quilez website that describes how to draw basic shapes with signed distance functions. I can work out the math on my own and come up with toy examples using Shadertoy. The problem I have is that I do not understand how I could I can call a function like drawCircle(...) from "normal" C code on the CPU to trigger the call to a function that draws a circle in a fragment shader. Of course I could draw the circle to a texture and send this to the GPU but that would not use the GPU for drawing.

What would be a reasonable software design where one could invoke draw calls from the CPU using a painters model and then these would be executed on the GPU in a fragment shader?

  • $\begingroup$ You make a screen oriented square out of 2 triangles bind it to your shader and ask the gpu to draw the screen. (This is also how shadertoy works) and after 10 or so steps is your users worrying about conflation artefacts. $\endgroup$ – joojaa Aug 7 at 13:45
  • $\begingroup$ That's what I do right now but what if I want to draw multiple things in my square? $\endgroup$ – Nils Aug 7 at 13:48
  • 1
    $\begingroup$ You dont actually have to clear the screen between calls. But its easier just to emit more polygons. Also look up accumulation buffers $\endgroup$ – joojaa Aug 7 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.