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
|
bool loadTextureGl3(GLuint & id, const std::string & fichierImage){
SDL_Surface *imageSDL = IMG_Load(fichierImage.c_str());
if(imageSDL == NULL){
std::cout << "Erreur, le fichier " << fichierImage<< " n'existe pas" << std::endl;
return false;
}
GLenum format(0);
if(imageSDL->format->BytesPerPixel == 3) format = GL_RGB;
else if(imageSDL->format->BytesPerPixel == 4) format = GL_RGBA;
else{ std::cout << "Erreur, format de l'image inconnu" << std::endl;
SDL_FreeSurface(imageSDL);
return false;
}
SDL_Surface* imageOpenGl = verticalMirror(imageSDL) ;
SDL_FreeSurface(imageSDL); #ifdef __USE_MIP_MAP_OPENGL__
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, imageOpenGl->format->BytesPerPixel, imageOpenGl->w, imageOpenGl->h, 0, format, GL_UNSIGNED_BYTE, imageOpenGl->pixels);
glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);
#else
glTexImage2D(GL_TEXTURE_2D, 0, imageOpenGl->format->BytesPerPixel, imageOpenGl->w, imageOpenGl->h, 0, format, GL_UNSIGNED_BYTE, imageOpenGl->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
#endif
glBindTexture(GL_TEXTURE_2D, 0); SDL_FreeSurface(imageOpenGl); return true;
}
|