Jump to content

  • Log In with Google      Sign In   
  • Create Account

Rendering text iPhone


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
1 reply to this topic

#1 Vorel512   Members   -  Reputation: 130

Like
0Likes
Like

Posted 13 August 2012 - 02:59 AM

Hi,

I would like to ask for a little help. I am stuck with displaying texts with OpenGL ES 2.0. I have read a lot of tutorial, but none of them working.
If anybody knows where can I find some working example please link it here.

Thanx,
RP

My existing, tho not working code:
[source lang="cpp"]- (GLuint)setupTextTexture:(NSString *)text { CGPoint position = CGPointMake(0,0); UIFont *font = [UIFont fontWithName:@"Arial" 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; label.alpha = 1; UIGraphicsBeginImageContext(label.frame.size); [[label layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); CGImageRef spriteImage = layerImage.CGImage; if (!spriteImage) { NSLog(@"Failed to setup text image %@", text); exit(1); } 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*height*4, CGColorSpaceCreateDeviceGray(), kCGImageAlphaNone); CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage); CGContextRelease(spriteContext); 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]

Sponsor:

#2 Vorel512   Members   -  Reputation: 130

Like
0Likes
Like

Posted 14 August 2012 - 01:53 AM

The problem was, that the frame size has to 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.



PARTNERS