Skip to main content
gamedev.net
🔒 Locked

distorted square

Started by run_g 4 replies 900+ views
Original Post
run_g
run_g
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]
smitty1276
smitty1276
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.
xerodsm
xerodsm
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 vectorglBegin( GL_QUADS );	glVertex3f( 0, 0, 0 );	glVertex3f( 5, 0, 0 );	glVertex3f( 5, 5, 0 );	glVertex3f( 0, 5, 0 );glEnd( );glutSwapBuffers();}
zedz
zedz
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)

Kalidor
Kalidor
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.
run_g
run_g

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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.