I got a good session in last night, doing some plumbing code for OpenGL games. My need for OpenGL is modest here. Basically I just want to be able to use it as a 2D API to render rectangular areas with images.
So I came up with a few simple objects to help me: VertexSquare, ColorSquare, TextureSquare. These encapsulate an array of values that need to be used in order to render a simple rectangle. These give me, respectively, the vertices, colors, and texture coordinates of the rectangle.
I have already set up a matrix to pretend that the upper left of the screen is (0,0) and the lower right is (40,25). This way I can use a grid of VertexSquares (actually, there is an object called VertexGrid for this purpose), and I can split up a texture into a bunch of TextureSquares (called a TextureGrid) in order to make a tileset.
I also encapsulate a VertexSquare, a ColorSquare, and a TextureSquare, in conjunction with a Texture object (that actually wraps a real texture) into something called a RenderSquare.
A lot of this exercise is to give myself those classes that I know will be useful in hammering out games. Pretty much any language and platform I’m on needs a set of things like these in order to make work go faster. I don’t want to have to put together texture coordinates and vertices and color arrays. I want to have an object to point to and say: use this texture, this part of the texture, this color, and at these coordinates, and render.
I’m also getting re-used to the retain/release memory management stuff in Objective-C. I stuff a series of TextureSquares into an NSMutableArray in order to create a TextureGrid. I always make mistakes initially until I’m reused to these things.