5
votes

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.

1
Note that there's not too much of a point in using glm if you're still using the deprecated matrix functions anyway. You should be using shader uniforms. In any case, check how glm stores its matrices whether they are stored row-major or column-major, and see if that matches glLoadMatrixf - Colonel Thirty Two
I'm also planning to switch away from the deprecated matrix functions as well, but was just starting to replace deprecated functionality with glm when I ran into this problem. I also need to remove my use of glut as well. As far as the order goes, glm is supposed to match up to what GL uses, since it would be a bit tough to use otherwise. The glLoadMatrix call was taken from their documentation as well. - Dennis Munsie

1 Answers

9
votes

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, ...).