# opengltexture.h

    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     /************************************************************************
    00144         Grab/restore
    00145     *************************************************************************/
    00151     void grabTexture(void);
    00152
    00153
    00158     void restoreTexture(void);
    00159
    00160
    00161 private:
    00162 #ifndef USE_DEVIL_LIBRARY
    00163 // These defines are used to tell us about the type of TARGA file it is
    00164 #       define TGA_RGB           2              // This tells us it's a normal RGB (really BGR) file
    00165 #       define TGA_A             3              // This tells us it's a ALPHA file
    00166 #       define TGA_RLE          10              // This tells us that the targa is Run-Length Encoded (RLE)
    00167
    00168         /*************************************************************************
    00169                 Implementation Struct
    00170         *************************************************************************/
    00171         // This is our image structure for our targa data
    00172         struct tImageTGA
    00173         {
    00174                 int channels;                   // The channels in the image (3 = RGB : 4 = RGBA)
    00175                 int sizeX;                              // The width of the image in pixels
    00176                 int sizeY;                              // The height of the image in pixels
    00177                 unsigned char *data;    // The image pixel data
    00178         };
    00179
    00180
    00181         // flips data for tImageTGA 'img'
    00182         static void flipImageTGA(tImageTGA* img);
    00183
    00184
    00185         // Took this code from http://www.gametutorials.com still ne
    00186     // tImageTGA *LoadTGA(const char *filename)
    00187     //
    00188     // This is our cool function that loads the targa (TGA) file, then returns it's data.
    00189     // This tutorial supports 16, 24 and 32 bit images, along with RLE compression.
    00190     //
    00191     //
    00192     // Ben Humphrey (DigiBen)
    00193     // Game Programmer
    00194     // DigiBen@GameTutorials.com
    00195     // Co-Web Host of www.GameTutorials.com
    00196     //
    00197         //
    00198         // Modified by Paul D Turner to accept a raw data buffer & it's length
    00199         // as input.
    00200         //
    00201     tImageTGA* OpenGLTexture::LoadTGA(const unsigned char* buffer, size_t buffer_size);
    00202
    00203 #endif
    00204         /*************************************************************************
    00205                 Implementation Data
    00206         *************************************************************************/
    00207     GLuint              d_ogltexture;
    00208     ushort              d_width;
    00209     ushort              d_height;
    00210     uint8*      d_grabBuffer;
    00211 };
    00212
    00213 } // End of  CEGUI namespace section
    00214
    00215
    00216 #endif  // end of guard _opengltexture_h_