diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 4d5d7a9317..88a679463c 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -157,6 +157,12 @@ bool Director::init(void) _renderer = new (std::nothrow) Renderer; _console = new (std::nothrow) Console; + + // default clear color + _clearColor.r = 0; + _clearColor.g = 0; + _clearColor.b = 0; + _clearColor.a = 1.0; return true; } @@ -242,7 +248,7 @@ void Director::setGLDefaultValues() setProjection(_projection); // set other opengl default values - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); } // Draw the Scene @@ -705,6 +711,12 @@ void Director::setDepthTest(bool on) CHECK_GL_ERROR_DEBUG(); } +void Director::setClearColor(const Color4F& clearColor) +{ + _clearColor = clearColor; + glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); +} + static void GLToClipTransform(Mat4 *transformOut) { if(nullptr == transformOut) return; diff --git a/cocos/base/CCDirector.h b/cocos/base/CCDirector.h index 5283d87db0..644722629d 100644 --- a/cocos/base/CCDirector.h +++ b/cocos/base/CCDirector.h @@ -322,6 +322,9 @@ public: /** enables/disables OpenGL alpha blending */ void setAlphaBlending(bool on); + + /** set clear values for the color buffers, value range of each element is [0.0, 1.0] */ + void setClearColor(const Color4F& clearColor); /** enables/disables OpenGL depth test */ void setDepthTest(bool on); @@ -463,6 +466,9 @@ protected: unsigned int _totalFrames; float _secondsPerFrame; + /* clear color set outside be used in setGLDefaultValues() */ + Color4F _clearColor; + /* The running scene */ Scene *_runningScene;