#import "GLTexture.h"
First we imported the GLTexture header file for our EAGLView header file to find. Later on we created our texture image:
// Create texture image.
GLTexture *diamond;
This code is included in @private of @interface EAGLView : UIView. When we are done making the proper modifications in the header file we now go into the implementation file in our function -(id)initWithCoder:(NSCoder*)coder. In this case we are setting very important properties here; first, before we start drawing our GLTexture which we recently setup in our header file of EAGLView we must setup our OpenGL ES system as follows:
// Get the bounds of the main screen
CGRect rect = [[UIScreen mainScreen] bounds];
// Set up OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, rect.size.width, 0, rect.size.height, -1, 1);
glMatrixMode(GL_MODELVIEW);
// Initialize OpenGL states
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- (void)drawView {
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
// Init image
diamond = [[GLTexture alloc] initWithImage:[UIImage imageNamed:@"Sprite.png"]];
[diamond drawAtPoint:CGPointMake(160.0f, 240.0f)];
// Draw game scene
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
No comments:
Post a Comment