- void GLFirstLayer::draw()
- {
-
-
-
-
- static GLfloat vertex[] = {
- 0,0,0,
- 200,0,0,
- 0,200,0,
- 200,200,0
- };
-
-
- static GLfloat coord[] = {
- 0,1,
- 1,1,
- 0,0,
- 1,0
- };
-
-
- static GLfloat color[] = {
- 1,1,1,1,
- 1,1,1,1,
- 1,1,1,1,
- 1,1,1,1
- };
-
-
-
- static CCTexture2D* texture2d = NULL;
- if (!texture2d) {
- texture2d = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png");
- }
-
-
- ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
- texture2d->getShaderProgram()->use();
- texture2d->getShaderProgram()->setUniformForModelViewProjectionMatrix();
-
-
-
- glBindTexture(GL_TEXTURE_2D, texture2d->getName());
-
-
-
- glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, vertex);
- glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, color);
- glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, coord);
-
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- }
上面就绘制了一个矩形,直接重写 draw()方法即可