PDA

View Full Version : Highlight w/o redrawing entire scene



ben
08-08-2000, 07:43 AM
Under Windows, how do you highlight an object in a scene without having to redraw the entire scene? I have used OpenGL to XOR the object on top of itself to highlight the object and then XOR the object again to get it to disappear, but I don't like the results. I was thinking about using layers (with wglCreateLayerContext), but this is unsupported in the generic Windows implementation of OpenGL.

dorbie
08-08-2000, 04:40 PM
Well this depends on how you have encapsulated state when you drew the object in the first place. If you can reproduce the state of the pipeline when you drew the object then you should be able to draw the object in any way you like, (black and yellow striped texture with texgen in EYE_LINEAR space for s&t and GL_REPLACE texenv could look quite striking for example). You can then unhighlight by EXACTLY reproducing the state when you drew the object in the first place, unfortunately this may require a traversal through lot's of transformations lighting and other incremental state changes applied in your graphics engine. On the other hand you may find it very easy to implement if you have state pretty much entirely stored with the object or have a limited set of state you deal with when rendering. Alternatively read framebuffer back to memory around the object pixels and glDrawPixels to unhighlight. The only problem I can see is that when you highlight you may not reproduce all the depth fragments exactly (even if it looks good on your card it won't on others) so you will want to mask the depth buffer, glDepthMask, keep the depth testing enabled though, and draw the highlight, same for when you unhighlight the object.

Relic
08-08-2000, 11:58 PM
XOR may not be hardware accelerated on all implementations.
There is another method which does not use XOR but glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO) which has the same effect of restoring the old values after the second overdraw.
This may not work precisely in dithered highcolor modes.

If you draw only the selected object, you could set the glDepthFunc(GL_EQUAL) to hit exactly the same pixels as before.

Another widely used method is to save the current image and z buffer with the GL_KTX_buffer_region extension functions, clear the depth buffer only, draw the selected object on top of the image. Restore the original buffers from the buffer regions afterwards. There is no need to re-render the complete scene then.

The extension is available on most graphics boards now, because it's used in 3DS MAX.