熟悉 iPhone 上的 OpenGL ES。
iPhone SDK 的 OpenGL ES 示例是一个很好的起点。
研究纹理映射。熟悉 glTexImage2D 后,使用它来加载图像。
这个例子可以很容易地扩展为:
有这些定义:
GLuint spriteTexture;
GLubyte *spriteData; // the perlin noise will be here
size_t width, height;
然后在 ESRenderer init 方法中为纹理创建空间:
- (id) init { ....
width = 512; // make sure the texture size is the power of 2
height = 512;
glGenTextures(1, &spriteTexture);
glBindTexture(GL_TEXTURE_2D, spriteTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);
//free(spriteData); // free this if not used any more
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
如果噪声周期性更新,在渲染方法中更新纹理
- (void) render { .....
glBindTexture(GL_TEXTURE_2D, spriteTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);