CHAPTER 8: Putting It All Together (^261)
other texture. Also, UI elements can be drawn to the GL layer as well using these
techniques.
Listing 8-9. A more flexible 2D texture renderer to support the addition of lens flares
-(void)renderTextureAt:(CGPoint)position name:(GLuint)name
size:(GLfloat)size r:(GLfloat)r g:(GLfloat)g b:(GLfloat)b a:(GLfloat)a; //1
{
float scaledX,scaledY;
GLfloat zoomBias=.1;
GLfloat scaledSize;
static const GLfloat squareVertices[] =
{
-1.0f, -1.0f, 0.0,
1.0f, -1.0f, 0.0,
-1.0f, 1.0f, 0.0,
1.0f, 1.0f, 0.0,
};
static GLfloat textureCoords[] =
{
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 1.0
};
CGRect frame = [[UIScreen mainScreen] bounds];
float aspectRatio=frame.size.height/frame.size.width;
scaledX=2.0position.x/frame.size.width;
scaledY=(2.0position.y/frame.size.height)aspectRatio;
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING); //2
glDisable(GL_CULL_FACE);
glDisableClientState(GL_COLOR_ARRAY);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrthof(-1,1,-1.0aspectRatio,1.0*aspectRatio, -1, 1); //3
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
singke
(singke)
#1