Exemplo n.º 1
0
void StaticMesh::compileColoredMeshList(){

	if(m_finalized){

		m_coloredMeshList = glGenLists(1);

		// Enable vertex / normal / color arrays
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_NORMAL_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);

		// Start new display list
		glNewList(m_coloredMeshList, GL_COMPILE);

		glEnable(GL_LIGHTING);
		glEnable(GL_COLOR_MATERIAL);

		setColorMaterial(0.1f, 0.1f, 0.1f);

		// Assign element pointers
		glVertexPointer( 3, GL_FLOAT, 0, m_vertices.get() );
		glNormalPointer( GL_FLOAT, 0, m_faceNormals );
		glColorPointer( 3, GL_UNSIGNED_BYTE, 0, m_colors.get() );

		// Draw elements
		glDrawElements(GL_TRIANGLES, (GLsizei)3 * m_numFaces, GL_UNSIGNED_INT, m_faces.get());


		// Draw mesh descriptions


		glEndList();

	}
}
Exemplo n.º 2
0
void TexturedMesh::render()
{
    MaterialFaceLists::iterator matListIt;
    list<int>::iterator matFaceIt;

    // Compute transformation matrix
    computeMatrix();

    glPushMatrix();
    glMultMatrixf(m_transformation);

    for(matListIt = m_matFaceLists.begin(); matListIt != m_matFaceLists.end(); matListIt++)
    {
        // Get list for current material
        MaterialFaceList* matList = *matListIt;

        // Get material
        Material* mat = m_materials[matList->m_matIndex];

        // Bind texture and set material properties
        if(mat->m_texture != 0)
        {
            mat->m_texture->bind();
        }
        setColorMaterial(mat->m_ambient, mat->m_diffuse, mat->m_specular, mat->m_shininess);

        // Render face group

        matFaceIt = matList->m_faces.begin();
        while(matFaceIt != matList->m_faces.end())
        {

            int a = *matFaceIt;
            ++matFaceIt;
            int b = *matFaceIt;
            ++matFaceIt;
            int c = *matFaceIt;
            ++matFaceIt;

            int a_pos = a * 3;
            int b_pos = b * 3;
            int c_pos = c * 3;

            int ta = a * 2;
            int tb = b * 2;
            int tc = c * 2;

            glBegin(GL_TRIANGLES);
            glTexCoord2f(m_textureCoords[ta], m_textureCoords[ta + 1]);
            glNormal3f(m_normalBuffer[a_pos], m_normalBuffer[a_pos + 1], m_normalBuffer[a_pos + 2]);
            glVertex3f(m_vertexBuffer[a_pos], m_vertexBuffer[a_pos + 1], m_vertexBuffer[a_pos + 2]);

            glTexCoord2f(m_textureCoords[tb], m_textureCoords[tb + 1]);
            glNormal3f(m_normalBuffer[b_pos], m_normalBuffer[b_pos + 1], m_normalBuffer[b_pos + 2]);
            glVertex3f(m_vertexBuffer[b_pos], m_vertexBuffer[b_pos + 1], m_vertexBuffer[b_pos + 2]);

            glTexCoord2f(m_textureCoords[tc], m_textureCoords[tc + 1]);
            glNormal3f(m_normalBuffer[c_pos], m_normalBuffer[c_pos + 1], m_normalBuffer[c_pos + 2]);
            glVertex3f(m_vertexBuffer[c_pos], m_vertexBuffer[c_pos + 1], m_vertexBuffer[c_pos + 2]);
            glEnd();
        }
    }

    glPopMatrix();

}