PDA

View Full Version : How to change the "camera" position in OpenGL - Mac OSX



openglbeginner123
07-01-2014, 05:28 PM
Hey guys,

I am quite new to OpenGL but I am trying to figure out how to draw things in 3D. I am trying to write a simple program in Xcode for Mac OSX which uses OpenGL library and the NSOpenGLView class to draw OpenGL graphics. I want to figure out how to change the position of the "camera" so the object can be viewed from top, bottom, right, left, at an angle, etc. The thing that is not working for me is the glLookAt() method. Apparently it was deprecated and now I have to use GLKMatrix4MakeLookAt(); The big problem though, is that this method appears to do nothing.

this is my method do do the basic drawing and change the position of the camera - am i doing something wrong?

-(void) display
{

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);


glLoadIdentity ();

GLKMatrix4MakeLookAt(10, 10, 10, 0.0, 0.0, 0.0, 0.5, 1.0, 0.0);

glPushMatrix();

// draw the cube

glPopMatrix();
}

Any advice? Any help is hugely appreciated as well as any additional approaches to manipulating perspectives or rotating stuff in OpenGL or code examples of how to do this


Thanks a lot for any feedback you guys might give.

Ed Daenar
07-01-2014, 06:07 PM
GLKMatrix4MakeLookAt, according to a fast check on google, returns a GLKMatrix4. It doesn't call any gl code. https://developer.apple.com/library/ios/documentation/GLkit/Reference/GLKMatrix4/Reference/reference.html#//apple_ref/c/func/GLKMatrix4MakeLookAt

So you are creating a matrix which you are not loading up anywhere. This is assuming you have the rest of your rendering setup correct and many other things not shown in your code.

Quite honestly, you likely won't enjoy hearing this, but you should probably put on your training wheels and grab a book on the subject because it's not only OpenGL what you'll have to learn and understand to actually "draw things in 3D". The OpenGL Superbible 6th Ed. is probably a good start, but I'm sure there's many other choices.

openglbeginner123
07-02-2014, 07:19 PM
Thank you for suggestions. can you or someone explain how to "load it up" (the matrix) if thats not too much trouble because I understand and know matrix mathematics, more generally linear algebra, but I can't really understand the syntax and what to do as far as transferring the math and matrices to code.