/*!**************************************************************************** @Function DrawFurShells @Description Draw the duck shells that represent the fur ******************************************************************************/ void OGLESFur::DrawFurShells() { // Get the mesh associated with the duck body int i32MeshID = m_Scene.pNode[eDuckBody].nIdx; SPODMesh* pMesh = &m_Scene.pMesh[i32MeshID]; // Bind the index buffer for the ducks body as the shells use the same indices glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_puiIndexVbo[i32MeshID]); // Enable alpha blending. The Alpha-test is not required and would be slower than alpha-blend glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Set up the lighting myglLightv(GL_LIGHT0, GL_SPECULAR, &c_vColourBlack.x); // Enable the texture coordinates. The vertices and normals should already be enabled glEnableClientState(GL_TEXTURE_COORD_ARRAY); SetMaterial(&c_pMaterial[0], m_aTexIDs[eTexFur]); for(int i = 0; i < m_i32FurShellNo; ++i) { // If we are drawing the most outer shell change the lighting if(i == m_i32FurShellNo - 1) myglLightv(GL_LIGHT0, GL_SPECULAR, &c_vLightColour.x); // Bind the VBO for the shells vertices glBindBuffer(GL_ARRAY_BUFFER, m_uiShellVbo[i]); // Setup the pointers glVertexPointer(3, VERTTYPEENUM, sizeof(SVertex), 0); glNormalPointer(VERTTYPEENUM, sizeof(SVertex), (GLvoid*) (sizeof(VERTTYPE) * 3)); glTexCoordPointer(2, VERTTYPEENUM, sizeof(SVertex), (GLvoid*) (sizeof(VERTTYPE) * 6)); // Draw primitive glDrawElements(GL_TRIANGLES, pMesh->nNumFaces * 3, GL_UNSIGNED_SHORT, 0); } // Unbind the VBOs glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // Disable blending as it is no longer needed glDisable(GL_BLEND); }
/*!**************************************************************************** @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 OGLESEvilSkull::InitView() { PVRTMat4 mPerspective; SPVRTContext sContext; // Initialize Print3D textures bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); if(m_Print3D.SetTextures(&sContext, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n"); return false; } /*********************** ** LOAD TEXTURES ** ***********************/ if(PVRTTextureLoadFromPVR(c_szIrisTexFile, &m_ui32Texture[0]) != PVR_SUCCESS) return false; myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szMetalTexFile, &m_ui32Texture[1]) != PVR_SUCCESS) return false; myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szFire02TexFile, &m_ui32Texture[2]) != PVR_SUCCESS) return false; myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szFire03TexFile, &m_ui32Texture[3]) != PVR_SUCCESS) return false; myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /****************************** ** GENERIC RENDER STATES ** *******************************/ // The Type Of Depth Test To Do glDepthFunc(GL_LEQUAL); // Enables Depth Testing glEnable(GL_DEPTH_TEST); // Enables Smooth Color Shading glShadeModel(GL_SMOOTH); // Blending mode glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Culling glEnable(GL_CULL_FACE); glCullFace(GL_BACK); // Create perspective matrix mPerspective = PVRTMat4::PerspectiveFovRH(f2vt(70.0f*(3.14f/180.0f)), f2vt((float)PVRShellGet(prefWidth) /(float)PVRShellGet(prefHeight) ), f2vt(10.0f), f2vt(10000.0f), PVRTMat4::OGL, bRotate); glMatrixMode(GL_PROJECTION); myglLoadMatrix(mPerspective.f); // Create viewing matrix m_mView = PVRTMat4::LookAtRH(m_CameraPos, m_CameraTo, m_CameraUp); glMatrixMode(GL_MODELVIEW); myglLoadMatrix(m_mView.f); // Enable texturing glEnable(GL_TEXTURE_2D); // Lights (only one side lighting) glEnable(GL_LIGHTING); // Light 0 (White directional light) PVRTVec4 fAmbient = PVRTVec4(f2vt(0.2f), f2vt(0.2f), f2vt(0.2f), f2vt(1.0f)); PVRTVec4 fDiffuse = PVRTVec4(f2vt(1.0f), f2vt(1.0f), f2vt(1.0f), f2vt(1.0f)); PVRTVec4 fSpecular = PVRTVec4(f2vt(1.0f), f2vt(1.0f), f2vt(1.0f), f2vt(1.0f)); myglLightv(GL_LIGHT0, GL_AMBIENT, fAmbient.ptr()); myglLightv(GL_LIGHT0, GL_DIFFUSE, fDiffuse.ptr()); myglLightv(GL_LIGHT0, GL_SPECULAR, fSpecular.ptr()); myglLightv(GL_LIGHT0, GL_POSITION, m_LightPos.ptr()); glEnable(GL_LIGHT0); glDisable(GL_LIGHTING); // Create the data used for the morphing CreateMorphData(); // Sets the clear color myglClearColor(f2vt(0.0f), f2vt(0.0f), f2vt(0.0f), f2vt(1.0f)); // Create vertex buffer objects LoadVbos(); 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 OGLESFur::InitView() { // Setup the projection matrix glMatrixMode(GL_PROJECTION); bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); m_mProj = PVRTMat4::PerspectiveFovRH(g_fFOV, f2vt((float)PVRShellGet(prefWidth) / (float)PVRShellGet(prefHeight)), g_fNear, g_fFar, PVRTMat4::OGL, bRotate); myglLoadMatrix(m_mProj.f); // Set clear colour myglClearColor(c_vFogColour.x, c_vFogColour.y, c_vFogColour.z, c_vFogColour.w); // Enable Smooth Color Shading glShadeModel(GL_SMOOTH); // Enable the depth buffer glEnable(GL_DEPTH_TEST); // Load fur data glGenBuffers(g_ui32MaxNoOfFurShells, m_uiShellVbo); UpdateFurShells(); // Initialise 3D text if(m_Print3D.SetTextures(NULL, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) return false; // Load textures CPVRTString ErrorStr; if(!LoadTextures(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Create VBOs if(!LoadVbos(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Initialise camera m_Scene.GetCameraPos(m_vCamFrom, m_vCamTo, 0); m_vCamFrom = PVRTVec3(f2vt(0.0f), f2vt(400.0f), f2vt(0.0f)); // Enable fog myglFog(GL_FOG_MODE, GL_EXP2); myglFog(GL_FOG_DENSITY, c_fFogDensity); myglFogv(GL_FOG_COLOR, &c_vFogColour.x); glEnable(GL_FOG); // Enable lighting myglLightv(GL_LIGHT0, GL_POSITION, &c_vLightPosition.x); myglLightv(GL_LIGHT0, GL_DIFFUSE, &c_vLightColour.x); myglLightv(GL_LIGHT0, GL_AMBIENT, &c_vLightAmbient.x); myglLightv(GL_LIGHT0, GL_SPECULAR, &c_vLightColour.x); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); // Disable culling glDisable(GL_CULL_FACE); // Initialise time m_ui32PrevTime = PVRShellGetTime(); return true; }