正文  游戏开发 > 游戏引擎 >

cocos2d-x中修改窗口背景色

cocos2d-x中默认的窗口背景色是黑色的。这个貌似因为opengl的默认初始化颜色就是黑色。 既然是opengl渲染的,那么初始化的颜色一定是用gl函数处理的,如下 [cpp]  ...

cocos2d-x中默认的窗口背景色是黑色的。这个貌似因为opengl的默认初始化颜色就是黑色。
 
既然是opengl渲染的,那么初始化的颜色一定是用gl函数处理的,如下
 
[cpp]  
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);  
 
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);搜索之,找到一个
 
 
[cpp] 
void CCDirector::setGLDefaultValues(void)  
{  
    // This method SHOULD be called only after openGLView_ was initialized   
    CCAssert(m_pobOpenGLView, "opengl view should not be null");  
  
    setAlphaBlending(true);  
    // XXX: Fix me, should enable/disable depth test according the depth format as cocos2d-iphone did   
    // [self setDepthTest: view_.depthFormat];   
    setDepthTest(true);  
    setProjection(m_eProjection);  
  
    // 这里设置默认颜色   
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);  
//    glClearColor(255.0f, 255.0f, 255.0f, 1.0f);   
}  
 
void CCDirector::setGLDefaultValues(void)
{
    // This method SHOULD be called only after openGLView_ was initialized
    CCAssert(m_pobOpenGLView, "opengl view should not be null");
 
    setAlphaBlending(true);
    // XXX: Fix me, should enable/disable depth test according the depth format as cocos2d-iphone did
    // [self setDepthTest: view_.depthFormat];
    setDepthTest(true);
    setProjection(m_eProjection);
 
    // 这里设置默认颜色
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//    glClearColor(255.0f, 255.0f, 255.0f, 1.0f);
}
底下修改为白色。