glshape.h

Go to the documentation of this file.
00001 /*
00002  *  glshape.h - Paint 2D shapes in OpenGL
00003  *
00004  *  Written: 7/16/02 - JSF
00005  *
00006  *  Copyright (C) 2002  The Exult Team
00007  *
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation; either version 2 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program; if not, write to the Free Software
00020  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #ifndef GLSHAPE_H
00024 #define GLSHAPE_H 1
00025 
00026 #ifdef HAVE_OPENGL
00027 
00028 class Xform_palette;
00029 class Shape_frame;
00030 class GL_texshape;
00031 class Image_buffer8;
00032 
00033 /*
00034  *  A 2D shape is rendered by painting a quad with the shape as a texture.
00035  */
00036 class GL_texshape
00037   {
00038   Shape_frame *frame;   // Source for this (or null if it came
00039           //   from someplace else).
00040   unsigned int texture;   // Texture ID.
00041   unsigned int texsize;   // Width/ht of texture (power of 2).
00042           // Least-recently used chain:
00043   GL_texshape *lru_next, *lru_prev;
00044           // Create from this source.
00045   void create(Image_buffer8 *src, unsigned char *pal, 
00046         Xform_palette *xforms = 0, int xfcnt = 0);
00047 public:
00048   friend class GL_manager;
00049   GL_texshape(Shape_frame *f, unsigned char *pal, 
00050         Xform_palette *xforms = 0, int xfcnt = 0);
00051   GL_texshape(Image_buffer8 *src, unsigned char *pal);
00052   ~GL_texshape();
00053   void paint(int px, int py); // Render at given position.
00054   };
00055 
00056 /*
00057  *  Handle OpenGL rendering.
00058  */
00059 class GL_manager
00060   {
00061   static GL_manager *instance;  // One one of these.
00062   int scale;      // Scale for drawing.
00063   int max_texsize;    // Largest size allowed.
00064   GL_texshape *shapes;    // Shapes in LRU chain.
00065   int num_shapes;
00066   unsigned char *palette;   // 3*256 bytes (rgb).
00067 public:
00068   friend class GL_texshape;
00069   GL_manager();
00070   ~GL_manager();
00071   static GL_manager *get_instance()
00072     { return instance; }
00073   void set_palette(unsigned char *pal)
00074     { delete palette; palette = pal; }
00075           // Create from src (but don't add to
00076           //   chain).
00077   GL_texshape *create(Image_buffer8 *src)
00078     { return new GL_texshape(src, palette); }
00079           // Window was resized.
00080   void resized(int new_width, int new_height, int new_scale);
00081           // Paint a shape & create GL_shape
00082           //   for it if necessary.
00083   void paint(Shape_frame *frame, int px, int py,
00084         Xform_palette *xforms = 0, int xfcnt = 0);
00085   };
00086 
00087 
00088 #else
00089 
00090 class GL_manager
00091 {
00092  public:
00093   static GL_manager *get_instance()
00094     { return 0; }
00095 };
00096 
00097 #endif  /* HAVE_OPENGL */
00098 
00099 
00100 #endif  /* GLSHAPE_H */

Generated on Mon Jul 9 14:42:50 2007 for ExultEngine by  doxygen 1.5.1