Pro OpenGL ES for iOS

(singke) #1

CHAPTER 7: Well-Rendered Miscellany (^213)
Figure 7-5. A six-blade iris (image by Dave Fischer)
The following steps are needed to generate the flare set:



  1. Import the various images.

  2. Detect where on the screen the source object is.

  3. Create the imaginary vector that goes through the center of the screen
    so as to hold the individual pieces of art.

  4. Add a dozen or more images, with random sizes, colors, and
    translucency, scattered up and down the vector.

  5. Support touch dragging to test it in all different positions.


I started with the standard template and added support for touching and dragging the
visuals. Following that, the sun image is loaded at startup and is drawn in drawInRect()
at the current position of a user’s finger, as demonstrated in Listing 7-5.


Listing 7-5. The top-level drawInRect()



  • (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
    {
    GLfloat cx,cy;
    CGPoint centerRelative;
    CGRect frame = [[UIScreen mainScreen] bounds];


glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);


cx=(frame.size.width/2.0); //1

Free download pdf