PDA

View Full Version : gluLookAt and gluPerpective problem



aus79er
05-14-2002, 11:15 AM
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

nexusone
05-14-2002, 11:39 AM
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.

http://www.opengl.org/discussion_boards/ubb/smile.gif



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).]

Bob
05-15-2002, 12:38 AM
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).]

Evil-Dog
05-15-2002, 05:31 AM
As said in the red book zNear must never be set to 0