$treeview $search $mathjax
Stratagus
2.2.7
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 1999-2011 by Lutz Sammer, Nehal Mistry, Jimmy Salmon and 00014 // Pali Rohár 00015 // 00016 // This program is free software; you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation; only version 2 of the License. 00019 // 00020 // This program is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 // GNU General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU General Public License 00026 // along with this program; if not, write to the Free Software 00027 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00028 // 02111-1307, USA. 00029 // 00030 00031 #ifndef __VIDEO_H__ 00032 #define __VIDEO_H__ 00033 00035 00036 #include "SDL.h" 00037 #ifdef USE_GLES 00038 #include "SDL_gles.h" 00039 #include "GLES/gl.h" 00040 #else 00041 #include "SDL_opengl.h" 00042 #endif 00043 00044 #include "guichan.h" 00045 00046 #include "color.h" 00047 #include "vec2i.h" 00048 00049 class CFont; 00050 00051 extern char ForceUseOpenGL; 00052 extern bool UseOpenGL; 00053 00054 class CGraphic : public gcn::Image 00055 { 00056 00057 struct frame_pos_t { 00058 short int x; 00059 short int y; 00060 }; 00061 00062 protected: 00063 CGraphic() : Surface(NULL), SurfaceFlip(NULL), frame_map(NULL), 00064 Width(0), Height(0), NumFrames(1), GraphicWidth(0), GraphicHeight(0), 00065 Refs(1), Resized(false), 00066 TextureWidth(0.f), TextureHeight(0.f), Textures(NULL), NumTextures(0) { 00067 frameFlip_map = NULL; 00068 } 00069 ~CGraphic() {} 00070 00071 public: 00072 // Draw 00073 void DrawClip(int x, int y) const; 00074 void DrawSub(int gx, int gy, int w, int h, int x, int y) const; 00075 void DrawSubClip(int gx, int gy, int w, int h, int x, int y) const; 00076 void DrawSubTrans(int gx, int gy, int w, int h, int x, int y, 00077 unsigned char alpha) const; 00078 void DrawSubClipTrans(int gx, int gy, int w, int h, int x, int y, 00079 unsigned char alpha) const; 00080 00081 // Draw frame 00082 void DrawFrame(unsigned frame, int x, int y) const; 00083 void DoDrawFrameClip(GLuint *textures, unsigned frame, int x, int y) const; 00084 void DrawFrameClip(unsigned frame, int x, int y) const; 00085 void DrawFrameTrans(unsigned frame, int x, int y, int alpha) const; 00086 void DrawFrameClipTrans(unsigned frame, int x, int y, int alpha) const; 00087 00088 // Draw frame flipped horizontally 00089 void DrawFrameX(unsigned frame, int x, int y) const; 00090 void DoDrawFrameClipX(GLuint *textures, unsigned frame, int x, int y) const; 00091 void DrawFrameClipX(unsigned frame, int x, int y) const; 00092 void DrawFrameTransX(unsigned frame, int x, int y, int alpha) const; 00093 void DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) const; 00094 00095 00096 static CGraphic *New(const std::string &file, int w = 0, int h = 0); 00097 static CGraphic *ForceNew(const std::string &file, int w = 0, int h = 0); 00098 00099 CGraphic *Clone() const; 00100 00101 static void Free(CGraphic *g); 00102 00103 void Load(); 00104 void Flip(); 00105 void UseDisplayFormat(); 00106 void Resize(int w, int h); 00107 bool TransparentPixel(int x, int y); 00108 void MakeShadow(); 00109 00110 inline bool IsLoaded() const { return Surface != NULL; } 00111 00112 //guichan 00113 virtual void *_getData() const { return Surface; } 00114 virtual int getWidth() const { return Width; } 00115 virtual int getHeight() const { return Height; } 00116 00117 std::string File; 00118 std::string HashFile; 00119 SDL_Surface *Surface; 00120 SDL_Surface *SurfaceFlip; 00121 frame_pos_t *frame_map; 00122 frame_pos_t *frameFlip_map; 00123 void GenFramesMap(); 00124 int Width; 00125 int Height; 00126 int NumFrames; 00127 int GraphicWidth; 00128 int GraphicHeight; 00129 int Refs; 00130 bool Resized; 00131 GLfloat TextureWidth; 00132 GLfloat TextureHeight; 00133 GLuint *Textures; 00134 int NumTextures; 00135 00136 friend class CFont; 00137 }; 00138 00139 class CPlayerColorGraphic : public CGraphic 00140 { 00141 protected: 00142 CPlayerColorGraphic() { 00143 memset(PlayerColorTextures, 0, sizeof(PlayerColorTextures)); 00144 } 00145 00146 public: 00147 void DrawPlayerColorFrameClipX(int player, unsigned frame, int x, int y); 00148 void DrawPlayerColorFrameClip(int player, unsigned frame, int x, int y); 00149 00150 static CPlayerColorGraphic *New(const std::string &file, int w = 0, int h = 0); 00151 static CPlayerColorGraphic *ForceNew(const std::string &file, int w = 0, int h = 0); 00152 00153 GLuint *PlayerColorTextures[PlayerMax]; 00154 }; 00155 00156 #ifdef USE_MNG 00157 #include <libmng.h> 00158 00159 class Mng 00160 { 00161 public: 00162 Mng(); 00163 ~Mng(); 00164 int Load(const std::string &name); 00165 void Reset(); 00166 void Draw(int x, int y); 00167 00168 std::string name; 00169 FILE *fd; 00170 mng_handle handle; 00171 SDL_Surface *surface; 00172 unsigned char *buffer; 00173 unsigned long ticks; 00174 int iteration; 00175 GLfloat texture_width; 00176 GLfloat texture_height; 00177 GLuint texture_name; 00178 }; 00179 #endif 00180 00187 struct EventCallback { 00188 00190 void (*ButtonPressed)(unsigned buttons); 00192 void (*ButtonReleased)(unsigned buttons); 00194 void (*MouseMoved)(const PixelPos &screenPos); 00196 void (*MouseExit)(); 00197 00199 void (*KeyPressed)(unsigned keycode, unsigned keychar); 00201 void (*KeyReleased)(unsigned keycode, unsigned keychar); 00203 void (*KeyRepeated)(unsigned keycode, unsigned keychar); 00204 00206 void (*NetworkEvent)(); 00207 00208 }; 00209 00210 #if SDL_BYTEORDER == SDL_LIL_ENDIAN 00211 #define RSHIFT 0 00212 #define GSHIFT 8 00213 #define BSHIFT 16 00214 #define ASHIFT 24 00215 #define RMASK 0x000000ff 00216 #define GMASK 0x0000ff00 00217 #define BMASK 0x00ff0000 00218 #define AMASK 0xff000000 00219 #else 00220 #define RSHIFT 24 00221 #define GSHIFT 16 00222 #define BSHIFT 8 00223 #define ASHIFT 0 00224 #define RMASK 0xff000000 00225 #define GMASK 0x00ff0000 00226 #define BMASK 0x0000ff00 00227 #define AMASK 0x000000ff 00228 #endif 00229 00230 00231 class CVideo 00232 { 00233 public: 00234 CVideo() : Width(0), Height(0), Depth(0), FullScreen(false) {} 00235 00236 void LockScreen(); 00237 void UnlockScreen(); 00238 00239 void ClearScreen(); 00240 bool ResizeScreen(int width, int height); 00241 00242 void DrawPixelClip(Uint32 color, int x, int y); 00243 void DrawTransPixelClip(Uint32 color, int x, int y, unsigned char alpha); 00244 00245 void DrawVLine(Uint32 color, int x, int y, int height); 00246 void DrawTransVLine(Uint32 color, int x, int y, int height, unsigned char alpha); 00247 void DrawVLineClip(Uint32 color, int x, int y, int height); 00248 void DrawTransVLineClip(Uint32 color, int x, int y, int height, unsigned char alpha); 00249 00250 void DrawHLine(Uint32 color, int x, int y, int width); 00251 void DrawTransHLine(Uint32 color, int x, int y, int width, unsigned char alpha); 00252 void DrawHLineClip(Uint32 color, int x, int y, int width); 00253 void DrawTransHLineClip(Uint32 color, int x, int y, int width, unsigned char alpha); 00254 00255 void DrawLine(Uint32 color, int sx, int sy, int dx, int dy); 00256 void DrawTransLine(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha); 00257 void DrawLineClip(Uint32 color, const PixelPos &pos1, const PixelPos &pos2); 00258 void DrawTransLineClip(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha); 00259 00260 void DrawRectangle(Uint32 color, int x, int y, int w, int h); 00261 void DrawTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha); 00262 void DrawRectangleClip(Uint32 color, int x, int y, int w, int h); 00263 void DrawTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha); 00264 00265 void FillRectangle(Uint32 color, int x, int y, int w, int h); 00266 void FillTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha); 00267 void FillRectangleClip(Uint32 color, int x, int y, int w, int h); 00268 void FillTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha); 00269 00270 void DrawCircle(Uint32 color, int x, int y, int r); 00271 void DrawTransCircle(Uint32 color, int x, int y, int r, unsigned char alpha); 00272 void DrawCircleClip(Uint32 color, int x, int y, int r); 00273 void DrawTransCircleClip(Uint32 color, int x, int y, int r, unsigned char alpha); 00274 00275 void FillCircle(Uint32 color, int x, int y, int radius); 00276 void FillTransCircle(Uint32 color, int x, int y, int radius, unsigned char alpha); 00277 void FillCircleClip(Uint32 color, const PixelPos &screenPos, int radius); 00278 void FillTransCircleClip(Uint32 color, int x, int y, int radius, unsigned char alpha); 00279 00280 inline Uint32 MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b) { 00281 if (!UseOpenGL) { 00282 return SDL_MapRGB(f, r, g, b); 00283 } else { 00284 return MapRGBA(f, r, g, b, 0xFF); 00285 } 00286 } 00287 inline Uint32 MapRGB(SDL_PixelFormat *f, const CColor &color) { 00288 return MapRGB(f, color.R, color.G, color.B); 00289 } 00290 inline Uint32 MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { 00291 if (!UseOpenGL) { 00292 return SDL_MapRGBA(f, r, g, b, a); 00293 } else { 00294 return ((r << RSHIFT) | (g << GSHIFT) | (b << BSHIFT) | (a << ASHIFT)); 00295 } 00296 } 00297 inline Uint32 MapRGBA(SDL_PixelFormat *f, const CColor &color) { 00298 return MapRGBA(f, color.R, color.G, color.B, color.A); 00299 } 00300 inline void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b) { 00301 if (!UseOpenGL) { 00302 SDL_GetRGB(c, f, r, g, b); 00303 } else { 00304 *r = (c >> RSHIFT) & 0xff; 00305 *g = (c >> GSHIFT) & 0xff; 00306 *b = (c >> BSHIFT) & 0xff; 00307 } 00308 } 00309 inline void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) { 00310 if (!UseOpenGL) { 00311 SDL_GetRGBA(c, f, r, g, b, a); 00312 } else { 00313 *r = (c >> RSHIFT) & 0xff; 00314 *g = (c >> GSHIFT) & 0xff; 00315 *b = (c >> BSHIFT) & 0xff; 00316 *a = (c >> ASHIFT) & 0xff; 00317 } 00318 } 00319 00320 int Width; 00321 int Height; 00322 int Depth; 00323 bool FullScreen; 00324 }; 00325 00326 extern CVideo Video; 00327 00335 extern int VideoSyncSpeed; 00336 00337 extern int SkipFrames; 00338 00340 extern char VideoForceFullScreen; 00341 00343 extern unsigned long NextFrameTicks; 00344 00346 extern unsigned long FrameCounter; 00347 00349 extern int SlowFrameCounter; 00350 00353 extern void SetPlayersPalette(); 00354 00356 extern SDL_Surface *TheScreen; 00357 00359 extern GLint GLMaxTextureSize; 00361 extern GLint GLMaxTextureSizeOverride; 00363 extern bool GLTextureCompressionSupported; 00365 extern bool UseGLTextureCompression; 00366 00368 extern void VideoCclRegister(); 00369 00371 extern void InitVideo(); 00372 00374 void DeInitVideo(); 00375 00377 extern int VideoValidResolution(int w, int h); 00378 00380 extern int LoadGraphicPNG(CGraphic *g); 00381 00383 extern void MakeTexture(CGraphic *graphic); 00385 extern void MakePlayerColorTexture(CPlayerColorGraphic *graphic, int player); 00386 00388 extern void ValidateOpenGLScreen(); 00389 00391 extern void FreeOpenGLGraphics(); 00393 extern void ReloadGraphics(); 00395 extern void ReloadOpenGL(); 00396 00398 extern void SetVideoSync(); 00399 00401 extern void InitLineDraw(); 00402 00404 extern void Invalidate(); 00405 00408 extern void InvalidateArea(int x, int y, int w, int h); 00409 00412 extern void SetClipping(int left, int top, int right, int bottom); 00413 00415 extern void RealizeVideoMemory(); 00416 00418 extern void SaveScreenshotPNG(const char *name); 00419 00421 extern void SetCallbacks(const EventCallback *callbacks); 00423 extern const EventCallback *GetCallbacks(); 00424 00426 extern void WaitEventsOneFrame(); 00427 00429 extern void ToggleFullScreen(); 00430 00432 extern void PushClipping(); 00433 00435 extern void PopClipping(); 00436 00438 extern unsigned long GetTicks(); 00439 00441 extern const char *SdlKey2Str(int key); 00442 00444 extern bool SdlGetGrabMouse(); 00446 extern void ToggleGrabMouse(int mode); 00447 00448 extern EventCallback GameCallbacks; 00449 extern EventCallback EditorCallbacks; 00450 00451 extern Uint32 ColorBlack; 00452 extern Uint32 ColorDarkGreen; 00453 extern Uint32 ColorBlue; 00454 extern Uint32 ColorOrange; 00455 extern Uint32 ColorWhite; 00456 extern Uint32 ColorGray; 00457 extern Uint32 ColorRed; 00458 extern Uint32 ColorGreen; 00459 extern Uint32 ColorYellow; 00460 00461 void DrawTexture(const CGraphic *g, GLuint *textures, int sx, int sy, 00462 int ex, int ey, int x, int y, int flip); 00463 00464 #ifdef DEBUG 00465 extern void FreeGraphics(); 00466 #endif 00467 00468 00469 // ARB_texture_compression 00470 #ifndef USE_GLES 00471 extern PFNGLCOMPRESSEDTEXIMAGE3DARBPROC glCompressedTexImage3DARB; 00472 extern PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB; 00473 extern PFNGLCOMPRESSEDTEXIMAGE1DARBPROC glCompressedTexImage1DARB; 00474 extern PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3DARB; 00475 extern PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2DARB; 00476 extern PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1DARB; 00477 extern PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB; 00478 #endif 00479 00480 // 00481 // Color Cycling stuff 00482 // 00483 00484 extern void VideoPaletteListAdd(SDL_Surface *surface); 00485 extern void VideoPaletteListRemove(SDL_Surface *surface); 00486 extern void ClearAllColorCyclingRange(); 00487 extern void AddColorCyclingRange(unsigned int begin, unsigned int end); 00488 extern void SetColorCycleAll(bool value); 00489 00491 extern void ColorCycle(); 00492 00494 00495 #endif // !__VIDEO_H__