I have been at this for quite some time now, reading tutorials and so on, and I can't work out what the heck is wrong with this, is anyone else able to help me understand what is going wrong?
// Sets up an array of values to use as the sprite vertices.
const GLfloat spriteVertices[] = {
20.0f, 50.5f,
305.0f, 50.0f,
10.5f, 200.5f,
300.5f, 300.5f,
};
// Sets up an array of values for the texture coordinates.
const GLshort spriteTexcoords[] = {
0, 0,
100, 0,
0, 100,
100, 100,
};
-(void)setupView:(GLView*)view {
glMatrixMode(GL_PROJECTION);
CGRect rect = view.bounds;
glOrthof(0, rect.size.width, rect.size.height, 0, -1, 1);
glViewport(0, 0, rect.size.width, rect.size.height);
glMatrixMode(GL_MODELVIEW);
glDepthMask(GL_FALSE);
glLoadIdentity();
CGImageRef spriteImage = [UIImage imageNamed:@"rss_icon.png"].CGImage;
size_t width = CGImageGetWidth(spriteImage);
size_t height = CGImageGetHeight(spriteImage);
GLubyte *spriteData =
(GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
CGContextRef spriteContext = CGBitmapContextCreate(
spriteData, width, height, 8, width * 4,
CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast
);
CGContextDrawImage(
spriteContext,
CGRectMake( 0.0, 0.0, (CGFloat)width, (CGFloat)height),
spriteImage
);
CGContextRelease(spriteContext);
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, spriteData
);
free(spriteData);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
}
Draw code:
- (void)drawView:(UIView *)theView {
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glVertexPointer(2, GL_FLOAT, 0, spriteVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_SHORT, 0, spriteTexcoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}