- int LoadTexture (char *filename, bool repeatable) {
- Image texImage;
- GLuint texid;
- // Image ist eine Klasse, die ein PNG-Bild in ein SDL-Surface lädt
- // und alle Imagedaten bereitstellt:
- if (texImage.LoadPng (filename) == false) return 0;
- glGenTextures (1, &texid);
- glBindTexture (GL_TEXTURE_2D, texid);
- glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
- // repeatable für fortlaufende Landschaftstexturen
- if (repeatable) {
- glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- } else {
- glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- }
- GLenum format;
- if (texImage.depth == 3) format = GL_RGB;
- else format = GL_RGBA;
- glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- gluBuild2DMipmaps (GL_TEXTURE_2D, texImage.depth, texImage.nx,
- texImage.ny, format, GL_UNSIGNED_BYTE, texImage.data);
- return texid;
- }