Jump to content
  • Advertisement
Sign in to follow this  
assainator

OpenGL OpenGL perspective problem

This topic is 2355 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 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?

perspectiveproblem.jpg

Thanks in advance.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
your projection matrix is not properly set for your rendering viewport

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

Share this post


Link to post
Share on other sites
I'm using OGL 2.0.

My code is:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0, Resolution.x, Resolution.y);
gluPerspective(90, (Resolution.x / Resolution.y), 1.0f, 5000.0f);
glMatrixMode(GL_MODELVIEW);

Share this post


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

[size=1]*: Unless height is greater than width, of course.

Share this post


Link to post
Share on other sites

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.

[size=1]*: 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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!