FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
glimage.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLIMAGE_H
23 #define FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLIMAGE_H
24 
25 // Standard C++ library includes
26 #include <vector>
27 
28 // Platform specific includes
29 #include "util/base/fife_stdint.h"
30 
31 // 3rd party library includes
32 #include <SDL_video.h>
33 
34 // FIFE includes
35 // These includes are split up in two parts, separated by one empty line
36 // First block: files included from the FIFE root src directory
37 // Second block: files included from the same folder
38 #include "video/image.h"
39 
40 #include "fife_opengl.h"
41 
42 namespace FIFE {
43  // FIXME: due to image chunking issues, GLImage uses SDLImage to draw primitives on its surface
44  // remember though that OpenGL backend is not separate thing of SDL; instead it sits on top of it
45  class SDLImage;
46 
47 
58  class GLImage : public Image {
59  public:
60  GLImage(SDL_Surface* surface);
61  GLImage(const uint8_t* data, unsigned int width, unsigned int height);
62  virtual ~GLImage();
63  void invalidate();
64  void render(const Rect& rect, SDL_Surface* dst, unsigned char alpha = 255);
65  void saveImage(const std::string& filename);
66  bool putPixel(int x, int y, int r, int g, int b, int a = 255);
67  void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255);
68  void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255);
69  void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
70  void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
71  void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255);
72  void drawVertex(const Point& p, const uint8_t size, int r, int g, int b, int a = 255);
73  void drawLightPrimitive(const Point& p, uint8_t intensity, float radius, int subdivisions, float xstretch, float ystretch, uint8_t red, uint8_t green, uint8_t blue);
74 
75  protected:
76  void setClipArea(const Rect& cliparea, bool clear);
77 
78  private:
79  // texture coords to use
80  float m_col_tex_coord;
81  // @see m_col_tex_coord
82  float m_row_tex_coord;
83 
86  GLuint* m_textureids;
87 
90  void cleanup();
91 
94  void resetGlimage();
95 
96  //void saveAsPng(const std::string& filename, SDL_Surface& surface);
97 
100  void generateGLTexture();
101 
109  SDLImage* m_sdlimage;
110 
111  uint32_t m_chunk_size_w;
112  uint32_t m_chunk_size_h;
113 
114  SDL_Color m_colorkey;
115  };
116 }
117 
118 #endif
119 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */