Page 1 of 1

Quick(hopefully) question.

Posted: Fri Aug 07, 2009 9:57 pm
by ibly31
Is there the concept of a camera in OpenGL? A camera as in a specific point in space, looking in a direction, and that is what is rendered, basically like an eye. I have made games in SDL, in which there is no concept of a camera(I think) and I had to make all my images display on a specific offset, and display only what would be visible in the view of my screen. But that would be very hard/confusing to do in OpenGL ES for the iPhone, so... I was wondering, how to go about doing this.

My game is 2D, so the only things I'd be changing would be the X,Y positions. No rotation needed.

My guess is it has something to do with calling:

glOrthof(x,y,w,h);
glViewport(0,0,320,480);

but that is just a guess. Also: what exactly do orthof and viewport do? Im pretty sure that orthof and frustmf define the chunk of space to be rendered, and I really have no idea what viewport does... didn't we already say what to render? Maybe it is telling it which ways to stretch/resize if necessary...

Anyway, after that long rant... please answer, because I am at a standstill in development for now until this is answered. Thanks, seeya.

Re: Quick(hopefully) question.

Posted: Sat Aug 08, 2009 9:23 am
by RyanPridgeon
You can use glTranslate and a bit of logic.

glTranslate basically moves where you're about to draw with a translation matrix.

ortho and frustum create projection matrices which change how the 3d coordinates will be projected onto 2d screen coordinates.

viewport is what openGL uses to turn the 2d coordinates into pixel coordinates on the screen.

Dont hurt me if any of that is slightly wrong D:

Re: Quick(hopefully) question.

Posted: Sat Aug 08, 2009 9:37 am
by ibly31
So, during the program, can I call glViewport(xoffset, yoffset, xoffset + 320, yoffset + 480); ????

Re: Quick(hopefully) question.

Posted: Sat Aug 08, 2009 9:50 am
by RyanPridgeon
You would do something like

- clear screen
- glTranslatef(camerax, cameray, 0.0f);
- draw objects
- update screen

Re: Quick(hopefully) question.

Posted: Sat Aug 08, 2009 1:28 pm
by Falco Girgis
And of course there is no concept of a "camera." OpenGL is a graphics API, not a game development library.

Re: Quick(hopefully) question.

Posted: Sat Aug 08, 2009 9:14 pm
by ibly31
Okay. I have a GLView class inheriting from UIView, and a GLViewController class inheriting from UIViewController, which has a setupView: and drawView: function. How would I pause the GLViewController, and switch control to a pause menu, and then switch back? Also, how exactly do you tell the app to start off with a user interface, like a menu, then go to a GLView? Sorry if these questions are repetitive, or stupid, no matter how many times I ask, I still don't fully(even partially) understand how the whole subview/viewcontroller/app delegate/application flow works.

Re: Quick(hopefully) question.

Posted: Tue Aug 11, 2009 4:35 am
by RyanPridgeon
Use glOrtho for the projection matrix to set up a 2d / orthographic view for the menu/overlay/HUD

Use glFrustum or gluPerspective to set up a 3d perspective view for the 3d scene

Re: Quick(hopefully) question.

Posted: Tue Aug 11, 2009 11:48 am
by ibly31
i don't think OpenGL ES has the glu prefixed methods...