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
| GLfloat vertices[] = {1,1,1, 1,1,0, 0,1,0, 0,1,1,
0,0,1, 0,0,0, 1,0,0, 1,0,1,
1,0,1, 1,0,0, 1,1,0, 1,1,1,
0,1,1, 0,1,0, 0,0,0, 0,0,1,
1,0,1, 1,1,1, 0,1,1, 0,0,1,
1,1,0, 1,0,0, 0,0,0, 0,1,0};
GLubyte indices[] = {0,1,2,3,4,5,6,7,7,6,1,0,3,2,5,4,7,0,3,4,1,6,5,2};
GLfloat texCoord[] = {1,1, 0,1, 0,0, 1,0,
0,0, 1,0, 1,1, 0,1,
0,0, 1,0, 1,1, 0,1,
1,1, 0,1, 0,0, 1,0,
1,0, 1,1, 0,1, 0,0,
0,1, 0,0, 1,0, 1,1};
GLuint texture;
void loadCubeTextures(void) {
texture = loadTexture("data/stone.png");
}
void drawQuad(unsigned short face) {
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texCoord);
glBindTexture(GL_TEXTURE_2D, texture);
if (face == 4) { // Face du dessus
glDrawRangeElements(GL_QUADS, 0,3, 4, GL_UNSIGNED_BYTE, indices);
}
else if (face == 5) { // Face du dessous
glDrawRangeElements(GL_LINE_LOOP, 4,7, 4, GL_UNSIGNED_BYTE, indices+4);
}
else if (face == 0) { // Face nord
glDrawRangeElements(GL_LINE_LOOP, 8,11, 4, GL_UNSIGNED_BYTE, indices+8);
}
else if (face == 1) { // Face sud
glDrawRangeElements(GL_LINE_LOOP, 12,15, 4, GL_UNSIGNED_BYTE, indices+12);
}
else if (face == 2) { // Face est
glDrawRangeElements(GL_LINE_LOOP, 16,19, 4, GL_UNSIGNED_BYTE, indices+16);
}
else { // Face ouest
glDrawRangeElements(GL_LINE_LOOP, 20,23, 4, GL_UNSIGNED_BYTE, indices+20);
}
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
} |
Partager