Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


distortion problem with glut >(

This topic is 5743 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
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);


	gluPerspective(45.0f, 640/480, 0.1f, 100.0f);


	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);

	if(!starTexture.loadBMP("star.bmp", false)) 
		MessageBox(NULL,"Error loading star texture!", "ERROR!", MB_OK);


	return 0;

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!