ultifinitus
ultifinitus

Reputation: 1883

OpenGL Change Coordinate Setup

I have an ortho screen set up in OpenGL ES on the iPhone and I would like to change my coordinate system from it's current setup.

I thought something like this would do it.

glOrthof(0, self.view.frame.size.width, 0, self.view.frame.size.height, -1, 1);
glViewport(0, 0, self.view.frame.size.width, self.view.frame.size.height);

However it doesn't seem to affect the screen coordinate system at all.. Currently it's set up so if I apply an object at the vertices { 0,-1,0, 1,0,0, 0,1,0, -1,0,0} I get a diamond shape the size of the whole screen (in other words my lower bound is -1 and upper bound is +1)

How would I change my view so that my bounds are 0,0 and screen_width,screen_height?

Upvotes: 2

Views: 862

Answers (1)

ultifinitus
ultifinitus

Reputation: 1883

Alright, well I got the answer, those two functions do in fact do what I needed.

However I was loading my identity projection matrix after calling those functions. So the options are either, not load ID matrix or call these functions after loading the identity matrix. So if I wanted my coordinates to go from 0-screensize I'd do the following:

- (void)drawFrame
{
 [(EAGLView *)self.view setFramebuffer];

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();

 glOrthof(0, self.view.frame.size.width, 0, self.view.frame.size.height, -1, 1);
 glViewport(0, 0, self.view.frame.size.width, self.view.frame.size.height);

 ///DRAWING STUFF HERE

 [(EAGLView *)self.view presentFramebuffer];
}

OR remove the following code from the above snippet

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrthof(0,self.view.frame.size.width, 0, self.view.frame.size.height,-1,1);
glViewport(0, 0, self.view.frame.size.width, self.view.frame.size.height);

then add it to your loading function, perhaps in your init- or awaken from nib, or viewDidLoad or viewWillAppear

It seems that not both are necessary, however it's working great now =]

Upvotes: 1

Related Questions