2
glPolygonMode(GL_FRONT, GL_FILL);
18
glEnable(GL_LINE_STIPPLE);
19
glLineStipple(1, 0x3F07);
29
void drawtriangle(float *v1, float *v2, float *v3, long i, int skel) {
30
float color[] = {((i+2)%3)/2,((i+1)%3)/2,(i%3)/2,1};
32
if (ENABLE_ANTIALIASING) {
33
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
38
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
39
glNormal3fv(v1); glVertex3fv(v1);
40
glNormal3fv(v2); glVertex3fv(v2);
41
glNormal3fv(v3); glVertex3fv(v3);
45
if (ENABLE_ANTIALIASING) {
46
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
50
glBegin(GL_LINE_LOOP);
59
void subdivide(float *v1, float *v2, float *v3, long depth, long idx, int skel) {
60
GLfloat v12[3], v23[3], v31[3];
64
drawtriangle(v1, v2, v3, idx, skel);
68
for (i = 0; i < 3; i++) {
74
// printf("%f %f %f\n %f %f %f\n %f %f %f\n\n", v1[0],v1[1],v1[2], v2[0], v2[1], v2[2], v3[0], v3[1], v3[2]);
75
// printf("%f %f %f\n\n", v12[0], v12[1], v12[2]);
80
subdivide(v1, v12, v31, depth-1, idx, skel);
81
subdivide(v2, v23, v12, depth-1, idx+(1<<(2*(depth-1))), skel);
82
subdivide(v3, v31, v23, depth-1, idx+(2<<(2*(depth-1))), skel);
83
subdivide(v12, v23, v31, depth-1, idx+(3<<(2*(depth-1))), skel);
87
void DrawPolyhedron(long depth, int skel) {
89
GLfloat d1[3], d2[3], norm[3];
91
#define X .525731112119133606
92
#define Z .850650808352039932
94
static GLfloat vdata[12][3] = {
95
{-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},
96
{0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},
97
{Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0}
100
static GLint tindices[20][3] = {
101
{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
102
{8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
103
{7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
104
{6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11}
107
for (i = 0; i < 20; i++) {
109
&vdata[tindices[i][0]][0],
110
&vdata[tindices[i][1]][0],
111
&vdata[tindices[i][2]][0],
119
void generateTexture(GLubyte *checkImage, long checkImageWidth, long checkImageHeight) {
122
for (i = 0; i < checkImageWidth; i++) {
123
for (j = 0; j < checkImageHeight; j++) {
124
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
125
checkImage[(i*checkImageHeight + j)*3 + 0] = (GLubyte) c;
126
checkImage[(i*checkImageHeight + j)*3 + 1] = (GLubyte) c;
127
checkImage[(i*checkImageHeight + j)*3 + 2] = (GLubyte) c;