I am having trouble with glorthof on the opengles/iphone. I have had this code that works with the standard opengl but when I go opengles, it seems that glorthof won’t recognize a 2d display:
I want to have the 3d display and also have a matrix for the heads up display to show scores and what - not.
Here is the main part of the code:
- (void) renderHUD:(EAGLView*)view {
/*
<code>
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof( 0, 320, 480, 0, 1, 0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDepthMask(GL_FALSE);
</code>
*/
/////////////////////////////////////////////
// Enable 2d mode for hud title displays
/////////////////////////////////////////////
CGRect rect = view.bounds;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glDisable(GL_LIGHTING);
// Depth testing and lighting are disabled for 2D rendering until
// we are finished rendering in 2D
glDisable(GL_DEPTH_TEST);
/////////////////////////////////////////////
/*
* void glOrtho ( GLdouble left , GLdouble right , GLdouble bottom ,
* GLdouble top , GLdouble zNear , GLdouble zFar );
*/
// glOrthof(0.0f, rect.size.width, rect.size.height, rect.size.height,
// -1.0f, 1.0f);
// Set up the orthographic projection
/*
glOrthof(0.0f, 320.0f, 480.0f,
0.0f, -1.0f, 1.0f);
*/
glOrthof(0.0f, rect.size.width, rect.size.height, 0.0f,
-1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/////////////////////////////////////////////
/// Render hud
/*
[self renderTextHUD:view];
*/
const GLfloat triVertices[] = {
0.0f, 5.7f, 0.0f,
-5.7f, -5.7f, 0.0f,
5.7f, -5.7f, 0.0f
};
glColor4f(0.0, 0.0, 1.0, 1.0);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, triVertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
glDisableClientState(GL_VERTEX_ARRAY);
/////////////////////////////////////////////
// Disable 2d display
/////////////////////////////////////////////
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_LIGHTING);
} // End of the Method //
/**
* Main setup the OpenGL view.
*/
-(void) setupView:(EAGLView*)view {
const GLfloat zNear = 0.1,
zFar = 1000.0,
fieldOfView = 60.0;
GLfloat size;
// Set the OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
CGRect rect = view.bounds;
glFrustumf( -size, size,
-size / (rect.size.width / rect.size.height),
size / (rect.size.width / rect.size.height),
zNear, zFar);
glViewport(0, 0, rect.size.width, rect.size.height);
// Make the OpenGL modelview matrix the default
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
/////////////////////////////////////////////
// Texture, text setup.
/////////////////////////////////////////////
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
NSString *testString = [NSString stringWithFormat: @"testing: %f", 0.0];
// Initialize our texture with the text specified in testString
_textures[0] = [[Texture2D alloc] initWithString:testString
dimensions:CGSizeMake(140, 20)
alignment:UITextAlignmentLeft
fontName:@"Arial"
fontSize:kLabelFontSize];
glBindTexture(GL_TEXTURE_2D, [_textures[0] name]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
// End of graphics text setup //
} // End of the Method //