home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-Native.exe / {app} / include / renderers / OpenGLGUIRenderer / opengltexture.h < prev   
Encoding:
C/C++ Source or Header  |  2005-11-21  |  6.9 KB  |  217 lines

  1. /************************************************************************
  2.     filename:    opengltexture.h
  3.     created:    9/4/2004
  4.     author:        Mark Strom
  5.                 mwstrom@gmail.com
  6.  
  7.     purpose:    Interface to Texture implemented via Opengl
  8. *************************************************************************/
  9. /*************************************************************************
  10.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  11.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  12.  
  13.     This library is free software; you can redistribute it and/or
  14.     modify it under the terms of the GNU Lesser General Public
  15.     License as published by the Free Software Foundation; either
  16.     version 2.1 of the License, or (at your option) any later version.
  17.  
  18.     This library is distributed in the hope that it will be useful,
  19.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  21.     Lesser General Public License for more details.
  22.  
  23.     You should have received a copy of the GNU Lesser General Public
  24.     License along with this library; if not, write to the Free Software
  25.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  26. *************************************************************************/
  27. #ifndef _opengltexture_h_
  28. #define _opengltexture_h_
  29.  
  30. #include "CEGUIBase.h"
  31. #include "CEGUIRenderer.h"
  32. #include "CEGUITexture.h"
  33. #include "renderers/OpenGLGUIRenderer/openglrenderer.h"
  34.  
  35. #include <list>
  36.  
  37.  
  38. // Start of CEGUI namespace section
  39. namespace CEGUI
  40. {
  41.  
  42. /*!
  43. \brief
  44.     Texture class that is created by OpenGLRenderer objects
  45. */
  46. class OPENGL_GUIRENDERER_API OpenGLTexture : public Texture
  47. {
  48. private:
  49.     /*************************************************************************
  50.         Friends (to allow construction and destruction)
  51.     *************************************************************************/
  52.     friend    Texture* OpenGLRenderer::createTexture(void);
  53.     friend    Texture* OpenGLRenderer::createTexture(const String& filename, const String& resourceGroup);
  54.     friend    Texture* OpenGLRenderer::createTexture(float size);
  55.     friend    void     OpenGLRenderer::destroyTexture(Texture* texture);
  56.  
  57.  
  58.     /*************************************************************************
  59.         Construction & Destruction (by Renderer object only)
  60.     *************************************************************************/
  61.     OpenGLTexture(Renderer* owner);
  62.     virtual ~OpenGLTexture(void);
  63.  
  64. public:
  65.     /*!
  66.     \brief
  67.         Returns the current pixel width of the texture
  68.  
  69.     \return
  70.         ushort value that is the current width of the texture in pixels
  71.     */
  72.     virtual    ushort    getWidth(void) const        {return d_width;}
  73.  
  74.  
  75.     /*!
  76.     \brief
  77.         Returns the current pixel height of the texture
  78.  
  79.     \return
  80.         ushort value that is the current height of the texture in pixels
  81.     */
  82.     virtual    ushort    getHeight(void) const        {return d_height;}
  83.  
  84.  
  85.     /*!
  86.     \brief
  87.         Loads the specified image file into the texture.  The texture is resized as required to hold the image.
  88.  
  89.     \param filename
  90.         The filename of the image file that is to be loaded into the texture
  91.  
  92.     \param resourceGroup
  93.         Resource group identifier passed to the resource provider.
  94.  
  95.     \return
  96.         Nothing.
  97.     */
  98.     virtual void    loadFromFile(const String& filename, const String& resourceGroup);
  99.  
  100.  
  101.     /*!
  102.     \brief
  103.         Loads (copies) an image in memory into the texture.  The texture is resized as required to hold the image.
  104.  
  105.     \param buffPtr
  106.         Pointer to the buffer containing the image data
  107.  
  108.     \param buffWidth
  109.         Width of the buffer (in 0xAARRGGBB pixels)
  110.  
  111.     \param buffHeight
  112.         Height of the buffer (in 0xAARRGGBB pixels)
  113.  
  114.     \return
  115.         Nothing.
  116.     */
  117.     virtual void    loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight);
  118.  
  119.  
  120.     /*!
  121.     \brief
  122.         Return a pointer to the internal texture id
  123.  
  124.     \return
  125.         Texture id that is loaded
  126.     */
  127.     GLuint    getOGLTexid(void) const {return d_ogltexture;}
  128.  
  129.  
  130.     /*!
  131.     \brief
  132.         set the size of the internal texture.
  133.  
  134.     \param size
  135.         pixel size of the new internal texture.  This will be rounded up to a power of 2.
  136.  
  137.     \return
  138.         Nothing.
  139.     */
  140.     void    setOGLTextureSize(uint size);
  141.  
  142.  
  143.     /************************************************************************
  144.         Grab/restore
  145.     *************************************************************************/
  146.     /*!
  147.     \brief
  148.         Grab the texture to a local buffer.
  149.         This will destroy the OpenGL texture, and restoreTexture must be called before using it again.
  150.     */
  151.     void grabTexture(void);
  152.  
  153.  
  154.     /*!
  155.     \brief
  156.         Restore the texture from the locally buffered copy previously create by a call to grabTexture.
  157.     */
  158.     void restoreTexture(void);
  159.  
  160.  
  161. private:
  162. #ifndef USE_DEVIL_LIBRARY
  163. // These defines are used to tell us about the type of TARGA file it is
  164. #    define TGA_RGB         2        // This tells us it's a normal RGB (really BGR) file
  165. #    define TGA_A         3        // This tells us it's a ALPHA file
  166. #    define TGA_RLE        10        // This tells us that the targa is Run-Length Encoded (RLE)
  167.  
  168.     /*************************************************************************
  169.         Implementation Struct
  170.     *************************************************************************/
  171.     // This is our image structure for our targa data
  172.     struct tImageTGA
  173.     {
  174.         int channels;            // The channels in the image (3 = RGB : 4 = RGBA)
  175.         int sizeX;                // The width of the image in pixels
  176.         int sizeY;                // The height of the image in pixels
  177.         unsigned char *data;    // The image pixel data
  178.     };
  179.  
  180.  
  181.     // flips data for tImageTGA 'img'
  182.     static void flipImageTGA(tImageTGA* img);
  183.     
  184.  
  185.     // Took this code from http://www.gametutorials.com still ne
  186.     // tImageTGA *LoadTGA(const char *filename)
  187.     //
  188.     // This is our cool function that loads the targa (TGA) file, then returns it's data.  
  189.     // This tutorial supports 16, 24 and 32 bit images, along with RLE compression.
  190.     //
  191.     //
  192.     // Ben Humphrey (DigiBen)
  193.     // Game Programmer
  194.     // DigiBen@GameTutorials.com
  195.     // Co-Web Host of www.GameTutorials.com
  196.     //
  197.     //
  198.     // Modified by Paul D Turner to accept a raw data buffer & it's length
  199.     // as input.
  200.     //
  201.     tImageTGA* OpenGLTexture::LoadTGA(const unsigned char* buffer, size_t buffer_size);
  202.  
  203. #endif
  204.     /*************************************************************************
  205.         Implementation Data
  206.     *************************************************************************/
  207.     GLuint         d_ogltexture;        //!< The 'real' texture.
  208.     ushort        d_width;            //!< cached width of the texture
  209.     ushort        d_height;            //!< cached height of the texture
  210.     uint8*      d_grabBuffer;       //!< cached image data for restoring the texture
  211. };
  212.  
  213. } // End of  CEGUI namespace section
  214.  
  215.  
  216. #endif    // end of guard _opengltexture_h_
  217.