iPhone opengl 2d sprites landscape mode
I am trying to run OpenGL in "pseudo" landscape mode. By pseudo, I mean there is no software hook to tell API I am running landscape mode in Open GL.
So, lurking through forums. I found this trick to add to my EAGLView.m code for a pseudo landscape mode in open GL.
// Setup view matrix for landscape view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(160.0f, 240.0f, 0.0f );
glRotatef(270.0, 0.0, 0.0, 1.0);
glScalef(1.0, -1.0, 1.0);
This appears to work. -BUT- my sprites are rendering with some mirrored feature.
The sprites are all facing left. Like their pixels where flipped. Cool effect. But I don't want it. I am using the sprite sheet code form 71squared tutorials.
Anyone know if I stumbled onto a feature or did I setup my open GL landscape mode wrong?
thanks.
So, lurking through forums. I found this trick to add to my EAGLView.m code for a pseudo landscape mode in open GL.
// Setup view matrix for landscape view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(160.0f, 240.0f, 0.0f );
glRotatef(270.0, 0.0, 0.0, 1.0);
glScalef(1.0, -1.0, 1.0);
This appears to work. -BUT- my sprites are rendering with some mirrored feature.

The sprites are all facing left. Like their pixels where flipped. Cool effect. But I don't want it. I am using the sprite sheet code form 71squared tutorials.
Anyone know if I stumbled onto a feature or did I setup my open GL landscape mode wrong?
thanks.
Did you try changing the glScalef in your snippet for landscape to maybe glScalef(1.0, 1.0, 1.0); ? [edit] hehe... don't do glScalef(1.0, 1.0, 1.0); though since that is a waste. Just delete or comment out the line instead ... silly me.[/edit] I always get confused about which way things are oriented with landscape
, but a -1 scaling is suspect when you're dealing with an unexpected mirroring issue.
, but a -1 scaling is suspect when you're dealing with an unexpected mirroring issue.
Indeed, glScalef(1.0, -1.0, 1.0) will mirror on the Y axis. glScalef(1.0, 1.0, 1.0) is a no-op, though.
LOL!!!
I can't believe I missed that. 
I was just focused on getting rid of the -1 and didn't even think about scaling to 1. How funny!
I can't believe I missed that. 
I was just focused on getting rid of the -1 and didn't even think about scaling to 1. How funny!
I commented out the glScalef line of code:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(160.0f, 240.0f, 0.0f );
glRotatef(270.0, 0.0, 0.0, 1.0);
//glScalef(1.0, -1.0, 1.0);
I saw a blank screen. Nothing was rendered.
Is there a better way of doing this or do I infact need the glRotatef for a landscape right effect?
thanks.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(160.0f, 240.0f, 0.0f );
glRotatef(270.0, 0.0, 0.0, 1.0);
//glScalef(1.0, -1.0, 1.0);
I saw a blank screen. Nothing was rendered.
Is there a better way of doing this or do I infact need the glRotatef for a landscape right effect?
thanks.
Hmm... That doesn't really make much sense to me ATM. Do you have culling enabled or something? I can't envision what's going on.
For clarity, here is my render scene snapshot, EAGLView.m
- (void)renderScene {
// If OpenGL has not yet been initialised then go and initialise it
if(!glInitialised) {
[self initOpenGL];
}
//Set up OpenGL projection matrix
// Setup view matrix for landscape view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// normal code
glTranslatef(160.0f, 240.0f, 0.0f );
glRotatef(270.0, 0.0, 0.0, 1.0);
glScalef(1.0, -1.0, 1.0);
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, screenBounds.size.width , screenBounds.size.height);
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Render the game Scene
[tile0 renderAtPoint:CGPointMake(240,160) centerOfImage:YES];
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
Any ideas????
thanks.
- (void)renderScene {
// If OpenGL has not yet been initialised then go and initialise it
if(!glInitialised) {
[self initOpenGL];
}
//Set up OpenGL projection matrix
// Setup view matrix for landscape view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// normal code
glTranslatef(160.0f, 240.0f, 0.0f );
glRotatef(270.0, 0.0, 0.0, 1.0);
glScalef(1.0, -1.0, 1.0);
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, screenBounds.size.width , screenBounds.size.height);
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Render the game Scene
[tile0 renderAtPoint:CGPointMake(240,160) centerOfImage:YES];
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
Any ideas????
thanks.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL Differences between iPhone Sim and Real iPhone | SparkyNZ | 5 | 5,548 |
Apr 13, 2011 11:40 AM Last Post: SparkyNZ |
|
| Attempting to add landscape IB buttons to an openGL View | Madrayken | 1 | 3,000 |
Oct 17, 2010 07:03 AM Last Post: iamflimflam1 |
|
| Landscape app sometimes thinks portrait | bruss14 | 1 | 1,859 |
Dec 30, 2009 01:32 PM Last Post: bruss14 |
|
| Chipmunk moonbuggy dynamic landscape | wonza | 5 | 3,085 |
Nov 6, 2009 01:08 AM Last Post: wonza |
|
| OpenGL sprites - please help this n00b | Gillissie | 15 | 7,273 |
Mar 15, 2009 12:22 AM Last Post: AnotherJake |
|

