Image inversion

Hello,
I’ve written an application in Visual C++ 6.0 using opengl support for displaying the image of an object. On execution the image is displayed without any problem. However, every time I open another window while the image is still on screen(eg opening the dialog box), the image is redrawn in a weird manner; it seems that the colours are inverted. Can anyone explain what is happening? How can I prevent the image from being redrawn after I open another window?
Thanks a lot.

Are you using a blend function in your code?
maybe post how you have setup the texture.

Originally posted by rosh:
Hello,
I’ve written an application in Visual C++ 6.0 using opengl support for displaying the image of an object. On execution the image is displayed without any problem. However, every time I open another window while the image is still on screen(eg opening the dialog box), the image is redrawn in a weird manner; it seems that the colours are inverted. Can anyone explain what is happening? How can I prevent the image from being redrawn after I open another window?
Thanks a lot.

You can’t prevent redrawing the window. When a window gets obscured by others, it looses a part of its contents. When you move that window into view, they must be redrawn again. Before coding GL, you should probably study the Windows API first.

When you say “the image of an object”, what do you mean? Is is a 2-d pixelmap or a 3-d object? Is the whole thing redrawn wrong, or just part of it (like the part that was obscured)? If you minimize the window and then restore it (forcing a total redraw) does it appear correctly? Is the image really inverted, or are the colors shifted (e.g., red becomes green, green becomes blue, etc.)?

Thanks for the response.I’ll explain in more details. The image I’m talking about is that of a textile fabric. The model is in 3D and I’ve used GL_ORTHO to project on the screen. I’ve also used GL_DEPTH in the program. The fabric’s design is input from a dialog box. OnOK from the dialog box, the dialog box is removed and the fabric’s image is displayed in a window. However with that window still on the screen, if I call the dialog box again, respecify the input(same input as previous od different, doen’t matter), the image is drawn in a weird manner. It seems then to be drawing the reverse of the fabric. It’s not actually colour inversion. On the other hand if I reexecute the program and then respecify the input, the image is drawn correctly.

I don’t really know what the problem is. It sounds like it could be a window system issue, or it could just be a bug in your code. Are you running this in 256-color mode? Maybe the dialog box is messing with the palette. I would try to make the dialog box only appear outside of the rendering window to see if it still messes up the color. If this isn’t it and it’s not the palette thing, then I would suspect bugs in your code.

What happens when you call your drawing code twice in a row?

Ie after accepting user input, don’t call the drawing code once, call it twice. If you get the same error, your drawing code relies on some OpenGL state being set to default values, but it got fudged somewhere.

Don’t rely on default values. OpenGL doesn’t return to a clean state just because you call glClear. You may have messed with your matrices or you may have enabled blending or something and your drawing routine relies on blending being disabled when it gets called.

That kind of stuff.