Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Clear at specific z plane

This topic is 4418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody, I am new to this forum and I would to compliment with all for this forum very rich of useful informations. So, I want to say hello to everybody, First I am sorry for my english level but it is not my native language. I start with a question. I am a newbie on OpenGl programming and I am working on a scientific application that must plot a signal scope in real-time using OpenGl under Linux and Windows. My app is very simple and it is in the first stage of development. Since I need only 2D graphics I use glOrtho() to use orthographic projection. I plot a grid on a z plane (i.e. z = -0.1f) and the signal scope on an another z plane (i.e. z = 0). My question is: since signal scope is update very frequenly while the grid is not, there is a method to clear vertices only at a specific z value? This allows me to do not replot the grid when updating the signal scope, a sort of a fixed background. Thank you in advance for every suggestion and I hope to provide my support in the future when I become stronger in OpenGl. Y.

Share this post

Link to post
Share on other sites
In short: you can separate display lists for the two depths and draw them separately. Just cease to render the foreground display list to "clear" the foreground. However, rendering the foreground will draw pixels on top of existing background pixels. These background pixels are then lost, and can only be restored by rendering the background again. You can clear all vertices and pixels at a given depth, but you cannot retrieve the background color.

Of course, since your background is a grid, you can choose to display only the grid tiles that contain foreground (since the others have not changed). If necessary, you can also draw only sections of tiles in a "dirty rect" fashion.

Watch out for swapping double buffering, though, as each buffer is displayed only once every two frames: you might want to use copying double buffer, or to pay attention to handle swaps correctly.

Share this post

Link to post
Share on other sites
Short answer: no, there is no way to clean values up to a certain z (depth) value.

Long answer: It might work to draw a black (or other background color) rectangle "between" background and the foreground (z = -0.05) using an inverted blend function (glBlendFunc(GL_GEQUAL), or something like that), but this is way slower than redrawing your grid. Render to texture and others might work too, but they are way more trouble than they're worth.

If you're doing 2d with opengl, you don't need to specify the z-coordinates, if you draw stuff in the correct order, from back to front (like in old school 2d). Just disable (or don't enable it as it's off by default) the depth test and draw everything with glVertex2f() (z is assumed as 0).

BTW, Are you building the signal scope for an oscilloscope or something or is it just a game?


Share this post

Link to post
Share on other sites
Thank you very much for your quick answers!!!
In fact until now I rendered the grid and the signal scope at every plot.
I though about cleaning only the foreground (the signal scope) by using
a big rectangle filled with the background color, or things like this,
but I have also to achive the speed requirements needed by a real-time
application, so I need to find a solution which require less rendering time.
I think that plotting the grid with a display list and plot vertices with
glVertex2f() would be the fastest solution, isn't it?

For RichardoX: Yes, I am working on an application that works like an oscilloscope
but the instention is to use it also as spectrum analyzer (like the WinAmp
spectrum of a sound signal). But I have to admit that programming OpenGl is very
interesting and amusing . . . like a game!

Share this post

Link to post
Share on other sites
Hello again,

after several investigations and internet searches about cleaning at a specific
z value I found different options:

1- Stencil buffer
2- Overlay planes
3- glEnable(GL_COLOR_LOGIC_OP) end glLogicOp(GL_XOR)

I personally use third option to create a rubber band which allow me to render
a rectangle when mouse move without repaint the entire scene. In fact using
twice the XOR operator is possible to restore the initial background.
But if I apply the same mechanism to signal scope the effect is not good when
rapid variations occurs.

What about the first two options? Stencil buffer can be an option but I think
it will put the grid in the foreground instead of the background.

I didn't found enough informations on Overlay planes which I think is not an
openGL specification but a window system (X11, win32) characteristics. And is
not available on GLUT.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!