• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# OpenGL perspective problem

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1assainator  Members

Posted 31 January 2012 - 12:32 PM

Hello all,

I'm working on a OpenGL project but I'm having troubles with the perspective. The meshes appear to be scaled up on the x-axis.
In the image below, you can see a sphere that is supposed to be, well, a sphere, round. Obviously it's not. What causes this behavior?

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

### #2Brother Bob  Moderators

Posted 31 January 2012 - 12:41 PM

Likely an incorrect aspect ratio. That is, your projection assumes the width and the height of the window are the same, but in reality the window is wider, and so the image looks stretched.

### #3themean  Members

Posted 31 January 2012 - 12:42 PM

which opengl you use
if you use 2.1 may be i can help
i think your window is stretched and you dont calculate this

### #4SaTANO  Members

Posted 31 January 2012 - 12:46 PM

check glViewPort(x,y,width,height) for aspect ratio (you are probably not rendering 1:1)
than set/create projection matrix for correct values

### #5assainator  Members

Posted 31 January 2012 - 12:56 PM

I'm using OGL 2.0.

My code is:
glMatrixMode(GL_PROJECTION);
glViewport(0,0, Resolution.x, Resolution.y);
gluPerspective(90, (Resolution.x / Resolution.y), 1.0f, 5000.0f);
glMatrixMode(GL_MODELVIEW);

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

### #6mhagain  Members

Posted 31 January 2012 - 01:27 PM

Are resolution.x and resolution.y ints? If so you'll always* get an aspect of 1 when you divide them. Cast them to floats instead.

*: Unless height is greater than width, of course.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #7assainator  Members

Posted 31 January 2012 - 02:50 PM

Are resolution.x and resolution.y ints? If so you'll always* get an aspect of 1 when you divide them. Cast them to floats instead.

*: Unless height is greater than width, of course.

Sometimes I just do not understand how I don't notice that kind of simple problems....

That, off course, fixed the problem.
"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

### #8NickWiggill  Members

Posted 07 July 2012 - 09:01 PM

Haha, this just helped me out too. Thanks mhagain.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.