PDA

View Full Version : Very Basic- Making objects Opaque.



shadowfax
10-08-2010, 01:09 PM
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.

Alfonse Reinheart
10-08-2010, 01:44 PM
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 (http://www.arcsynthesis.org/gltut/Positioning/Tut05%20Overlap%20and%20Depth%20Buffering.html) and not worry about it.

strattonbrazil
10-09-2010, 09:22 AM
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?

mhagain
10-09-2010, 02:46 PM
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.

BionicBytes
10-09-2010, 03:36 PM
You need to disable blending with gldisable (gl-blend)

shadowfax
10-11-2010, 02:10 AM
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)
{
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.0f, 1.0f);
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor (1.0, 1.0, 1.0, 1.0);
glClearDepth(0.0);
glShadeModel (GL_FLAT);
glColor3f(1.0,1.0,1.0);
}

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

Alfonse Reinheart
10-11-2010, 02:12 AM
Are you sure you have created a depth buffer when you initialized what appears to be some from of GLUT?

shadowfax
10-12-2010, 09:45 PM
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.