00001 /************************************************************************ 00002 filename: opengltexture.h 00003 created: 9/4/2004 00004 author: Mark Strom 00005 mwstrom@gmail.com 00006 00007 purpose: Interface to Texture implemented via Opengl 00008 *************************************************************************/ 00009 /************************************************************************* 00010 Crazy Eddie's GUI System (http://www.cegui.org.uk) 00011 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk) 00012 00013 This library is free software; you can redistribute it and/or 00014 modify it under the terms of the GNU Lesser General Public 00015 License as published by the Free Software Foundation; either 00016 version 2.1 of the License, or (at your option) any later version. 00017 00018 This library is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00021 Lesser General Public License for more details. 00022 00023 You should have received a copy of the GNU Lesser General Public 00024 License along with this library; if not, write to the Free Software 00025 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 *************************************************************************/ 00027 #ifndef _opengltexture_h_ 00028 #define _opengltexture_h_ 00029 00030 #include "CEGUIBase.h" 00031 #include "CEGUIRenderer.h" 00032 #include "CEGUITexture.h" 00033 #include "renderers/OpenGLGUIRenderer/openglrenderer.h" 00034 00035 #include <list> 00036 00037 00038 // Start of CEGUI namespace section 00039 namespace CEGUI 00040 { 00041 00046 class OPENGL_GUIRENDERER_API OpenGLTexture : public Texture 00047 { 00048 private: 00049 /************************************************************************* 00050 Friends (to allow construction and destruction) 00051 *************************************************************************/ 00052 friend Texture* OpenGLRenderer::createTexture(void); 00053 friend Texture* OpenGLRenderer::createTexture(const String& filename, const String& resourceGroup); 00054 friend Texture* OpenGLRenderer::createTexture(float size); 00055 friend void OpenGLRenderer::destroyTexture(Texture* texture); 00056 00057 00058 /************************************************************************* 00059 Construction & Destruction (by Renderer object only) 00060 *************************************************************************/ 00061 OpenGLTexture(Renderer* owner); 00062 virtual ~OpenGLTexture(void); 00063 00064 public: 00072 virtual ushort getWidth(void) const {return d_width;} 00073 00074 00082 virtual ushort getHeight(void) const {return d_height;} 00083 00084 00098 virtual void loadFromFile(const String& filename, const String& resourceGroup); 00099 00100 00117 virtual void loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight); 00118 00119 00127 GLuint getOGLTexid(void) const {return d_ogltexture;} 00128 00129 00140 void setOGLTextureSize(uint size); 00141 00142 00143 private: 00144 #ifndef USE_DEVIL_LIBRARY 00145 // These defines are used to tell us about the type of TARGA file it is 00146 # define TGA_RGB 2 // This tells us it's a normal RGB (really BGR) file 00147 # define TGA_A 3 // This tells us it's a ALPHA file 00148 # define TGA_RLE 10 // This tells us that the targa is Run-Length Encoded (RLE) 00149 00150 /************************************************************************* 00151 Implementation Struct 00152 *************************************************************************/ 00153 // This is our image structure for our targa data 00154 struct tImageTGA 00155 { 00156 int channels; // The channels in the image (3 = RGB : 4 = RGBA) 00157 int sizeX; // The width of the image in pixels 00158 int sizeY; // The height of the image in pixels 00159 unsigned char *data; // The image pixel data 00160 }; 00161 00162 00163 // flips data for tImageTGA 'img' 00164 static void flipImageTGA(tImageTGA* img); 00165 00166 00167 // Took this code from http://www.gametutorials.com still ne 00168 // tImageTGA *LoadTGA(const char *filename) 00169 // 00170 // This is our cool function that loads the targa (TGA) file, then returns it's data. 00171 // This tutorial supports 16, 24 and 32 bit images, along with RLE compression. 00172 // 00173 // 00174 // Ben Humphrey (DigiBen) 00175 // Game Programmer 00176 // DigiBen@GameTutorials.com 00177 // Co-Web Host of www.GameTutorials.com 00178 // 00179 // 00180 // Modified by Paul D Turner to accept a raw data buffer & it's length 00181 // as input. 00182 // 00183 tImageTGA* OpenGLTexture::LoadTGA(const unsigned char* buffer, unsigned int buffer_size); 00184 00185 #endif 00186 /************************************************************************* 00187 Implementation Data 00188 *************************************************************************/ 00189 GLuint d_ogltexture; 00190 ushort d_width; 00191 ushort d_height; 00192 }; 00193 00194 } // End of CEGUI namespace section 00195 00196 00197 #endif // end of guard _opengltexture_h_