Esempio n. 1
0
// Draw the SCene
void CCDirector::drawScene(void)
{
	// calculate "global" dt
	calculateDeltaTime();

	//tick before glClear: issue #533
	if (! m_bPaused)
	{
		CCScheduler::sharedScheduler()->tick(m_fDeltaTime);
	}

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /* to avoid flickr, nextScene MUST be here: after tick and before draw.
	 XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */
	if (m_pNextScene)
	{
		setNextScene();
	}

	glPushMatrix();

	applyOrientation();

	// By default enable VertexArray, ColorArray, TextureCoordArray and Texture2D
	CC_ENABLE_DEFAULT_GL_STATES();

	// draw the scene
    if (m_pRunningScene)
    {
        m_pRunningScene->visit();
    }

	// draw the notifications node
	if (m_pNotificationNode)
	{
		m_pNotificationNode->visit();
	}

	if (m_bDisplayFPS)
	{
		showFPS();
	}

#if CC_ENABLE_PROFILERS
	showProfilers();
#endif

	CC_DISABLE_DEFAULT_GL_STATES();

	glPopMatrix();

	m_uTotalFrames++;

	// swap buffers
	if (m_pobOpenGLView)
    {
        m_pobOpenGLView->swapBuffers();
    }
}
Esempio n. 2
0
void CCRenderTexture::begin()
{
    // Save the current matrix
    glPushMatrix();

    const CCSize& texSize = m_pTexture->getContentSizeInPixels();

    // Calculate the adjustment ratios based on the old and new projections
    CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels();
    float widthRatio = size.width / texSize.width;
    float heightRatio = size.height / texSize.height;

    // Adjust the orthographic propjection and viewport
    ccglOrtho((float)-1.0 / widthRatio,  (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1);
    glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);
//     CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, texSize.width, texSize.height);

    glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
    ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);//Will direct drawing to the frame buffer created above

    // Issue #1145
    // There is no need to enable the default GL states here
    // but since CCRenderTexture is mostly used outside the "render" loop
    // these states needs to be enabled.
    // Since this bug was discovered in API-freeze (very close of 1.0 release)
    // This bug won't be fixed to prevent incompatibilities with code.
    //
    // If you understand the above mentioned message, then you can comment the following line
    // and enable the gl states manually, in case you need them.

    CC_ENABLE_DEFAULT_GL_STATES();
}
Esempio n. 3
0
void CCRenderTexture::beginWithClear(float r, float g, float b, float a)
{
    this->saveGLstate();

    CC_DISABLE_DEFAULT_GL_STATES();
    // Save the current matrix
    glPushMatrix();

    CCSize texSize = m_pTexture->getContentSizeInPixels();

    // Calculate the adjustment ratios based on the old and new projections
    CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels();
    float widthRatio = size.width / texSize.width;
    float heightRatio = size.height / texSize.height;

    // Adjust the orthographic propjection and viewport
    ccglOrtho((float)-1.0 / widthRatio,  (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1);
    glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);

    glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
    ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);//Will direct drawing to the frame buffer created above

    glClearColor(r, g, b, a);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    CC_ENABLE_DEFAULT_GL_STATES();
}