/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER #include "texture.h" #include "debug.h" #include "compiler.h" #include "sdlincl.h" /** * @brief creates a new Texture Data. */ TextureData::TextureData() { this->bAlpha = false; this->texture = 0; this->image = NULL; } /** * @brief Destructor of a Texture * * Frees Data, and deletes the textures from GL */ TextureData::~TextureData() { if (this->texture != 0) glDeleteTextures(1, &this->texture); if (this->image != NULL) SDL_FreeSurface(this->image); } /** * @brief Loads an SDL_Surface. * @param surface the Surface to Load. * @param target the GL-Target to load the Surface to default GL_TEXTURE_2D * @returns true on success, false otherwise. */ bool TextureData::loadSurface(SDL_Surface* surface, GLenum target) { if (Texture::getTextureEnableState()) { SDL_Surface* newSurf = Texture::prepareSurface(surface, this->bAlpha); if (newSurf != NULL) { this->setSurface(newSurf); this->setTexture(Texture::loadTexToGL(newSurf, target)); return true; } } return false; } /** * @brief set the surface this Texture handles * @param newSurface the new Surface to set as the image for this Texture. * @returns true on success. * * This deletes the old version of the stored Texture, * and sets the newly given Surface as current. */ bool TextureData::setSurface(SDL_Surface* newSurface) { if (this->image != NULL) SDL_FreeSurface(this->image); this->image = newSurface; return (this->image != NULL); } /** * @brief sets a new Texture to the Data. * @param texture the Texture * @returns true on success. */ bool TextureData::setTexture(GLuint texture) { // unload the old Texture. if (this->texture != 0 && glIsTexture(this->getTexture())) { glDeleteTextures(1, &this->texture); } this->texture = texture; return (texture != 0); }