我在 cocos2d-x 中将代码从 ES 1.0 更改为 ES 2.0
ES 1.0 版本中的代码
const float DARK=30.0f;
int n = m_sGridSize.x * m_sGridSize.y;
glEnable(GL_CULL_FACE);
glDisableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, m_pVertices);
glTexCoordPointer(2, GL_FLOAT, 0, m_pTexCoordinates);
glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, m_pIndices);
glFrontFace(GL_CW);
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glColor4ub(255-(m_AnimationProgress*DARK), 255-(m_AnimationProgress*DARK), 255-(m_AnimationProgress*DARK), 255);
glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, m_pIndices);
glColor4f(255, 255, 255, 255);
glFrontFace(GL_CCW);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
ES 2.0 版本中的代码
const float DARK=30.0f;
m_pShaderProgram->use();
m_pShaderProgram->setUniformForModelViewProjectionMatrix();
int n = m_sGridSize.x * m_sGridSize.y;
glEnable(GL_CULL_FACE);
glDisableVertexAttribArray(kCCVertexAttrib_Color);
glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, m_pVertices);
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pTexCoordinates);
glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, m_pIndices);
glFrontFace(GL_CW);
glDisable(GL_TEXTURE_2D);
glDisableVertexAttribArray(kCCVertexAttrib_TexCoords);
ccDrawColor4B(255-(m_AnimationProgress*DARK), 255-(m_AnimationProgress*DARK), 255-(m_AnimationProgress*DARK), 255);
glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, m_pIndices);
ccDrawColor4B(255, 255, 255, 255);
glFrontFace(GL_CCW);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glEnableVertexAttribArray(kCCVertexAttrib_TexCoords);
glEnableVertexAttribArray(kCCVertexAttrib_Color);
结果如下输出(XCode)
Cocos2d: OpenGL error 0x0500 in /cocos2dx/sprite_nodes/CCSprite.cpp draw 616
我做错了什么?我认为一切都很好,经过几次测试。