/*!**************************************************************************** @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 OGLES3ShadowMapping::InitView() { CPVRTString ErrorStr; 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 (!LoadPFX(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Map the individual effects to make it easier to address them for (unsigned int i=0; i < m_pPFXEffectParser->GetNumberEffects(); i++) { // Store the indices for the individual effects if (m_pPFXEffectParser->GetEffect(i).Name == c_RenderShadowMapEffectName) m_iEffectIndex[INDEX_RENDERSHADOW] = i; else if (m_pPFXEffectParser->GetEffect(i).Name == c_RenderSceneEffectName) m_iEffectIndex[INDEX_RENDERSCENE] = i; } if (!CreateFBO(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Initialize Print3D if (m_Print3D.SetTextures(0, PVRShellGet(prefWidth), PVRShellGet(prefHeight),m_bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialize Print3D\n"); return false; } // Use a nice bright blue as clear colour glClearColor(0.6f, 0.8f, 1.0f, 1.0f); // Enable culling glEnable(GL_CULL_FACE); // and depth testing glEnable(GL_DEPTH_TEST); 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 OGLES3MagicLantern::InitView() { CPVRTString ErrorStr; // At this point m_Scene should have been already processed by InitApplication() // and all the POD data properly loaded, but lets do a little test just in case. if (!m_Scene.IsLoaded()) { PVRShellSet(prefExitMessage, "ERROR: POD file has not been loaded correctly. Cannot continue. \n"); return false; } // Initialize VBO data if(!LoadVbos()) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Load and compile the shaders, link programs and load textures. if(!LoadPFX()) { 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; } // Enable backface culling and depth test glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); // Black as clear colour glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Disable blending glDisable(GL_BLEND); // Set up the view and projection matrices from the camera. // The camera does not moves so these matrices only need to be // calculated once. // If you want to make the camera dynamic, re-calculate the view matrix // every frame. PVRTVec3 vFrom, vTo(0.0f), vUp(0.0f, 1.0f, 0.0f); float fFOV; // Camera nodes are after the mesh and light nodes in the array. // We grab camera num 0 (the only one in the scene) const int g_ui32Camera = 0; int i32CamID = m_Scene.pNode[m_Scene.nNumMeshNode + m_Scene.nNumLight + g_ui32Camera].nIdx; // Get the camera position and target if(m_Scene.pCamera[i32CamID].nIdxTarget != -1) // Does the camera have a target? m_Scene.GetCameraPos( vFrom, vTo, g_ui32Camera); // vTo is taken from the target node. else m_Scene.GetCamera( vFrom, vTo, vUp, g_ui32Camera); // vTo is calculated from the rotation. // Calculate the FOV depending of the screen dimensions so everything fit in view // regardless whether the screen is rotated or not. // if the aspect ratio is different than 640x480 adapt FOV so the scene still looks correct. float fRatioWoverH = (480.0f/640.0f) * ((!bRotate) ? (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight) : (float)PVRShellGet(prefHeight)/(float)PVRShellGet(prefWidth)); fFOV = m_Scene.pCamera[i32CamID].fFOV / fRatioWoverH; // We can build the model view matrix from the camera position, target and an up vector. m_mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp); // Calculate the projection matrix. m_mProjection = PVRTMat4::PerspectiveFovRH(fFOV, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), m_Scene.pCamera[i32CamID].fNear, m_Scene.pCamera[i32CamID].fFar, PVRTMat4::OGL, bRotate); return true; }