From 97b4a5904a989e216b1fbb4d0a55b7340bd7f88a Mon Sep 17 00:00:00 2001 From: pixel Date: Tue, 31 Jan 2006 17:02:39 +0000 Subject: Way too much changes - all over. --- lib/texture.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'lib/texture.cc') diff --git a/lib/texture.cc b/lib/texture.cc index a06c345..b94882a 100644 --- a/lib/texture.cc +++ b/lib/texture.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: texture.cc,v 1.11 2004-11-27 21:48:03 pixel Exp $ */ +/* $Id: texture.cc,v 1.12 2006-01-31 17:02:39 pixel Exp $ */ #include #include @@ -135,6 +135,64 @@ mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) : } } +mogltk::texture::texture(SDL_Surface * temp, bool plane) throw (GeneralException) : + texture_allocated(false), planar(plane), tainted(true), taintable(true) { + + width = temp->w; + height = temp->h; + +#ifdef DEBUG + printm(M_INFO, "Creating texture from file: size %ix%i\n", height, width); +#endif + + if ((!ISPOT(width)) || (!ISPOT(height))) { + throw GeneralException(_("Size of the texture not a power of 2!")); + } + + SDL_PixelFormat f; + + f.palette = 0; + f.BitsPerPixel = 32; + f.BytesPerPixel = 4; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + f.Amask = 0x000000ff; + f.Bmask = 0x0000ff00; + f.Gmask = 0x00ff0000; + f.Rmask = 0xff000000; + f.Ashift = 0; + f.Bshift = 8; + f.Gshift = 16; + f.Rshift = 24; +#else + f.Rmask = 0x000000ff; + f.Gmask = 0x0000ff00; + f.Bmask = 0x00ff0000; + f.Amask = 0xff000000; + f.Rshift = 0; + f.Gshift = 8; + f.Bshift = 16; + f.Ashift = 24; +#endif + f.Rloss = 0; + f.Gloss = 0; + f.Bloss = 0; + f.Aloss = 0; + + if (!(surface = SDL_ConvertSurface(temp, &f, 0))) { + throw GeneralException("Could not convert texture to OpenGL format"); + } + + next = 0; + prev = footer; + footer = this; + if (!header) { + header = this; + } + if (prev) { + prev->next = this; + } +} + inline static unsigned int nextpower(unsigned int n) { unsigned int i; -- cgit v1.2.3