Example #1
0
/*!****************************************************************************
 @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 OGLES2ShadowMapping::InitView()
{
	CPVRTString ErrorStr;

	if(!CPVRTgles2Ext::IsGLExtensionSupported("GL_OES_depth_texture"))
	{
		PVRShellSet(prefExitMessage, "Error: Unable to run this training course as it requires extension 'GL_OES_depth_texture'");
		return false;
	}

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

	// Initialize VBO data
	if(!LoadVbos(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	//	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;
	}

	// Create a frame buffer with only the depth buffer attached
	glGenFramebuffers(1, &m_uiFrameBufferObject);
	glBindFramebuffer(GL_FRAMEBUFFER, m_uiFrameBufferObject);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_uiShadowMapTexture, 0);
 
	if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
	{
		PVRShellSet(prefExitMessage, "ERROR: Frame buffer not set up correctly\n");
		return false;
		
	}

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

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

	// 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 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 OGLESPVRScopeRemote::InitView()
{
	CPPLProcessingScoped PPLProcessingScoped(m_psSPSCommsData,
		__FUNCTION__, static_cast<unsigned int>(strlen(__FUNCTION__)), m_i32FrameCounter);

	CPVRTString ErrorStr;
	/*
		Initialize Print3D
	*/
    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;
	}

	// Sets the clear color
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	// Enables texturing
	glEnable(GL_TEXTURE_2D);

	//	Initialize VBO data
	if(!LoadVbos(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

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

	/*
		Calculate the projection and view matrices
	*/

	m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PIf/6, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), CAM_NEAR, CAM_FAR, PVRTMat4::OGL, bRotate);

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

	// Enable the depth test
	glEnable(GL_DEPTH_TEST);

	// Enable culling
	glEnable(GL_CULL_FACE);

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

	return true;
}
Example #3
0
/*!***************************************************************************
@Function		LoadEffect
@Output			ppEffect
@Input			pszEffectName
@Input			pszFileName
@Return			bool	
@Description	Loads a PFX Effect.
*****************************************************************************/
bool OGLES3Skybox2::LoadEffect( CPVRTPFXEffect **ppEffect, const char * pszEffectName, const char *pszFileName )
{
	if(!ppEffect)
		return false;

	unsigned int	nUnknownUniformCount;
	CPVRTString		error;
	CPVRTPFXEffect* pEffect = *ppEffect;

	// Load an effect from the file
	if(!pEffect)
	{
		*ppEffect = new CPVRTPFXEffect();
		pEffect   = *ppEffect;

		if(!pEffect)
		{
			delete m_pEffectParser;
			PVRShellSet(prefExitMessage, "Failed to create effect.\n");
			return false;
		}
	}

	if(pEffect->Load(*m_pEffectParser, pszEffectName, pszFileName, NULL, nUnknownUniformCount, &error) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}

	if(nUnknownUniformCount)
	{
		PVRShellOutputDebug(error.c_str());
		PVRShellOutputDebug("Unknown uniform semantic count: %d\n", nUnknownUniformCount);
	}

	/* Set the textures for each effect */
	unsigned int			i,j ;
	const CPVRTArray<SPVRTPFXTexture>& sTex = pEffect->GetTextureArray();

	for(i = 0; i < sTex.GetSize(); ++i)
	{
		for(j = 0; j < g_ui32TexNo; ++j)
		{
			int iTexIdx = m_pEffectParser->FindTextureByName(sTex[i].Name);
			const CPVRTStringHash& FileName = m_pEffectParser->GetTexture(iTexIdx)->FileName;
			if(FileName == g_aszTextureNames[j])
			{
				if(j == 3 || j == 4)
					pEffect->SetTexture(i, m_ui32TextureIDs[j], PVRTEX_CUBEMAP);
				else
					pEffect->SetTexture(i, m_ui32TextureIDs[j]);
				break;
			}
		}
	}

	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 OGLES2ChameleonMan::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;
	}

	/*
		Initialize Print3D
	*/

	// Is the screen rotated?
	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;
	}

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

	glEnable(GL_DEPTH_TEST);

	// Use black as our clear colour
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

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

	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 OGLES3TextureStreaming::InitView()
{
	CPVRTString ErrorStr;

	//	Initialize VBO data
	if(!LoadVbos(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	//	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;
	}

	/*
		Initialize the textures used by Print3D.
		To properly display text, Print3D needs to know the viewport dimensions
		and whether the text should be rotated. We get the dimensions using the
		shell function PVRShellGet(prefWidth/prefHeight). We can also get the
		rotate parameter by checking prefIsRotated and prefFullScreen.
	*/
	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;
	}

	//Set OpenGL ES render states needed for this demo

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

	glEnable(GL_DEPTH_TEST);

	// Sets the clear color
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	// Setup the AV capture
	if(!m_Camera.InitialiseSession(ePVRTHWCamera_Front))
		return false;

	return true;
}
Example #6
0
/*!****************************************************************************
 @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 OGLES3IntroducingPOD::InitView()
{
	CPVRTString ErrorStr;

	/*
		Initialize VBO data
	*/
	if(!LoadVbos(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	/*
		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;
	}

	/*
		Initialize Print3D
	*/
	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;
	}

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

	glEnable(GL_DEPTH_TEST);

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

	return true;
}
Example #7
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 dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES3EdgeDetection::InitView()
{
	// Store width and height of the viewport.
	m_i32TexWidth = PVRShellGet(prefWidth);
	m_i32TexHeight = PVRShellGet(prefHeight);

	/*	Get the current frame buffer object. As the program hasn't set it yet, this is the default buffer.
		On most platforms this just gives 0, but there are exceptions.	*/
	glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_i32OriginalFramebuffer);

	// Create string for error codes.
	CPVRTString ErrorStr;

	// Checks to see if the screen is rotated or not.
    bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	// Initialize VBO data
	if(!LoadVbos(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

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

	// Load external textures and create internal ones.
	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;
	}

	// Creates and checks FBO creation
	if (!CreateFBO(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	SetupView(bRotate);

	return true;
}
Example #8
0
/*!****************************************************************************
 @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 OGLES2ParticleSystem::InitView()
{	
	CPVRTString ErrorStr;
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

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

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

	//	Load and compile the shaders & link programs
	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;
	}

	// Creates the projection matrix.
	m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI / 3.0f, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate);
			
	m_pParticleSystem = new ParticleSystemCPU();
	if (!m_pParticleSystem->Init(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	m_pParticleSystem->SetNumberOfParticles(g_ui32InitialNoParticles);
	m_pParticleSystem->SetCollisionSpheres(g_caSpheres, g_cuiNumSpheres);

	glBindBuffer(GL_ARRAY_BUFFER, 0);

	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;
}
/*!****************************************************************************
 @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 OGLES3AlphaBlend::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;
	}

	/*
		Get screen rotation state
	*/
	m_bRotateScreen = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

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

	// Disable the depth test
	glDisable(GL_DEPTH_TEST);

	// Enable culling
	glEnable(GL_CULL_FACE);
	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 OGLESRenderToTexture::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));
	
	/*
		Loads the scene from the .pod file into a CPVRTModelPOD object.
		We could also export the scene as a header file and
		load it with ReadFromMemory().
	*/

	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'.";
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	return true;
}
Example #12
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 OGLES2FilmTV::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)
	{
		CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'.";
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		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;
	}

	return true;
}
Example #13
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 OGLES2EdgeDetection::InitApplication()
{
#ifdef SHOW_MAX_FPS
	// Disable v-sync
	PVRShellSet(prefSwapInterval,0);
#endif

	// 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));

	/*	Loads the scene from the .pod file into a CPVRTModelPOD object.
		We could also export the scene as a header file and
		load it with ReadFromMemory().	*/
	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'.";
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	//Initialises the time variables.
	m_ulCurrentTime = PVRShellGetTime();
	m_ulPreviousTimeAngle = m_ulCurrentTime;
	m_ulPreviousTimeFPS = m_ulCurrentTime;

	return true;
}
Example #14
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 dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES3PhantomMask::InitView()
{
    CPVRTString ErrorStr;

    // Initialise VBO data
    if(!LoadVbos(&ErrorStr))
    {
        PVRShellSet(prefExitMessage, ErrorStr.c_str());
        return false;
    }

    // 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;
    }

    // Initialise Print3D
    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;
    }

    // Initialise the background
    if(m_Background.Init(0, bRotate, &ErrorStr) != PVR_SUCCESS)
    {
        PVRShellSet(prefExitMessage, ErrorStr.c_str());
        return false;
    }

    // Use a nice bright blue as clear colour
    glClearColor(0.6f, 0.8f, 1.0f, 1.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 OGLES3TextureStreaming::InitApplication()
{
	m_i32Frame       = 0;
	m_puiVbo         = 0;
	m_puiIndexVbo    = 0;
	m_ulGlowTime     = 0;
	m_iNoiseCoordIdx = 0;
	m_uiTVScreen     = -1;
	m_bGlowState     = false;

	/*
		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));

	// Load the scene
	if(m_Scene.ReadFromFile(c_pszSceneFile) != PVR_SUCCESS)
	{
		CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_pszSceneFile) + "'.\n";
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		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.0f;
	m_fBandScroll = -c_fBandWidth;
	m_ulTimePrev = PVRShellGetTime();

	return true;
}
Example #16
0
/*!****************************************************************************
 @Function		LoadTextures
 @Return		bool			true if no error occured
 @Description	Loads the textures required for this training course
******************************************************************************/
bool OGLES2FilmTV::LoadTextures(CPVRTString* pErrorStr)
{
	/*
		Loads the textures.
		For a more detailed explanation, see Texturing and IntroducingPVRTools
	*/

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

	if(!m_puiTextureIDs)
	{
		*pErrorStr = "ERROR: Insufficient memory.";
		return false;
	}

	for(unsigned int i = 0; i < m_Scene.nNumMaterial; ++i)
	{
		m_puiTextureIDs[i] = 0;
		SPODMaterial* pMaterial = &m_Scene.pMaterial[i];

		if(pMaterial->nIdxTexDiffuse != -1)
		{
			/*
				Using the tools function PVRTTextureLoadFromPVR load the textures required by the pod file.

				Note: This function only loads .pvr files. You can set the textures in 3D Studio Max to .pvr
				files using the PVRTexTool plug-in for max. Alternatively, the pod material properties can be
				modified in PVRShaman.
			*/

			CPVRTString sTextureName = m_Scene.pTexture[pMaterial->nIdxTexDiffuse].pszName;

			if(sTextureName == "TV.pvr")
				m_uiTVScreen = i;

			if(PVRTTextureLoadFromPVR(sTextureName.c_str(), &m_puiTextureIDs[i]) != PVR_SUCCESS)
			{
				*pErrorStr = "ERROR: Failed to load " + sTextureName + ".";

				// Check to see if we're trying to load .pvr or not
				CPVRTString sFileExtension = PVRTStringGetFileExtension(sTextureName);

				if(sFileExtension.toLower() != "pvr")
					*pErrorStr += "Note: FilmTV can only load .pvr files.";

				return false;
			}
		}
	}

	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;
}
/*!****************************************************************************
 @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 OGLESPVRScopeExample::InitApplication()
{
	// At the time of writing, this counter is the USSE load for vertex + pixel processing
	m_i32Counter	= 46;
	m_i32Group		= 0;
	m_i32Interval	= 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));

	/*
		Loads the scene from the .pod file into a CPVRTModelPOD object.
		We could also export the scene as a header file and
		load it with ReadFromMemory().
	*/

	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'.";
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Process the command line
	{
		const unsigned int	nOptNum			= PVRShellGet(prefCommandLineOptNum);
		const SCmdLineOpt	* const psOpt	= (const SCmdLineOpt*)PVRShellGet(prefCommandLineOpts);
		for(unsigned int i = 0; i < nOptNum; ++i)
		{
			if(_stricmp(psOpt[i].pArg, "-counter") == 0 && psOpt[i].pVal)
			{
				m_i32Counter = atoi(psOpt[i].pVal);
			}
			else if(_stricmp(psOpt[i].pArg, "-group") == 0 && psOpt[i].pVal)
			{
				m_i32Group = atoi(psOpt[i].pVal);
			}
			else if(_stricmp(psOpt[i].pArg, "-interval") == 0 && psOpt[i].pVal)
			{
				m_i32Interval = atoi(psOpt[i].pVal);
			}
		}
	}

	return true;
}
Example #19
0
	Texture::Texture(const CPVRTString& strFilename)
	{
		PVR_Texture_Header sOldHeader;
		if(PVRTTextureLoadFromPVR(strFilename.c_str(),(GLuint*)&m_u32Handle,&sOldHeader) == PVR_SUCCESS)
		{
			m_strFilename = strFilename;
			m_bIsCubeMap = (sOldHeader.dwpfFlags&PVRTEX_CUBEMAP)!=0;
		}
		else
		{
			ConsoleLog::inst().log("PVREngine::Texture: Could not load texture.\n");
			return;
		}
	}
Example #20
0
/*!***************************************************************************
 @Function		PVRTShaderLoadFromFile
 @Input			pszBinFile			binary shader filename
 @Input			pszSrcFile			source shader filename
 @Input			Type				type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
 @Input			Format				shader binary format, or 0 for source shader
 @Output		pObject				the resulting shader object
 @Output		pReturnError		the error message if it failed
 @Input			pContext			Context
 @Input			aszDefineArray		Array of defines to be pre-appended to shader string
 @Input			uiDefArraySize		Size of the define array
 @Return		PVR_SUCCESS on success and PVR_FAIL on failure (also fills pReturnError)
 @Description	Loads a shader file into memory and passes it to the GL. 
				It also passes defines that need to be pre-appended to the shader before compilation.
*****************************************************************************/
EPVRTError PVRTShaderLoadFromFile(	const char* const pszBinFile,
									const char* const pszSrcFile,
									const GLenum Type,
									const GLenum Format,
									GLuint* const pObject,
									CPVRTString* const pReturnError,
									const SPVRTContext* const pContext,
									const char* const* aszDefineArray, GLuint uiDefArraySize)
{
	PVRT_UNREFERENCED_PARAMETER(pContext);

	*pReturnError = "";

	/* 	
		Prepending defines relies on altering the source file that is loaded.
		For this reason, the function calls the source loader instead of the binary loader if defines have
		been passed in.
	*/
	if(Format && pszBinFile && uiDefArraySize == 0)
	{
		CPVRTResourceFile ShaderFile(pszBinFile);
		if (ShaderFile.IsOpen())
		{
			if(PVRTShaderLoadBinaryFromMemory(ShaderFile.DataPtr(), ShaderFile.Size(), Type, Format, pObject, pReturnError) == PVR_SUCCESS)
				return PVR_SUCCESS;
		}

		*pReturnError += CPVRTString("Failed to open shader ") + pszBinFile + "\n";
	}

	CPVRTResourceFile ShaderFile(pszSrcFile);
	if (!ShaderFile.IsOpen())
	{
		*pReturnError += CPVRTString("Failed to open shader ") + pszSrcFile + "\n";
		return PVR_FAIL;
	}
 
	CPVRTString ShaderFileString;
	const char* pShaderData = (const char*) ShaderFile.DataPtr();

	// Is our shader resource file data null terminated?
	if(pShaderData[ShaderFile.Size()-1] != '\0')
	{
		// If not create a temporary null-terminated string
		ShaderFileString.assign(pShaderData, ShaderFile.Size());
		pShaderData = ShaderFileString.c_str();
	}

	return PVRTShaderLoadSourceFromMemory(pShaderData, Type, pObject, pReturnError, aszDefineArray, uiDefArraySize);
}
unsigned createProgramFromSource(
        const char *    vss,        // vertex shader source
        const char *    fss,        // fragment shader source
        const char**    attribs,    // attribute list
        unsigned *      attrLocal,  // store attribute locations
        const unsigned  num         // attribute list size
    )
{
    unsigned id = 0;
    unsigned vs = 0;
    unsigned fs = 0;
    EPVRTError ret = PVR_SUCCESS;
    CPVRTString msg;
    int step = 0;
    do
    {
        if (!vss || !fss || (num && (!attribs || !attrLocal)))
        {
            Debug::logd("There's no shader source!!");
            break;
        }
        // 1 Compile vertex shader.
        step = 1;
        if (PVR_SUCCESS != PVRTShaderLoadSourceFromMemory(
                vss, GL_VERTEX_SHADER, &vs, &msg, 0, 0))
            break;
        // 2 Compile fragment shader.
        step = 2;
        if (PVR_SUCCESS != PVRTShaderLoadSourceFromMemory(
                fss, GL_FRAGMENT_SHADER, &fs, &msg, 0, 0))
            break;
        // 3 Link two shaders to program, and bind attribs to specific locations.
        step = 3;
        if (PVR_SUCCESS != PVRTCreateProgram( &id, vs, fs, attribs, num, &msg))
            break;
        for (unsigned i = 0; i < num; i++)  *(attrLocal + i) = i;
    } while (false);
    if (! id)
    {
        Debug::logd("(step:%d)%s", step, msg.c_str());
    }
    return id;
}
Example #22
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;
	}
Example #23
0
/*!****************************************************************************
 @Function		LoadTextures
 @Output		pErrorStr		A CPVRTString describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads the textures required for this training course
******************************************************************************/
bool OGLES3ShadowMapping::LoadTextures(CPVRTString* const pszErrorStr)
{
	for (unsigned int i=0; i < c_uiNumTextureNames; i++)
	{		
		// Check if the texture already exists in the map
		if(m_TextureCache.Exists(c_sTextureNames[i]))
			continue;

		CPVRTString filename = c_sTextureNames[i].String() + CPVRTString(".pvr");
		
		// Texture is not loaded. Load and add to the map.
		GLuint uiHandle;
		PVRTextureHeaderV3 sHeader;
		if(PVRTTextureLoadFromPVR(filename.c_str(), &uiHandle, &sHeader) != PVR_SUCCESS)
		{
			*pszErrorStr = CPVRTString("Failed to load texture: ") + filename;
			return false;		
		}

		m_TextureCache[c_sTextureNames[i]] = uiHandle;		
	}	
	
	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;
}
Example #27
0
bool PODPlayer::InitApplication()
{
	// set up console/log
	m_pConsole = ConsoleLog::ptr();

	// grab pointers to these handlers and initialise them
	m_pUniformHandler = UniformHandler::ptr();
	m_pTimeController = TimeController::ptr();

	m_psMeshManager = NULL;
	m_psTransparentMeshManager = NULL;
	m_pOptionsMenu = NULL;

	// deal with command line
	int i32NumCLOptions = PVRShellGet(prefCommandLineOptNum);
	SCmdLineOpt* sCLOptions = (SCmdLineOpt*)PVRShellGet(prefCommandLineOpts);
	CPVRTString strFilename;

	PVRESParser cParser;

	bool bFoundFile = false;
	if(sCLOptions)
	{
		for(int i=0;i<i32NumCLOptions;++i)
		{
			if(!sCLOptions[i].pVal)
			{	// could be script or pod
				strFilename=sCLOptions[i].pArg;
				// determine whether a script or a POD or nothing
				CPVRTString strExtension = PVRTStringGetFileExtension(strFilename);
				if(strExtension.compare(".pvres")==0
					|| strExtension.compare(".PVRES")==0)
				{	// script file
					m_pConsole->log("Found script:%s\n", strFilename.c_str());
					cParser.setScriptFileName(strFilename);
					bFoundFile = true;
				}
				else
				{
					if(strExtension.compare(".pod")==0
						|| strExtension.compare(".POD")==0)
					{	// pod file
						m_pConsole->log("Found POD\n");
						cParser.setPODFileName(strFilename);
						bFoundFile = true;
					}
					else
					{
						m_pConsole->log("Unrecognised filetype.\n");
					}
				}
			}
		}
	}
	if(!bFoundFile)
	{	// no command line options so open default pvres
		CPVRTString strDefaultPVRES((char*)(PVRShellGet(prefReadPath)));
		strDefaultPVRES += "Sample.pvres";
		cParser.setScriptFileName(strDefaultPVRES);
	}

	m_cPVRES = cParser.Parse();


	// sets up whether the console should write out constantly or not
	CPVRTString strLogPath = CPVRTString((char*)PVRShellGet(prefWritePath));
	m_pConsole->setOutputFile(strLogPath+="log.txt");
	m_pConsole->setStraightToFile(m_cPVRES.getLogToFile());

	m_pConsole->log("PODPlayer v0.2 alpha\n\n Initialising...\n");


	CPVRTString error = cParser.getError();
	if(!error.empty())
	{
		m_pConsole->log("Couldn't parse script: %s:\n%s",m_cPVRES.getScriptFileName().c_str(),error.c_str());
		PVRShellSet(prefExitMessage, m_pConsole->getLastLogLine().c_str());
		return false;
	}

	// Deal with results of script read


	// Load the scene from the .pod file into a CPVRTModelPOD object.
	if(m_Scene.ReadFromFile(m_cPVRES.getPODFileName().c_str()) != PVR_SUCCESS)
	{
		m_pConsole->log("Error: couldn't open POD file: %s\n",m_cPVRES.getPODFileName().c_str());
		PVRShellSet(prefExitMessage, m_pConsole->getLastLogLine().c_str());
		return false;
	}

	// The cameras are stored in the file. Check if it contains at least one.
	if(m_Scene.nNumCamera == 0)
	{
		m_bFreeCamera = true;
	}
	else
	{
		m_bFreeCamera = false;
	}
	// use camera 0 to begin with
	m_u32CurrentCameraNum = 0;

	// 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)
		{
			m_pConsole->log("ERROR: The meshes in the scene should use an indexed triangle list\n");
			PVRShellSet(prefExitMessage, m_pConsole->getLastLogLine().c_str());
			return false;
		}
	}

	PVRShellSet(prefFSAAMode,m_cPVRES.getFSAA());					// set fullscreen anti-aliasing
	PVRShellSet(prefPowerSaving,m_cPVRES.getPowerSaving());			// set power saving mode
	PVRShellSet(prefHeight,m_cPVRES.getHeight());					// set height of window
	PVRShellSet(prefWidth,m_cPVRES.getWidth());						// set width of window
	PVRShellSet(prefPositionX,m_cPVRES.getPosX());					// set horizontal position of window
	PVRShellSet(prefPositionY,m_cPVRES.getPosY());					// set vertical position of window
	PVRShellSet(prefQuitAfterTime,m_cPVRES.getQuitAfterTime());		// time after which PODPlayer will automatically quit
	PVRShellSet(prefQuitAfterFrame,m_cPVRES.getQuitAfterFrame());	// frame after which PODplayer will automatically quit
	PVRShellSet(prefSwapInterval,m_cPVRES.getVertSync()?1:0);		// set vertical sync with monitor
	PVRShellSet(prefFullScreen, m_cPVRES.getFullScreen());			// set fullscreen

	m_pUniformHandler->setScene(&m_Scene);
	m_pUniformHandler->setLightManager(LightManager::ptr());

	// Initialize variables used for the animation
	m_bOptions = false;												// don't show options at start up
	m_bOverlayOptions = false;										// don't overlay the options by default
	m_pTimeController->setNumFrames(m_Scene.nNumFrame);				// set the number of frames to animate across
	m_pTimeController->setFrame(m_cPVRES.getStartFrame());			// set the frame from which to start the animation
	m_pTimeController->setAnimationSpeed(m_cPVRES.getAnimationSpeed());	// set the speed with which to animate


	// set PODPlayer to initialising state
	m_i32Initialising = 1;

	m_pConsole->log("Initial setup Succeeded\n");
	return true;
}
/*!****************************************************************************
 @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 dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES2ParallaxBumpMap::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, "basemap"), 0);
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "normalmap"), 1);
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "heightmap"), 2);

	// 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_mView = PVRTMat4::LookAtRH(PVRTVec3(0, 0, 150), PVRTVec3(0, 0, 0), PVRTVec3(0, 1, 0));
	m_mViewProj = PVRTMat4::PerspectiveFovFloatDepthRH(CAM_FOV, fAspect, CAM_NEAR, PVRTMat4::OGL, bRotate);
	m_mViewProj *= m_mView;

	/*
		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);

	return true;
}
Example #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;
}
/*!****************************************************************************
 @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 OGLESPVRScopeRemote::InitApplication()
{
	// We want a data connection to PVRPerfServer
	{
		m_psSPSCommsData = pplInitialise("PVRScopeRemote", 14);
		m_bCommsError = false;

		// Demonstrate that there is a good chance of the initial data being
		// lost - the connection is normally completed asynchronously.
		pplSendMark(m_psSPSCommsData, "lost", static_cast<unsigned int>(strlen("lost")));

		// This is entirely optional. Wait for the connection to succeed, it will
		// timeout if e.g. PVRPerfServer is not running.
		int nBoolConnected;
		pplWaitForConnection(m_psSPSCommsData, &nBoolConnected, 1, 200);
	}

	CPPLProcessingScoped PPLProcessingScoped(m_psSPSCommsData,
		__FUNCTION__, static_cast<unsigned int>(strlen(__FUNCTION__)), m_i32FrameCounter);

	// set thickness variation of the film
	m_fMaxVariation		= 100.0f;
	// set the minimum thickness of the film
	m_fMinThickness		= 100.0f;

	m_i32FrameCounter = 0;
	m_i32Frame10Counter = 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));

	/*
		Loads the scene from the .pod file into a CPVRTModelPOD object.
		We could also export the scene as a header file and
		load it with ReadFromMemory().
	*/

	if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
	{
		CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'.";
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	/*
		Remotely editable library items
	*/
	if(m_psSPSCommsData)
	{
		SSPSCommsLibraryItem	asItems[8];
		unsigned int			nItemCount = 0;

		// Want editable: min thickness
		m_sCommsLibMinThickness.fCurrent	= m_fMinThickness;
		m_sCommsLibMinThickness.fMin		= 0.0f;
		m_sCommsLibMinThickness.fMax		= 500.0f;
		asItems[nItemCount].pszName		= "min thickness";
		asItems[nItemCount].nNameLength	= (unsigned int)strlen(asItems[nItemCount].pszName);

		asItems[nItemCount].eType		= eSPSCommsLibTypeFloat;

		asItems[nItemCount].pData		= (const char*)&m_sCommsLibMinThickness;
		asItems[nItemCount].nDataLength	= sizeof(m_sCommsLibMinThickness);
		++nItemCount;

		// Want editable: max variation
		m_sCommsLibMaxVariation.fCurrent	= m_fMaxVariation;
		m_sCommsLibMaxVariation.fMin		= 50.0f;
		m_sCommsLibMaxVariation.fMax		= 150.0f;
		asItems[nItemCount].pszName		= "max variation";
		asItems[nItemCount].nNameLength	= (unsigned int)strlen(asItems[nItemCount].pszName);

		asItems[nItemCount].eType		= eSPSCommsLibTypeFloat;

		asItems[nItemCount].pData		= (const char*)&m_sCommsLibMaxVariation;
		asItems[nItemCount].nDataLength	= sizeof(m_sCommsLibMaxVariation);
		++nItemCount;

		_ASSERT(nItemCount < sizeof(asItems) / sizeof(*asItems));

		/*
			Ok, submit our library
		*/
		if(!pplLibraryCreate(m_psSPSCommsData, asItems, nItemCount))
		{
			PVRShellOutputDebug("PVRScopeRemote: pplLibraryCreate() failed\n");
		}
	}

	/*
		User defined counters
	*/
	if(m_psSPSCommsData)
	{
		SSPSCommsCounterDef	asDefs[eCounterNum];
		for(unsigned int i = 0; i < eCounterNum; ++i)
		{
			asDefs[i].pszName		= c_apszDefs[i];
			asDefs[i].nNameLength	= (unsigned int)strlen(c_apszDefs[i]);
		}

		if(!pplCountersCreate(m_psSPSCommsData, asDefs, eCounterNum))
		{
			PVRShellOutputDebug("PVRScopeRemote: pplCountersCreate() failed\n");
		}
	}

	return true;
}