CHAPTER 8: Putting It All Together (^281)
-(void)renderAtPoint:(CGPoint)point depth:(CGFloat)depth red:(float)red
green:(float)green
blue:(float)blue alpha:(float)alpha
{
float scale;
int boxRect[4];
glBindTexture(GL_TEXTURE_2D,m_Name);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColor4f(red, green, blue, alpha);
boxRect[0]=0;
boxRect[1]=0;
boxRect[2]=m_Width;
boxRect[3]=m_Height;
scale=[[UIScreen mainScreen] scale]; //10
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,(GLint )boxRect); //11
glDrawTexfOES(point.xscale, (480-point.y)*scale, depth, m_Width,m_Height); //12
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
}
@end
Here’s what is happening:
The parameters in line 1 include the string, its size as determined by using
the ever-so-handy sizeWithFont() method of NSString, the alignment, and
the UIFont.
Here in lines 2ff, the size of the desired texture is upped to be power-of-two
(POT) needed for older devices. You can check the APPLE_texture2D
limited_npot extension. If it exists, any size textures will work.
We need to first use CoreGraphics to generate a bitmap with the desired
text, in line 3, and then convert it to an OpenGL ES texture. Lines 4ff now
allocate memory for the actual data and then create a new bitmap context
with the data block.
singke
(singke)
#1