Пример #1
0
/*!****************************************************************************
 @Function		DrawSceneWithShadow
 @Input			viewMat The view matrix to use for rendering
 @Description	Draws the scene with the shadow
******************************************************************************/
void OGLES2ShadowMapping::DrawSceneWithShadow(PVRTMat4 viewMat)
{
	for (unsigned int i = 0; i < m_Scene.nNumMeshNode; ++i)
	{	
		if(i == 1) continue;

		SPODNode& Node = m_Scene.pNode[i];

		PVRTMat4 mWorld, mModelView;
		m_Scene.GetWorldMatrix(mWorld, Node);

		PVRTMatrixMultiply(mModelView, mWorld, viewMat);

		glUniformMatrix4fv(m_ShadowShaderProgram.uiModelViewMatrixLoc, 1, GL_FALSE, mModelView.f);

		// Calculate the light direction for the diffuse lighting
		PVRTVec4 vLightDir;
		PVRTTransformBack(&vLightDir, &m_vLightDirection, &mWorld);
		PVRTVec3 vLightDirModel = *(PVRTVec3*)&vLightDir;
		PVRTMatrixVec3Normalize(vLightDirModel, vLightDirModel);
		glUniform3fv(m_ShadowShaderProgram.uiLightDirLoc, 1, &vLightDirModel.x);

		// Load the correct texture using our texture lookup table
		GLuint uiTex = 0;

		if (Node.nIdxMaterial != -1)
			uiTex = m_puiTextureIDs[Node.nIdxMaterial];

		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, uiTex);

		DrawMesh(i);
	}
}
Пример #2
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;
}