- voidGLFirstLayer::draw()
- {
- //CCLayer::draw();
- //顶点数据
- staticGLfloatvertex[]={
- 0,
- 200,
- };
- //纹理坐标
- staticGLfloatcoord[]={
- 1,0); background-color:inherit">//颜色数据
- staticGLfloatcolor[]={
- 1,1
- //初始化纹理
- staticCCTexture2D*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,vertex);
- glVertexAttribPointer(kCCVertexAttrib_Color,4,color);
- glVertexAttribPointer(kCCVertexAttrib_TexCoords,2,coord);
- //绘图
- glDrawArrays(GL_TRIANGLE_STRIP,4);
- }