X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fvideo%2Fgl%2Fgl_texture.cpp;h=fe3864c0a635f1ccd31e5ce8049441d684458c79;hb=6c4ea2270fe41f7e049e6409016986422261254c;hp=008e96fa3cea4b9d54705ee7d28c19396ce69cbe;hpb=966efec01b3d46a52c0647dfc4c781bf36294b42;p=supertux.git diff --git a/src/video/gl/gl_texture.cpp b/src/video/gl/gl_texture.cpp index 008e96fa3..fe3864c0a 100644 --- a/src/video/gl/gl_texture.cpp +++ b/src/video/gl/gl_texture.cpp @@ -35,70 +35,71 @@ inline int next_power_of_two(int val) } // namespace GLTexture::GLTexture(unsigned int width, unsigned int height) : - handle(), - texture_width(), - texture_height(), - image_width(), - image_height() + m_handle(), + m_texture_width(), + m_texture_height(), + m_image_width(), + m_image_height() { #ifdef GL_VERSION_ES_CM_1_0 assert(is_power_of_2(width)); assert(is_power_of_2(height)); #endif - texture_width = width; - texture_height = height; - image_width = width; - image_height = height; + m_texture_width = width; + m_texture_height = height; + m_image_width = width; + m_image_height = height; assert_gl("before creating texture"); - glGenTextures(1, &handle); + glGenTextures(1, &m_handle); try { - glBindTexture(GL_TEXTURE_2D, handle); + glBindTexture(GL_TEXTURE_2D, m_handle); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width, - texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + m_texture_width, m_texture_height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); set_texture_params(); } catch(...) { - glDeleteTextures(1, &handle); + glDeleteTextures(1, &m_handle); throw; } } GLTexture::GLTexture(SDL_Surface* image) : - handle(), - texture_width(), - texture_height(), - image_width(), - image_height() + m_handle(), + m_texture_width(), + m_texture_height(), + m_image_width(), + m_image_height() { #ifdef GL_VERSION_ES_CM_1_0 - texture_width = next_power_of_two(image->w); - texture_height = next_power_of_two(image->h); + m_texture_width = next_power_of_two(image->w); + m_texture_height = next_power_of_two(image->h); #else if (GLEW_ARB_texture_non_power_of_two) { - texture_width = image->w; - texture_height = image->h; + m_texture_width = image->w; + m_texture_height = image->h; } else { - texture_width = next_power_of_two(image->w); - texture_height = next_power_of_two(image->h); + m_texture_width = next_power_of_two(image->w); + m_texture_height = next_power_of_two(image->h); } #endif - image_width = image->w; - image_height = image->h; + m_image_width = image->w; + m_image_height = image->h; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE, - texture_width, texture_height, 32, + SDL_Surface* convert = SDL_CreateRGBSurface(0, + m_texture_width, m_texture_height, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); #else - SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE, - texture_width, texture_height, 32, + SDL_Surface* convert = SDL_CreateRGBSurface(0, + m_texture_width, m_texture_height, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); #endif @@ -106,11 +107,11 @@ GLTexture::GLTexture(SDL_Surface* image) : throw std::runtime_error("Couldn't create texture: out of memory"); } - SDL_SetAlpha(image, 0, 0); + SDL_SetSurfaceBlendMode(image, SDL_BLENDMODE_NONE); SDL_BlitSurface(image, 0, convert, 0); assert_gl("before creating texture"); - glGenTextures(1, &handle); + glGenTextures(1, &m_handle); try { GLenum sdl_format; @@ -118,10 +119,12 @@ 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); + glBindTexture(GL_TEXTURE_2D, m_handle); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); #ifdef GL_UNPACK_ROW_LENGTH glPixelStorei(GL_UNPACK_ROW_LENGTH, convert->pitch/convert->format->BytesPerPixel); @@ -136,17 +139,14 @@ GLTexture::GLTexture(SDL_Surface* image) : SDL_LockSurface(convert); } - if (true) - { // no not use mipmaps - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width, - texture_height, 0, sdl_format, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + m_texture_width, m_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); + + // no not use mipmaps + if(false) + { + glGenerateMipmap(GL_TEXTURE_2D); } if(SDL_MUSTLOCK(convert)) @@ -158,7 +158,7 @@ GLTexture::GLTexture(SDL_Surface* image) : set_texture_params(); } catch(...) { - glDeleteTextures(1, &handle); + glDeleteTextures(1, &m_handle); SDL_FreeSurface(convert); throw; } @@ -167,7 +167,7 @@ GLTexture::GLTexture(SDL_Surface* image) : GLTexture::~GLTexture() { - glDeleteTextures(1, &handle); + glDeleteTextures(1, &m_handle); } void