Thank you. I was wondering how, for the Ultimate iPhone Template, to make it rotate so that it is upright? Also, I noticed that when you ran the game, if you clicked the "play" button it would run fine, but then I made a button to go back to the main menu, and if you pressed this and then clicked "play" again the screen would be rotated strangely. I changed the code in the beginning of GameView.m to this and it seemed to fix the problem:
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>
#import "GameView.h"
#import "AppDelegate.h"
#define USE_DEPTH_BUFFER 0
@implementation GameView
@synthesize context;
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder {
if ((self = [super initWithCoder:coder])) {
// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context]) {
[self release];
return nil;
}
//CGRect rect = [[UIScreen mainScreen] bounds];
// Set up OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, 480, 0, 320, -1, 1);
glViewport(0, 0, 480, 320);
//glTranslatef(-100, -320/2, 0.0f );
glMatrixMode(GL_MODELVIEW);
//glTranslatef(-0, -240.0f, 0.0f );
//glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
//glScalef(-1.0, 1.0, 1.0);
// Initialize OpenGL states
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glEnableClientState(GL_VERTEX_ARRAY);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
screenDimensions = CGPointMake([self bounds].size.width, [self bounds].size.height);
//[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
rotationNeg = CGPointMake(1, -1);
rotationOffset = CGPointMake(0, 320);
glRotatef(-90.0, 0.0f, 0.0f, 1.0f);
glTranslatef(-480.0, 0.0, 0.0f );
//[self setTransform:CGAffineTransformMakeRotation(M_PI/2)];
[self setFrame:CGRectMake(0, 0, 320, 480)];
//[gameView setCenter:CGPointMake(320/4, 320/2)];
// Set up OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, 320, 0, 480, -1, 1);
glViewport(0, 0, 320, 480);
//glTranslatef(-100, -320/2, 0.0f );
glMatrixMode(GL_MODELVIEW);
//glTranslatef(-0, -240.0f, 0.0f );
//glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
//glScalef(-1.0, 1.0, 1.0);
// Initialize OpenGL states
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glEnableClientState(GL_VERTEX_ARRAY);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
}
return self;
}
- (void)renderScene {
// Make sure we are renderin to the frame buffer
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
// Clear the color buffer with the glClearColor which has been set
glClear(GL_COLOR_BUFFER_BIT);
AppDelegate* delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
// Save the current matrix to the stack
glPushMatrix();
// Set client states so that the Texture Coordinate Array will be used during rendering
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Enable Texture_2D
glEnable(GL_TEXTURE_2D);
// Enable blending as we want the transparent parts of the image to be transparent
glEnable(GL_BLEND);
[delegate drawGame];
// Now we are done drawing disable blending
glDisable(GL_BLEND);
// Disable as necessary
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// Restore the saved matrix from the stack
glPopMatrix();
// Switch the render buffer and framebuffer so our scene is displayed on the screen
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}