int main(int argc, char **argv)
{
glutInit(&argc, argv); //initialize glut framework
glutInitWindowSize(640, 480);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); //set up display mode
glutCreateWindow("OpenGL"); //create window
glutDisplayFunc(redraw); //specify redraw function
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, 640/480, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
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);
//glEnable(GL_TEXTURE_2D);
if(!starTexture.loadBMP("star.bmp", false))
MessageBox(NULL,"Error loading star texture!", "ERROR!", MB_OK);
glutMainLoop();
return 0;
}
distortion problem with glut >(
I''ve just tried glut and it''s fairly straightforward to set up a window and everything but when I draw a quad it appears stretched sideways as opposed to being a perfect square..
This is how I set it up:
Change this:
To this:
gluPerspective(45.0f, 640/480, 0.1f, 100.0f);
To this:
gluPerspective(45.0, 640.0/480.0, 0.1, 100.0);
quote:Original post by Null and Void
Change this:gluPerspective(45.0f, 640/480, 0.1f, 100.0f);
To this:gluPerspective(45.0, 640.0/480.0, 0.1, 100.0);
:O thanks, why does it make a difference though?
quote:Original post by Kyo
O thanks, why does it make a difference though?
''640'' and ''480'' are integers. When you divide an integer by an integer the result is an integer, which cannot store floating point data so it is truncated. The answer to 640/480 is 1.333333, which is truncated to 1. If we use ''640.0'' and ''480.0'' (they are doubles because of the ''.0'' suffix; doubles can store floating point data) the answer isn''t truncated so the aspect ratio is correct.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement