Ejemplo n.º 1
0
/*******************************************************************************
 * Function Name  : RenderScene
 * Returns		  : true if no error occured
 * Description    : Main rendering loop function of the program. The shell will
 *					call this function every frame.
 *******************************************************************************/
bool OGLESPolybump::RenderScene()
{
	if(PVRShellIsKeyPressed(PVRShellKeyNameACTION1))
		m_bDrawWithDot3 = !m_bDrawWithDot3;

	PVRTVec4 LightVector;
	PVRTMat4 mRotateY, mModelView;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	LightVector.x = PVRTSIN(m_i32Frame / 40.0f);
	LightVector.y = 0.0f;
	LightVector.z = -PVRTABS(PVRTCOS(m_i32Frame / 40.0f));
	LightVector.w = 0.0f;

	PVRTTransformBack(&LightVector, &LightVector, &m_mView);

	// Normalize light vector in case it is not
	LightVector.normalize();

	if(m_bDrawWithDot3)
	{
		// Setup texture blend modes

		// First layer (Dot3)
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, m_ui32CloneMap);

		if(m_bCombinersPresent)
		{
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
			glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);
			glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
			glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
		}
		else if(m_bIMGTextureFFExtPresent)
		{
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DOT3_RGBA);
		}

		// Second layer (modulate)
		glActiveTexture(GL_TEXTURE1);
		glEnable(GL_TEXTURE_2D);

		glBindTexture(GL_TEXTURE_2D, m_ui32DiffuseMap);

		if(m_bCombinersPresent)
		{
			glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
			glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
			glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
		}
		else if (m_bIMGTextureFFExtPresent)
		{
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		}

		// Calculate Dot3 light direction
		CalculateDot3LightDirection(LightVector);
	}
	else
	{
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_2D);

		glBindTexture(GL_TEXTURE_2D, m_ui32DiffuseMap);
		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);

		LightVector.z = -LightVector.z;
		glLightfv(GL_LIGHT0, GL_POSITION, &LightVector.x);
	}

	glMatrixMode(GL_MODELVIEW);

	// Render mesh
	SPODNode& Node = m_Scene.pNode[0];

	// Rotate the mesh around a point
	mModelView = m_mView * PVRTMat4::RotationY((float) sin(m_i32Frame * 0.003f) - PVRT_PI_OVER_TWOf);
	glLoadMatrixf(mModelView.f);

	DrawMesh(Node.nIdx);

	// Disable the second layer of texturing
	if(m_bDrawWithDot3)
	{
		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
	}
	else
		glDisable(GL_LIGHTING);


	// Display info text
	m_Print3D.DisplayDefaultTitle("PolyBump", m_bDrawWithDot3 ? m_pDescription : "Standard GL lighting" , ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	// Increase frame counter
	++m_i32Frame;

	return true;
}