Pro OpenGL ES for iOS

(singke) #1

214 CHAPTER 7: Well-Rendered Miscellany^


cy=(frame.size.height/2.0);

centerRelative=CGPointMake(m_PointerLocation.x-cx,cy-m_PointerLocation.y);
//2
[[OpenGLCreateTexture getObject]renderTextureAt:centerRelative name:m_FlareSource
size:3.0 r:1.0 g:1.0 b:1.0 a:1.0];
//3
[m_LensFlare execute:[[UIScreen mainScreen]applicationFrame]
source:m_PointerLocation];
}
I put the helper routines for creating and rendering a texture on their own module,
renderTextureAt(), which is covered in Listing 7-6. However, there are three lines to
take note of:
„ Lines 1ff get the center of the screen and creates the information
needed to track the flare source (the sun) with the pointer.
„ In line 2, the flare’s source object, usually the sun, is rendered.
„ Line 3 calls the helper routine that draws our 2D sun graphic in
the sky.
Listing 7-6. Rendering a 2D texture

-(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.0, -1.0, 0.0,
1.0, -1.0, 0.0,
-1.0, 1.0, 0.0,
1.0, 1.0, 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.0*position.x/frame.size.width; //2
scaledY=2.0*position.y/frame.size.height;

glDisable(GL_DEPTH_TEST); //3
Free download pdf