次のコード スニペットを使用して、テキストをテクスチャとしてオーバーレイしようとしました。
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();
しかし、それは見えません。OpenGL を使用して画像をテクスチャとして表示するために、次のコード スニペットを試しました。
/// 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];
しかし、画像が表示されません。iOSでOpenGLを使用してテキストをテクスチャとして表示する他の方法はありますか?