我在cocos2d-x中将代码从ES 1.0更改为ES 2.0
I changed code from ES 1.0 to ES 2.0 in cocos2d-x
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我做错了什么?我认为一切都很好,经过几次测试.
what did I do wrong? I think all is well, a few times tested.
推荐答案在OpenGL ES 1.1中,使用glEnable和.
In OpenGL ES 1.1, texture mapping for fragments (there's no vertex texture mapping in ES 1.1) is turned on and off, using glEnable, and glDisable, respectively.
在OpenGL ES 2.0中,仅当片段纹理映射被编码到片段着色器中时,才执行片段纹理映射,因此无需启用或禁用它.我怀疑GL_INVALID_ENUM来自剩余的glEnable(GL_TEXTURE_2D);和glDisable(GL_TEXTURE_2D);.我猜你不止一次看到该错误.
In OpenGL ES 2.0, fragment texture mapping is only done if it's coded into the fragment shader, so there's no need to enable or disable it. I suspect the GL_INVALID_ENUM is from the leftover glEnable(GL_TEXTURE_2D); and glDisable(GL_TEXTURE_2D);. I'm guessing you're seeing that error more than once.
更多推荐
将OpenGL代码从ES 1.0更改为ES 2.0后的错误
发布评论