Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: problem with glTranslatef

  1. #1
    Intern Newbie
    Join Date
    Oct 2004
    Posts
    30

    problem with glTranslatef

    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
    anyone know why and can help me ?

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

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2003
    Location
    Germany
    Posts
    232

    Re: problem with glTranslatef

    Looks like you're moving your triangle behind your zFar-Plane, where it disappears.
    Try setting your zFar-Plane further away via gluPerspective.

  3. #3
    Intern Newbie
    Join Date
    Oct 2004
    Posts
    30

    Re: problem with glTranslatef

    hum... it's not working 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

  4. #4
    Junior Member Regular Contributor
    Join Date
    May 2003
    Location
    Germany
    Posts
    232

    Re: problem with glTranslatef

    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 :
    Code :
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity;
    gluPerspective(...);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity;
    glBegin(...)

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: problem with glTranslatef

    And another typical mistake; the near clip plane in gluPerspective must be positive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •