<p>I have the following object in the game
<a href="https://i.sstatic.net/FozUp.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FozUp.jpg" alt="enter image description here"></a>
It is a dial with the little triangle showing what part of the disk is being valued.</p>

<p>The dial serves as a controller that sets a variable from 0-1. If the disk has 0 degrees facing left then it is 0, if the disk has 180 degrees facing left then it is 0.5. Somehow I will eventually find a way to express that so the disk will not be uniform.</p>

<p>Anyway so the inner disk you see will spin meanwhile the outer disk with the triangle thing will stay in place.</p>

<p>Something that would be nice is if the area of the spinning disk that is inside of the triangle would disappear.
<a href="https://i.sstatic.net/Nhq1p.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Nhq1p.png" alt="enter image description here"></a></p>

<p>The problem is I have no clue how to do this.</p>

<p>Currently the rotation of the disk is done by a matrix that rotates the quad that is rendering this.</p>

<p>I have two ideas
1. Edit the quad into a mesh cutting out the triangle, however this would not work as the mesh is translated in my current model.
2. Run costly trigonometric calculations to figure out where each fragment is in real space then figure out its angle and distance from the center of the circle.</p>

<p>I know doing a little trig on each fragment might not sound like much, however just rendering the disk adds 1ms of rendering time when rendering on the lowest possible hardware this could run on.</p>

<p>How do people achieve real-time masking in opengl?</p>

CC BY-SA 3.0
2016-09-29T03:23:48.760Z
You could look into stencil buffers. You can draw the masking triangle into the stencil buffer only. Then the rest of the circle can be drawn using the stencil buffer as a mask.
PaulHK
CC BY-SA 3.0
2016-10-05T15:26:35.230Z
How are the components drawn? Are they images or generated by a frag shader? Is the triangle drawn as a single triangle, or as part of the outer circle? I don't think it's possible to make a useful suggestion without knowing how all the components relate in terms of draw calls.
Dan Hulme
CC BY-SA 3.0
2016-10-05T15:59:35.110Z
I tried doing an offscreen fbo that leveraged the fact that I'm using additive blending but that cut fps in half.  I am still working on figuring out stencil buffer.
J.Doe
CC BY-SA 3.0
2016-10-05T16:00:37.247Z
So the outer ring with a triangle is a GLQUAD and the inner circle is another GLQuad. The outer one never gets transformed while the inner one does get rotated.
J.Doe
<masking>
Mask out parts of an image in OpenGL ES
J.Doe
# Mask out parts of an image in OpenGL ES

(Asked by: username_0 on 2016-09-28)

I have the following object in the game
[![enter image description here](https://i.sstatic.net/FozUp.jpg)](https://i.sstatic.net/FozUp.jpg)
It is a dial with the little triangle showing what part of the disk is being valued.

The dial serves as a controller that sets a variable from 0-1. If the disk has 0 degrees facing left then it is 0, if the disk has 180 degrees facing left then it is 0.5. Somehow I will eventually find a way to express that so the disk will not be uniform.

Anyway so the inner disk you see will spin meanwhile the outer disk with the triangle thing will stay in place.

Something that would be nice is if the area of the spinning disk that is inside of the triangle would disappear.
[![enter image description here](https://i.sstatic.net/Nhq1p.png)](https://i.sstatic.net/Nhq1p.png)

The problem is I have no clue how to do this.

Currently the rotation of the disk is done by a matrix that rotates the quad that is rendering this.

I have two ideas
1. Edit the quad into a mesh cutting out the triangle, however this would not work as the mesh is translated in my current model.
2. Run costly trigonometric calculations to figure out where each fragment is in real space then figure out its angle and distance from the center of the circle.

I know doing a little trig on each fragment might not sound like much, however just rendering the disk adds 1ms of rendering time when rendering on the lowest possible hardware this could run on.

How do people achieve real-time masking in opengl?

**Tags:** masking

> **Comments:**
> **username_1**: You could look into stencil buffers. You can draw the masking triangle into the stencil buffer only. Then the rest of the circle can be drawn using the stencil buffer as a mask.  
> **username_2**: How are the components drawn? Are they images or generated by a frag shader? Is the triangle drawn as a single triangle, or as part of the outer circle? I don't think it's possible to make a useful suggestion without knowing how all the components relate in terms of draw calls.  
> **username_0**: I tried doing an offscreen fbo that leveraged the fact that I'm using additive blending but that cut fps in half.  I am still working on figuring out stencil buffer.  
> **username_0**: So the outer ring with a triangle is a GLQUAD and the inner circle is another GLQuad. The outer one never gets transformed while the inner one does get rotated.  

---

## 0 answers

