1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <windows.h>
#include <GL\gl.h>
#include <GL\glu.h>
struct sample_MATERIAL{
GLfloat ambient[3];
GLfloat diffuse[3];
GLfloat specular[3];
GLfloat emission[3];
GLfloat alpha;
GLfloat phExp;
int texture;
};
static sample_MATERIAL materials [4] = {
{{0.188235f,0.368627f,0.0431373f}, {0.188235f,0.368627f,0.0431373f}, {0.431059f,0.431059f,0.431059f}, {0.0f,0.0f,0.0f}, 1.0f,4.0f,-1}, //03 - Default
.... // autres materiaux
};
// 832 Verticies
// 3900 Texture Coordinates
// 3900 Normals
// 1300 Triangles
static short face_indicies[1300][9] = {
// Sphere01
{0,1,2 ,0,1,2 ,0,1,2 }, {482,2,3 ,3,4,5 ,3,4,5 }, {483,3,4 ,6,7,8 ,6,7,8 },
...
{828,819,829 ,3894,3895,3896 ,3894,3895,3896 }, {830,819,831 ,3897,3898,3899 ,3897,3898,3899 }
};
static GLfloat vertices [832][3] = {
{-0.230178f,0.0525743f,0.0913675f},{-0.230178f,0.0717191f,0.0894818f},{-0.233913f,0.0713512f,0.0894818f},
.......
{-0.369039f,-0.318314f,-0.00674889f}
};
static GLfloat normals [3900][3] = {
{-0.00965372f,0.0980127f,0.995138f},{-0.0223671f,0.227095f,0.973616f},{-0.0474507f,0.209109f,0.97674f},
...........
{0.0f,0.0f,-1.0f},{0.0f,0.0f,-1.0f},{0.0f,0.0f,-1.0f}
};
static GLfloat textures [3900][2] = {
{0.0f,1.0f},{0.0f,0.9375f},{0.03125f,0.9375f},
........
{1.0f,1.0f},{0.5f,1.5f},{0.0f,1.0f},
{0.0f,1.0f},{0.5f,1.5f},{0.0f,2.0f}
};
/*Material indicies*/
/*{material index,face count}*/
static int material_ref [4][2] = {
{0,960},
{1,12},
{2,320},
{3,8}
};
void MyMaterial(GLenum mode,GLfloat *f,GLfloat alpha)
{
GLfloat d[4];
d[0]=f[0];
d[1]=f[1];
d[2]=f[2];
d[3]=alpha;
glMaterialfv (GL_FRONT_AND_BACK,mode,d);
}
/*
* SelectMaterial uses OpenGL commands to define facet colors.
*
* Returns:
* Nothing
*/
void SelectMaterial(int i)
{
//
// Define the reflective properties of the 3D Object faces.
//
glEnd();
GLfloat alpha=materials[i].alpha;
MyMaterial (GL_AMBIENT, materials[i].ambient,alpha);
MyMaterial (GL_DIFFUSE, materials[i].diffuse,alpha);
MyMaterial (GL_SPECULAR, materials[i].specular,alpha);
MyMaterial (GL_EMISSION, materials[i].emission,alpha);
glMaterialf (GL_FRONT_AND_BACK,GL_SHININESS,materials[i].phExp);
glBegin(GL_TRIANGLES);
};
GLint Gen3DObjectList()
{
int i;
int j;
GLint lid=glGenLists(1);
int mcount=0;
int mindex=0;
glNewList(lid, GL_COMPILE);
glBegin (GL_TRIANGLES);
for(i=0;i<sizeof(face_indicies)/sizeof(face_indicies[0]);i++)
{
if(!mcount)
{
SelectMaterial(material_ref[mindex][0]);
mcount=material_ref[mindex][1];
mindex++;
}
mcount--;
for(j=0;j<3;j++)
{
int vi=face_indicies[i][j];
int ni=face_indicies[i][j+3];//Normal index
int ti=face_indicies[i][j+6];//Texture index
glNormal3f (normals[ni][0],normals[ni][1],normals[ni][2]);
glTexCoord2f(textures[ti][0],textures[ti][1]);
glVertex3f (vertices[vi][0],vertices[vi][1],vertices[vi][2]);
}
}
glEnd ();
glEndList();
return lid;
}; |
Partager