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 OGLES2Shaders::InitView() { // Is the screen rotated bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); /* Initialize Print3D textures */ if (m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) { PVRShellOutputDebug("ERROR: Cannot initialise Print3D\n"); return false; } glClearColor(0.6f, 0.8f, 1.0f, 1.0f); m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI/6, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), CAM_NEAR, CAM_FAR, PVRTMat4::OGL, bRotate); m_mView = PVRTMat4::Identity(); /* Loads the textures. */ // Textures // Get pointer to the texture name CPVRTString ErrorStr; char *pTexture = 0; PVRTextureHeaderV3 Header; for(int i = 0; i < g_numTextures; ++i) { if(strcmp(g_TextureList[i], "base") == 0) pTexture = (char*) g_aszTextureNames[eTexBase]; else if(strcmp(g_TextureList[i], "reflection") == 0) pTexture = (char*) g_aszTextureNames[eTexReflection]; else if(strcmp(g_TextureList[i], "cubemap") == 0) pTexture = (char*) g_aszTextureNames[eTexCubeMap]; else if(strcmp(g_TextureList[i], "anisotropicmap") == 0) pTexture = (char*) g_aszTextureNames[eTexAnisotropic]; if(PVRTTextureLoadFromPVR(pTexture, &m_puiTextureHandle[i], &Header) != PVR_SUCCESS) { ErrorStr = CPVRTString("ERROR: Could not open texture file ") + pTexture; PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Get texture flags form the header m_uiTextureFlags[i] = (Header.u32NumFaces==6?PVRTEX_CUBEMAP:0) | (Header.u32MIPMapCount>1?PVRTEX_MIPMAP:0) | (Header.u32Depth>1?PVRTEX_VOLUME:0); } /* Load the effect file */ for(int j = 0; j < g_numShaders; j++) { CPVRTString fileName; unsigned int nUnknownUniformCount; CPVRTString error; /* Parse the file */ m_ppEffectParser[j] = new CPVRTPFXParser(); fileName = CPVRTString(g_ShaderList[j]) + ".pfx"; if(m_ppEffectParser[j]->ParseFromFile(fileName.c_str(), &error) != PVR_SUCCESS) { error = CPVRTString("Parse failed for ") + fileName + ":\n\n" + error; PVRShellSet(prefExitMessage, error.c_str()); FreeMemory(); return false; } /* Load the effect from the file */ error = ""; m_ppEffect[j] = new CPVRTPFXEffect(); if(m_ppEffect[j]->Load(*(m_ppEffectParser[j]), "myEffect", fileName.c_str(), NULL, nUnknownUniformCount, &error) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, error.c_str()); FreeMemory(); return false; } if(nUnknownUniformCount) { error = PVRTStringFromFormattedStr("PFX File: %s\n%s Unknown uniform semantic count: %d\n", fileName.c_str(), error.c_str(), nUnknownUniformCount); PVRShellSet(prefExitMessage, error.c_str()); FreeMemory(); return false; } if(!error.empty()) { PVRShellOutputDebug(error.c_str()); } /* Link the textrues to the effect. */ const CPVRTArray<SPVRTPFXTexture>& sTex = m_ppEffect[j]->GetTextureArray(); // Loop over textures used in the CPVRTPFXEffect for(unsigned int i = 0; i < sTex.GetSize(); ++i) { int iTexIdx = m_ppEffectParser[j]->FindTextureByName(sTex[i].Name); const CPVRTStringHash& FileName = m_ppEffectParser[j]->GetTexture(iTexIdx)->FileName; int k; // Loop over available textures for( k = 0; k < g_numTextures; k++) { CPVRTString texName; texName = CPVRTString(g_TextureList[k]) + ".pvr"; if(FileName == texName) { // Set the current texture if((m_uiTextureFlags[k] & CUBEMAP_FLAG) != 0) glBindTexture(GL_TEXTURE_CUBE_MAP, m_puiTextureHandle[k]); else glBindTexture(GL_TEXTURE_2D, m_puiTextureHandle[k]); // Link the texture to the CPVRTPFXEffect and apply filtering m_ppEffect[j]->SetTexture(i, m_puiTextureHandle[k], m_uiTextureFlags[k]); break; } } if(k == g_numTextures) { // Texture not found PVRShellOutputDebug("Warning: effect file requested unrecognised texture: \"%s\"\n", FileName.c_str()); m_ppEffect[j]->SetTexture(i, 0); } } } glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); // Create the surface m_Surface = new ParametricSurface(50,50); ComputeSurface(m_nCurrentSurface); return true; }