/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2Glass::RenderScene()
{
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))	m_iEffect -= 1;
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))	m_iEffect += 1;
	m_iEffect = (m_iEffect + g_iNumEffects) % g_iNumEffects;

	UpdateScene();

	DrawIntoParaboloids(PVRTVec3(0, 0, 0));

	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Draw the ball
	DrawBall();

	// Draw the balloons
	DrawBalloons(&m_DefaultProgram, m_mProjection, m_mView, m_mModels, 2);

	// Draw the skybox
	DrawSkybox();

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("Glass", g_aszEffectNames[m_iEffect], ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}
Exemple #2
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2Fog::RenderScene()
{
	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Keyboard input (cursor to change fog function)
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_eFogMode = EFogMode((m_eFogMode + eNumFogModes - 1) % eNumFogModes);
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_eFogMode = EFogMode((m_eFogMode + 1) % eNumFogModes);
	}

	// Use the loaded shader program
	glUseProgram(m_ShaderProgram.uiId);

	// Bind texture
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_uiTexture);

	// Set uniforms
	glUniform1i(m_ShaderProgram.uiFogFuncLoc, m_eFogMode);

	// Rotate and translate the model matrix
	PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY);
	m_fAngleY += PVRT_PI / 90;
	mModel.preTranslate(0, 0, 500 * cos(m_fPositionZ) - 450);	
	m_fPositionZ += (2*PVRT_PI)*0.0008f;

	// Feed Projection and Model View matrices to the shaders
	PVRTMat4 mModelView = m_mView * mModel;
	PVRTMat4 mMVP = m_mProjection * mModelView;

	glUniformMatrix4fv(m_ShaderProgram.uiModelViewLoc, 1, GL_FALSE, mModelView.ptr());
	glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr());

	// Pass the light direction transformed with the inverse of the ModelView matrix
	// This saves the transformation of the normals per vertex. A simple dot3 between this direction
	// and the un-transformed normal will allow proper smooth shading.
	PVRTVec3 vMsLightDir = (PVRTMat3(mModel).inverse() * PVRTVec3(1, 1, 1)).normalized();
	glUniform3fv(m_ShaderProgram.uiLightDirLoc, 1, vMsLightDir.ptr());

	/*
		Now that the model-view matrix is set and the materials ready,
		call another function to actually draw the mesh.
	*/
	DrawMesh(0);

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("Fog", "", ePVRTPrint3DLogoIMG);
	m_Print3D.Print3D(0.3f, 7.5f, 0.75f, PVRTRGBA(255,255,255,255), "Fog Mode: %s", g_FogFunctionList[m_eFogMode]);
	m_Print3D.Flush();

	return true;
}
Exemple #3
0
/*!****************************************************************************
 @Function		HandleInput
 @Description	Handles user input and updates live variables accordingly.
******************************************************************************/
void OGLES2Bloom::HandleInput()
{
	// Keyboard input (cursor to change Reflection Flag)
	if (PVRShellIsKeyPressed(PVRShellKeyNameUP) || PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		m_bApplyBloom = !m_bApplyBloom;
	}

	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT) && (m_fBloomIntensity > 0.0f))
		m_fBloomIntensity -= 0.1f;

	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
		m_fBloomIntensity += 0.1f;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES3ComplexLighting::RenderScene()
{
	// Clears the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Keyboard input (cursor to change light)
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_eLightType = ELightType((m_eLightType + eNumLightTypes - 1) % eNumLightTypes);
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_eLightType = ELightType((m_eLightType + 1) % eNumLightTypes);
	}

	// Use shader program
	glUseProgram(m_ShaderProgram.uiId);

	// Bind texture
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_uiTexture);

	glUniform1i(m_ShaderProgram.uiLightSelLoc, m_eLightType);

	// Rotate and Translation the model matrix
	PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY);
	m_fAngleY += PVRT_PI / 150;

	// Set model view projection matrix
	PVRTMat4 mModelView = m_mView * mModel;
	PVRTMat4 mMVP = m_mProjection * mModelView;
	glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr());

	// Set model view matrix
	glUniformMatrix4fv(m_ShaderProgram.uiModelViewLoc, 1, GL_FALSE, mModelView.ptr());

	// Set model view inverse transpose matrix
	PVRTMat3 mModelViewIT = PVRTMat3(mModelView).inverse().transpose();
	glUniformMatrix3fv(m_ShaderProgram.uiModelViewITLoc, 1, GL_FALSE, mModelViewIT.ptr());

	DrawMesh(0);

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("ComplexLighting", c_aszLightTypeList[m_eLightType], ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}
Exemple #5
0
/*!****************************************************************************
 @Function		HandleInput
 @Description	Handles user input and updates live variables accordingly.
******************************************************************************/
void OGLES2ParticleSystem::HandleInput()
{
	// Keyboard input (cursor to change Reflection Flag)

	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		unsigned int numParticles = m_pParticleSystem->GetNumberOfParticles();			
		if (numParticles / 2 >= g_ui32MinNoParticles)
			if (!m_pParticleSystem->SetNumberOfParticles(numParticles/2))
				PVRShellOutputDebug("Error: Failed decreasing number of particles to %d\n", numParticles/2);
	}

	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		unsigned int numParticles = m_pParticleSystem->GetNumberOfParticles();		
		if (numParticles * 2 <= g_ui32MaxNoParticles)
			if (!m_pParticleSystem->SetNumberOfParticles(numParticles*2))
				PVRShellOutputDebug("Error: Failed increasing number of particles to %d\n", numParticles/2);
	}	
}
Exemple #6
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occurred
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevant OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2Shaders::RenderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Keyboard input (cursor to change shaders and meshes)
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_nCurrentShader--;
		if(m_nCurrentShader<0) m_nCurrentShader=(g_numShaders-1);
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_nCurrentShader++;
		if(m_nCurrentShader>(g_numShaders-1)) m_nCurrentShader=0;
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		m_nCurrentSurface--;
		if(m_nCurrentSurface<0) m_nCurrentSurface=(g_numSurfaces-1);
		ComputeSurface(m_nCurrentSurface);
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		m_nCurrentSurface++;
		if(m_nCurrentSurface>(g_numSurfaces-1)) m_nCurrentSurface=0;
		ComputeSurface(m_nCurrentSurface);
	}

	// Draw the mesh
	ComputeViewMatrix();
	DrawModel();

	// Display screen info
	m_Print3D.DisplayDefaultTitle("Shaders", NULL, ePVRTPrint3DSDKLogo);
	m_Print3D.Print3D(0.3f, 7.5f, 0.75f, 0xFFFFFFFF, "Shader: %s\nMesh: %s", g_ShaderList[m_nCurrentShader], g_SurfacesList[m_nCurrentSurface]);
	m_Print3D.Flush();

	return true;
}
Exemple #7
0
/*!****************************************************************************
 @Function		Update
 @Description	Handles user input and updates all timing data.
******************************************************************************/
void OGLES3ShadowMapping::Update()
{
	if (PVRShellIsKeyPressed(PVRShellKeyNameSELECT)) m_bDebug = !m_bDebug;
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) m_fBias *= 0.9f;
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) m_fBias *= 1.1f;

	// Calculates the frame number to animate in a time-based manner.
	// Uses the shell function PVRShellGetTime() to get the time in milliseconds.
	static unsigned long ulTimePrev = PVRShellGetTime();
	unsigned long ulTime = PVRShellGetTime();
	unsigned long ulDeltaTime = ulTime - ulTimePrev;
	ulTimePrev = ulTime;
	static float fFrame = 0;
	if (!m_bDebug)
		fFrame += (float)ulDeltaTime * 0.05f;

	if (fFrame > m_Scene.nNumFrame-1)
		fFrame = 0;

	// Update the animation data
	m_Scene.SetFrame(fFrame);

	PVRTVec3 vFrom, vTo, vUp;	
	float fFOV = m_Scene.GetCamera(vFrom, vTo, vUp, 0) * 0.75f;
		

	m_mProjection = PVRTMat4::PerspectiveFovRH(fFOV, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), m_Scene.pCamera[0].fNear, m_Scene.pCamera[0].fFar, PVRTMat4::OGL, m_bRotate);
	m_mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp);
	
	m_Scene.GetLight(m_vLightPosition, m_vLightDirection, 0);
	
	PVRTVec3 lightFrom, lightTo, lightUp;
	m_Scene.GetCamera(lightFrom, lightTo, lightUp, 1);
	m_mLightView = PVRTMat4::LookAtRH(lightFrom, lightTo, lightUp);
	m_mLightProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI_OVER_TWO, 1.0f, m_Scene.pCamera[1].fNear, m_Scene.pCamera[1].fFar, PVRTMat4::OGL, m_bRotate);	
}
/*!****************************************************************************
 @Function		HandleInput
 @Description	Handles user input and updates live variables accordingly.
******************************************************************************/
bool OGLES2ProceduralTextures::HandleInput()
{
	static unsigned long prevTime = PVRShellGetTime();
	unsigned long curTime = PVRShellGetTime();
	unsigned long deltaTime = curTime - prevTime;

	if (m_bDemoMode && deltaTime > 2500)
	{
		prevTime = curTime;
		m_uiVisualisation++;
		if (m_uiVisualisation == NUM_VISUALISATIONS)
		{
			m_uiVisualisation = 0;
			m_uiGenerator = (m_uiGenerator + 1) % NUM_GENERATORS;
		}

		return GenerateFnTexture();
	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT) || (m_bDemoMode && deltaTime > 5000))
	{
		m_uiGenerator = (m_uiGenerator + 1) % NUM_GENERATORS;
		return GenerateFnTexture();

	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		if (m_uiGenerator > 0)
		{ m_uiGenerator = (m_uiGenerator - 1) % NUM_GENERATORS; }
		else
		{ m_uiGenerator = NUM_GENERATORS - 1; }
		return GenerateFnTexture();
	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		m_uiVisualisation = (m_uiVisualisation + 1) % NUM_VISUALISATIONS;
	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		if (m_uiVisualisation > 0)
		{ m_uiVisualisation--; }
		else
		{ m_uiVisualisation = NUM_VISUALISATIONS - 1; }
	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameACTION1))
	{
		m_Scalars[m_uiGenerator] *= 0.95f;
		GenerateFnTexture();
	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameACTION2))
	{
		m_Scalars[m_uiGenerator] *= 1.05f;
		GenerateFnTexture();
	}

	return true;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important and relevant OS events.
				The user has access to these events through an abstraction
				layer provided by PVRShell.
******************************************************************************/
bool OGLES3EdgeDetection::RenderScene()
{
	// Declares world orientation variables.
	PVRTMat4 mWorld, mMVP;

	// Updates the current time.
	m_ulCurrentTime=PVRShellGetTime();

#ifdef SHOW_MAX_FPS
	//Updates and checks framerate.
	m_iFrameCount+=1;
	if (m_ulCurrentTime-m_ulPreviousTimeFPS>=1000)
	{
		m_fFPS=(GLfloat)m_iFrameCount/(GLfloat)(m_ulCurrentTime-m_ulPreviousTimeFPS)*1000.0f;
		m_ulPreviousTimeFPS=m_ulCurrentTime;
		m_iFrameCount=0;
	}
	// Display fps data
	m_Print3D.Print3D(2.0f, 10.0f, 0.75f, 0xff0000ff, "%i fps", (int)m_fFPS);
#endif

	// Time dependant updates for the rotational velocity of the scene.
	m_fAngleY += 0.0002f*PVRT_PI*(m_ulCurrentTime-m_ulPreviousTimeAngle);
	m_ulPreviousTimeAngle=PVRShellGetTime();

	// Render to our texture (bracketed for viewing convenience)
	{
		// Use the first shader program to perform the initial render of the mask.
		glUseProgram(m_PreShader.uiId);

		// Bind render-to-texture frame buffer and set the viewPort
		glBindFramebuffer(GL_FRAMEBUFFER, m_uiFramebufferObject);

		if(m_i32TexWidth != m_i32WinWidth || m_i32TexHeight != m_i32WinHeight)
			glViewport(0, 0, m_i32TexWidth, m_i32TexHeight);

#if defined(__PALMPDK__)
		// Enable writing to the alpha channel again as usually it is disabled so
		// we don't blend with the video layer on webOS devices.
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
#endif
		// Clear the color and depth buffer of our FBO
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// Rotates the scene and sets the model-view-projection matrix
		mWorld = PVRTMat4::RotationY(m_fAngleY);
		mMVP = m_mR2TProjection * m_mR2TView * mWorld;

		// Send the view matrix information to the shader.
		glUniformMatrix4fv(m_PreShader.auiLoc[eMVPMatrix], 1, GL_FALSE, mMVP.f);

		// Enable vertex attribute array
		glEnableVertexAttribArray(eVERTEX_ARRAY);

		//Enable depth testing and culling.
		glEnable(GL_DEPTH_TEST);
		glFrontFace(GL_CCW);
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);

		// Draw our models by looping through each mesh as defined by nNumMesh.
		for (unsigned int i=0; i<m_Scene.nNumMeshNode; i++)
		{
			DrawMesh(i);
		}

		// Unbind the VBO and index buffer.
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_CULL_FACE);

		//Invalidate the framebuffer attachments we don't need to avoid unnecessary copying to system memory
		const GLenum attachment = GL_DEPTH_ATTACHMENT;
		glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, &attachment);
	}

	// Bind the original frame buffer to draw to screen and set the Viewport.
	glBindFramebuffer(GL_FRAMEBUFFER, m_i32OriginalFramebuffer);

	if(m_i32TexWidth != m_i32WinWidth || m_i32TexHeight != m_i32WinHeight)
		glViewport(0, 0, m_i32WinWidth, m_i32WinHeight);

	// Clear the color and depth buffers for the screen.
	glClear(GL_COLOR_BUFFER_BIT);

	// Uses PVRShell input handling to update the line width in the edge detection shaders.
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_fLineWidth++;
		if (m_fLineWidth>10) m_fLineWidth=10;
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_fLineWidth--;
		if (m_fLineWidth<1) m_fLineWidth=1;
	}
	// Uses PVRShell input to choose which post shader program to use for post processing.
	// Loops through all shaders defined in EPostShaders
	if (PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		if (m_uiShaderID==eNumPostShaders-1) m_uiShaderID=0;
		else m_uiShaderID++;
	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		if (m_uiShaderID==0) m_uiShaderID=eNumPostShaders-1;
		else m_uiShaderID--;
	}

	// Sets the shader based on the shader ID value, and sets the line width each frame (as it can change);
	glUseProgram(m_PostShaders[m_uiShaderID].uiId);
	glUniform2f(m_PostShaders[m_uiShaderID].auiLoc[ePixelSize],m_fLineWidth/(float)m_i32TexWidth,m_fLineWidth/(float)m_i32TexHeight);

	/*  Note: We do not need to pass any projection data to these shaders as they are used only to render a texture to a
		full screen quad which is parallel with the viewport. The model meshes have already been positioned in the previous
		shader and now only exist as a 2D image.*/

	// Enable texture attribute array
	glEnableVertexAttribArray(eTEXCOORD_ARRAY);
	// Draw the fullscreen quad to render the screen to.
	DrawQuad();

	// Disable the vertex and texture attribute arrays
	glDisableVertexAttribArray(eTEXCOORD_ARRAY);
	glDisableVertexAttribArray(eVERTEX_ARRAY);

	// Print the demo title, current post shader's name and the line width if applicable
	m_Print3D.DisplayDefaultTitle("Edge Detection", "", ePVRTPrint3DSDKLogo);
	m_Print3D.Print3D(5,80,1,0xff885500,g_aszPostShaderNames[m_uiShaderID]);
	if (!strcmp(c_aszPostShaderDefines[m_uiShaderID][0],"EDGE_DETECTION"))
		m_Print3D.Print3D(5,90,0.7f,0xff000055,"Line Width = %i", (int)m_fLineWidth);
	m_Print3D.Flush();

	return true;
}
/*******************************************************************************
 * 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;
}
Exemple #11
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 CStrokeStyles::RenderScene()
{
	/*
		If the left or right arrow keys are pressed then change the
		CapStyle or JoinStyle or DashStyle depending on which one is
		selected.
	*/
	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		switch(m_i32Selected)
		{
			case 0: m_i32CapStyle  = (m_i32CapStyle +  2) % 3; break;
			case 1: m_i32JoinStyle = (m_i32JoinStyle + 2) % 3; break;
			case 2: m_i32DashStyle = (m_i32DashStyle + 2) % 3; break;
		}
	}
	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		switch(m_i32Selected)
		{
			case 0: m_i32CapStyle  = (m_i32CapStyle +  1) % 3; break;
			case 1: m_i32JoinStyle = (m_i32JoinStyle + 1) % 3; break;
			case 2: m_i32DashStyle = (m_i32DashStyle + 1) % 3; break;
		}
	}

	/*
		If the up or down arrow is pressed then change which item is
		selected.
	*/
	if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
		m_i32Selected = (m_i32Selected + 2) % 3;

	if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
		m_i32Selected = (m_i32Selected + 1) % 3;

	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();
	vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight));

	// Clear the screen with clear colour.
	vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight));

	// Draw the path with the stroke styles that we want
	vgSeti(VG_STROKE_CAP_STYLE  , VG_CAP_BUTT   + m_i32CapStyle);
	vgSeti(VG_STROKE_JOIN_STYLE , VG_JOIN_MITER + m_i32JoinStyle);
	vgSetf(VG_STROKE_MITER_LIMIT, m_fMiterLimit * PVRShellGet(prefHeight));

	if(m_i32DashStyle > 0)
	{
		vgSetf(VG_STROKE_DASH_PHASE, m_fDashPhase);

		static float s_afDashes[] = { 0.1f, 0.15f, 0.23f, 0.11f };
		vgSetfv(VG_STROKE_DASH_PATTERN, 4, s_afDashes);

		if(m_i32DashStyle == 2)
			m_fDashPhase += 0.01f;
	}
	else
	{
		vgSetfv(VG_STROKE_DASH_PATTERN, 0, NULL);
	}

	vgSetf(VG_STROKE_LINE_WIDTH, 20.0f / PVRShellGet(prefHeight));

	vgDrawPath(m_vgPath, VG_STROKE_PATH);

	/*	Draw the text.

		If one of the pieces of text is currently selected then it will be
		drawn in yellow.
	*/

	static char* apszCapStrings[]  = { "Butt", "Round", "Square" };
	static char* apszJoinStrings[] = { "Miter", "Round", "Bevel" };
	static char* apszDashStrings[] = { "None", "Pattern", "Moving" };

	m_PrintVG.DisplayDefaultTitle("StrokeStyles", "", ePVRTPrint3DLogoIMG);

	float fHeight = PVRShellGet(prefHeight) - 40.0f;

	/*
		Draw the Cap text.
	*/
	m_PrintVG.DrawString(2.0f , fHeight, 0.6f, "Cap:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszCapStrings[m_i32CapStyle],
			m_i32Selected == 0 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	/*
		Draw the Join text.
	*/
	fHeight -= 20.0f;
	m_PrintVG.DrawString(2.0f, fHeight, 0.6f, "Join:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszJoinStrings[m_i32JoinStyle],
			m_i32Selected == 1 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	/*
		Draw the Dash text.
	*/
	fHeight -= 20.0f;
	m_PrintVG.DrawString(2.0f,fHeight, 0.6f, "Dash:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszDashStrings[m_i32DashStyle],
			m_i32Selected == 2 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	return true;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2Iridescence::RenderScene()
{
	// Keyboard input (cursor up/down to change thickness variation)
	if (PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		m_fMaxVariation += 1.0f;
	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		m_fMaxVariation = PVRT_MAX(0.0f, m_fMaxVariation - 1.0f);
	}

	// Keyboard input (cursor left/right to change minimum thickness)
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_fMinThickness += 1.0f;
	}
	else if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_fMinThickness = PVRT_MAX(0.0f, m_fMinThickness - 1.0f);
	}

	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Use shader program
	glUseProgram(m_ShaderProgram.uiId);

	// Bind texture
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_uiTexture);

	// Rotate and Translation the model matrix
	PVRTMat4 mModel;
	mModel = PVRTMat4::RotationY(m_fAngleY);
	m_fAngleY += (2*PVRT_PI/60)/7;

	// Set model view projection matrix
	PVRTMat4 mModelView, mMVP;
	mModelView = m_mView * mModel;
	mMVP =  m_mProjection * mModelView;
	glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr());

	// Set light direction in model space
	PVRTVec4 vLightDirModel;
	vLightDirModel = mModel.inverse() * PVRTVec4(1, 1, 1, 0);

	glUniform3fv(m_ShaderProgram.uiLightDirLoc, 1, &vLightDirModel.x);

	// Set eye position in model space
	PVRTVec4 vEyePosModel;
	vEyePosModel = mModelView.inverse() * PVRTVec4(0, 0, 0, 1);
	glUniform3fv(m_ShaderProgram.uiEyePosLoc, 1, &vEyePosModel.x);

	/*
		Set the iridescent shading parameters
	*/
	// Set the minimum thickness of the coating in nm
	glUniform1f(m_ShaderProgram.uiMinThicknessLoc, m_fMinThickness);

	// Set the maximum variation in thickness of the coating in nm
	glUniform1f(m_ShaderProgram.uiMaxVariationLoc, m_fMaxVariation);

	/*
		Now that the uniforms are set, call another function to actually draw the mesh.
	*/
	DrawMesh(0);

	m_Print3D.Print3D(2.0f, 10.0f, 0.75f, 0xffffffff, "Minimum Thickness:");
	m_Print3D.Print3D(2.0f, 15.0f, 0.75f, 0xffffffff, "%8.0f nm", m_fMinThickness);
	m_Print3D.Print3D(2.0f, 20.0f, 0.75f, 0xffffffff, "Maximum Variation:");
	m_Print3D.Print3D(2.0f, 25.0f, 0.75f, 0xffffffff, "%8.0f nm", m_fMaxVariation);

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("Iridescence", "", ePVRTPrint3DLogoIMG);
	m_Print3D.Flush();

	return true;
}
Exemple #13
0
void SEDemo::handleInput(int width, int height)
{
    static float prevPointer[2];
    static bool bPressed = false;
    int buttonState = PVRShellGet(prefButtonState);
    float* pointerLocation = (float*)PVRShellGet(prefPointerLocation);
    /*LOGI("## buttonstate = %d ##\n", buttonState);*/
    if(pointerLocation)
    {
		//LOGI("### pointer location = %f, %f ###\n", pointerLocation[0], pointerLocation[1]);
        prevPointer[0] = pointerLocation[0];
        prevPointer[1] = pointerLocation[1];
    }
    if((buttonState & ePVRShellButtonLeft))
    {
		SE_MotionEventCommand* c = (SE_MotionEventCommand*)SE_Application::getInstance()->createCommand("SE_MotionEventCommand");
		if(c)
		{
			SE_MotionEvent* ke = new SE_MotionEvent(SE_MotionEvent::DOWN, prevPointer[0] * width, prevPointer[1] * height);
			c->motionEvent = ke;
			SE_Application::getInstance()->postCommand(c);
		}
	    bPressed = 1;
    }
    else if(bPressed)
    {
        SE_MotionEventCommand* c = (SE_MotionEventCommand*)SE_Application::getInstance()->createCommand("SE_MotionEventCommand");
		if(c)
		{
			SE_MotionEvent* ke = new SE_MotionEvent(SE_MotionEvent::UP, prevPointer[0] * width, prevPointer[1] * height);
			c->motionEvent = ke;
			SE_Application::getInstance()->postCommand(c);
		}
        bPressed = 0;
    }
    if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
    {
		/*
		if(mSelectedSpatial)
		{
            SE_ElementManager* elementManager = SE_Application::getInstance()->getElementManager();
			SE_Element* element = elementManager->findByName(mSelectedSpatial->getElementID().getStr());
            if(element)
            {
                SE_Animation* anim = element->getAnimation();
				if(anim)
				{
					SE_Animation* newAnim = anim->clone();
                    SE_AnimationManager* animationManager = SE_Application::getInstance()->getAnimationManager();
					SE_AnimationID animID = mSelectedSpatial->getAnimationID();
					animationManager->removeAnimation(animID);
					animID = animationManager->addAnimation(newAnim);
			        mSelectedSpatial->setAnimationID(animID);
                    newAnim->run();
				}
			}
        }
		else
		{
			SE_SceneManager* sceneManager = SE_Application::getInstance()->getSceneManager();
	        SE_Spatial* root = sceneManager->getRoot();
	        SE_RunAllAnimationTravel rat;
	        root->travel(&rat, true);
		}
		*/
		SE_ElementManager* elementManager = SE_Application::getInstance()->getElementManager();
		SE_Element* root = elementManager->getRoot();
		root->startAnimation();
        LOGI("## left ##\n");
    }
    else if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
    {
		if(mSelectedSpatial)
		{
		    SE_AnimationID animID = mSelectedSpatial->getAnimationID();
		    SE_AnimationManager* animManager = SE_Application::getInstance()->getAnimationManager();
		    SE_Animation* anim = animManager->getAnimation(animID);
			if(anim)
		        anim->nextFrame(30, 30);
		}
        LOGI("## right ##\n");
    }
    else if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
    {
		if(mSelectedSpatial)
		{
			SE_PauseAllAnimationTravel rat;
			mSelectedSpatial->travel(&rat, true);
		}
		else
		{
            SE_SceneManager* sceneManager = SE_Application::getInstance()->getSceneManager();
	        SE_Spatial* root = sceneManager->getRoot();
	        SE_PauseAllAnimationTravel rat;
	        root->travel(&rat, true);
		}
  	    LOGI("## up ##\n");
    }
    else if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
    {
		SE_SceneManager* sceneManager = SE_Application::getInstance()->getSceneManager();
		sceneManager->setSelectedSpatial(NULL);
		mSelectedSpatial = NULL;
	    LOGI("## down ##\n");
    }
}
Exemple #14
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLESFur::RenderScene()
{
	// Reset the states that print3D changes
	glDisable(GL_CULL_FACE);
	glEnable(GL_FOG);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);

	//	User input
	bool bNewPage = false;

	if(PVRShellIsKeyPressed(PVRShellKeyNameSELECT))
		m_bPause = !m_bPause;

	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		if(--m_i32WndPage < 0)
			m_i32WndPage = 5;

		bNewPage = true;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		if(++m_i32WndPage > 5)
			m_i32WndPage = 0;

		bNewPage = true;
	}

	if(bNewPage)
	{
		switch(m_i32WndPage)
		{
			case 0:
				m_bViewMode = false;
				m_i32FurShellNo = 7;
				break;
			case 1:
				m_bViewMode = true;
				m_i32FurShellNo = 0;
				break;
			case 2:
				m_bViewMode = true;
				m_i32FurShellNo = 1;
				break;
			case 3:
				m_bViewMode = true;
				m_i32FurShellNo = 2;
				break;
			case 4:
				m_bViewMode = true;
				m_i32FurShellNo = 7;
				break;
			case 5:
				m_bViewMode = false;
				m_i32FurShellNo = 7;
				break;
		}

		// Since the number of fur shells has changed, update them
		UpdateFurShells();
	}

	// Clear
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Animation
	DoAnimation();

	// View matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(m_mView.f);

	// Enable the vertex and normal arrays
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	// Begin Scene
	if(!m_bViewMode)
		DrawEnvironment();

	// Draw the Duck
	DrawDuck();

	// Display Paused if the app is paused
	if(m_bPause)
		m_Print3D.Print3D(78.0f, 2.0f, 1.0f, PVRTRGBA(255,255,255,255), "Paused");

	// Disable the normals before our drawing of the print3D content
	glDisableClientState(GL_NORMAL_ARRAY);
	
	char szDesc[256];
	snprintf(szDesc, 256, "Displaying %d shells", m_i32FurShellNo);

	// Display the IMG logo
	m_Print3D.DisplayDefaultTitle("Fur", szDesc, ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();
	return true;
}
Exemple #15
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 OGLESOptimizeMesh::RenderScene()
{
	unsigned long ui32Time;

	// Clear the depth and frame buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//	Time
	ui32Time = PVRShellGetTime();
	m_ui32TimeDiff = ui32Time - m_ui32LastTime;
	m_ui32LastTime = ui32Time;

	// FPS
	++m_ui32FPSFrameCnt;
	m_ui32FPSTimeDiff += m_ui32TimeDiff;

	if(m_ui32FPSTimeDiff >= g_ui32TimeFPSUpdate)
	{
		m_fFPS = m_ui32FPSFrameCnt * 1000.0f / (float) m_ui32FPSTimeDiff;
		m_ui32FPSFrameCnt = 0;
		m_ui32FPSTimeDiff = 0;
	}

	// Change mode when necessary
	m_ui32SwitchTimeDiff += m_ui32TimeDiff;

	if((m_ui32SwitchTimeDiff > g_ui32TimeAutoSwitch) || PVRShellIsKeyPressed(PVRShellKeyNameACTION1))
	{
		m_ui32SwitchTimeDiff = 0;
		++m_i32Page;

		if(m_i32Page >= (int) m_ui32PageNo)
			m_i32Page = 0;
	}

	PVRTVec3 From;
	float fFactor;

	From.x = g_fViewDistance * PVRTSIN(m_fViewAngle);
	From.y = 0.0f;
	From.z = g_fViewDistance * PVRTCOS(m_fViewAngle);

	// Increase the rotation
	fFactor = 0.005f * (float) m_ui32TimeDiff;
	m_fViewAngle += fFactor;

	// Ensure it doesn't grow huge and lose accuracy over time
	while(m_fViewAngle > PVRT_PI)
		m_fViewAngle -= PVRT_TWO_PI;

	// Compute and set the matrix
	m_mView = PVRTMat4::LookAtRH(From, PVRTVec3(0,0,0), PVRTVec3(0,1,0));

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(m_mView.f);

	// Setup the lighting
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	PVRTVec4 vLightDir(From.x, From.y, From.z, 0);
	vLightDir = vLightDir.normalize();

	// Set the light direction
	glLightfv(GL_LIGHT0, GL_POSITION, vLightDir.ptr());
	glLightfv(GL_LIGHT0, GL_DIFFUSE, PVRTVec4(0.8f,0.8f,0.8f,1.0f).ptr());

	// Draw the model
	DrawModel(m_i32Page);

	// Display the frame rate
	CPVRTString title;
	const char * pDesc;

	title = PVRTStringFromFormattedStr("Optimize Mesh %.1ffps", m_fFPS);

	// Print text on screen
	switch(m_i32Page)
	{
	default:
		pDesc = "Indexed Tri List: Unoptimized";
		break;
	case 1:
		pDesc = "Indexed Tri List: Optimized (at export time)";
		break;
	}

	m_Print3D.DisplayDefaultTitle(title.c_str(), pDesc, ePVRTPrint3DSDKLogo);

	// Flush all Print3D commands
	m_Print3D.Flush();

	return true;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES3Refraction::RenderScene()
{
	// Keyboard input (cursor to change Reflection Flag)
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT) || PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_bSpecular = !m_bSpecular;
	}

	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	m_Background.Draw(m_uiTexture);

	// Enable backface culling and depth test
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);

	// Use shader program
	glUseProgram(m_ShaderProgram.uiId);

	// Bind textures
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_uiTexture);

	// Calculate the model matrix
	PVRTMat4 mRotX, mRotY, mModel;
	mRotX = PVRTMat4::RotationX(m_fAngleX);
	mRotY = PVRTMat4::RotationY(m_fAngleY);
	mModel = mRotX * mRotY;

	m_fAngleX += PVRT_PI / 111;
	m_fAngleY += PVRT_PI / 150;

	// Set model view projection matrix
	PVRTMat4 mModelView, mMVP;
	mModelView = m_mView * mModel;
	mMVP = m_mProjection * mModelView;

	glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMVPMatrix], 1, GL_FALSE, mMVP.ptr());

	// Set light direction in model space
	PVRTVec4 vLightDirModel;
	vLightDirModel =  mModelView.inverse() * PVRTVec4(0.57735f, 0.57735f, 0.57735f, 0);

	glUniform3fv(m_ShaderProgram.auiLoc[eLightDirModel], 1, &vLightDirModel.x);

	// Set eye position in model space
	PVRTVec4 vEyePosModel;
	vEyePosModel = mModelView.inverse() * PVRTVec4(0, 0, 0, 1);

	glUniform3fv(m_ShaderProgram.auiLoc[eEyePosModel], 1, &vEyePosModel.x);

	// Set specular flag
	glUniform1i(m_ShaderProgram.auiLoc[eSpecular], m_bSpecular);

	// Set rotation flag
	glUniform1i(m_ShaderProgram.auiLoc[eRotate], m_bRotate);

	/*
		Now that the uniforms are set, call another function to actually draw the mesh.
	*/
	DrawMesh(0);

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("Refraction", m_bSpecular ? "Specular reflection: on" : "Specular reflection: off", ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();
	return true;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLESPVRScopeExample::RenderScene()
{
	// Keyboard input (cursor up/down to cycle through counters)
	if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		m_i32Counter++;

		if(m_i32Counter > (int) m_pScopeGraph->GetCounterNum())
			m_i32Counter = m_pScopeGraph->GetCounterNum();
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		m_i32Counter--;

		if(m_i32Counter < 0)
			m_i32Counter = 0;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameACTION2))
		m_pScopeGraph->ShowCounter(m_i32Counter, !m_pScopeGraph->IsCounterShown(m_i32Counter));

	// Keyboard input (cursor left/right to change active group)
	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_pScopeGraph->SetActiveGroup(m_pScopeGraph->GetActiveGroup()+1);
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_pScopeGraph->SetActiveGroup(m_pScopeGraph->GetActiveGroup()-1);
	}

	// Clears the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Loads the projection matrix
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(m_mProjection.f);

	// Specify the modelview matrix
	PVRTMat4 mModel;
	SPODNode& Node = m_Scene.pNode[0];

	m_Scene.GetWorldMatrix(mModel, Node);

	// Rotate and Translate the model matrix
	m_fAngleY += (2*PVRT_PIf/60)/7;

	// Set model view projection matrix
	PVRTMat4 mModelView;
	mModelView = m_mView * PVRTMat4::RotationY(m_fAngleY) * mModel;

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(mModelView.f);

	/*
		Load the light direction from the scene if we have one
	*/

	// Enables lighting. See BasicTnL for a detailed explanation
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	// Set light direction
	PVRTVec4 vLightDirModel;
	vLightDirModel = mModel.inverse() * PVRTVec4(1, 1, 1, 0);
	glLightfv(GL_LIGHT0, GL_POSITION, (float*)&vLightDirModel.x);

	// Enable the vertex position attribute array
	glEnableClientState(GL_VERTEX_ARRAY);

	// bind the texture
	glBindTexture(GL_TEXTURE_2D, m_uiTexture);

	/*
		Now that the model-view matrix is set and the materials are ready,
		call another function to actually draw the mesh.
	*/
	DrawMesh(Node.nIdx);

	// Disable the vertex positions
	glDisableClientState(GL_VERTEX_ARRAY);

	char Description[256];

	if(m_pScopeGraph->GetCounterNum())
	{
		sprintf(Description, "Active Grp %i\n\nCounter %i (Grp %i) \nName: %s\nShown: %s\nuser y-axis: %.2f  max: %.2f%s",
			m_pScopeGraph->GetActiveGroup(), m_i32Counter,
			m_pScopeGraph->GetCounterGroup(m_i32Counter),
			m_pScopeGraph->GetCounterName(m_i32Counter),
			m_pScopeGraph->IsCounterShown(m_i32Counter) ? "Yes" : "No",
			m_pScopeGraph->GetMaximum(m_i32Counter),
			m_pScopeGraph->GetMaximumOfData(m_i32Counter),
			m_pScopeGraph->IsCounterPercentage(m_i32Counter) ? "%%" : "");
	}
	else
	{
		sprintf(Description, "No counters present");
	}

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("PVRScopeExample", Description, ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	// Update counters and draw the graph
	m_pScopeGraph->Ping();

	return true;
}
Exemple #18
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occurred
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevant OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES3PhantomMask::RenderScene()
{
    if(PVRShellIsKeyPressed(PVRShellKeyNameACTION1))
        m_bEnableSH = !m_bEnableSH;

    // Clear the colour and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Draw the background
    m_Background.Draw(m_ui32TexBackground);

    // Enable culling
    glEnable(GL_CULL_FACE);

    // Enable depth testing
    glEnable(GL_DEPTH_TEST);

    // Use shader program
    GLuint ProgramID, MVPLoc, ModelLoc;

    if(m_bEnableSH)
    {
        ProgramID = m_SHShaderProgram.uiId;
        MVPLoc	  = m_SHShaderProgram.auiLoc[eSHMVPMatrix];
        ModelLoc  = m_SHShaderProgram.auiLoc[eSHModel];
    }
    else
    {
        ProgramID = m_DiffuseShaderProgram.uiId;
        MVPLoc	  = m_DiffuseShaderProgram.auiLoc[eDifMVPMatrix];
        ModelLoc  = m_DiffuseShaderProgram.auiLoc[eDifModel];
    }

    glUseProgram(ProgramID);

    /*
    	Calculates the frame number to animate in a time-based manner.
    	Uses the shell function PVRShellGetTime() to get the time in milliseconds.
    */
    unsigned long ulTime = PVRShellGetTime();

    if(ulTime > m_ulTimePrev)
    {
        unsigned long ulDeltaTime = ulTime - m_ulTimePrev;
        m_fFrame += (float)ulDeltaTime * g_fDemoFrameRate;

        if(m_fFrame > m_Scene.nNumFrame - 1)
            m_fFrame = 0;

        // Sets the scene animation to this frame
        m_Scene.SetFrame(m_fFrame);
    }

    m_ulTimePrev = ulTime;

    /*
    	Set up the view and projection matrices from the camera
    */
    PVRTMat4 mView, mProjection;
    PVRTVec3	vFrom, vTo(0.0f), vUp(0.0f, 1.0f, 0.0f);
    float fFOV;

    // Setup the camera
    bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

    // Camera nodes are after the mesh and light nodes in the array
    int i32CamID = m_Scene.pNode[m_Scene.nNumMeshNode + m_Scene.nNumLight + g_ui32Camera].nIdx;

    // Get the camera position, target and field of view (fov)
    if(m_Scene.pCamera[i32CamID].nIdxTarget != -1) // Does the camera have a target?
        fFOV = m_Scene.GetCameraPos( vFrom, vTo, g_ui32Camera); // vTo is taken from the target node
    else
        fFOV = m_Scene.GetCamera( vFrom, vTo, vUp, g_ui32Camera); // vTo is calculated from the rotation

    fFOV *= bRotate ? (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight) : (float)PVRShellGet(prefHeight)/(float)PVRShellGet(prefWidth);

    // We can build the model view matrix from the camera position, target and an up vector.
    // For this we usePVRTMat4LookAtRH()
    mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp);

    // Calculate the projection matrix
    mProjection = PVRTMat4::PerspectiveFovRH(fFOV, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate);

    SPODNode& Node = m_Scene.pNode[0];

    // Get the node model matrix
    PVRTMat4 mWorld;
    mWorld = m_Scene.GetWorldMatrix(Node);

    // Set the model inverse transpose matrix
    PVRTMat3 mMat3 = PVRTMat3(mWorld);

    if(m_bEnableSH)
        mMat3 *= PVRTMat3::RotationY(-1.047197f);

    glUniformMatrix3fv(ModelLoc, 1, GL_FALSE, mMat3.f);

    // Pass the model-view-projection matrix (MVP) to the shader to transform the vertices
    PVRTMat4 mModelView, mMVP;
    mModelView = mView * mWorld;
    mMVP = mProjection * mModelView;
    glUniformMatrix4fv(MVPLoc, 1, GL_FALSE, mMVP.f);

    glBindTexture(GL_TEXTURE_2D, m_ui32TexMask);
    DrawMesh(Node.nIdx);

    // Print text on screen

    if(m_bEnableSH)
    {
        // Base
        m_Print3D.DisplayDefaultTitle("PhantomMask", "Spherical Harmonics Lighting", ePVRTPrint3DSDKLogo);
    }
    else
    {
        // Base
        m_Print3D.DisplayDefaultTitle("PhantomMask", "Vertex Lighting", ePVRTPrint3DSDKLogo);
    }

    m_Print3D.Flush();

    return true;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2PVRScopeExample::RenderScene()
{
	// Keyboard input (cursor up/down to cycle through counters)
	if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		m_i32Counter++;

		if(m_i32Counter > (int) m_pScopeGraph->GetCounterNum())
			m_i32Counter = m_pScopeGraph->GetCounterNum();
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		m_i32Counter--;

		if(m_i32Counter < 0)
			m_i32Counter = 0;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameACTION2))
		m_pScopeGraph->ShowCounter(m_i32Counter, !m_pScopeGraph->IsCounterShown(m_i32Counter));

	// Keyboard input (cursor left/right to change active group)
	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_pScopeGraph->SetActiveGroup(m_pScopeGraph->GetActiveGroup()+1);
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_pScopeGraph->SetActiveGroup(m_pScopeGraph->GetActiveGroup()-1);
	}

	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Use shader program
	glUseProgram(m_ShaderProgram.uiId);

	// Bind texture
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_uiTexture);

	// Rotate and Translation the model matrix
	PVRTMat4 mModel;
	mModel = PVRTMat4::RotationY(m_fAngleY);
	m_fAngleY += (2*PVRT_PI/60)/7;

	// Set model view projection matrix
	PVRTMat4 mModelView, mMVP;
	mModelView = m_mView * mModel;
	mMVP =  m_mProjection * mModelView;
	glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr());

	// Set light direction in model space
	PVRTVec4 vLightDirModel;
	vLightDirModel = mModel.inverse() * PVRTVec4(1, 1, 1, 0);

	glUniform3fv(m_ShaderProgram.uiLightDirLoc, 1, &vLightDirModel.x);

	// Set eye position in model space
	PVRTVec4 vEyePosModel;
	vEyePosModel = mModelView.inverse() * PVRTVec4(0, 0, 0, 1);
	glUniform3fv(m_ShaderProgram.uiEyePosLoc, 1, &vEyePosModel.x);

	/*
		Set the iridescent shading parameters
	*/
	// Set the minimum thickness of the coating in nm
	glUniform1f(m_ShaderProgram.uiMinThicknessLoc, m_fMinThickness);

	// Set the maximum variation in thickness of the coating in nm
	glUniform1f(m_ShaderProgram.uiMaxVariationLoc, m_fMaxVariation);

	/*
		Now that the uniforms are set, call another function to actually draw the mesh.
	*/
	DrawMesh(0);

	char Description[256];

	if(m_pScopeGraph->GetCounterNum())
	{
		sprintf(Description, "Active Grp %i\n\nCounter %i (Grp %i) \nName: %s\nShown: %s\nuser y-axis: %.2f  max: %.2f%s",
			m_pScopeGraph->GetActiveGroup(), m_i32Counter,
			m_pScopeGraph->GetCounterGroup(m_i32Counter),
			m_pScopeGraph->GetCounterName(m_i32Counter),
			m_pScopeGraph->IsCounterShown(m_i32Counter) ? "Yes" : "No",
			m_pScopeGraph->GetMaximum(m_i32Counter),
			m_pScopeGraph->GetMaximumOfData(m_i32Counter),
			m_pScopeGraph->IsCounterPercentage(m_i32Counter) ? "%%" : "");
	}
	else
	{
		sprintf(Description, "No counters present");
	}

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("PVRScopeExample", Description, ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	// Update counters and draw the graph
	m_pScopeGraph->Ping();

	return true;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES3Skinning::RenderScene()
{
	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Use shader program
	glUseProgram(m_ShaderProgram.uiId);
	glActiveTexture(GL_TEXTURE0);

	/*
		Calculates the frame number to animate in a time-based manner.
		Uses the shell function PVRShellGetTime() to get the time in milliseconds.
	*/
	unsigned long iTime = PVRShellGetTime();

	if(iTime > m_iTimePrev)
	{
		float fDelta = (float) (iTime - m_iTimePrev);
		m_fFrame += fDelta * g_fDemoFrameRate;

		// Modify the transformation matrix if it is needed
		bool bRebuildTransformation = false;

		if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
		{
			m_fAngle -= 0.03f;

			if(m_fAngle < PVRT_TWO_PIf)
				m_fAngle += PVRT_TWO_PIf;

			bRebuildTransformation = true;
		}

		if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
		{
			m_fAngle += 0.03f;

			if(m_fAngle > PVRT_TWO_PIf)
				m_fAngle -= PVRT_TWO_PIf;

			bRebuildTransformation = true;
		}

		if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
		{
			m_fDistance -= 10.0f;

			if(m_fDistance < -500.0f)
				m_fDistance = -500.0f;

			bRebuildTransformation = true;
		}

		if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
		{
			m_fDistance += 10.0f;

			if(m_fDistance > 200.0f)
				m_fDistance = 200.0f;

			bRebuildTransformation = true;
		}

		if(bRebuildTransformation)
			m_Transform = PVRTMat4::Translation(0,0, m_fDistance) * PVRTMat4::RotationY(m_fAngle);

	}

	m_iTimePrev	= iTime;

	if(m_fFrame > m_Scene.nNumFrame - 1)
		m_fFrame = 0;

	// Set the scene animation to the current frame
	m_Scene.SetFrame(m_fFrame);

	/*
		Set up camera
	*/
	PVRTVec3	vFrom, vTo, vUp(0, 1, 0);
	PVRTMat4 mView, mProjection;
	float fFOV;

	// We can get the camera position, target and field of view (fov) with GetCameraPos()
	fFOV = m_Scene.GetCamera(vFrom, vTo, vUp, 0);

	/*
		We can build the model view matrix from the camera position, target and an up vector.
		For this we use PVRTMat4::LookAtRH().
	*/
	mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp);

	// Calculate the projection matrix
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);
	mProjection = PVRTMat4::PerspectiveFovRH(fFOV,  (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate);

	// Read the light direction from the scene
	PVRTVec4 vLightDirWorld = PVRTVec4( 0, 0, 0, 0 );
	vLightDirWorld = m_Scene.GetLightDirection(0);
	glUniform3fv(m_ShaderProgram.auiLoc[eLightDirWorld], 1, &vLightDirWorld.x);

	// Set up the View * Projection Matrix
	PVRTMat4 mViewProjection;

	mViewProjection = mProjection * mView;
	glUniformMatrix4fv(m_ShaderProgram.auiLoc[eViewProj], 1, GL_FALSE, mViewProjection.ptr());

	/*
		A scene is composed of nodes. There are 3 types of nodes:
		- MeshNodes :
			references a mesh in the pMesh[].
			These nodes are at the beginning of the pNode[] array.
			And there are nNumMeshNode number of them.
			This way the .pod format can instantiate several times the same mesh
			with different attributes.
		- lights
		- cameras
		To draw a scene, you must go through all the MeshNodes and draw the referenced meshes.
	*/
	for (unsigned int i32NodeIndex = 0; i32NodeIndex < m_Scene.nNumMeshNode; ++i32NodeIndex)
	{
		SPODNode& Node = m_Scene.pNode[i32NodeIndex];

		// Get the node model matrix
		PVRTMat4 mWorld;
		mWorld = m_Scene.GetWorldMatrix(Node);

		// Set up shader uniforms
		PVRTMat4 mModelViewProj;
		mModelViewProj = mViewProjection * mWorld;
		glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMVPMatrix], 1, GL_FALSE, mModelViewProj.ptr());

		PVRTVec4 vLightDirModel;
		vLightDirModel = mWorld.inverse() * vLightDirWorld;
		glUniform3fv(m_ShaderProgram.auiLoc[eLightDirModel], 1, &vLightDirModel.x);

		// Loads the correct texture using our texture lookup table
		if(Node.nIdxMaterial == -1)
			glBindTexture(GL_TEXTURE_2D, 0); // It has no pMaterial defined. Use blank texture (0)
		else
			glBindTexture(GL_TEXTURE_2D, m_puiTextures[Node.nIdxMaterial]);

		DrawMesh(i32NodeIndex);
	}

	// Display the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("Skinning", "", ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}
Exemple #21
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occurred
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevant OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES3Skybox2::RenderScene()
{
	unsigned int i, j;

	// Clears the colour and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/*
		Calculates the frame number to animate in a time-based manner.
		Uses the shell function PVRShellGetTime() to get the time in milliseconds.
	*/

	unsigned long iTime = PVRShellGetTime();

	if(!bPause)
	{
		// Calculate the model view matrix turning around the balloon
		ComputeViewMatrix();

		if(iTime > m_iTimePrev)
		{
			float fDelta = (float) (iTime - m_iTimePrev) * g_fFrameRate;
			m_fFrame   += fDelta;
			fDemoFrame += fDelta;
			fBurnAnim  += fDelta * 0.02f;

			if(fBurnAnim >= 1.0f)
				fBurnAnim = 1.0f;
		}
	}

	m_iTimePrev	= iTime;

	/* KeyBoard input processing */

	if(PVRShellIsKeyPressed(PVRShellKeyNameACTION1))
		bPause=!bPause;

	if(PVRShellIsKeyPressed(PVRShellKeyNameACTION2))
		fBurnAnim = 0.0f;

	/* Keyboard Animation and Automatic Shader Change over time */
	if(!bPause && (fDemoFrame > 500 || (m_i32Effect == 2 && fDemoFrame > 80)))
	{
		if(++m_i32Effect >= (int) g_ui32NoOfEffects)
		{
			m_i32Effect = 1;
			m_fFrame = 0.0f;
		}

		fDemoFrame = 0.0f;
		fBurnAnim  = 0.0f;
	}

	/* Change Shader Effect */

	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		if(++m_i32Effect >= (int) g_ui32NoOfEffects)
			m_i32Effect = 1;

		fDemoFrame = 0.0f;
		fBurnAnim  = 0.0f;
		m_fFrame = 0.0f;
	}
	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		if(--m_i32Effect < 1)
			m_i32Effect = g_ui32NoOfEffects - 1;

		fDemoFrame = 0.0f;
		fBurnAnim  = 0.0f;
		m_fFrame = 0.0f;
	}

	/* Change Skybox Texture */
	if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		for(i = 0; i < g_ui32NoOfEffects; ++i)
			ChangeSkyboxTo(m_ppEffects[i], m_ui32TextureIDs[4]);

		fBurnAnim = 0.0f;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		for(i = 0; i < g_ui32NoOfEffects; ++i)
			ChangeSkyboxTo(m_ppEffects[i], m_ui32TextureIDs[3]);

		fBurnAnim = 0.0f;
	}

	/* Setup Shader and Shader Constants */
	int location;

	glDisable(GL_CULL_FACE);

	DrawSkybox();

	glEnable(GL_CULL_FACE);

	m_ppEffects[m_i32Effect]->Activate();

	for(i = 0; i < m_Scene.nNumMeshNode; i++)
	{
		SPODNode* pNode = &m_Scene.pNode[i];

		// Gets pMesh referenced by the pNode
		SPODMesh* pMesh = &m_Scene.pMesh[pNode->nIdx];

		// Gets the node model matrix
		PVRTMat4 mWorld, mWORLDVIEW;
		mWorld = m_Scene.GetWorldMatrix(*pNode);

		mWORLDVIEW = m_mView * mWorld;

		glBindBuffer(GL_ARRAY_BUFFER, m_aiVboID[i]);

		const CPVRTArray<SPVRTPFXUniform>& Uniforms = m_ppEffects[m_i32Effect]->GetUniformArray();
		for(j = 0; j < Uniforms.GetSize(); ++j)
		{
			switch(Uniforms[j].nSemantic)
			{
				case ePVRTPFX_UsPOSITION:
				{
					glVertexAttribPointer(Uniforms[j].nLocation, 3, GL_FLOAT, GL_FALSE, pMesh->sVertex.nStride, pMesh->sVertex.pData);
					glEnableVertexAttribArray(Uniforms[j].nLocation);
				}
				break;
				case ePVRTPFX_UsNORMAL:
				{
					glVertexAttribPointer(Uniforms[j].nLocation, 3, GL_FLOAT, GL_FALSE, pMesh->sNormals.nStride, pMesh->sNormals.pData);
					glEnableVertexAttribArray(Uniforms[j].nLocation);
				}
				break;
				case ePVRTPFX_UsUV:
				{
					glVertexAttribPointer(Uniforms[j].nLocation, 2, GL_FLOAT, GL_FALSE, pMesh->psUVW[0].nStride, pMesh->psUVW[0].pData);
					glEnableVertexAttribArray(Uniforms[j].nLocation);
				}
				break;
				case ePVRTPFX_UsWORLDVIEWPROJECTION:
				{
					PVRTMat4 mMVP;

					/* Passes the model-view-projection matrix (MVP) to the shader to transform the vertices */
					mMVP = m_mProjection * mWORLDVIEW;
					glUniformMatrix4fv(Uniforms[j].nLocation, 1, GL_FALSE, mMVP.f);
				}
				break;
				case ePVRTPFX_UsWORLDVIEW:
				{
					glUniformMatrix4fv(Uniforms[j].nLocation, 1, GL_FALSE, mWORLDVIEW.f);
				}
				break;
				case ePVRTPFX_UsWORLDVIEWIT:
				{
					PVRTMat4 mWORLDVIEWI, mWORLDVIEWIT;

					mWORLDVIEWI = mWORLDVIEW.inverse();
					mWORLDVIEWIT= mWORLDVIEWI.transpose();

					PVRTMat3 WORLDVIEWIT = PVRTMat3(mWORLDVIEWIT);

					glUniformMatrix3fv(Uniforms[j].nLocation, 1, GL_FALSE, WORLDVIEWIT.f);
				}
				break;
				case ePVRTPFX_UsVIEWIT:
				{
					PVRTMat4 mViewI, mViewIT;

					mViewI  = m_mView.inverse();
					mViewIT = mViewI.transpose();

					PVRTMat3 ViewIT = PVRTMat3(mViewIT);

					glUniformMatrix3fv(Uniforms[j].nLocation, 1, GL_FALSE, ViewIT.f);
				}
				break;
				case ePVRTPFX_UsLIGHTDIREYE:
				{
					PVRTVec4 vLightDirectionEyeSpace;

					// Passes the light direction in eye space to the shader
					vLightDirectionEyeSpace = m_mView * PVRTVec4(1.0,1.0,-1.0,0.0);
					glUniform3f(Uniforms[j].nLocation, vLightDirectionEyeSpace.x, vLightDirectionEyeSpace.y, vLightDirectionEyeSpace.z);
				}
				break;
				case ePVRTPFX_UsTEXTURE:
				{
					// Set the sampler variable to the texture unit
					glUniform1i(Uniforms[j].nLocation, Uniforms[j].nIdx);
				}
				break;
			}
		}

		location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "myEyePos");

		if(location != -1)
			glUniform3f(location, vCameraPosition.x, vCameraPosition.y, vCameraPosition.z);

		//set animation
		location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "fAnim");

		if(location != -1)
			glUniform1f(location, fBurnAnim);

		location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "myFrame");

		if(location != -1)
			glUniform1f(location, m_fFrame);

		if(g_bBlendShader[m_i32Effect])
		{
			glEnable(GL_BLEND);

			// Correct render order for alpha blending through culling
			// Draw Back faces
			glCullFace(GL_FRONT);

			location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "bBackFace");

			glUniform1i(location, 1);

			DrawMesh(pMesh);

			glUniform1i(location, 0);

			glCullFace(GL_BACK);
		}
		else
		{
			location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "bBackFace");

			if(location != -1)
				glUniform1i(location, 0);

			glDisable(GL_BLEND);
		}

		/* Everything should now be setup, therefore draw the mesh*/
		DrawMesh(pMesh);

		glBindBuffer(GL_ARRAY_BUFFER, 0);

		for(j = 0; j < Uniforms.GetSize(); ++j)
		{
			switch(Uniforms[j].nSemantic)
			{
			case ePVRTPFX_UsPOSITION:
				{
					glDisableVertexAttribArray(Uniforms[j].nLocation);
				}
				break;
			case ePVRTPFX_UsNORMAL:
				{
					glDisableVertexAttribArray(Uniforms[j].nLocation);
				}
				break;
			case ePVRTPFX_UsUV:
				{
					glDisableVertexAttribArray(Uniforms[j].nLocation);
				}
				break;
			}
		}
	}

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	if(!bPause)
		m_Print3D.DisplayDefaultTitle("Skybox2", "", ePVRTPrint3DSDKLogo);
	else
		m_Print3D.DisplayDefaultTitle("Skybox2", "Paused", ePVRTPrint3DSDKLogo);

	m_Print3D.Flush();

	return true;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2ChameleonMan::RenderScene()
{
	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Use shader program
	glUseProgram(m_SkinnedShaderProgram.uiId);

	if(PVRShellIsKeyPressed(PVRShellKeyNameACTION1))
	{
		m_bEnableDOT3 = !m_bEnableDOT3;
		glUniform1i(m_SkinnedShaderProgram.auiLoc[ebUseDot3], m_bEnableDOT3);
	}

	/*
		Calculates the frame number to animate in a time-based manner.
		Uses the shell function PVRShellGetTime() to get the time in milliseconds.
	*/
	unsigned long iTime = PVRShellGetTime();

	if(iTime > m_iTimePrev)
	{
		float fDelta = (float) (iTime - m_iTimePrev);
		m_fFrame += fDelta * g_fDemoFrameRate;

		// Increment the counters to make sure our animation works
		m_fLightPos	+= fDelta * 0.0034f;
		m_fWallPos	+= fDelta * 0.00027f;
		m_fBackgroundPos += fDelta * -0.000027f;

		// Wrap the Animation back to the Start
		if(m_fLightPos >= PVRT_TWO_PI)
			m_fLightPos -= PVRT_TWO_PI;

		if(m_fWallPos >= PVRT_TWO_PI)
			m_fWallPos -= PVRT_TWO_PI;

		if(m_fBackgroundPos <= 0)
			m_fBackgroundPos += 1.0f;

		if(m_fFrame > m_Scene.nNumFrame - 1)
			m_fFrame = 0;
	}

	m_iTimePrev	= iTime;

	// Set the scene animation to the current frame
	m_Scene.SetFrame(m_fFrame);

	// Set up camera
	PVRTVec3	vFrom, vTo, vUp(0.0f, 1.0f, 0.0f);
	PVRTMat4 mView, mProjection;
	PVRTVec3	LightPos;
	float fFOV;
	int i;

	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	// Get the camera position, target and field of view (fov)
	if(m_Scene.pCamera[0].nIdxTarget != -1) // Does the camera have a target?
		fFOV = m_Scene.GetCameraPos( vFrom, vTo, 0); // vTo is taken from the target node
	else
		fFOV = m_Scene.GetCamera( vFrom, vTo, vUp, 0); // vTo is calculated from the rotation

	fFOV *= bRotate ? (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight) : (float)PVRShellGet(prefHeight)/(float)PVRShellGet(prefWidth);

	/*
		We can build the model view matrix from the camera position, target and an up vector.
		For this we use PVRTMat4::LookAtRH().
	*/
	mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp);

	// Calculate the projection matrix
	mProjection = PVRTMat4::PerspectiveFovRH(fFOV,  (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate);

	// Update Light Position and related VGP Program constant
	LightPos.x = 200.0f;
	LightPos.y = 350.0f;
	LightPos.z = 200.0f * PVRTABS(sin((PVRT_PI / 4.0f) + m_fLightPos));

	glUniform3fv(m_SkinnedShaderProgram.auiLoc[eLightPos], 1, LightPos.ptr());

	// Set up the View * Projection Matrix
	PVRTMat4 mViewProjection;

	mViewProjection = mProjection * mView;
	glUniformMatrix4fv(m_SkinnedShaderProgram.auiLoc[eViewProj], 1, GL_FALSE, mViewProjection.ptr());

	// Enable the vertex attribute arrays
	for(i = 0; i < eNumAttribs; ++i) glEnableVertexAttribArray(i);

	// Draw skinned meshes
	for(unsigned int i32NodeIndex = 0; i32NodeIndex < 3; ++i32NodeIndex)
	{
		// Bind correct texture
		switch(i32NodeIndex)
		{
			case eBody:
				glActiveTexture(GL_TEXTURE1);
				glBindTexture(GL_TEXTURE_2D, m_ui32TexHeadNormalMap);
				glActiveTexture(GL_TEXTURE0);
				glBindTexture(GL_TEXTURE_2D, m_ui32TexHeadBody);
				break;
			case eLegs:
				glActiveTexture(GL_TEXTURE1);
				glBindTexture(GL_TEXTURE_2D, m_ui32TexLegsNormalMap);
				glActiveTexture(GL_TEXTURE0);
				glBindTexture(GL_TEXTURE_2D, m_ui32TexLegs);
				break;
			default:
				glActiveTexture(GL_TEXTURE1);
				glBindTexture(GL_TEXTURE_2D, m_ui32TexBeltNormalMap);
				glActiveTexture(GL_TEXTURE0);
				glBindTexture(GL_TEXTURE_2D, m_ui32TexBelt);
				break;
		}

		DrawSkinnedMesh(i32NodeIndex);
	}

	// Safely disable the vertex attribute arrays
	for(i = 0; i < eNumAttribs; ++i) glDisableVertexAttribArray(i);

	// Draw non-skinned meshes
	glUseProgram(m_DefaultShaderProgram.uiId);

	// Enable the vertex attribute arrays
	for(i = 0; i < eNumDefaultAttribs; ++i) glEnableVertexAttribArray(i);

	for(unsigned int i32NodeIndex = 3; i32NodeIndex < m_Scene.nNumMeshNode; ++i32NodeIndex)
	{
		SPODNode& Node = m_Scene.pNode[i32NodeIndex];
		SPODMesh& Mesh = m_Scene.pMesh[Node.nIdx];

		// bind the VBO for the mesh
		glBindBuffer(GL_ARRAY_BUFFER, m_puiVbo[Node.nIdx]);

		// bind the index buffer, won't hurt if the handle is 0
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_puiIndexVbo[Node.nIdx]);

		// Get the node model matrix
		PVRTMat4 mWorld;
		mWorld = m_Scene.GetWorldMatrix(Node);

		// Setup the appropriate texture and transformation (if needed)
		switch(i32NodeIndex)
		{
			case eWall:
				glBindTexture(GL_TEXTURE_2D, m_ui32TexWall);

				// Rotate the wall mesh which is circular
				mWorld *= PVRTMat4::RotationY(m_fWallPos);

				glUniform1f(m_DefaultShaderProgram.auiLoc[eDefaultUOffset], 0);

				break;
			case eBackground:
				glBindTexture(GL_TEXTURE_2D, m_ui32TexSkyLine);

				glUniform1f(m_DefaultShaderProgram.auiLoc[eDefaultUOffset], m_fBackgroundPos);
				break;
			case eLights:
				{
					glBindTexture(GL_TEXTURE_2D, m_ui32TexLamp);

					PVRTMat4 mWallWorld = m_Scene.GetWorldMatrix(m_Scene.pNode[eWall]);
					mWorld = mWallWorld * PVRTMat4::RotationY(m_fWallPos) * mWallWorld.inverse() * mWorld;

					glUniform1f(m_DefaultShaderProgram.auiLoc[eDefaultUOffset], 0);
				}
				break;
			default:
			break;
		};

		// Set up shader uniforms
		PVRTMat4 mModelViewProj;
		mModelViewProj = mViewProjection * mWorld;
		glUniformMatrix4fv(m_DefaultShaderProgram.auiLoc[eDefaultMVPMatrix], 1, GL_FALSE, mModelViewProj.ptr());

		// Set the vertex attribute offsets
		glVertexAttribPointer(DEFAULT_VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, Mesh.sVertex.nStride,  Mesh.sVertex.pData);
		glVertexAttribPointer(DEFAULT_TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, Mesh.psUVW[0].nStride, Mesh.psUVW[0].pData);

		// Indexed Triangle list
		glDrawElements(GL_TRIANGLES, Mesh.nNumFaces*3, GL_UNSIGNED_SHORT, 0);
	}

	// Safely disable the vertex attribute arrays
	for(i = 0; i < eNumAttribs; ++i) glDisableVertexAttribArray(i);

	// unbind the VBOs
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	// Display the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	const char * pDescription;

	if(m_bEnableDOT3)
		pDescription = "Skinning with DOT3 Per Pixel Lighting";
	else
		pDescription = "Skinning with Vertex Lighting";

	m_Print3D.DisplayDefaultTitle("Chameleon Man", pDescription, ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2AnisotropicLighting::RenderScene()
{
	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Keyboard input (cursor to change render mode)
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_eRenderMode = ERenderMode((m_eRenderMode + eNumRenderModes - 1) % eNumRenderModes);
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_eRenderMode = ERenderMode((m_eRenderMode + 1) % eNumRenderModes);
	}

	// Rotate the model matrix
	PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY);
	m_fAngleY += 0.02f;

	// Calculate model view projection matrix
	PVRTMat4 mMVP = m_mViewProj * mModel;

	if (m_eRenderMode == eTexLookup)
	{
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, m_uiTexture);

		glUseProgram(m_FastShader.uiId);

		glUniformMatrix4fv(m_FastShader.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr());

		/*
			The inverse of a rotation matrix is the transposed matrix
			Because of v * M = transpose(M) * v, this means:
			v * R == inverse(R) * v
			So we don't have to actually invert or transpose the matrix
			to transform back from world space to model space
		*/
		PVRTVec3 vMsEyePos = PVRTVec3(PVRTVec4(0, 0, 150, 1) * mModel);
		glUniform3fv(m_FastShader.uiMsEyePosLoc, 1, vMsEyePos.ptr());

		PVRTVec3 vMsLightDir = PVRTVec3(PVRTVec4(1, 1, 1, 1) * mModel).normalized();
		glUniform3fv(m_FastShader.uiMsLightDirLoc, 1, vMsLightDir.ptr());
	}
	else
	{
		glUseProgram(m_SlowShader.uiId);

		glUniformMatrix4fv(m_SlowShader.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr());

		PVRTVec3 vMsEyeDir = PVRTVec3(PVRTVec4(0, 0, 150, 1) * mModel).normalized();
		glUniform3fv(m_SlowShader.uiMsEyeDirLoc, 1, vMsEyeDir.ptr());

		PVRTVec3 vMsLightDir = PVRTVec3(PVRTVec4(1, 1, 1, 1) * mModel).normalized();
		glUniform3fv(m_SlowShader.uiMsLightDirLoc, 1, vMsLightDir.ptr());
	}

	/*
		Now that the uniforms are set, call another function to actually draw the mesh.
	*/
	DrawMesh(0);

	// Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("AnisotropicLighting", "", ePVRTPrint3DLogoIMG);
	m_Print3D.Print3D(0.3f, 7.5f, 0.75f, PVRTRGBA(255,255,255,255), c_aszRenderModes[m_eRenderMode]);
	m_Print3D.Flush();

	return true;
}
Exemple #24
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES3ShadowVolumes::RenderScene()
{
	//Calculate the time passes since the last frame so we can rotate the cogs in a time-based manner
	unsigned long ulTime = PVRShellGetTime();
	unsigned long ulDeltaTime = ulTime - m_ulTimePrev;

	m_ulTimePrev = ulTime;

    // If the cog is classed as dynamic then we need to update its angle of rotation
	if(m_i32ObjectType[eBigCog] == eDynamicObject)
	{
		m_fBigCogAngle   += ulDeltaTime * 0.001f;

		while(m_fBigCogAngle > PVRT_TWO_PI)
			m_fBigCogAngle -= PVRT_TWO_PI;
	}

	if(m_i32ObjectType[eSmallCog] == eDynamicObject)
	{
		m_fSmallCogAngle -= ulDeltaTime * 0.004f;

		while(m_fSmallCogAngle > PVRT_TWO_PI)
			m_fSmallCogAngle -= PVRT_TWO_PI;
	}

	// If the action key has been pressed then switch between drawing and not drawing the shadow volumes
	if (PVRShellIsKeyPressed(PVRShellKeyNameACTION1))
		m_bDisplayVolumes = !m_bDisplayVolumes;

	// Clear the colour, stencil and depth buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	/*
		To create shadows we are going to do the following steps

		1) Using the tools we are going to update any of the shadow volumes for the dynamic objects
		2) Draw the scene as we would any other.
		3) Enable the stencil test.
		4) Draw Shadow Volumes to fill the stencil buffer with data.
		5) Then we are going to draw a fullscreen quad which will only appear where the stencil buffer is not zero.
		6) Disable the stencil test
	*/

	/*
		Update the shadow volumes for any dynamic objects as they have moved so we requrie a different
		shadow volume. If the light position was also dynamic we would have to update volumes for all
		the static objects as well.
	*/

	for(unsigned int i = 0; i < m_ui32NoOfShadows; ++i)
	{
		if(m_i32ObjectType[m_pui32MeshIndex[i]] == eDynamicObject)
		{
			BuildVolume(i, &m_vLightPosWorld);
		}
	}

	// Draw the scene lit.
	DrawScene();

	// Enable the stencil test
	glEnable(GL_STENCIL_TEST);

	// Do the stencil test
	DoStencilTest();

	// Draw a full screen quad
	DrawFullScreenQuad();

	// Disable the stencil test as it is no longer needed.
	glDisable(GL_STENCIL_TEST);

	// Display the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
	m_Print3D.DisplayDefaultTitle("ShadowVolumes", "", ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}
/*******************************************************************************
 * 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 OGLESSkinning::RenderScene()
{
	// Increase the frame number
	m_fFrame += 0.3f;

	while(m_fFrame > m_Scene.nNumFrame-1)
		m_fFrame -= m_Scene.nNumFrame-1;

	// Modify the transformation matrix if it is needed
	bool bRebuildTransformation = false;

	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_fAngle -= 0.03f;

		if(m_fAngle < PVRT_TWO_PIf)
			m_fAngle += PVRT_TWO_PIf;

		bRebuildTransformation = true;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_fAngle += 0.03f;

		if(m_fAngle > PVRT_TWO_PIf)
			m_fAngle -= PVRT_TWO_PIf;

		bRebuildTransformation = true;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		m_fDistance -= 10.0f;

		if(m_fDistance < -500.0f)
			m_fDistance = -500.0f;

		bRebuildTransformation = true;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		m_fDistance += 10.0f;

		if(m_fDistance > 200.0f)
			m_fDistance = 200.0f;

		bRebuildTransformation = true;
	}

	if(bRebuildTransformation)
		m_mTransform = PVRTMat4::Translation(0,0, m_fDistance) * PVRTMat4::RotationY(m_fAngle);

	// Clear the depth and frame buffer
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Set Z compare properties
	glEnable(GL_DEPTH_TEST);

	// Disable Blending
	glDisable(GL_BLEND);

	// Calculate the model view matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(m_mView.f);

	// Draw the model
	DrawModel();

	// Print text on screen
	m_Print3D.DisplayDefaultTitle("Skinning", "", ePVRTPrint3DSDKLogo);

	// Flush all Print3D commands
	m_Print3D.Flush();

	return true;
}
Exemple #26
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLESCoverflow::RenderScene()
{
	// Clears the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glDisable(GL_CULL_FACE);

	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) //input permmanently set for demo purposes
		m_bGoRight = true;

	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
		m_bGoRight = false;

	m_fLerpDir = m_bGoRight ? 1.0f : -1.0f;

	unsigned long ulTime = PVRShellGetTime();
	unsigned long ulDeltaTime = ulTime - m_ulTimePrev;
	m_ulTimePrev = ulTime;

	m_fLerp += (ulDeltaTime*.0001f)*m_fCyclesPerSecond*m_fLerpDir;

	if(m_fLerpDir && (m_fLerp >= 1.0 || m_fLerp <= -1.0))
	{
		if(m_fLerpDir < 0)
		{
			m_iCoverIndex++;
			if(m_iCoverIndex > g_i32CoverNo)
				m_iCoverIndex = 1;
		}
		else
		{
			m_iCoverIndex--;
			if(m_iCoverIndex < 0)
				m_iCoverIndex = g_i32CoverNo-1;
		}
		m_fLerpDir = 0.f;
		m_fLerp = 0;
	}

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	//the order in which the covers are drawn is very important for the transparency here. As the covers flip from
	//one position to the next there is a point in the cycle where the center cover moves from being in front of the
	//position following it to behind it. The draw order needs to reflect this so that the blend is still drawn correctly.
	if(m_fLerp < -0.5)
	{
		DrawLeftCovers();
		DrawInPosition(eFront, m_fLerp, m_iCoverIndex);
		DrawRightCovers();
	}
	else if(m_fLerp >  0.5)
	{
		DrawRightCovers();
		DrawInPosition(eFront, m_fLerp, m_iCoverIndex);
		DrawLeftCovers();
	}
	else
	{
		DrawRightCovers();
		DrawLeftCovers();
		DrawInPosition(eFront, m_fLerp, m_iCoverIndex);
	}

	// unbind the vertex buffers as we don't need them bound anymore
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

	m_Print3D.DisplayDefaultTitle("Coverflow", "", ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}