code_junkie

Is there a decent OpenGL text drawing library for the iPhone SDK

Nov 14th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. struct FontGlyph
  2. {
  3.  
  4. u32 char_code;
  5.  
  6. u32 m_x; // base x position on tpage
  7.  
  8. u32 m_y; // base y position on tpage
  9.  
  10. u32 m_width; // glyph width
  11.  
  12. u32 m_height; // glyph height
  13.  
  14. i32 m_horiBearingX; // Distance to X shift
  15.  
  16. i32 m_horiBearingY; // Distance to Y shift
  17.  
  18. u32 m_horiAdvance; // Total Horizontal advance this character requires
  19.  
  20. u32 m__tpage_index; // Which tpage does this glyph use?
  21.  
  22. };
  23.  
  24. UIGraphicsBeginImageContext(yourLabel.frame.size);
  25. [yourLabel.layer renderInContext:UIGraphicsGetCurrentContext()];
  26. UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext();
  27. UIGraphicsEndImageContext();
  28.  
  29. Font font("Verdena");
  30. font.print("Hello World!", x, y, z);
  31.  
  32. font.print(x, y, z) << "fps: " << fps;
  33.  
  34. - (void) drawText:(NSString*)theString AtX:(float)X Y:(float)Y {
  35. // Use black
  36. glColor4f(0, 0, 0, 1.0);
  37.  
  38. // Set up texture
  39. Texture2D* statusTexture = [[Texture2D alloc] initWithString:theString dimensions:CGSizeMake(150, 150) alignment:UITextAlignmentLeft fontName:@"Helvetica" fontSize:11];
  40.  
  41. // Bind texture
  42. glBindTexture(GL_TEXTURE_2D, [statusTexture name]);
  43.  
  44. // Enable modes needed for drawing
  45. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  46. glEnableClientState(GL_VERTEX_ARRAY);
  47. glEnable(GL_TEXTURE_2D);
  48. glEnable(GL_BLEND);
  49.  
  50. glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  51.  
  52. // Draw
  53. [statusTexture drawInRect:CGRectMake(X,Y-1,1,1)];
  54.  
  55. // Disable modes so they don't interfere with other parts of the program
  56. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  57. glDisableClientState(GL_VERTEX_ARRAY);
  58. glDisable(GL_TEXTURE_2D);
  59. glDisable(GL_BLEND);
  60. }
  61.  
  62. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_ALPHA)
Add Comment
Please, Sign In to add comment