Beginner (depth test)

Started by
5 comments, last by Kwak 18 years, 4 months ago
I've been reading Dave Astles book and maybe im jumping ahead, but heres the question. Im using the following code and I dont know what specific gl function(s) i need. //move into the screen glTranslate(0,0,.1); Eventually the screen goes blank (I'm guessing because it is out of depth view). I have tried these functions and nothing happens. Thanks for any help. glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Advertisement



Do you call glLoadIdentity everyframe on your model view matrix, or do you just accumulate transforms until your object moves off the screen?

Try adding glLoadIdentity(); to your draw code and see if your object just stays put.

The other functions you have mentioned are usualy used at startup. You havn't provided very much information so you can't expect much help. So..

What are you trying to acheive?

How exactly is it NOT doing what you want?

Post more code.
Ok i made a new project and heres the code:

//ALL OPENGL ANIMATION GOES HERE

glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);

glTranslatef(0,0,-.1);

glBegin(GL_LINES);
glVertex3f(0,0,0);
glVertex3f(0,1,0);
glEnd();

SwapBuffers(hDC);

so every loop I make the lines translate into the screen by .1. But after so many loops, I'm assuming when the line becomes (0,0,1)....the line disappears. Do i need glViewport() in order to set depth to the scene?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

If you call glTranslate in each loop your objects will eventually move out of your view. To reset view each frame to the origin you have to load identity matrix to modelview matrix at the beginning of each frame.

glMatrixMode(GL_MODELVIEW);glLoadIdentity();


You don't need to cal glMatrixMode if you do not change matrix mode during the frame.
You have a view volume. Everything you might draw is not visible, just the parts within the view volume. The view volume is defined by six planes, i.e. near, far, left, right, top and bottom. Anything to the left of the left plane is to the left of the viewport and isn't visible. The same applies to the near and far plane even though some of those objects might be within the viewport.
Keys to success: Ability, ambition and opportunity.
I understand the concept of draw distance and draw start...but how do I set it up? What function(s)? thanks.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

//init    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);						    glClearDepth(1.0f);								    glEnable(GL.GL_DEPTH_TEST);							    glDepthFunc(GL.GL_LEQUAL);    glHint(GL.GLPERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);			    glMatrixMode(GL.GL_PROJECTION);    glLoadIdentity();    gluPerspective(60.0f, 300.0f/300.0f, 0.1f, 100.0f);    // or ortho mode//-------------------------------------------------------------//draw    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);    gl.glMatrixMode(gl.GL_MODELVIEW);    gl.glLoadIdentity();    // !!!!!!!    //move into the screen    glTranslate(0,0,.1);     glBegin(GL_LINES);    glVertex3f(0,0,0);    glVertex3f(0,1,0);    glEnd();


the gl.glLoadIdentity(); must be done every time you draw the line.
It basicly sets your camera back at the origin.
If you dont do so, the box will be drawn a little (0.1) further every time you do the drawing code.

(so i'm actually saying the exact same thing as b2b3)

This topic is closed to new replies.

Advertisement