3
int load_texture(const char pFilename[], GLuint *pTexture)
6
GLenum texture_format = GL_RGB;
9
if ((surface = SDL_LoadBMP(pFilename))) {
10
if ((surface->w & (surface->w - 1)) != 0)
11
printf("warning: image.bmp's width is not a power of 2\n");
13
if ((surface->h & (surface->h - 1)) != 0)
14
printf("warning: image.bmp's height is not a power of 2\n");
16
nOfColors = surface->format->BytesPerPixel;
18
if (surface->format->Rmask == 0x000000ff)
19
texture_format = GL_RGBA;
21
fprintf(stderr, "Error: %s: Unsupported pixel format BGRA\n", pFilename);
27
if (surface->format->Rmask == 0x000000ff)
28
texture_format = GL_RGB;
30
fprintf(stderr, "Error: %s: Unsupported pixel format BGR\n", pFilename);
35
printf("warning: the image is not truecolor.. this will probably break\n");
39
glGenTextures(3, pTexture);
41
// Create Nearest Filtered Texture
42
glBindTexture(GL_TEXTURE_2D, pTexture[0]);
43
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
44
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
45
glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
46
texture_format, GL_UNSIGNED_BYTE, surface->pixels);
48
// Create Linear Filtered Texture
49
glBindTexture(GL_TEXTURE_2D, pTexture[1]);
50
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
51
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
52
glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
53
texture_format, GL_UNSIGNED_BYTE, surface->pixels);
55
// Create trilinear filtered mipmapped texture
56
glBindTexture(GL_TEXTURE_2D, pTexture[2]);
57
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
58
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
59
glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
60
texture_format, GL_UNSIGNED_BYTE, surface->pixels);
61
glGenerateMipmap(GL_TEXTURE_2D);
64
fprintf(stderr, "SDL could not load image.bmp: %s\n", SDL_GetError());
69
SDL_FreeSurface(surface);