Results 1 to 4 of 4

Thread: gluLookAt doesn't work

  1. #1
    Member Newbie
    Join Date
    Jan 2009
    Posts
    47

    gluLookAt doesn't work

    Can you please check my codes? Why it doesn't work?

    Init()
    Code :
    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				glClearDepth(1.0f);										glEnable(GL_DEPTH_TEST);							
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glViewport(0,0,800,600);
    glMatrixMode(GL_PROJECTION);							glLoadIdentity();									
    gluPerspective(54.0f,(GLfloat)800/(GLfloat)600,1.0f,500.0);
    glMatrixMode(GL_MODELVIEW);


    Draw()
    Code :
    gluLookAt (locx, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    videodriver->draw3DTriangle(vector3df(0,0,-5),vector3df(1,1,-4),vector3df(2,0,-5));
    locx++;

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: gluLookAt doesn't work

    Not quite sure what you are trying to achieve and what exactly does not work!
    Have you set gldisable (GL_CULL_FACE) so that both front <u>and</u> back polys are visible?

    Also, you seem to be drawing a triangle at the origin, but the Z value is behind where the camera is looking & positioned. Try changing the triangle to use +ve Z instead and set the camera's eyeposition further away,

    glulookat (x,0,-10 , 0,0,0, 0,1,0)

    Now you should see your trangle infront of the camera, athough you have not specified any colour at each vertex or texture coords?

    This is a bit of an odd thing to do in a draw loop, because you are moving the camera position (possibly 1000+ times a second) away from your object and it may be better to just fix the eyeposition for now.

    glulookat (0,0,-10 , 0,0,0, 0,1,0)

  3. #3
    Member Newbie
    Join Date
    Jan 2009
    Posts
    47

    Re: gluLookAt doesn't work

    I found the problem. The glLoadIdentity(); on draw function is the problem. I changed it to glPushMatrix()/glPopMatrix() so it works correctly now.

    This is a bit of an odd thing to do in a draw loop, because you are moving the camera position (possibly 1000+ times a second) away from your object and it may be better to just fix the eyeposition for now.
    What do you it's a bit of an odd thing to do it in a draw loop? Is it bad to do gluLookAt(); in draw function? What if I want to use it as a player's camera. So I have a variable for each. like the code below I found on a book. It is called in the draw function.

    Code :
    gluLookAt(m_whiteViewPos.x, m_whiteViewPos.y, m_whiteViewPos.z, 4.0, 0.0, 4.0, 0.0, 1.0, 0.0);

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: gluLookAt doesn't work

    It is up to you, gluLookAt just affects the current active matrix stack. You are not forced to call this function each frame as long as the modelview matrix is not set to identity. You can save camera matrix state with glPush/glPop calls as you seem to do.

Similar Threads

  1. Change eye position of gluLookAt() doesn't work
    By jiaoyang_28 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-15-2012, 03:21 PM
  2. How does gluLookAt() work with gluPerspective()?
    By myst_iori in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-08-2011, 01:25 PM
  3. gluLookAt, can you work out how much it sees?
    By Andrew Davey in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 04-29-2004, 06:19 PM
  4. Does gluLookAt work with gluOrtho2D
    By yablo0 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-30-2003, 08:40 AM
  5. gluLookAt - does it work? (or am i too stupid :-)
    By Schleppi in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-23-2001, 12:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean