Plotting using OpenGL

I have a program that displays data in orthographic mode. I have it optimized so that it will not call glVertex2d if the data is to be plotted on the same pixel. How can I do this in 3D mode? Is there any need to try to limit data points that will map to the same pixel? I have a lot of time history data to plot and the camera can be moved to several positions. It seems I could save some CPU load by not plotting the redundant data points. How can I determine if I will be plotting to the same pixel?

You could use the stencil buffer. Depending on the OS you have there are different methods of enabling the stencil buffer. In Windows you have to modify the PIXELFORMATDESCRIPTOR structure (the cStencilBits member). With GLUT you pass GL_STENCIL to the glutInitDisplayMOde function. See the documentation of glStencilFunc, glStencilOp.

In order to use the stencil buffer you’ll have to enable the stencil test with

glEnable(GL_STENCIL_TEST);

Also be sure to clear the stencil buffer when you need that with glClear(GL_STENCIL_BUFFER_BIT) (or add that bit to the other clearing bits you have)

I think you’ll need something like

glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);

and

glStencilFunc(GL_EQUAL, 0, 1);

Maybe this will help.

I do not think stencil buffers are what I am
looking for. I just want to test to see if a plotted data point is in the same pixal as the previaous point and not call the line plot function. How do I resolve the pixal that a point will be plotted to?

On hardware that supports it, you can use occlusion queries. It might be too ineffective for your case though. It is usually used to render bounding volumes and check if some of it passed the depth test.

How do I resolve the pixal that a point will be plotted to?

That is probably not as easy as you might think. You would have to transform and rasterize that point yourself to find the exact window coordinates. Depending on point size, OpenGL might rasterize points to several pixels which makes this hard. If you can, just turn on depth testing and render all points with some gross culling. If your data is somewhat static, put it in a display list. That will save cpu work.