Pro OpenGL ES for iOS

(singke) #1

CHAPTER 7: Well-Rendered Miscellany (^215)
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION); //4
glPushMatrix();
glLoadIdentity();
glOrthof(-1,1,-1.0aspectRatio,1.0aspectRatio, -1, 1); //5
glMatrixMode(GL_MODELVIEW); //6
glLoadIdentity();
glTranslatef(scaledX,scaledY,0); //7
scaledSize=zoomBias*size; //8
glScalef(scaledSize,scaledSize, 1); //9
glVertexPointer(3, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D); //10
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
glBindTexture(GL_TEXTURE_2D,name);
glTexCoordPointer(2, GL_FLOAT,0,textureCoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glColor4f(r,g,b,a); //11
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glMatrixMode(GL_PROJECTION); //12
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
}
So, here is what’s going on:
„ In line 1, the position is the origin of the texture in pixels relative to the
center, which is converted to normalized values later. The size is
relative and needs to be played with to find the most appropriate. The
final parameters are the colors and alpha. If you don’t want any
coloring, pass 1.0 for all of the values. Following this line, you’ll
recognize our old friends, the vertices and texture coordinates.

Free download pdf