예제 #1
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();
}
예제 #2
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();
}
예제 #3
0
void CCDirector::setProjection(ccDirectorProjection kProjection)
{
	CCSize size = m_obWinSizeInPixels;
	float zeye = this->getZEye();
	switch (kProjection)
	{
	case kCCDirectorProjection2D:
        if (m_pobOpenGLView) 
        {
            m_pobOpenGLView->setViewPortInPoints(0, 0, size.width, size.height);
        }
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		ccglOrtho(0, size.width, 0, size.height, -1024 * CC_CONTENT_SCALE_FACTOR(), 
			1024 * CC_CONTENT_SCALE_FACTOR());
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		break;

	case kCCDirectorProjection3D:		
        if (m_pobOpenGLView) 
        {
            m_pobOpenGLView->setViewPortInPoints(0, 0, size.width, size.height);
        }
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		// accommodate iPad retina while keep backward compatibility
		if (m_pobOpenGLView && m_pobOpenGLView->isIpad() && m_pobOpenGLView->getMainScreenScale() > 1.0)
		{
			gluPerspective(60, (GLfloat)size.width/size.height, zeye-size.height/2, zeye+size.height/2);	
		}
		else
		{
			gluPerspective(60, (GLfloat)size.width/size.height, 0.5f, 1500.0f);
		}				
		
		glMatrixMode(GL_MODELVIEW);	
		glLoadIdentity();
		gluLookAt( size.width/2, size.height/2, zeye,
				 size.width/2, size.height/2, 0,
				 0.0f, 1.0f, 0.0f);				
		break;
			
	case kCCDirectorProjectionCustom:
		if (m_pProjectionDelegate)
		{
			m_pProjectionDelegate->updateProjection();
		}
		break;
			
	default:
		CCLOG("cocos2d: Director: unrecognized projecgtion");
		break;
	}

	m_eProjection = kProjection;
}
예제 #4
0
	void CCGridBase::set2DProjection()
	{
		CGSize winSize = CCDirector::sharedDirector()->getWinSizeInPixels();

		glLoadIdentity();
		glViewport((GLsizei)0, (GLsizei)0, (GLsizei)winSize.width, (GLsizei)winSize.height);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		ccglOrtho(0, winSize.width, 0, winSize.height, -1024, 1024);
		glMatrixMode(GL_MODELVIEW);
	}
예제 #5
0
void CCDirector::setProjection(ccDirectorProjection kProjection)
{
	CCSize size = m_obWinSizeInPixels;
	switch (kProjection)
	{
	case kCCDirectorProjection2D:
// 		glViewport((GLsizei)0, (GLsizei)0, (GLsizei)size.width, (GLsizei)size.height);
        CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		ccglOrtho(0, size.width, 0, size.height, -1024 * CC_CONTENT_SCALE_FACTOR(), 
			1024 * CC_CONTENT_SCALE_FACTOR());
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		break;

	case kCCDirectorProjection3D:
// 		glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height);
        CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(60, (GLfloat)size.width/size.height, 0.5f, 1500.0f);
			
		glMatrixMode(GL_MODELVIEW);	
		glLoadIdentity();
		gluLookAt( size.width/2, size.height/2, getZEye(),
				 size.width/2, size.height/2, 0,
				 0.0f, 1.0f, 0.0f);				
		break;
			
	case kCCDirectorProjectionCustom:
		if (m_pProjectionDelegate)
		{
			m_pProjectionDelegate->updateProjection();
		}
		break;
			
	default:
		CCLOG("cocos2d: Director: unrecognized projecgtion");
		break;
	}

	m_eProjection = kProjection;
}