gluPerspective vs. GLKMatrix4MakePerspective use in OSX OpenGL

Hello,

I am programming a Mac OSX application in Xcode and I am running into some problems with the GL functions. I need to use the gluPerspective function to do some set up but apparently its is deprecated for osx. Xcode suggests using GLKMatrix4MakePerspective function as a substitute but even after researching the documentation I can’t figure out how to use it. :confused:
Here is a part of my code:

glLoadIdentity();
gluPerspective(30f,[self bounds].size.width/(GLfloat)[self bounds].size.width,1.0f,1000.0f);
glEnable(GL_DEPTH_TEST);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);

And again, the gluPerspective is deprecated so I can’t get the result i am looking for.

If anyone who is good at this could explain it to me how to use the new function as a substitute I would be very grateful.

Thanks in advance for any feedback.

The fact gluPerspective is deprecated shouldn’t affect your ability to use it. It looks like you have a typo for your aspect ratio–you are dividing width by width, and not width by height. If you fix that it should work.

gluPerspective creates a perspective projection matrix and then multiplies it onto the current selected matrix stack, while GLKMatrix4MakePerspective creates a matrix and returns it.

You can accomplish the same effect by doing something like:


glMatrixMode( GL_PROJECTION ); // select our projection matrix
glLoadIdentity();
glMultMatrix( GLKMatrix4MakePerspective(30f,[self bounds].size.width/(GLfloat)[self bounds].size.height,1.0f,1000.0f ).m ); // << .m is the GLfloat* you are accessing
glEnable(GL_DEPTH_TEST);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
//...etc... for model drawing
glMatrixMode( GL_MODELVIEW );
//...drawing, etc.

Thanks a lot. I appreciate the explanation.