Rubberband selection?

Started by
3 comments, last by mohitsinghal 16 years, 8 months ago
I have a OpenGL routine that renders a rubberband rectangle, while I drag the cursor: glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_XOR); However, the problem with this, is that I don't want the color of the background to be XORed: glClearColor( background.r, background.g, background.b ); So, how would I draw a rubberband rectangle while ignoring (err...preserving) the color of the background? I only want the foreground elements to be XORed. [Edited by - JakeM on July 10, 2007 6:58:12 PM]
Advertisement
If you want per pixel control over what is XORed or not, look into a per pixel rasterization decision mechanism. For example, depth test or stencil buffer.

Using the stencil buffer, set the stencil clear value to zero and stencil function to write one where you draw an object. When drawing the rectangle, draw it first without XOR where the stencil test succeeds agains zero, and then draw it with XOR where the stencil test succeeds against one.

Depth buffer can be used in a similar way. If you clear the depth buffer with 1.0, draw without XOR where the depth is equal to 1.0. That means you have to draw the rectangle on the far clipping plane so fragments are rasterized with maximum depth value. Then draw with XOR and depth test seto to not equal, or less, or something else that passes for anything not 1.0.
Thanks,
Using the depth buffer is probably best way for me.

Are you saying the pixels drawn by glClearColor() can be depth tested
or when I'm drawing the foreground elements?

Rendering each frame is usually set to this:
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

How would this change when drawing the foreground elements?
And then it would change again when drawing the rubberband rectangle?

Not quite sure I understand when drawing the rectangle, since these all of
these pixels will always be drawn.
If you clear the buffers, you have a framebuffer filled with color specified by glClearColor and depth specified by glClearDepth (1.0 by default). If you draw anything, somewhere, the depth buffer is changed. If, after drawing everything, the depth buffer contains 1.0, it must be the background, becuase you haven't drawn anything there.
is there a way to doing same means rubberband drawing in directx

This topic is closed to new replies.

Advertisement