Results 1 to 4 of 4

Thread: gluLookAt and gluPerpective problem

  1. #1
    Member Contributor
    Join Date
    Mar 2002
    Location
    CA,USA
    Posts
    57

    gluLookAt and gluPerpective problem

    Hi,
    I am learning OpenGL.
    I have written following code in (MFC)Vc++...

    void CSim_4_26_02View::draw3dobject()
    {
    glClear ( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ) ;

    glColor3f ( 1.0f, 1.0f, 1.0f ) ;

    glBegin ( GL_LINES);
    glVertex3f(0.0f,0.5f,0.0f);
    glVertex3f(0.5f,0.5f,0.0f);


    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(1.0f,1.0f,0.0f);

    glVertex3f(-0.5f,-0.5f,0.0f);
    glVertex3f(-0.75f,-0.75f,0.0f);

    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(-1.0f,-1.0f,0.0f);


    glEnd();
    glFlush();
    }
    When I run the program i am able to see line ..
    But when I add commands like gluLookAt or gluPerepective in the code...I am not able to see any thing....what can be the problem...

    void CSim_4_26_02View::OnSize(UINT nType, int cx, int cy)
    {
    CView::OnSize(nType, cx, cy);

    // TODO: Add your message handler code here

    glViewport(0,0,cx,cy);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluPerspective(90.0,1.0,1.0,10.0);
    // gluLookAt(0,0,3,0,0,0,0,1,0);
    //glFrustum ( -5.0, 5.0, -5.0, 5.0, -2.0, 7.0 ) ;
    draw3dobject();
    }

    Can anybody tell me what I am doing wrong...
    Thanks in advance
    aus

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: gluLookAt and gluPerpective problem

    With gluPerspective(90.0,1.0,1.0,10.0) you have your far/near area set from 1 to 10 on the z-axis, anything before 1 is not rendered. You are drawing your object at z = 0, so your object will not be drawn. Translate your object to something above 1 on the z axis.




    Originally posted by aus79er:
    Hi,
    I am learning OpenGL.
    I have written following code in (MFC)Vc++...

    void CSim_4_26_02View::draw3dobject()
    {
    glClear ( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ) ;

    glColor3f ( 1.0f, 1.0f, 1.0f ) ;

    glBegin ( GL_LINES);
    glVertex3f(0.0f,0.5f,0.0f);
    glVertex3f(0.5f,0.5f,0.0f);


    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(1.0f,1.0f,0.0f);

    glVertex3f(-0.5f,-0.5f,0.0f);
    glVertex3f(-0.75f,-0.75f,0.0f);

    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(-1.0f,-1.0f,0.0f);


    glEnd();
    glFlush();
    }
    When I run the program i am able to see line ..
    But when I add commands like gluLookAt or gluPerepective in the code...I am not able to see any thing....what can be the problem...

    void CSim_4_26_02View::OnSize(UINT nType, int cx, int cy)
    {
    CView::OnSize(nType, cx, cy);

    // TODO: Add your message handler code here

    glViewport(0,0,cx,cy);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluPerspective(90.0,1.0,1.0,10.0);
    // gluLookAt(0,0,3,0,0,0,0,1,0);
    //glFrustum ( -5.0, 5.0, -5.0, 5.0, -2.0, 7.0 ) ;
    draw3dobject();
    }

    Can anybody tell me what I am doing wrong...
    Thanks in advance
    aus


    [This message has been edited by nexusone (edited 05-15-2002).]

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: gluLookAt and gluPerpective problem

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluPerspective(90.0,1.0,1.0,10.0);
    // gluLookAt(0,0,3,0,0,0,0,1,0);
    //glFrustum ( -5.0, 5.0, -5.0, 5.0, -2.0, 7.0 ) ;
    gluPerspective and glFrustum should go in the projection matrix, no the modelview. It may seems to work at first, but you will at some point have problems related to this.

    And the glFrustum call is not correct. The near planes are not allowed to be less than or equal to zero.

    You can change your gluPerspective to this gluPerspective(90.0,1.0,0.0,10.0)
    No you can't. Same rule (read above) for gluPerspective as for glFrustum.

    [This message has been edited by Bob (edited 05-15-2002).]

  4. #4
    Member Contributor
    Join Date
    Jul 2001
    Location
    Sherbrooke
    Posts
    95

    Re: gluLookAt and gluPerpective problem

    As said in the red book zNear must never be set to 0
    Let's have a funny day

Similar Threads

  1. gluperpective not working
    By the_hunter in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 09-28-2013, 09:01 AM
  2. Problem with gluLookAt
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-13-2006, 04:55 PM
  3. Problem with gluLookAt
    By wazoo in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 09-24-2004, 06:42 PM
  4. Problem with gluLookAt
    By djavan in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-04-2003, 08:18 AM
  5. gluLookAt PROBLEM!
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-04-2000, 09:05 AM

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