00001 /*************************************************************************** 00002 * Copyright (C) 2005-2008 by the FIFE team * 00003 * http://www.fifengine.de * 00004 * This file is part of FIFE. * 00005 * * 00006 * FIFE is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Lesser General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2.1 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * Lesser General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with this library; if not, write to the * 00018 * Free Software Foundation, Inc., * 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00020 ***************************************************************************/ 00021 00022 #ifndef FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLIMAGE_H 00023 #define FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLIMAGE_H 00024 00025 // Standard C++ library includes 00026 #include <vector> 00027 00028 // Platform specific includes 00029 #include "util/base/fife_stdint.h" 00030 00031 // 3rd party library includes 00032 #include <SDL_video.h> 00033 00034 // FIFE includes 00035 // These includes are split up in two parts, separated by one empty line 00036 // First block: files included from the FIFE root src directory 00037 // Second block: files included from the same folder 00038 #include "video/image.h" 00039 00040 #include "fife_opengl.h" 00041 00042 namespace FIFE { 00043 // FIXME: due to image chunking issues, GLImage uses SDLImage to draw primitives on its surface 00044 // remember though that OpenGL backend is not separate thing of SDL; instead it sits on top of it 00045 class SDLImage; 00046 00047 00058 class GLImage : public Image { 00059 public: 00060 GLImage(SDL_Surface* surface); 00061 GLImage(const uint8_t* data, unsigned int width, unsigned int height); 00062 virtual ~GLImage(); 00063 void render(const Rect& rect, SDL_Surface* dst, unsigned char alpha = 255); 00064 void saveImage(const std::string& filename); 00065 bool putPixel(int x, int y, int r, int g, int b); 00066 void drawLine(const Point& p1, const Point& p2, int r, int g, int b); 00067 void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b); 00068 void drawVertex(const Point& p, const uint8_t size, int r, int g, int b); 00069 00070 protected: 00071 void setClipArea(const Rect& cliparea, bool clear); 00072 00073 private: 00074 // number of rows into which this image is sliced, so that it "becomes power of 2 compatible" 00075 unsigned int m_rows; 00076 // see m_rows 00077 unsigned int m_cols; 00078 00079 // ratio of texture fill in last column. E.g. in case image width = 300, chunk = 256x256, 00080 // last column chunk width = 64 -> ratio is (300-256) / 64 = 0.6875 00081 // this means that texture fills 68.75% the last column 00082 float m_last_col_fill_ratio; 00083 // @see m_last_col_fill_ratio 00084 float m_last_row_fill_ratio; 00085 00089 unsigned int m_last_col_width; 00090 // see m_last_col_width 00091 unsigned int m_last_row_height; 00092 00095 GLuint* m_textureids; 00096 00099 void cleanup(); 00100 00103 void resetGlimage(); 00104 00105 //void saveAsPng(const std::string& filename, SDL_Surface& surface); 00106 00110 void generateTextureChunks(); 00111 00119 SDLImage* m_sdlimage; 00120 00121 unsigned int m_chunk_size; 00122 SDL_Color m_colorkey; 00123 }; 00124 } 00125 00126 #endif 00127 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */