rendering a UIImage using openGL
I use the following code to render a UIImage using openGL. the Texture2D
class is from Apple, so I assume it's correct. The image does not get
displayed. I just get the background color produced by glClearColor. My
app is based on paintGL sample code from Apple, so the setup is correct
and I am able to draw lines using openGL just fine.
Is this render code below missing something?
Thanks,
- (void) render:(UIImage *)image
{ [EAGLContext setCurrentContext:context]; glViewport(0, 0, backingWidth,
backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// texturing will need these
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
// glOrthof(0, self.bounds.size.width, 0, self.bounds.size.height, -1, 1);
glOrthof(0, backingWidth, 0, backingHeight, -1, 1);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Texture2D *texture = [[Texture2D alloc] initWithImage:image];
[texture drawInRect: self.frame];
// This application only creates a single color renderbuffer which is
already bound at this point.
// This call is redundant, but needed if dealing with multiple renderbuffers.
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];
}
No comments:
Post a Comment