<p>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 <a href="https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm" rel="nofollow noreferrer">Inigo Quilez website</a> 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 &quot;normal&quot; 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.</p>
<p>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?</p>

CC BY-SA 4.0
2020-08-07T13:45:03.767Z
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.
joojaa
CC BY-SA 4.0
2020-08-07T13:48:14.870Z
That's what I do right now but what if I want to draw multiple things in my square?
Nils
CC BY-SA 4.0
2020-08-07T13:49:57.180Z
You dont actually have to clear the screen between calls. But its easier just to emit more polygons. Also look up accumulation buffers
joojaa
<gpu><fragment-shader><signed-distance-field>
GPU accelerated 2D graphics library with signed distance functions
Nils
# GPU accelerated 2D graphics library with signed distance functions

(Asked by: username_0 on 2020-08-06)

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](https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) 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?

**Tags:** gpu, fragment-shader, signed-distance-field

> **Comments:**
> **username_1**: 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.  
> **username_0**: That's what I do right now but what if I want to draw multiple things in my square?  
> **username_1**: You dont actually have to clear the screen between calls. But its easier just to emit more polygons. Also look up accumulation buffers  

---

## 0 answers

