Ignore background color when using glReadPixels?

Started by
11 comments, last by BytePtr 12 years ago
It sounds like you are accidentally flipping the buffer between drawing the 'picking' colors, and drawing the actual graphics.
It should work fine the way you are doing it, but the ugly flickering shouldn't be there. Somewhere between the first draw and the second draw, the first draw is showing up on-screen.

It should go something like:

MyDrawFunction()
{
if(...time-to-pick...)
{
DrawPickingBackground();
DrawPickingColors();
ProcessPick();
}

DrawNormalBackground();
DrawNormal();

FlipBuffers(); //Only flipped after a normal draw.
}


I see you have a functon called SwapBuffer(), but are you sure your code is double buffered? Have you tested it to make sure it doesn't just look like it's working?

If you're using the Win32 SwapBuffers() function (which I'm not personally familiar with), did you actually enable double buffering?
The function documentation says:
"[color=#000000]Specifies a device context. [color=#ff0000]*If*[color=#000000] the current pixel format for the window referenced by this device context includes a back buffer, the function exchanges the front and back buffers."
[color=#000000]...
[color=#000000]"If the current pixel format for the window referenced by the device context does not include a back buffer, this call has no effect and the content of the back buffer is undefined when the function returns."
Advertisement
I actually looked for another SwapBuffers(), and haven't found it.
Something is really wrong in my code. Well it works but anyway, i also think that it shouldn't flicker.

I will take a look what's up with my pixelformat.

EDIT: yes, pixelfmt has the PFD_DOUBLEBUFFER included.

Dunno what is wrong with it. I will make some small test app. Something is very wrong there.
I will use your last pseudo code.
OK, another idea i was thinking about is as follows:
Z can only holds values from 0 to 7. So if i do simple logic like:

if(R<=255 & G<=255 & B >7) {
// Ignore All Three Color Values Read
// Because They Are Background Color Values.
}


So basically do not allow user to choose color, which B (blue) is less than or equal to 7.


I think it will work and still it is possible to use a lot more colors than some very limited amount of colors for background.
But somebody's other thoughts on this will also help me.

This topic is closed to new replies.

Advertisement