PDA

View Full Version : whats wrong with this code?



jesh
02-28-2003, 03:09 AM
this is a very simple program that draws a cube with the perspective projection. but i 'am not able to get any display.


void display(void)
{
glClea(GL_COLOR_BUFFER_BIT); glLoadIdentity();
gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
glutWireCube(2.0);
}


void keyboard(unsigned char key,int x,int y)
{
if(key == 27)
exit(0);
}

void reshape(int w, int h)
{

glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,(GLfloat)w/(GLfloat)h,1.0,100);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("perspective view");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);

glutMainLoop();
return 0;
}

roffe
02-28-2003, 03:22 AM
You are missing a glFlush/glFinish in your display routine.

These calls tell OpenGL to flush queued commands(glFlush) or wait/block until all commands are completed(glFinish).

Gavin
02-28-2003, 06:20 AM
where is your

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

???
I assume glClea is a typo

jebus
02-28-2003, 07:05 AM
call glutSwapBuffers() after you draw everything

jebus

Mihail121
03-01-2003, 05:04 AM
There are several wrong things with your code.First of all no glutDisplayMode is called.Just type glutDisplayMode(GLUT_RGBA | GLUT_DOUBLEBUFFER); after glutInit();Now the only thing that you must do is to call glutSwapBuffer(); each frame.The next error is pure logical.You are putting the camera 5 units forward and you are drawing the cube from -2 to 2.You cannot see it cause it's far behind your back.Change the third parameter of LookAt with -5.That's all