I tried to overlay text as a texture using following code snippet:
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
myLabel.text = @"Hello world!";
myLabel.font = [UIFont fontWithName:@"Helvetica" size:18];
myLabel.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
myLabel.backgroundColor = [UIColor clearColor];
UIGraphicsBeginImageContext(myLabel.bounds.size);
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, 30);
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0);
[myLabel.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
But it's not visible. For displaying image as a texture using OpenGL I tried the following code snippet:
/// here image is the layerImage created in above piece of code
GLuint width = CGImageGetWidth(image.CGImage);
GLuint height = CGImageGetHeight(image.CGImage);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
void *imageData = malloc( height * width * 4 );
CGContextRef context = CGBitmapContextCreate( imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );
CGColorSpaceRelease( colorSpace );
CGContextClearRect( context, CGRectMake( 0, 0, width, height ) );
CGContextTranslateCTM( context, 0, height - height );
CGContextDrawImage( context, CGRectMake( 0, 0, width, height ), image.CGImage );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
CGContextRelease(context);
free(imageData);
[image release];
[texData release];
But the image is not getting displayed. Is there any other approach to display text as a texture using OpenGL in ios?