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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
//***************j'initialise mes constantes :
#define GL_TEXTURE_CUBE_MAP 0x8513
#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
#define CUBE_MAP_SIZE 256
//***************Puis je crée mes texture target
vector<GLenum> cube_map_target;
cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_NEGATIVE_X);
cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_POSITIVE_X);
cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y);
cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_POSITIVE_Y);
cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_POSITIVE_Z);
//***************fonction de chargement d'image
int LoadTex(string file, sf::Image& Image)
{
if (!Image.LoadFromFile(file))
return EXIT_FAILURE;
return 0;
}
//**********chargement des textures
vector<sf::Image> textures;
LoadTex("Skybox/XN.bmp", textures[0]);
LoadTex("Skybox/XP.bmp", textures[1]);
LoadTex("Skybox/YN.bmp", textures[2]);
LoadTex("Skybox/YP.bmp", textures[3]);
LoadTex("Skybox/ZN.bmp", textures[4]);
LoadTex("Skybox/ZP.bmp", textures[5]);
//****************** Génération d'une texture CubeMap
GLuint cube_map_texture_ID;
glEnable(GL_TEXTURE_CUBE_MAP);
GLuint cube_map_texture_ID;
glGenTextures(1, &cube_map_texture_ID);
// Configuration de la texture
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_map_texture_ID);
//Création de la texture
for (int i = 0; i < 6; i++)
{
sf::Image im = textures[i];
glTexImage2D(cube_map_target[i], 0, 3, im.GetWidth(), im.GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, im.GetPixelsPtr());
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP);
//************Création du cube
//vertices
// Taille du cube
float t = 1.0f;
float t_vertices[72] = {
-t,-t,-t,
-t,t,-t,
t,t,-t,
t,-t,-t,
-t,-t,t,
-t,t,t,
t,t,t,
t,-t,t,
-t,-t,-t,
-t,t,-t,
-t,t,t,
-t,-t,t,
t,-t,-t,
t,t,-t,
t,t,t,
t,-t,t,
-t,-t,t,
-t,-t,-t,
t,-t,-t,
t,-t,t,
-t,t,t,
-t,t,-t,
t,t,-t,
t,t,t
};
//indices
int t_indices[24] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
};
//coordonnées de textures (identiques aux coordonnées de vertices)
float t_texcoords[72] = {
-t,-t,-t,
-t,t,-t,
t,t,-t,
t,-t,-t,
-t,-t,t,
-t,t,t,
t,t,t,
t,-t,t,
-t,-t,-t,
-t,t,-t,
-t,t,t,
-t,-t,t,
t,-t,-t,
t,t,-t,
t,t,t,
t,-t,t,
-t,-t,t,
-t,-t,-t,
t,-t,-t,
t,-t,t,
-t,t,t,
-t,t,-t,
t,t,-t,
t,t,t
};
//*************Rendu
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_map_texture_ID);
//(les VBO ont été préalablement alloués)
// Utilisation des données des buffers
glBindBuffer(GL_ARRAY_BUFFER, VBObuffersId[0]);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
//stride de 3 car cube map
glTexCoordPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(VBOverticesSize*sizeof(float));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBObuffersId[1]);
glDrawElements(GL_QUADS, VBOindicesSize[2], GL_UNSIGNED_INT, 0); |
Partager