Beispiel #1
0
// ---------------------------------------------------------------
bool MyPVRDemo::InitView()
	{
	CPVRTString ErrorStr;

	LoadVBOs();
	bool bResult = true;
	bResult &= LoadTextures(&ErrorStr);
	bResult &= LoadShaders(&ErrorStr);
	bResult &= CreateFBOs(&ErrorStr);
	
	if(!bResult)
		{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
		}

	m_bRotated = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	// --- Set up light position, projection and view
	m_vLightPos   = PVRTVec3(0, 125, 200);
	m_mxLightProj = PVRTMat4::PerspectiveFovRH(PVRT_PI / 4, 1.0f, 10.0f, 1000.0f, PVRTMat4::OGL, m_bRotated);
	m_mxLightView = PVRTMat4::LookAtRH(m_vLightPos, PVRTVec3(0,25,0), PVRTVec3(0,1,0));
	m_mxLightBias = PVRTMat4(0.5f, 0.0f, 0.0f, 0.0f,
							 0.0f, 0.5f, 0.0f, 0.0f,
							 0.0f, 0.0f, 0.5f, 0.0f,
							 0.5f, 0.5f, 0.5f, 1.0f);

	// --- Set up Camera projection and view
	float fAspect = PVRShellGet(prefWidth) / (float)PVRShellGet(prefHeight);
	m_mxProjection = PVRTMat4::PerspectiveFovFloatDepthRH(0.75f, fAspect, 10.0f, PVRTMat4::OGL, m_bRotated);
	m_mxCam = PVRTMat4::LookAtRH(PVRTVec3(0, 55, 150), PVRTVec3(0, 35, 0), PVRTVec3(0, 1, 0));

	// --- Set GL states
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_GEQUAL);
	glClearDepthf(0.0f);
	glClearColor(0,0,0,1);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	return true;
	}
/*******************************************************************************
 * Function Name  : InitApplication
 * Inputs		  : argc, *argv[], uWidth, uHeight
 * Returns        : true if no error occured
 * Description    : Code in InitApplication() will be called by the Shell ONCE per
 *					run, early on in the execution of the program.
 *					Used to initialize variables that are not dependant on the
 *					rendering context (e.g. external modules, loading meshes, etc.)
 *******************************************************************************/
bool OGLESPolybump::InitApplication()
{
	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Get and set the load/release functions for loading external files.
	// In the majority of cases the PVRShell will return NULL function pointers implying that
	// nothing special is required to load external files.
	CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));

	// Load the scene
	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	return true;
}
Beispiel #3
0
/*!***************************************************************************
@Function		RenderTitle
@Input			fFadeAmount
@Description	Draws the title text.
*****************************************************************************/
void OGLES2IntroducingPrint3D::RenderTitle(float fFadeAmount)
{
	unsigned int uiCol = (((unsigned int)(fFadeAmount * 255)) << 24) | 0x00FFFF;

	float fW = PVRShellGet(prefWidth) * 0.5f;
	float fH = PVRShellGet(prefHeight) * 0.5f;
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	/*
		Print3D can optionally be provided with user-defined projection and modelview matrices
		which allow custom layout of text. Here we are just providing a projection matrix
		so that text can be placed in viewport coordinates, rather than the default, more 
		abstract coordinate system of 0.0-100.0.
	*/
	PVRTMat4 mProjection = PVRTMat4::Ortho(-fW, fH, fW, -fH, -1.0f, 1.0f, PVRTMat4::OGL, bRotate);
	m_IntroText.SetProjection(mProjection);

	/*
		Using the MeasureText() method provided by Print3D, we can determine the bounding-box
		size of a string of text. This can be useful for justify text centrally, as we are
		doing here.
	*/
	float fLine1W = 0.0f;
	float fLine2W = 0.0f;
	m_IntroText.MeasureText(&fLine1W, NULL, 1.0f, "introducing");
	m_IntroText.MeasureText(&fLine2W, NULL, 1.0f, "print3d");

	/*
		Display some text.
		Print3D() function allows to draw text anywhere on the screen using any colour.
		Param 1: Position of the text along X
		Param 2: Position of the text along Y
		Param 3: Scale of the text
		Param 4: Colour of the text (0xAABBGGRR format)
		Param 5: Formatted string (uses the same syntax as printf)
		...
	*/
	m_IntroText.Print3D(-fLine1W*0.5f, 50.0f, 1.0f, uiCol, "introducing");
	m_IntroText.Print3D(-fLine2W*0.5f, 0.0f,   1.0f, uiCol, "print3d");

	// Tells Print3D to do all the pending text rendering now
	m_IntroText.Flush();
}
Beispiel #4
0
// ---------------------------------------------------------------
void MyPVRDemo::RenderShadowScene()
	{
	// --- Bind the shadow map FBO
	glBindFramebuffer(GL_FRAMEBUFFER, m_uiShadowMapFBO);
	glViewport(0, 0, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);			// Turn off colour writing

	glUseProgram(m_SimpleShader.uiID);
	// Create MVP using the light's matrix properties
	PVRTMat4 mxMVP = m_mxLightProj * m_mxLightView * PVRTMat4::Identity();
	glUniformMatrix4fv(m_SimpleShader.uiMVP, 1, GL_FALSE, mxMVP.ptr());
	DrawMesh(enumMODEL_Statue, FLAG_VRT);

	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);				// We can turn colour writing back on.

	glBindFramebuffer(GL_FRAMEBUFFER, m_nOrigFBO);		// Done. Use the original framebuffer.
	glViewport(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight));
	}
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLESIntroducingPVRTools::InitApplication()
{
	/*
		CPVRTResourceFile is a resource file helper class. Resource files can
		be placed on disk next to the executable or in a platform dependent
		read path. We need to tell the class where that read path is.
		Additionally, it is possible to wrap files into cpp modules and
		link them directly into the executable. In this case no path will be
		used. Files on disk will override "memory files".
	*/

	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Get and set the load/release functions for loading external files.
	// In the majority of cases the PVRShell will return NULL function pointers implying that
	// nothing special is required to load external files.
	CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));
	return true;
}
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occured
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependent on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES2ProceduralTextures::InitView()
{
	CPVRTString ErrorStr;
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	if (!LoadShaders(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Initialize Print3D textures
	if (m_Print3D.SetTextures(NULL, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "Error: Cannot initialise Print3D.\n");
		return false;
	}

	if (!m_pProceduralTextures->Init(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	if (!GenerateFnTexture())
	{
		PVRShellSet(prefExitMessage, "Error: Failed to generate texture.\n");
		return false;
	}

	glGenTextures(1, &m_ui32ColourSplineTexture);
	glBindTexture(GL_TEXTURE_2D, m_ui32ColourSplineTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, c_pszColourSplineData);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glBindTexture(GL_TEXTURE_2D, 0);

	return true;
}
Beispiel #7
0
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLES3IntroducingPOD::InitApplication()
{
	m_puiVbo = 0;
	m_puiIndexVbo = 0;
	m_puiTextureIDs = 0;

	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Get and set the load/release functions for loading external files.
	// In the majority of cases the PVRShell will return NULL function pointers implying that
	// nothing special is required to load external files.
	CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));

	// Load the scene
	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	// The cameras are stored in the file. We check it contains at least one.
	if(m_Scene.nNumCamera == 0)
	{
		PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a camera. Please add one and re-export.\n");
		return false;
	}

	// We also check that the scene contains at least one light
	if(m_Scene.nNumLight == 0)
	{
		PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a light. Please add one and re-export.\n");
		return false;
	}

	// Initialize variables used for the animation
	m_fFrame = 0;
	m_ulTimePrev = PVRShellGetTime();

	return true;
}
Beispiel #8
0
/*******************************************************************************
 * Function Name  : InitView
 * Inputs		  : uWidth, uHeight
 * Returns        : true if no error occured
 * Description    : Code in InitView() will be called by the Shell upon a change
 *					in the rendering context.
 *					Used to initialise variables that are dependent on the rendering
 *					context (e.g. textures, vertex buffers, etc.)
 *******************************************************************************/
bool CStrokeStyles::InitView()
{
	/*
	Create path
	*/
	CreatePath();

	/*
	The clear colour will be used whenever calling vgClear(). The colour is given
	as non-premultiplied sRGBA.
	*/
	VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f };
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	/*
	Initialise custom text drawing
	*/
	m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight));

	return true;
}
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLESIntroducingPFX::InitApplication()
{
	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Get and set the load/release functions for loading external files.
	// In the majority of cases the PVRShell will return NULL function pointers implying that
	// nothing special is required to load external files.
	CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));

	// Load the scene
	if (m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	// The cameras are stored in the file. We check it contains at least one.
	if(m_Scene.nNumCamera == 0)
	{
		PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a camera\n");
		return false;
	}

	// Ensure that all meshes use an indexed triangle list
	for(unsigned int i = 0; i < m_Scene.nNumMesh; ++i)
	{
		if(m_Scene.pMesh[i].nNumStrips || !m_Scene.pMesh[i].sFaces.pData)
		{
			PVRShellSet(prefExitMessage, "ERROR: The meshes in the scene should use an indexed triangle list\n");
			return false;
		}
	}

	// Initialize variables used for the animation
	m_fFrame = 0;
	m_iTimePrev = PVRShellGetTime();

	return true;
}
Beispiel #10
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 CImage::RenderScene()
{
	//Clear the screen with the current clear colour.
	vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight));

	//Change the matrix mode to VG_MATRIX_IMAGE_USER_TO_SURFACE so we can transform the images
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);

	//Set the current matrix to the identity
	vgLoadIdentity();

	//Translate the image to the desired position
	vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f + 5);

	//Draw the first image
	vgDrawImage(m_avgImage[0]);

	//Reset the current matrix...
	vgLoadIdentity();

	//...Perform a translation to position the second image...
	vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f - IMG_SIZE - 5);

	//...and draw
	vgDrawImage(m_avgImage[1]);

	m_PrintVG.DisplayDefaultTitle("Image", "", ePVRTPrint3DLogoIMG);
	return true;
}
Beispiel #11
0
/****************************************************************************
** InitApplication() is called by PVRShell to enable user to initialise    **
** the application														   **
****************************************************************************/
bool OVGFont::InitApplication()
{
	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*) PVRShellGet(prefReadPath));

	// This sets up PVRShell to use an OpenVG context
	PVRShellSet(prefOpenVGContext, true);

	// Set the anti-alias mode to 'better'
	PVRShellSet(prefFSAAMode, 2);

	return true;
}
Beispiel #12
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 CTransforms::RenderScene()
{
	m_ui32AbsTime = PVRShellGetTime();

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

	// Set fill paint
	vgSetPaint(m_vgPaint, VG_FILL_PATH);

	unsigned int ui32TimeSinceStart = PVRShellGetTime() - m_ui32StartTime;
	// toggle segment type every 3 seconds
	int ui32ActiveTransform = (ui32TimeSinceStart % (3000 * 7)) / 3000;

	switch(ui32ActiveTransform)
	{
		case 0: DoTranslate(); break;
		case 1: DoScaleCentered(); break;
		case 2: DoScaleOrigin(); break;
		case 3: DoRotateCentered(); break;
		case 4: DoRotateOrigin(); break;
		case 5: DoShearCentered(); break;
		case 6: DoShearOrigin(); break;
	}

	// Draw user interface
	static char* apszTransforms[] = {
		"Translation",
		"Scaling (centered on object)",
		"Scaling (from origin)",
		"Rotate (centered on object)",
		"Rotate (around origin)",
		"Shear (centered on object)",
		"Shear (from origin)",
	};

	m_PrintVG.DisplayDefaultTitle("Transforms", apszTransforms[ui32ActiveTransform], ePVRTPrint3DLogoIMG);
	return true;
}
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occured
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES2Coverflow::InitView()
{
	CPVRTString ErrorStr;

	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Get and set the load/release functions for loading external files.
	// In the majority of cases the PVRShell will return NULL function pointers implying that
	// nothing special is required to load external files.
	CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));
	
	if (!LoadTextures(&ErrorStr))
	{
        PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}
	
	if (!LoadShaders(&ErrorStr))
	{
        PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

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

	if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	PVRTVECTOR3	vFrom = {0.0f, 0.0f, 15.0f },
		vTo = { 0, 0, 0 },
		vUp = { 0, 1, 0 };
	
	PVRTMatrixPerspectiveFovRH(m_mProjection, g_FOV, f2vt((float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight)), f2vt(g_fCameraNear), f2vt(g_fCameraFar), bRotate);

	PVRTMatrixLookAtRH(m_mView, vFrom, vTo, vUp);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	//this must be called after InitApplication
	CreateCover();

	// Enable culling
	glEnable(GL_CULL_FACE);
	return true;
}
Beispiel #14
0
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occurred
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLES2Glass::InitApplication()
{
	m_puiVbo = 0;
	m_puiIndexVbo = 0;
	m_puiBalloonVbo = 0;
	m_puiBalloonIndexVbo = 0;

	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Get and set the load/release functions for loading external files.
	// In the majority of cases the PVRShell will return NULL function pointers implying that
	// nothing special is required to load external files.
	CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));

	// Load the mask
	if (m_Ball.ReadFromFile(c_szBallFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	// Load the balloon
	if (m_Balloon.ReadFromFile(c_szBalloonFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	m_ulTime = ULONG_MAX;

	m_afAngles[0] = 0.0f;
	m_afAngles[1] = 0.0f;

	m_iEffect = 0;

	return true;
}
Beispiel #15
0
// ---------------------------------------------------------------
bool MyPVRDemo::InitApplication()
	{
#ifdef PLATFORM_IOS
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));
#endif
	
	if (m_Model.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
		{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
		}

	assert(enumMODEL_MAX == m_Model.nNumMesh);

	// Calculate a bounding box around the statue that we can use later on
	SPODMesh* pMesh = &m_Model.pMesh[m_Model.pNode[enumMODEL_Statue].nIdx];
	PVRTBOUNDINGBOX bb;
	PVRTBoundingBoxComputeInterleaved(&bb, pMesh->pInterleaved, pMesh->nNumVertex, 0, pMesh->sVertex.nStride);

	// We need to calculate the longest possible length for our bounding box on the X and Z axis (as we're rotating around Y).
	float fLen[4];
	fLen[0] = sqrt(bb.Point[7].x * bb.Point[7].x + bb.Point[7].z * bb.Point[7].z);	// FR quadrant
	fLen[1] = sqrt(bb.Point[3].x * bb.Point[3].x + bb.Point[3].z * bb.Point[3].z);	// FL quadrant
	fLen[2] = sqrt(bb.Point[6].x * bb.Point[6].x + bb.Point[6].z * bb.Point[6].z);	// BR quadrant
	fLen[3] = sqrt(bb.Point[2].x * bb.Point[2].x + bb.Point[2].z * bb.Point[2].z);	// BL quadrant
	
	float fLongest = max(fLen[0], fLen[1]);
	fLongest = max(fLongest, fLen[2]);
	fLongest = max(fLongest, fLen[3]);
		
	// Calculate the top left and bottom right of the bounding box in 2D space
	m_bbStatueTL = PVRTVec4(-fLongest, bb.Point[3].y, bb.Point[3].z, 1.0f);
	m_bbStatueBR = PVRTVec4( fLongest, bb.Point[5].y, bb.Point[5].z, 1.0f);

	// Some nice variables
	m_fAngleY = 0.0f;
	m_fBloomMulti = 0.3f;
	m_ulCurrTime = 0;
	m_fLightAngle = PVRT_PI / 8;	// Offset by 22.5degrees to begin with, so we see the shadow slightly offset from behind the model.

	m_fTexelOffset = 1.0f / RTT_SIZE;
	float w1 = 0.0555555f;
	float w2 = 0.2777777f;
	float intraTexelOffset = (w2 / (w1 + w2)) * m_fTexelOffset;		// Weight between 2 texels so that hardware filtering will
																	// interpolate the texels for us. Effectively reducing a 5x5 kernel
																	// to a 3x3.
	m_fTexelOffset += intraTexelOffset;

	return true;
	}
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLES2LightMap::InitApplication()
{
	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Get and set the load/release functions for loading external files.
	// In the majority of cases the PVRShell will return NULL function pointers implying that
	// nothing special is required to load external files.
	CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));

	// Load the scene files
	if(!m_Models[0].ReadFromFile(c_szMaskFile) ||
		!m_Models[1].ReadFromFile(c_szPlaneFile))
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	m_fAngleX = 0.0f;
	m_fAngleY = 0.0f;

	return true;
}
Beispiel #17
0
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLESEvilSkull::InitApplication()
{
	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Load the scene
	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	return true;
}
Beispiel #18
0
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occurred
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependent on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLES2Shaders::InitApplication()
{
	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Get and set the load/release functions for loading external files.
	// In the majority of cases the PVRShell will return NULL function pointers implying that
	// nothing special is required to load external files.
	CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));

	/*
		Analyse command line
		the format is: -s=? -m=? where s in the shader and m is the mesh
		e.g. OGLES2Shaders -s=3 -m=4
	*/
	int nClNum	= PVRShellGet(prefCommandLineOptNum);
	const SCmdLineOpt* pOpt	= (const SCmdLineOpt*)PVRShellGet(prefCommandLineOpts);

	for(int i = 0; i < nClNum; ++i)
	{
		if(pOpt[i].pArg[0] == '-')
		{
			switch (pOpt[i].pArg[1])
			{
			case 's':case 'S':
				m_nCurrentShader	= atoi(pOpt[i].pVal) % g_numShaders;
				continue;

			case 'm':case 'M':
				m_nCurrentSurface	= atoi(pOpt[i].pVal) % g_numSurfaces;
				continue;
			}
		}
	}

	return true;
}
Beispiel #19
0
/*!****************************************************************************
 @Function		SetUpMatrices
 @Description	Creates the view and projection matrices for the light and camera
******************************************************************************/
void OGLES2ShadowMapping::SetUpMatrices()
{
	PVRTVec3 vFrom = PVRTVec3(-130.0f, 130.0f, -130.0f ),
			vTo = PVRTVec3( 0, 10, 0 ),
			vUp = PVRTVec3( 0, 1, 0 );

	float fFOV= 0.78539819f;

	m_BiasMatrix = PVRTMat4(0.5f, 0.0f, 0.0f, 0.0f,
							0.0f, 0.5f, 0.0f, 0.0f,
							0.0f, 0.0f, 0.5f, 0.0f,
							0.5f, 0.5f, 0.5f, 1.0f);
	
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	m_Projection = PVRTMat4::PerspectiveFovRH(fFOV, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate);
	
	m_View = PVRTMat4::LookAtRH(vFrom, vTo, vUp);
	
	m_LightProjection = PVRTMat4::PerspectiveFovRH(fFOV, 1.0f, 70.0f, 270.0f, PVRTMat4::OGL, m_bRotate);
	
	m_LightView = PVRTMat4::LookAtRH(m_vLightPosition, vTo, vUp);

}
Beispiel #20
0
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLES2Bumpmap::InitApplication()
{
	m_puiVbo = 0;
	m_puiIndexVbo = 0;

	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Load the scene
	if (m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	m_fAngleY = 0.0f;

	return true;
}
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLES2StencilBuffer::InitApplication()
{
	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Load the scene files
	if(!m_Cylinder.ReadFromFile(c_szCylinderFile) || 
		!m_Sphere.ReadFromFile(c_szSphereFile))
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	// Initialise the angle variable
	m_fAngle = 0.0f;

	// Request Stencil Buffer support
	PVRShellSet(prefStencilBufferContext, true);
	return true;
}
Beispiel #22
0
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLESFur::InitApplication()
{
	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Load the scene
	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	m_ui32WindowID[0] = m_Print3D.CreateDefaultWindow(1.0f, 1.0f, 60, (char*) WINDOW_TITLE, 0);
	m_ui32WindowID[1] = m_Print3D.CreateDefaultWindow(1.0f, 1.0f, 60, (char*) WINDOW_TITLE" (1 of 5)", (char*) &c_szWindowDesc1[0]);
	m_ui32WindowID[2] = m_Print3D.CreateDefaultWindow(1.0f, 1.0f, 60, (char*) WINDOW_TITLE" (2 of 5)", (char*) &c_szWindowDesc2[0]);
	m_ui32WindowID[3] = m_Print3D.CreateDefaultWindow(1.0f, 1.0f, 60, (char*) WINDOW_TITLE" (3 of 5)", (char*) &c_szWindowDesc3[0]);
	m_ui32WindowID[4] = m_Print3D.CreateDefaultWindow(1.0f, 1.0f, 60, (char*) WINDOW_TITLE" (4 of 5)", (char*) &c_szWindowDesc4[0]);
	m_ui32WindowID[5] = m_Print3D.CreateDefaultWindow(1.0f, 1.0f, 60, (char*) WINDOW_TITLE" (5 of 5)", (char*) &c_szWindowDesc5[0]);
	return true;
}
Beispiel #23
0
/*!****************************************************************************
 @Function		InitApplication
 @Return		bool		true if no error occured
 @Description	Code in InitApplication() will be called by PVRShell once per
				run, before the rendering context is created.
				Used to initialize variables that are not dependant on it
				(e.g. external modules, loading meshes, etc.)
				If the rendering context is lost, InitApplication() will
				not be called again.
******************************************************************************/
bool OGLES2IntroducingPOD::InitApplication()
{
	m_puiVbo = 0;
	m_puiIndexVbo = 0;
	m_puiTextureIDs = 0;

	// Get and set the read path for content files
	CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));

	// Load the scene
	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
		return false;
	}

	// The cameras are stored in the file. We check it contains at least one.
	if(m_Scene.nNumCamera == 0)
	{
		PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a camera. Please add one and re-export.\n");
		return false;
	}

	// We also check that the scene contains at least one light
	if(m_Scene.nNumLight == 0)
	{
		PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a light. Please add one and re-export.\n");
		return false;
	}

	// Initialize variables used for the animation
	m_fFrame = 0;
	m_iTimePrev = PVRShellGetTime();

	return true;
}
Beispiel #24
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);	
}
Beispiel #25
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 CChildImage::RenderScene()
{
	//Clear the screen with the current clear color.
	vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight));

	//Change the matrix mode to VG_MATRIX_IMAGE_USER_TO_SURFACE so we can transform the images
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);

	//Set the current matrix to the identiy
	vgLoadIdentity();

	//Translate the image to the desired position
	vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f + 5.0f);

	//Draw the main image
	vgDrawImage(m_vgImage);

	//Reset the current matrix...
	vgLoadIdentity();

	//...Perform a translation to position the first child image...
	int i32Height = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT);
	vgTranslate(PVRShellGet(prefWidth) * 0.5f - (vgGetParameteri(m_avgChildImages[1], VG_IMAGE_WIDTH) * 0.5f), PVRShellGet(prefHeight)* 0.5f - i32Height - 5.0f);

	//...and draw
	vgDrawImage(m_avgChildImages[0]);

	//Reset the current matrix...
	vgLoadIdentity();

	//...Perform a translation to position the second child image...
	i32Height = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT) + vgGetParameteri(m_avgChildImages[1], VG_IMAGE_HEIGHT);
	vgTranslate(PVRShellGet(prefWidth) * 0.5f - (vgGetParameteri(m_avgChildImages[1], VG_IMAGE_WIDTH) * 0.5f), PVRShellGet(prefHeight)* 0.5f - i32Height - 10.0f);

	//...and draw
	vgDrawImage(m_avgChildImages[1]);

	m_PrintVG.DisplayDefaultTitle("ChildImage", "", ePVRTPrint3DLogoIMG);
	return true;
}
/*******************************************************************************
 * Function Name  : InitView
 * Returns        : true if no error occured
 * Description    : Code in InitView() will be called by the Shell upon a change
 *					in the rendering context.
 *					Used to initialize variables that are dependant on the rendering
 *					context (e.g. textures, vertex buffers, etc.)
 *******************************************************************************/
bool OGLESSkinning::InitView()
{
	CPVRTString error;

	//	Check to see whether the matrix palette extension is supported.
	if(!CPVRTglesExt::IsGLExtensionSupported("GL_OES_matrix_palette"))
	{
		PVRShellSet(prefExitMessage, "ERROR: The extension GL_OES_matrix_palette is unsupported.\n");
		return false;
	}

	// Initialise the matrix palette extensions
	m_Extensions.LoadExtensions();

	// Load the textures
	if(!LoadTextures(&error))
	{
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}

	// Init Print3D to display text on screen
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	if(m_Print3D.SetTextures(0, PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	// Model View Matrix
	CameraGetMatrix();

	// Projection Matrix
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(m_mProjection.f);

	// GENERIC RENDER STATES

	// Enables Depth Testing
	glEnable(GL_DEPTH_TEST);

	// Enables Smooth Colour Shading
	glShadeModel(GL_SMOOTH);

	// Enable texturing
	glEnable(GL_TEXTURE_2D);

	// Define front faces
	glFrontFace(GL_CW);

	// Enables texture clamping
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

	// Reset the model view matrix to position the light
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Setup ambiant light
    glEnable(GL_LIGHTING);

	PVRTVec4 lightGlobalAmbient = PVRTVec4(1.0f, 1.0f, 1.0f, 1.0f);
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lightGlobalAmbient.ptr());

	// Setup a directional light source
	PVRTVec4 lightPosition = PVRTVec4(-0.7f, -1.0f, 0.2f, 0.0f);
    PVRTVec4 lightAmbient  = PVRTVec4(1.0f, 1.0f, 1.0f, 1.0f);
    PVRTVec4 lightDiffuse  = PVRTVec4(1.0f, 1.0f, 1.0f, 1.0f);
    PVRTVec4 lightSpecular = PVRTVec4(0.2f, 0.2f, 0.2f, 1.0f);

    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, lightPosition.ptr());
    glLightfv(GL_LIGHT0, GL_AMBIENT,  lightAmbient.ptr());
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  lightDiffuse.ptr());
    glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular.ptr());

	LoadVbos();

	/*
		Initialise an array to lookup the textures
		for each material in the scene.
	*/
	m_puiTextures = new GLuint[m_Scene.nNumMaterial];

	for(unsigned int i = 0; i < m_Scene.nNumMaterial; ++i)
	{
		m_puiTextures[i] = m_uiLegTex;

		SPODMaterial* pMaterial = &m_Scene.pMaterial[i];
		if(strcmp(pMaterial->pszName, "Mat_body") == 0)
		{
			m_puiTextures[i] = m_uiBodyTex;
		}
		else if(strcmp(pMaterial->pszName, "Mat_legs") == 0)
		{
			m_puiTextures[i] = m_uiLegTex;
		}
		else if(strcmp(pMaterial->pszName, "Mat_belt") == 0)
		{
			m_puiTextures[i] = m_uiBeltTex;
		}
	}

	return true;
}
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occured
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES3Refraction::InitView()
{
	CPVRTString ErrorStr;

	/*
		Initialize VBO data
	*/
	LoadVbos();

	/*
		Load textures
	*/
	if (!LoadTextures(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	/*
		Load and compile the shaders & link programs
	*/
	if (!LoadShaders(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Set the sampler2D uniforms to corresponding texture units
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "sTexture"), 0);

	// Is the screen rotated?
	m_bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);
	/*
		Initialize Print3D
	*/
	if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), m_bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	/*
		Initalise the background
	*/

	if(m_Background.Init(0, m_bRotate, &ErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	/*
		Calculate the projection and view matrices
	*/
	m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI/6, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), CAM_NEAR, CAM_FAR, PVRTMat4::OGL, m_bRotate);

	m_mView = PVRTMat4::LookAtRH(PVRTVec3(0, 0, 150), PVRTVec3(0, 0, 0), PVRTVec3(0, 1, 0));

	/*
		Set OpenGL ES render states needed for this training course
	*/

	// Use a nice bright blue as clear colour
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	return true;
}
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occured
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES2AnisotropicLighting::InitView()
{
	CPVRTString ErrorStr;

	/*
		Initialize VBO data
	*/
	LoadVbos();

	/*
		Load textures
	*/
	if (!LoadTextures(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	/*
		Load and compile the shaders & link programs
	*/
	if (!LoadShaders(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Is the screen rotated?
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);
	/*
		Initialize Print3D
	*/
	if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	/*
		Calculate the projection and view matrices
	*/
	float fAspect = PVRShellGet(prefWidth) / (float)PVRShellGet(prefHeight);
	m_mViewProj = PVRTMat4::PerspectiveFovFloatDepthRH(CAM_FOV, fAspect, CAM_NEAR, PVRTMat4::OGL, bRotate);
	m_mViewProj *= PVRTMat4::LookAtRH(PVRTVec3(0.f, 0.f, 150.f), PVRTVec3(0.f), PVRTVec3(0.f, 1.f, 0.f));

	/*
		Set uniforms that are constant throughout this training course
	*/
	// Set the sampler2D variable to the first texture unit
	glUseProgram(m_FastShader.uiId);
	glUniform1i(glGetUniformLocation(m_FastShader.uiId, "sTexture"), 0);

	// Define material properties
	glUseProgram(m_SlowShader.uiId);
	float afMaterial[4] = {
		0.4f,	// Diffuse intensity scale
		0.6f,	// Diffuse intensity bias
		0.82f,	// Specular intensity scale
		0.0f,	// Specular bias
	};
	glUniform4fv(glGetUniformLocation(m_SlowShader.uiId, "Material"), 1, afMaterial);
	// Set surface grain direction
	PVRTVec3 vMsGrainDir = PVRTVec3(2, 1, 0).normalized();
	glUniform3fv(glGetUniformLocation(m_SlowShader.uiId, "GrainDir"), 1, vMsGrainDir.ptr());

	/*
		Set OpenGL ES render states needed for this training course
	*/
	// Enable backface culling and depth test
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);

	// Enable z-buffer test
	// We are using a projection matrix optimized for a floating point depth buffer,
	// so the depth test and clear value need to be inverted (1 becomes near, 0 becomes far).
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_GEQUAL);
	glClearDepthf(0.0f);

	// Use a nice bright blue as clear colour
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	m_fAngleY = 0;
	m_eRenderMode = eTexLookup;

	return true;
}
Beispiel #29
0
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occurred
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependent on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES3Skybox2::InitView()
{
	// Sets the clear colour
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	// Enables depth test using the z-buffer
	glEnable(GL_DEPTH_TEST);

	CPVRTString ErrorStr;

	/*
		Load textures
	*/
	if(!LoadTextures(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	/*********************/
	/* Create the Skybox */
	/*********************/
	float* skyboxVertices;
	float* skyboxUVs;

	PVRTCreateSkybox( 500.0f, true, 512, &skyboxVertices, &skyboxUVs );

	glGenBuffers(1, &m_iSkyVboID);
	glBindBuffer(GL_ARRAY_BUFFER, m_iSkyVboID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 24, &skyboxVertices[0], GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	PVRTDestroySkybox(skyboxVertices, skyboxUVs);

	/**********************/
	/* Create the Effects */
	/**********************/

	{
		// Parse the file
		m_pEffectParser = new CPVRTPFXParser();

		if(m_pEffectParser->ParseFromFile(g_pszEffectFileName, &ErrorStr) != PVR_SUCCESS)
		{
			delete m_pEffectParser;
			PVRShellSet(prefExitMessage, ErrorStr.c_str());
			return false;
		}

		m_ppEffects = new CPVRTPFXEffect*[g_ui32NoOfEffects];
		memset(m_ppEffects, 0, sizeof(CPVRTPFXEffect*) * g_ui32NoOfEffects);

		// Skybox shader
		if(!LoadEffect(&m_ppEffects[0], "skybox_effect", g_pszEffectFileName))
		{
			delete m_pEffectParser;
			delete[] m_ppEffects;
			return false;
		}

		// The Balloon Shaders
		if(!LoadEffect(&m_ppEffects[1], "balloon_effect1", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[2], "balloon_effect2", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[3], "balloon_effect3", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[4], "balloon_effect4", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[5], "balloon_effect5", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[6], "balloon_effect6", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[7], "balloon_effect7", g_pszEffectFileName))
		{
			delete m_pEffectParser;
			delete[] m_ppEffects;
			return false;
		}
	}

	// Create Geometry Buffer Objects.
	m_aiVboID = new GLuint[m_Scene.nNumMeshNode];
	glGenBuffers(m_Scene.nNumMeshNode, m_aiVboID);

	for(unsigned int 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];

		// Genereta a vertex buffer and set the interleaved vertex datas.
		glBindBuffer(GL_ARRAY_BUFFER, m_aiVboID[i]);
		glBufferData(GL_ARRAY_BUFFER, pMesh->sVertex.nStride*pMesh->nNumVertex, pMesh->pInterleaved, GL_STATIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);

	}

	/**********************
	** Projection Matrix **
	**********************/
	/* Projection */
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);
	m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI / 6, (float) PVRShellGet(prefWidth) / (float) PVRShellGet(prefHeight), 4.0f, 1000.0f, PVRTMat4::OGL, bRotate);

	// Calculate the model view matrix turning around the balloon
	ComputeViewMatrix();

	/* Init Values */
	bPause = false;
	fDemoFrame = 0.0;
	fBurnAnim = 0.0f;

	m_i32Effect = 1;

	// Initialise Print3D
	if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	// Initialise variables used for the animation
	m_iTimePrev = PVRShellGetTime();

	return true;
}
Beispiel #30
0
/*******************************************************************************
 * Function Name  : InitView
 * Returns        : true if no error occured
 * Description    : Code in InitView() will be called by the Shell upon a change
 *					in the rendering context.
 *					Used to initialise variables that are dependent on the rendering
 *					context (e.g. textures, vertex buffers, etc.)
 *******************************************************************************/
bool CChildImage::InitView()
{
	//Create an image
	m_vgImage = vgCreateImage(VG_sRGBA_8888, IMG_SIZE, IMG_SIZE, VG_IMAGE_QUALITY_NONANTIALIASED);

	/*
	Populate the image from memory. A 32bit integer array (8bits per component)
	is created and populated.
	*/

	VGuint* pui32ImgData = new VGuint[IMG_SIZE*IMG_SIZE];

	for(int i = 0; i < IMG_SIZE; ++i)
	{
		for(int j = 0; j < IMG_SIZE; ++j)
		{
			// Fills the data with a fancy pattern
			if ( ((i*j)/8) % 2 )
				pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255,255,0,255);
			else
				pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255, 255 - (j * 2), 255 - i, 255 - (i * 2));
		}
	}

	/*
	The data in the array is then copied to the portion of the image starting at (0,0) through to (IMG_SIZE, IMG_SIZE), in
	this case that is the whole image. The coordinate system of the image places (0,0) at the bottom left-hand corner and
	(IMG_SIZE, IMG_SIZE) at the top right-hand corner.
	*/
	vgImageSubData(m_vgImage, pui32ImgData, sizeof(VGuint) * IMG_SIZE, VG_sRGBA_8888, 0, 0, IMG_SIZE, IMG_SIZE);

	// Delete the image data as it is now in OpenVG memory
	delete[] pui32ImgData;
	pui32ImgData = 0;

	//Create child images

	/*
	The first child is a child of m_vgImage and is made up of the region of m_vgImage from (0,0) to (IMG_SIZE / 2, IMG_SIZE / 2).
	Note: The area specified must be in the bounds of the parent.
	*/
	m_avgChildImages[0] = vgChildImage(m_vgImage,  0, 0, (VGint) (IMG_SIZE * 0.5), (VGint) (IMG_SIZE * 0.5));

	//The second child is a clone of the first child.

	//Get the dimensions of the first child..
	int i32ChildWidth = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_WIDTH);
	int i32ChildHeight= vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT);

	//..and use them to define the region for creating the second child.
	m_avgChildImages[1] = vgChildImage(m_avgChildImages[0],  0, 0, i32ChildWidth,  i32ChildHeight);

	/*
	Clear a small portion of the bottom left-hand corner of m_avgChildImages[0] to red.
	This change will be seen in all relatives of m_avgChildImages[0], reason being they
	all share the same physical memory.

	Note:

	When clearing you specify the coordinate you want to start from and then how many pixels
	across and up you want to clear.
	*/
	VGfloat afClearColour[] = {1.0f, 0.0f, 0.0f, 1.0f};
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);
	vgClearImage(m_avgChildImages[0], 0, 0, 10, 10);

	//Set the clear colour for clearing the sceen
	afClearColour[0] = 0.6f;
	afClearColour[1] = 0.8f;
	afClearColour[2] = 1.0f;
	afClearColour[3] = 1.0f;

	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight));
	return true;
}