问题
I changed code from ES 1.0 to ES 2.0 in cocos2d-x
Code in ES 1.0 version
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);
Code in ES 2.0 version
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);
Results in the following output (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.
回答1:
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.
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.
回答2:
0x0500 is an "illegal enum" error. Check the error codes here.
This most likely refers to the enums like GL_CULL_FACE or GL_TRIANGLES. Refer to the DL ES reference which ones might not be available in 2.0, or which of those can't be used under certain circumstances.
来源:https://stackoverflow.com/questions/14478604/errors-after-changed-opengl-code-from-es-1-0-to-es-2-0