Jump to content
  • Advertisement
Sign in to follow this  
run_g

OpenGL distorted square

This topic is 4163 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

Hello, I am developing an OpenGL application that requires very high precision. Below is a relevant extract of my code. As you can see in the GL_QUADS function i should have a square, but the output is a rectangle. I have tried all modifications i can think of, but the width always comes much longer than the height Unfortunately this site doesn't allow direct insertion of images otherwise i would have let you see how much longer the width is than the height. Does anyone know how i can fix this problem? Thanks
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

glutSwapBuffers(); 

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

//                          fovy,      aspect,     near,       far
gluPerspective(   60.0,      1,              0.01,        1000000000.0);

glViewport( 0,  0,  600,  600  );

gluLookAt  (   0,      0,     0,       //camera
		0,    10,      0,     //center of screen
                        0,    1,      0  );   //up vector
……..
……..
……..
glBegin( GL_QUADS );
	glVertex3f( 0, 0, 0 );
	glVertex3f( 5, 0, 0 );
	glVertex3f( 5, 5, 0 );
	glVertex3f( 0, 5, 0 );
glEnd( );
glFlush( );






[Edited by - run_g on July 2, 2007 10:22:23 AM]

Share this post


Link to post
Share on other sites
Advertisement
I don't expect this to fix the problem, but...

You're quad extends from <0,0,0> to <5,5,0>, on the plane formed by the x and y axes. You're looking at it from <0,0,0>--the camera is located at the exact point of the "bottom left" corner of the quad. Try moving the camera back to <0,,0, 5> or something.

Also, did you call glMatrixMode(GL_MODELVIEW) before drawing the quad? I'm assuming yes.

Also, lower your far clipping-plane value. That's much too large for what you're doing. You just need something bigger than 10.0 or 15.0 for this particular scene.

Share this post


Link to post
Share on other sites
gluPerspective( 60.0, 1, 0.01, 1000000000.0);

Try:

gluPerspective( 45.0, 1, 0.01, 1000000000.0);

Also, replace your glFlush with the glutSwapBuffers() and delete the glutSwapBuffers. Also, when you render you want to be in the modelview matrix, not the projection matrix.

Put this in your init function:

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(45,width/height,0.4f,1000000.0f);
glMatrixMode(GL_MODELVIEW);

And in your draw function it should look like:


void render()
{

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt ( 0, 0, 0, //camera
0, 10, 0, //center of screen
0, 1, 0 ); //up vector

glBegin( GL_QUADS );
glVertex3f( 0, 0, 0 );
glVertex3f( 5, 0, 0 );
glVertex3f( 5, 5, 0 );
glVertex3f( 0, 5, 0 );
glEnd( );

glutSwapBuffers();

}

Share this post


Link to post
Share on other sites
this will have clipping problems
0.01, 1000000000.0

use 2 depth buffers

eg
0.01 1000 (draw near stuff) + 500 100000000 (draw far stuff)

Share this post


Link to post
Share on other sites
I'm surprised you see anything at all. Your call to gluLookAt is bad... the up vector can't be parallel to the vector from eye to center. And if what you really wanted was to be looking down the positive y-axis from the origin, since your quad is in the z=0 plane, you'd be looking edge-on at the quad (from one corner towards the other in the same plane) which is probably not what you wanted.

Share this post


Link to post
Share on other sites

If you get the idea (if not see the simple code (though with improper coordinates) in my first post), does anyone know why a square should come out as a rectangle, Please as this problem refuses to yeild to any solution so far??

[Edited by - run_g on July 2, 2007 10:03:10 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!