复制代码
static void initCheckImage(void) { GLfloat initColor = 1.0f; for(int row = 0; row < 64; row++) { if((row & 7) == 0) initColor = 1.0f - initColor; GLfloat color1 = 1.0f - initColor; CGFloat color2 = initColor; for(int col = 0; col < 64; col++) { if((col & 7) == 0) { color1 = 1.0f - color1; color2 = 1.0f - color2; } checkImage[row * 64 * 4 + col * 4 + 0] = color1; checkImage[row * 64 * 4 + col * 4 + 1] = 0.0f; checkImage[row * 64 * 4 + col * 4 + 2] = color2; checkImage[row * 64 * 4 + col * 4 + 3] = 1.0f; } } }
static GLfloat texCoords[] = { // left 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // front 0.8f, 0.8f, 1.8f, 0.8f, 0.8f, 1.8f, 1.8f, 1.8f, // right 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // back 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // top 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // bottom 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f };
- (void)prepareOpenGL { initCheckImage(); glEnable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_MULTISAMPLE); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glFrontFace(GL_CCW); glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); glClearColor(0.4, 0.4, 0.4, 1.0); GLuint texName; glPixelStorei(GL_UNPACK_ALIGNMENT, 8); glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_FLOAT, checkImage); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glVertexPointer(3, GL_FLOAT, 0, vertices); glColorPointer(4, GL_FLOAT, 0, colors); glViewport(0, 0, 320, 320); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, 1.0, 5.0); glMatrixMode(GL_MODELVIEW); [[NSTimer scheduledTimerWithTimeInterval:0.05f target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:NO] retain]; }
|