Implemented set_gamma()
[supertux.git] / src / video / gl / gl_texture.cpp
index ec20565..edc8751 100644 (file)
@@ -77,8 +77,16 @@ GLTexture::GLTexture(SDL_Surface* image) :
   texture_width = next_power_of_two(image->w);
   texture_height = next_power_of_two(image->h);
 #else
-  texture_width  = image->w;
-  texture_height = image->h;
+  if (GLEW_ARB_texture_non_power_of_two)
+  {
+    texture_width  = image->w;
+    texture_height = image->h;
+  }
+  else
+  {
+    texture_width = next_power_of_two(image->w);
+    texture_height = next_power_of_two(image->h);
+  }
 #endif
 
   image_width  = image->w;
@@ -98,7 +106,7 @@ GLTexture::GLTexture(SDL_Surface* image) :
     throw std::runtime_error("Couldn't create texture: out of memory");
   }
 
-  SDL_SetAlpha(image, 0, 0);
+  //SDL_SetAlpha(image, 0, 0);
   SDL_BlitSurface(image, 0, convert, 0);
 
   assert_gl("before creating texture");
@@ -110,8 +118,10 @@ GLTexture::GLTexture(SDL_Surface* image) :
       sdl_format = GL_RGB;
     else if(convert->format->BytesPerPixel == 4)
       sdl_format = GL_RGBA;
-    else
+    else {
+      sdl_format = GL_RGBA;
       assert(false);
+    }
 
     glBindTexture(GL_TEXTURE_2D, handle);
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -127,9 +137,20 @@ GLTexture::GLTexture(SDL_Surface* image) :
     {
       SDL_LockSurface(convert);
     }
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
+
+    if (true)
+    { // no not use mipmaps
+      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
                  texture_height, 0, sdl_format,
                  GL_UNSIGNED_BYTE, convert->pixels);
+    }
+    else
+    { // build mipmaps
+      gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, texture_width,
+                        texture_height, sdl_format,
+                        GL_UNSIGNED_BYTE, convert->pixels);
+    }
+
     if(SDL_MUSTLOCK(convert))
     {
       SDL_UnlockSurface(convert);
@@ -156,11 +177,9 @@ GLTexture::set_texture_params()
 {
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-#ifdef GL_CLAMP
-  /* OpenGL ES doesn't support it */
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-#endif
+
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
   assert_gl("set texture params");
 }