Animation Cocos2d-x 2.0中CCTransitionPageTurn的背面颜色

Animation Cocos2d-x 2.0中CCTransitionPageTurn的背面颜色,animation,opengl-es,cocos2d-x,transitions,Animation,Opengl Es,Cocos2d X,Transitions,使用CCTransitionPageTurn时,如何指定场景背面的颜色?在cocos2d iphone 1.0中,我对CCGrid.m中的blot()做了如下修改: NSInteger n = gridSize_.x * gridSize_.y; // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // Needed states: GL_TEXTURE_

使用CCTransitionPageTurn时,如何指定场景背面的颜色?在cocos2d iphone 1.0中,我对CCGrid.m中的blot()做了如下修改:

NSInteger n = gridSize_.x * gridSize_.y;
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
    // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY
    // Unneeded states: GL_COLOR_ARRAY
    //enable culling, the default cull face is back
    glEnable(GL_CULL_FACE);
    //now only the front facing polygons are drawn
    glDisableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoordinates);
    glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, indices);
// This is very important, otherwise the backside of picture will be random color
    glDisable(GL_TEXTURE_2D);
//change the winding of what OpenGl considers front facing
    //only the back facing polygons will be drawn
    //this works better then changing the cull face
    glFrontFace(GL_CW);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glColor4ub(255,255,255,255);
    glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, indices);
//restore GL default states
    glFrontFace(GL_CCW);
    glDisable(GL_CULL_FACE);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

这是cpp代码,我想我可以在cocos2d-x中使用。但不幸的是,这段代码不适用于2.0。有人能建议如何将其转换为2.0吗?或者,在CCTransitionPageTurn期间,是否有其他方法可以设置场景背面的颜色?

基于您的代码片段和其他谷歌搜索,我成功地实现了以下目标:

void CCGrid3D::blit(void)
{

    CCLOG("CCGrid3D::blit()");
    int n = m_sGridSize.width * m_sGridSize.height;

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords );
    m_pShaderProgram->use();
    m_pShaderProgram->setUniformsForBuiltins();;

    //
    // Attributes
    //
#ifdef EMSCRIPTEN
    // Size calculations from calculateVertexPoints().
    unsigned int numOfPoints = (m_sGridSize.width+1) * (m_sGridSize.height+1);

    // position
    setGLBufferData(m_pVertices, numOfPoints * sizeof(ccVertex3F), 0);
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, 0);

    // texCoords
    setGLBufferData(m_pTexCoordinates, numOfPoints * sizeof(ccVertex2F), 1);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, 0);

    setGLIndexData(m_pIndices, n * 12, 0);
    glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, 0);
#else

    glEnable(GL_CULL_FACE);
    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);

    glDisable(GL_TEXTURE_2D);

    glFrontFace(GL_CW);
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position);

    glEnable(GL_BLEND);

    glDrawElements(GL_TRIANGLES, (GLsizei)n*6, GL_UNSIGNED_SHORT, m_pIndices);

    glFrontFace(GL_CCW);

    glDisable(GL_BLEND);
    glDisable(GL_CULL_FACE);

#endif // EMSCRIPTEN
    CC_INCREMENT_GL_DRAWS(1);
}

它只有一个缺点:它不允许您指定背景色,而是获取左下角像素的颜色并使用它。我希望这对您来说已经足够了,或者您可以更改它,以便我们可以指定所需的颜色。

基于您的代码片段和其他谷歌搜索,我成功地实现了这一点:

void CCGrid3D::blit(void)
{

    CCLOG("CCGrid3D::blit()");
    int n = m_sGridSize.width * m_sGridSize.height;

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords );
    m_pShaderProgram->use();
    m_pShaderProgram->setUniformsForBuiltins();;

    //
    // Attributes
    //
#ifdef EMSCRIPTEN
    // Size calculations from calculateVertexPoints().
    unsigned int numOfPoints = (m_sGridSize.width+1) * (m_sGridSize.height+1);

    // position
    setGLBufferData(m_pVertices, numOfPoints * sizeof(ccVertex3F), 0);
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, 0);

    // texCoords
    setGLBufferData(m_pTexCoordinates, numOfPoints * sizeof(ccVertex2F), 1);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, 0);

    setGLIndexData(m_pIndices, n * 12, 0);
    glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, 0);
#else

    glEnable(GL_CULL_FACE);
    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);

    glDisable(GL_TEXTURE_2D);

    glFrontFace(GL_CW);
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position);

    glEnable(GL_BLEND);

    glDrawElements(GL_TRIANGLES, (GLsizei)n*6, GL_UNSIGNED_SHORT, m_pIndices);

    glFrontFace(GL_CCW);

    glDisable(GL_BLEND);
    glDisable(GL_CULL_FACE);

#endif // EMSCRIPTEN
    CC_INCREMENT_GL_DRAWS(1);
}

它只有一个缺点:它不允许您指定背景色,而是获取左下角像素的颜色并使用它。我希望这对您来说已经足够了,或者您可以更改它,以便让我们指定所需的颜色。

但是如何更改?你能提供更详细的建议吗。谢谢,但是怎么做呢?你能提供更详细的建议吗。谢谢