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 7 of 7

Thread: GluLookAt

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2001
    Posts
    5

    GluLookAt

    Can someone tell me whats wrong here... When ever i run this I always get a black screen... Im prety sure its with glulookat function...


    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
    {
    if (height==0)
    {
    height=1; }

    glViewport(0,0,width,height);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,-10,0,0,0,0,1,0);

    }

    int Draw

    {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity(); glTranslatef(12.0f,0.0f,-24.0f);
    glColor3f(0.5f,0.5f,1.0f);
    glBegin(GL_QUADS); glVertex3f( 1.0f, 2.0f, 0.0f); glVertex3f( 1.0f,-2.0f, 0.0f); glVertex3f(-.05f,-2.0f, 0.0f); glVertex3f(-.05f, 2.0f, 0.0f);
    }


    this isnt the entire code but if you could give a look at how i use the gluLookAt and drawing. The code will display an object without the gluLookAt

  2. #2
    Intern Contributor
    Join Date
    Jan 2001
    Posts
    55

    Re: GluLookAt

    if you are using orthographic projection then glulookat probably won't work (i had this same problem when i started using GL)

    try putting this (or a variant) in your glResize() function after glViewport(), if you don't have it...

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60, (double) width / height, 1, 4096);
    where width & height are the width & height of your gl window.

    then, in your rendering function:
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(-4, 2, 2, 0, 0, 0, 0, 1, 0);
    then
    glutSolidCube(2.0f); or whatever you are gonna draw

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,755

    Re: GluLookAt

    gluLookAt(0,0,-10,0,0,0,0,1,0);

    Is basically equivalent to

    glTranslate(0, 0, 10);

    You then do...
    glLoadIdentity(); glTranslatef(12.0f,0.0f,-24.0f);

    The loadIdentity is basically going to reset what you set in gluLookAt, so I'm not sure why it would work without the gluLookAt, but won't work with it.

    Try using glPushMatrix, glPopMatrix instead of resetting the matrix every time.

    For instance

    glPushMatrix();
    glTranslatef(12.0f,0.0f,-24.0f);
    // draw your scene
    glPopMatrix();

    You don't show how you setup your projection matrix so I'm not sure if that will keep your object in the scene or not.
    Deiussum
    Software Engineer and OpenGL enthusiast

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: GluLookAt

    Even though you said this is not the entire code, I must ask you about a missing function.

    In the Draw-function, you call glBegin, but I can see no glEnd. All I can see is the end of the Draw-function. Do you have any glEnd at all?

  5. #5
    Intern Contributor
    Join Date
    Nov 2000
    Location
    Thuringia, Germany
    Posts
    86

    Re: GluLookAt

    I had the same problem. It was because the objects wheren't in the cam-range. try something like

    int t=0;

    void draw()
    {
    //reset....
    t++;
    gluLookAt(10*sin(t/100),10*cos(t/100),0, 0,0,0, 0,1,0);

    this will look throug the scene. it's good to "find" an object

    Bastian.

  6. #6
    Intern Contributor
    Join Date
    Jan 2001
    Posts
    55

    Re: GluLookAt

    also, if you are using gluLookAt to look directly into the up vector that you specify, you will get a blank screen. [another pull-my-hair-out-because-this-should-be-working-but-it-isn't GL nightmare]. but i guess its all part of the experience

  7. #7
    Junior Member Newbie
    Join Date
    Feb 2001
    Location
    Islamabad, FC, Pakistan
    Posts
    6

    Re: GluLookAt

    Yes, you must check the rest of the code. you need to call glEnd(); function and SwapBuffer() since you are using double buffers. Also the object is small in size and placed at (12, 0, -24) and camra at (0, 0, -10) and focused at (0,0,0). This suggest that (1) object is ou of feild-of-vision becasue 12-units translation along x-axis or (2) it is in the scene but since it is very far away from the camer (at a distance of "14"- units along z-axis) so its not visible.
    Also try focussing your camer at the object by passing (12, 0, -24) as the focus point.... If the object is there you'll see it.
    In order to make object more visible uyou can also use glPointSize(); funcion.
    Well...hope any of these things work
    EycEwinD

Posting Permissions

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