From 2ec65975046c3aa98f2958ca0988d20a36abf5fa Mon Sep 17 00:00:00 2001 From: pixel Date: Wed, 25 Dec 2002 14:26:31 +0000 Subject: Bleh --- lib/gltexture.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 9 deletions(-) (limited to 'lib/gltexture.cc') diff --git a/lib/gltexture.cc b/lib/gltexture.cc index 3b1ee78..49a5157 100644 --- a/lib/gltexture.cc +++ b/lib/gltexture.cc @@ -1,9 +1,12 @@ #include -#include -#include #include +#include +#include #include #include "gltexture.h" +#include "engine.h" + +#define _(x) x #define DEBUG 1 @@ -17,7 +20,7 @@ mogltk::texture * mogltk::texture::active = 0; mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : width(w), height(h), texture_allocated(false), planar(plane), tainted(true) { if ((BITCOUNT(w) != 1) || (BITCOUNT(h) != 1)) - throw GeneralException("Size of the texture not a power of 2!"); + throw GeneralException(_("Size of the texture not a power of 2!")); if (!(surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -32,8 +35,57 @@ mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : wi 0xff000000 #endif ))) { - throw GeneralException("Can't create RGB Surface"); + throw GeneralException(_("Can't create RGB Surface")); + } + +#ifdef TRACE_TEXTURES + next = 0; + prev = footer; + footer = this; + if (!header) { + header = this; } + if (prev) { + prev->next = this; + } +#endif +} + +mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) : + texture_allocated(false), planar(plane), tainted(true) { + + SDL_Surface * temp; + + if (!(temp = IMG_Load_RW(engine::RWFromHandle(h), 1))) + throw GeneralException(_("Can't load image from Handle ") + h->GetName()); + + width = temp->w; + height = temp->h; + + if ((BITCOUNT(width) != 1) || (BITCOUNT(height) != 1)) { + SDL_FreeSurface(temp); + throw GeneralException(_("Size of the texture not a power of 2!")); + } + + if (!(surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + 0xff000000, + 0x00ff0000, + 0x0000ff00, + 0x000000ff +#else + 0x000000ff, + 0x0000ff00, + 0x00ff0000, + 0xff000000 +#endif + ))) { + SDL_FreeSurface(temp); + throw GeneralException(_("Can't create RGB Surface")); + } + + SDL_BlitSurface(temp, 0, surface, 0); + SDL_FreeSurface(temp); #ifdef TRACE_TEXTURES next = 0; @@ -87,21 +139,21 @@ void mogltk::texture::Generate() { glGenTextures(1, &tex); #ifdef DEBUG - printm(M_INFO, "Generated texture index: %i\n", tex); + printm(M_INFO, _("Generated texture index: %i\n"), tex); #endif glBindTexture(GL_TEXTURE_2D, tex); if (planar) { #ifdef DEBUG - printm(M_INFO, "Generating planar texture: %i\n", tex); + printm(M_INFO, _("Generating planar texture: %i\n"), tex); #endif glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); } else { #ifdef DEBUG - printm(M_INFO, "Generating 3D texture: %i\n", tex); + printm(M_INFO, _("Generating 3D texture: %i\n"), tex); #endif glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -122,7 +174,7 @@ void mogltk::texture::Bind(bool expand) { if (active == this) return; #ifdef DEBUG - printm(M_INFO, "Binding texture index %i.\n", tex); + printm(M_INFO, _("Binding texture index %i.\n"), tex); #endif glBindTexture(GL_TEXTURE_2D, tex); if (expand) { @@ -167,7 +219,7 @@ void mogltk::texture::Unbind(void) { glDisable(GL_TEXTURE_2D); active = 0; #ifdef DEBUG - printm(M_INFO, "Unbinding texture.\n"); + printm(M_INFO, _("Unbinding texture.\n")); #endif } -- cgit v1.2.3