Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Create textures from text OpenGL ES 2.0 / GLKit

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Vorel512   Members   

130
Like
0Likes
Like

Posted 28 June 2012 - 02:21 AM

Hi all,

I have a code snippet, and it seems not working, if anyone run into the same problem and solved, please post the know how.
The error is, the image results in a black plain. Other images I use are work nice, just this text rendering not...
[source lang="cpp"]NSString *aString = [NSString stringWithFormat:@"Hello World."]; CGPoint position = CGPointMake(10,10); // Make a UILabel with the string UIFont *font = [UIFont fontWithName:@"Georgia" size:50]; CGSize size = [aString sizeWithFont:font forWidth:20 lineBreakMode:UILineBreakModeClip]; CGRect frame; frame.origin = position; frame.size = size; UILabel *label = [[UILabel alloc]initWithFrame:frame]; label.backgroundColor = [UIColor clearColor]; label.text = aString; label.textColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1]; label.font = font; // Make a UIImage with the UILabel UIGraphicsBeginImageContext(label.frame.size); [[label layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // Get a textureInfo from the UILabel texture = [GLKTextureLoader textureWithCGImage:layerImage.CGImage options:options error:&error]; if (texture == nil) { NSLog(@"Texture Error:%@", error); }[/source]

#2 Vorel512   Members   

130
Like
0Likes
Like

Posted 27 July 2012 - 12:25 AM

I've made a new function just for text rendering, but the picture is black anyway. I've tried to change the color values in the label, but still black output.

[source lang="cpp"]- (GLuint)setupTextTexture:(NSString *)text { //0 CGPoint position = CGPointMake(0,0); // Make a UILabel with the string UIFont *font = [UIFont fontWithName:@"Georgia" size:12]; CGSize size = [text sizeWithFont:font forWidth:12 lineBreakMode:UILineBreakModeClip]; CGRect frame; frame.origin = position; frame.size = size; UILabel *label = [[UILabel alloc]initWithFrame:frame]; label.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; label.text = text; label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; label.font = font; // Make a UIImage with the UILabel UIGraphicsBeginImageContext(label.frame.size); [[label layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // 1 CGImageRef spriteImage = layerImage.CGImage; if (!spriteImage) { NSLog(@"Failed to setup text image %@", text); exit(1); } // 2 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); // 3 CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage); CGContextRelease(spriteContext); // 4 GLuint texName; glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData); free(spriteData); return texName; }[/source]

#3 Vorel512   Members   

130
Like
0Likes
Like

Posted 14 August 2012 - 01:54 AM

Resolved! The problem was, that the frame size should be power of two.
Please mark this topic "Resolved"!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.