Jump to content
  • Advertisement
Sign in to follow this  
Tiresias

OpenGL help on glOrthof wanted

This topic is 2801 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello.

I am migrating a 2D game from desktop to iPhone.
So far i didnt encounter too many issues, openglES being quiet similar to openGL.

I have now a issue concerning the zooming.

on the windows version, the zooming is achieved through glOrtho. This is the only opengl call that achieves the zooming, the Blit coordinates etc are same with or wo zoom.

the glOrtho is this one. It is called before each frame rendering.

glOrtho( (w-w*s)/2,
s*w + (w-w*s)/2,
s*h + (h-h*s)/2,
(h-h*s)/2, -1, 1) ;

Where w and h are screen resolution, (1048x768 for ex)
and s is the scale factor (could be < 1 for zoomedin, > 1 for zoomed out)

for ex with s=1 (no zoom) we have glOrtho(0, w, h,0, -1,1);

This works good.


On Iphone i had to add some other matrice operation to enter landscape mode.
It becomes:


glRotatef(90.0, 0.0, 0.0, 1.0); // Landscape

glOrthof( (w-w*s)/2,
s*w + (w-w*s)/2,
(h-h*s)/2,
s*h + (h-h*s)/2,
-1, 1));

glScalef(1.0f, -1.0f, 1.0f);
glTranslatef(0.0f, -s*h, 0.0f);

Note here that we call Ortho in a different way (on windows it was glOrtho(x0,x1,y0,y1,-1,1), for iphone it is (x0,x1, y1, y0,-1,1) -> y0,y1 are swapped.

Note that in the translate, -s*h is in fact (y1-y0)

My problem is that if s=1 all is fine.

when s is > 1 for ex, i am having trouble (i believe the scene is translated upward, for ex if a texture must be displayed at y=200, i believe it will show up on y < 200, )


do you know what could be wrong ?

(i am adding the code with s=2 maybe it ll help:

windows:
glOrtho( -0.5f*w, 1.5f*w , 1.5f*h, -0.5f*h, -1, 1) ;

iphone:

glRotatef(90.0, 0.0, 0.0, 1.0); // Landscape
glOrtho( -0.5f*w, 1.5f*w, -0.5f*h, 1.5f*h, -1, 1) ;

glScalef(1.0f, -1.0f, 1.0f);
glTranslatef(0.0f, -2*h, 0.0f);

actually writting this i realized: the glTranslate shall only be about -h, not -s*h right?!
)

[Edited by - Tiresias on November 12, 2010 3:44:37 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!