iPhone opengl 2d sprites landscape mode

Nibbie
Posts: 4
Joined: 2009.09
Post: #1
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. Mad

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.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #2
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 Wacko, but a -1 scaling is suspect when you're dealing with an unexpected mirroring issue.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
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. Smile
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #4
LOL!!! LOL I can't believe I missed that. Rasp

I was just focused on getting rid of the -1 and didn't even think about scaling to 1. How funny!
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.09
Post: #5
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.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #6
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.
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.09
Post: #7
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Differences between iPhone Sim and Real iPhone SparkyNZ 5 6,868 Apr 13, 2011 11:40 AM
Last Post: SparkyNZ
  Attempting to add landscape IB buttons to an openGL View Madrayken 1 3,838 Oct 17, 2010 07:03 AM
Last Post: iamflimflam1
  Landscape app sometimes thinks portrait bruss14 1 2,286 Dec 30, 2009 01:32 PM
Last Post: bruss14
  Chipmunk moonbuggy dynamic landscape wonza 5 3,800 Nov 6, 2009 01:08 AM
Last Post: wonza
  OpenGL sprites - please help this n00b Gillissie 15 8,800 Mar 15, 2009 12:22 AM
Last Post: AnotherJake