//------------------------------------------------------------- //- RenderT //- Transform and render the meshes //------------------------------------------------------------- void CMs3d::RenderT() { glEnable(GL_TEXTURE_2D); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); for(int x = 0; x < m_usNumMeshes; x++) { //Set up materials if(m_pMeshes[x].m_cMaterial >= 0) { SMs3dMaterial * pCurMat = &m_pMaterials[m_pMeshes[x].m_cMaterial]; //Set the alpha for transparency pCurMat->m_fDiffuse[3] = pCurMat->m_fTransparency; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, pCurMat->m_fAmbient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pCurMat->m_fDiffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pCurMat->m_fSpecular); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pCurMat->m_fEmissive); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, pCurMat->m_fShininess); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Texture map pCurMat->m_Texture.Bind(); } else glDisable(GL_BLEND); //Draw mesh //Transformed vertices and normals CVector3 vecNormal; CVector3 vecVertex; glBegin(GL_TRIANGLES); //Loop through triangles for(int y = 0; y < m_pMeshes[x].m_usNumTris; y++) { //Set triangle pointer to triangle #1 SMs3dTriangle * pTri = &m_pTriangles[m_pMeshes[x].m_uspIndices[y]]; //Loop through each vertex for(int z = 0; z < 3; z++) { //Get the vertex SMs3dVertex * pVert = &m_pVertices[pTri->m_usVertIndices[z]]; //If it has no bone, render as is if(pVert->m_cBone == -1) { //Send all 3 components without modification glTexCoord2f(pTri->m_fTexCoords[0][z], pTri->m_fTexCoords[1][z]); glVertex3fv(pVert->m_vVert.Get()); glNormal3fv(pTri->m_vNormals[z].Get()); } //Otherwise, transform the vertices and normals before displaying them else { //Send the texture coordinates glTexCoord2f(pTri->m_fTexCoords[0][z], pTri->m_fTexCoords[1][z]); SMs3dJoint * pJoint = &m_pJoints[pVert->m_cBone]; //Transform the normals vecNormal = pTri->m_vNormals[z]; //Only rotate it, no translation vecNormal.Transform3(pJoint->m_matFinal); //Send the normal to OpenGL glNormal3fv(vecNormal.Get()); //Transform the vertex vecVertex = pVert->m_vVert; //translate as well as rotate vecVertex.Transform4(pJoint->m_matFinal); //Send vertex to openGL glVertex3fv(vecVertex.Get()); } } } glEnd(); } }