PDA

View Full Version : problem with glTranslatef



lud2k
09-04-2003, 12:54 AM
hi,

i've just started to progam with opengl and i've a little problem with glTranslatef().
glTranslatef(x,y,z);
when i use x and y it's moving well on right and up but when i try to move with z the TRIANGLE that i've made disappears http://www.opengl.org/discussion_boards/ubb/frown.gif
anyone know why and can help me ?

sorry for my bad english i'm french.
i'm using dev-cpp.
Thanks a lot.

PanzerSchreck
09-04-2003, 01:07 AM
Looks like you're moving your triangle behind your zFar-Plane, where it disappears.
Try setting your zFar-Plane further away via gluPerspective.

lud2k
09-04-2003, 01:26 AM
hum... it's not working http://www.opengl.org/discussion_boards/ubb/frown.gif maybe i've done something wrong. this this a part of my code:
-------------------------------------------
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluPerspective(0.0f,2.0f,0,40.0f);
glTranslatef(0.0f, 0.0f, -0.01f);

glPushMatrix ();
glRotatef (theta, 0.0f, 0.0f, 1.0f);
glBegin (GL_TRIANGLES);
glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.87f, -0.5f);
glColor3f (0.0f, 0.0f, 1.0f); glVertex2f (-0.87f, -0.5f);
glEnd ();
glPopMatrix ();

SwapBuffers (hDC);

theta += 1.0f;
Sleep (1);
-------------------------------------------
anyone can help me ?
thanks a lot

PanzerSchreck
09-04-2003, 03:06 AM
You make a typical mistake : You don't watch your matrices!
Things like gluPerspective have to be put into the (guess what) Projection-Matrix, whereas your drawing-calls go into the Modelview-Matrix.
Your code should look like this :


glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(...);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glBegin(...)

Bob
09-04-2003, 04:07 AM
And another typical mistake; the near clip plane in gluPerspective must be positive.