PDA

View Full Version : background image as opposed to clear color



dhuffman
04-11-2003, 08:41 AM
I'm working on a weather radar display project that received real-time data from a radar signal processor and displays the data. Currently I set up my modelview/projection matrices clear the buffers, and render a map of the area of interest with the stencil buffer set up in such a way that when I draw the live data the map is not obscurred by the live data (standard stuff so far.) Rather than simply having the background color be the clear color, I would like an image (jpeg, bmp, etc.) as the background, with the map (and it's stencil operations) on top of it. Bear in mind that this is a real time app and the data is continuously being drawn over the stenciled map, so I can't simply rerender the scene in the back buffer. Anybody know of a way using per-pixel logic ops or some other method to create a "clear image" rather than a "clear color"?

jwatte
04-11-2003, 09:34 AM
What's wrong with just re-rendering the entire image every frame? If you can't do that, then here are some other ideas:

After you set up stencil, depth, and color buffers, you could read back all buffers, and then draw them back at the start of each frame, instead of clearing the image.

What is your OS? Does it support something like pbuffers? If so, render background into one pbuffer, copy to texture, render image to another pbuffer, copy to texture, and then composite into frame buffer.

If the map data is supposed to punch over the real-time data, how about rendering real-time data first, and then the map data?

dhuffman
04-11-2003, 11:44 AM
Sorry, I should have included some details. OS: Windows 2000, graphics accelerator: FireGL 3.

I can't re-render the entire scene every frame because that would entail blowing through about 30 MBytes of data every frame, not to mention the user interface threads, storage threads, etc. I've not found it to be practical.

Keeping in mind that the dataset is constantly changing, each data element called a radial (in case you're not familiar with radar terminology) extends from the location of the radar transmitter radially accross the earth's surface (corrected for earth curvature and other parameters). After much experimentation I've found that the most efficient way to draw the data in real time is to:

1: Clear the buffers (color, depth, stencil).
2: Render the map at the current viewpoint (can be anywhere within a 600 km radius of the radar location) with stencil write value of 1.
3: Redraw the portion of the dataset currently visible at the current viewpoint with stencil value of zero and glStencilFunc of GL_NOTEQUAL.

At this point I can draw each new data packet as it arrives without having to do anything else to the projection/modelview matrices or stencil buffer. When the user changes the viewpoint I simply repeat this process.

My customers have requested that rather than a single background color (black, let's say) they would like a shaded relief background (like a rendered topoquad, but it could be any image). Therefore when new data arrives, as my drawing commands pass through the rendering pipeline if a pixel is determined to revert to the clear color (no data or map in that pixel) rather than lighting it the clear color, can you think of a way to light that pixel to the same color as a corresponding pixel in an offscreen bitmap of the same dimensions as the client area that the onscreen buffers are shown?

Thanks for the reply.

jwatte
04-11-2003, 02:34 PM
How about scissoring the area that is affected by a packet going away or coming back, and re-rendering that rectangle, starting from background, but not rendering the stencil stuff? I e, your loop becomes:

forever
render map with stencil
set stencil test
while not moving viewpoint
receive packet
scissor to old location of packet
render background
render all packets that intersect scissor region
scissor to new location of packet
render new packet

"render all packets that intersect scissor region" needs some simple spatial index to be efficient; hopefully you already have one somewhere.

Of course, a FireGL should support pbuffers just fine, so that's also a possible solution.

The only other thing I can think of is to somehow get alpha in there, and put your background as a texture; use multi-texturing to stuff in background image in environment 0, and packet indication in environment 1, and have the packet indication use alpha to blend between background and packet. However, that still suffers problems if you have two intersecting packets -- you really need to re-render intersecting areas to make it work out right.