Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glm::perspective vs gluPerspective

I'm replacing my use of glu methods in my project with glm and I seem to have run into an odd difference that I cannot explain. When I was using this code to set the projection matrix using gluPerspective, I get this displayed:

gluPerspective version

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0f, (GLfloat)w / (GLfloat)h, 0.0001f, 1000.0f);

If I switch to glm::perspective, I get this:

glm::perspective version

glMatrixMode(GL_PROJECTION);
glm::mat4 projectionMatrix = glm::perspective(70.0f, (GLfloat)w / (GLfloat)h, 0.0001f, 1000.0f);
glLoadMatrixf(&projectionMatrix[0][0]);

It's pretty clear that the object I'm rendering is taking up more of the display now with the glm version. There are no other changes in the two versions besides swapping out gluPerspective for glm::perspective.

I'm guessing that I'm probably doing something wrong, because my understanding is that glm::perspective should be a drop in replacement for gluPerspective. But I don't know exactly what that is at this point.

Also, the difference in orientation is because the object is being rotated in the scene. I just ended up taking a screenshot at different times in the animation.

like image 981
Dennis Munsie Avatar asked Jul 15 '15 22:07

Dennis Munsie


Video Answer


1 Answers

glm nowadays uses radians by default, while gluPerspective() uses degrees, so you have to use

glm::perspective(glm::radians(70.0f), ...);

to get the same result as gluPerspective(70.0f, ...).

like image 73
derhass Avatar answered Oct 11 '22 22:10

derhass