Very Basic- Making objects Opaque.

Hi I am new to opengl and I am writing code to draw cubes/boxes. But what I am drawing is transparent by default. I am able to see what is behind my boxes. Please somebody tell me how to turn off this and draw opaque solid objects. I guess I might be missing something very basic.

But what I am drawing is transparent by default. I am able to see what is behind my boxes.

That doesn’t mean that you’re drawing tings “transparently”. OpenGL draws everything exactly as you tell it, in the order that you tell it to draw them. OpenGL does not understand the concept of boxes, objects, or anything else. It just draws triangles.

Therefore, if you want to make sure that objects behind other objects are not seen, you must either render the objects in order from the farthest to the nearest. Or you can just use depth buffering and not worry about it.

What are you using as a windowing system? Transparency isn’t usually on. If you specify an alpha value of 1 like glColor(1,0,0,1), is it still transparent? Are you using shaders?

Basic things to check: make sure that you’ve requested a depth buffer at startup (how to do this depends on your OS), make sure that you’ve got a glEnable (GL_DEPTH_TEST), make sure that your glDepthFunc and glDepthRange are set, and make sure that you’re glClear’ing GL_DEPTH_BUFFER_BIT at the start of each frame.

You need to disable blending with gldisable (gl-blend)

Hi all, thanks alot for your help, my code work perfectly on windows, however strange thing is that on linux , opaque thing is not working. I have used following code for initial set up:

void init(void)
glDepthRange(0.0f, 1.0f);
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClearColor (1.0, 1.0, 1.0, 1.0);
glShadeModel (GL_FLAT);

is there any different arrangements need to be done in case of linux? I am using fedora 12 and compiling through terminal with makefile.

Are you sure you have created a depth buffer when you initialized what appears to be some from of GLUT?

Hi, problem solved, in linux the order in which we invoke these functions is important. Not the case with windows.

Thanks again for the help, guyz.