$treeview $search $mathjax
Stratagus
2.2.6
$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 #include "guichan.h" 00044 00045 class CFont; 00046 00047 extern char ForceUseOpenGL; 00048 extern bool UseOpenGL; 00049 00050 class CGraphic : public gcn::Image { 00051 00052 struct frame_pos_t { 00053 short int x; 00054 short int y; 00055 }; 00056 00057 protected: 00058 CGraphic() : Surface(NULL), SurfaceFlip(NULL), frame_map(NULL), 00059 Width(0), Height(0), NumFrames(1), GraphicWidth(0), GraphicHeight(0), 00060 Refs(1), Resized(false), 00061 TextureWidth(0.f), TextureHeight(0.f), Textures(NULL), NumTextures(0) 00062 { 00063 frameFlip_map = NULL; 00064 } 00065 ~CGraphic() {} 00066 00067 public: 00068 // Draw 00069 void DrawClip(int x, int y) const; 00070 void DrawSub(int gx, int gy, int w, int h, int x, int y) const; 00071 void DrawSubClip(int gx, int gy, int w, int h, int x, int y) const; 00072 void DrawSubTrans(int gx, int gy, int w, int h, int x, int y, 00073 unsigned char alpha) const; 00074 void DrawSubClipTrans(int gx, int gy, int w, int h, int x, int y, 00075 unsigned char alpha) const; 00076 00077 // Draw frame 00078 void DrawFrame(unsigned frame, int x, int y) const; 00079 void DoDrawFrameClip(GLuint *textures, unsigned frame, int x, int y) const; 00080 void DrawFrameClip(unsigned frame, int x, int y) const; 00081 void DrawFrameTrans(unsigned frame, int x, int y, int alpha) const; 00082 void DrawFrameClipTrans(unsigned frame, int x, int y, int alpha) const; 00083 00084 // Draw frame flipped horizontally 00085 void DrawFrameX(unsigned frame, int x, int y) const; 00086 void DoDrawFrameClipX(GLuint *textures, unsigned frame, int x, int y) const; 00087 void DrawFrameClipX(unsigned frame, int x, int y) const; 00088 void DrawFrameTransX(unsigned frame, int x, int y, int alpha) const; 00089 void DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) const; 00090 00091 00092 static CGraphic *New(const std::string &file, int w = 0, int h = 0); 00093 static CGraphic *ForceNew(const std::string &file, int w = 0, int h = 0); 00094 00095 CGraphic *Clone() const; 00096 00097 static void Free(CGraphic *g); 00098 00099 void Load(); 00100 void Flip(); 00101 void UseDisplayFormat(); 00102 void Resize(int w, int h); 00103 bool TransparentPixel(int x, int y); 00104 void MakeShadow(); 00105 00106 inline bool IsLoaded() const { return Surface != NULL; } 00107 00108 //guichan 00109 virtual void *_getData() const { return Surface; } 00110 virtual int getWidth() const { return Width; } 00111 virtual int getHeight() const { return Height; } 00112 00113 std::string File; 00114 std::string HashFile; 00115 SDL_Surface *Surface; 00116 SDL_Surface *SurfaceFlip; 00117 frame_pos_t *frame_map; 00118 frame_pos_t *frameFlip_map; 00119 void GenFramesMap(); 00120 int Width; 00121 int Height; 00122 int NumFrames; 00123 int GraphicWidth; 00124 int GraphicHeight; 00125 int Refs; 00126 bool Resized; 00127 GLfloat TextureWidth; 00128 GLfloat TextureHeight; 00129 GLuint *Textures; 00130 int NumTextures; 00131 00132 friend class CFont; 00133 }; 00134 00135 class CPlayerColorGraphic : public CGraphic 00136 { 00137 protected: 00138 CPlayerColorGraphic() { 00139 memset(PlayerColorTextures, 0, sizeof(PlayerColorTextures)); 00140 } 00141 00142 public: 00143 void DrawPlayerColorFrameClipX(int player, unsigned frame, int x, int y); 00144 void DrawPlayerColorFrameClip(int player, unsigned frame, int x, int y); 00145 00146 static CPlayerColorGraphic *New(const std::string &file, int w = 0, int h = 0); 00147 static CPlayerColorGraphic *ForceNew(const std::string &file, int w = 0, int h = 0); 00148 00149 GLuint *PlayerColorTextures[PlayerMax]; 00150 }; 00151 00152 #ifdef USE_MNG 00153 #include <libmng.h> 00154 00155 class Mng { 00156 public: 00157 Mng(); 00158 ~Mng(); 00159 int Load(const std::string &name); 00160 void Reset(); 00161 void Draw(int x, int y); 00162 00163 std::string name; 00164 FILE *fd; 00165 mng_handle handle; 00166 SDL_Surface *surface; 00167 unsigned char *buffer; 00168 unsigned long ticks; 00169 int iteration; 00170 GLfloat texture_width; 00171 GLfloat texture_height; 00172 GLuint texture_name; 00173 }; 00174 #endif 00175 00177 class CColor { 00178 public: 00179 CColor(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0, 00180 unsigned char a = 0) : R(r), G(g), B(b), A(a) {} 00181 00183 operator SDL_Color() const { 00184 SDL_Color c = { R, G, B, A }; 00185 return c; 00186 }; 00187 00188 unsigned char R; 00189 unsigned char G; 00190 unsigned char B; 00191 unsigned char A; 00192 }; 00193 00194 class CUnitColors { 00195 public: 00196 CUnitColors() : Colors(NULL) {} 00197 00198 SDL_Color *Colors; 00199 }; 00200 00207 typedef struct _event_callback_ { 00208 00210 void (*ButtonPressed)(unsigned buttons); 00212 void (*ButtonReleased)(unsigned buttons); 00214 void (*MouseMoved)(int x, int y); 00216 void (*MouseExit)(); 00217 00219 void (*KeyPressed)(unsigned keycode, unsigned keychar); 00221 void (*KeyReleased)(unsigned keycode, unsigned keychar); 00223 void (*KeyRepeated)(unsigned keycode, unsigned keychar); 00224 00226 void (*NetworkEvent)(); 00227 00228 } EventCallback; 00229 00230 #if SDL_BYTEORDER == SDL_LIL_ENDIAN 00231 #define RSHIFT 0 00232 #define GSHIFT 8 00233 #define BSHIFT 16 00234 #define ASHIFT 24 00235 #define RMASK 0x000000ff 00236 #define GMASK 0x0000ff00 00237 #define BMASK 0x00ff0000 00238 #define AMASK 0xff000000 00239 #else 00240 #define RSHIFT 24 00241 #define GSHIFT 16 00242 #define BSHIFT 8 00243 #define ASHIFT 0 00244 #define RMASK 0xff000000 00245 #define GMASK 0x00ff0000 00246 #define BMASK 0x0000ff00 00247 #define AMASK 0x000000ff 00248 #endif 00249 00250 00251 class CVideo 00252 { 00253 public: 00254 CVideo() : Width(0), Height(0), Depth(0), FullScreen(false) {} 00255 00256 void LockScreen(); 00257 void UnlockScreen(); 00258 00259 void ClearScreen(); 00260 bool ResizeScreen(int x, int y); 00261 00262 void DrawPixelClip(Uint32 color, int x, int y); 00263 void DrawTransPixelClip(Uint32 color, int x, int y, unsigned char alpha); 00264 00265 void DrawVLine(Uint32 color, int x, int y, int height); 00266 void DrawTransVLine(Uint32 color, int x, int y, int height, unsigned char alpha); 00267 void DrawVLineClip(Uint32 color, int x, int y, int height); 00268 void DrawTransVLineClip(Uint32 color, int x, int y, int height, unsigned char alpha); 00269 00270 void DrawHLine(Uint32 color, int x, int y, int width); 00271 void DrawTransHLine(Uint32 color, int x, int y, int width, unsigned char alpha); 00272 void DrawHLineClip(Uint32 color, int x, int y, int width); 00273 void DrawTransHLineClip(Uint32 color, int x, int y, int width, unsigned char alpha); 00274 00275 void DrawLine(Uint32 color, int sx, int sy, int dx, int dy); 00276 void DrawTransLine(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha); 00277 void DrawLineClip(Uint32 color, int sx, int sy, int dx, int dy); 00278 void DrawTransLineClip(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha); 00279 00280 void DrawRectangle(Uint32 color, int x, int y, int w, int h); 00281 void DrawTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha); 00282 void DrawRectangleClip(Uint32 color, int x, int y, int w, int h); 00283 void DrawTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha); 00284 00285 void FillRectangle(Uint32 color, int x, int y, int w, int h); 00286 void FillTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha); 00287 void FillRectangleClip(Uint32 color, int x, int y, int w, int h); 00288 void FillTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha); 00289 00290 void DrawCircle(Uint32 color, int x, int y, int r); 00291 void DrawTransCircle(Uint32 color, int x, int y, int r, unsigned char alpha); 00292 void DrawCircleClip(Uint32 color, int x, int y, int r); 00293 void DrawTransCircleClip(Uint32 color, int x, int y, int r, unsigned char alpha); 00294 00295 void FillCircle(Uint32 color, int x, int y, int radius); 00296 void FillTransCircle(Uint32 color, int x, int y, int radius, unsigned char alpha); 00297 void FillCircleClip(Uint32 color, int x, int y, int radius); 00298 void FillTransCircleClip(Uint32 color, int x, int y, int radius, unsigned char alpha); 00299 00300 inline Uint32 MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b) { 00301 if (!UseOpenGL) { 00302 return SDL_MapRGB(f, r, g, b); 00303 } else { 00304 return MapRGBA(f, r, g, b, 0xFF); 00305 } 00306 } 00307 inline Uint32 MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { 00308 if (!UseOpenGL) { 00309 return SDL_MapRGBA(f, r, g, b, a); 00310 } else { 00311 return ((r << RSHIFT) | (g << GSHIFT) | (b << BSHIFT) | (a << ASHIFT)); 00312 } 00313 } 00314 inline void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b) { 00315 if (!UseOpenGL) { 00316 SDL_GetRGB(c, f, r, g, b); 00317 } else { 00318 *r = (c >> RSHIFT) & 0xff; 00319 *g = (c >> GSHIFT) & 0xff; 00320 *b = (c >> BSHIFT) & 0xff; 00321 } 00322 } 00323 inline void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) { 00324 if (!UseOpenGL) { 00325 SDL_GetRGBA(c, f, r, g, b, a); 00326 } else { 00327 *r = (c >> RSHIFT) & 0xff; 00328 *g = (c >> GSHIFT) & 0xff; 00329 *b = (c >> BSHIFT) & 0xff; 00330 *a = (c >> ASHIFT) & 0xff; 00331 } 00332 } 00333 00334 int Width; 00335 int Height; 00336 int Depth; 00337 bool FullScreen; 00338 }; 00339 00340 extern CVideo Video; 00341 00349 extern int VideoSyncSpeed; 00350 00351 extern int SkipFrames; 00352 00354 extern char VideoForceFullScreen; 00355 00357 extern unsigned long NextFrameTicks; 00358 00360 extern unsigned long FrameCounter; 00361 00363 extern int SlowFrameCounter; 00364 00367 extern void SetPlayersPalette(); 00368 00370 extern SDL_Surface *TheScreen; 00371 00373 extern GLint GLMaxTextureSize; 00375 extern GLint GLMaxTextureSizeOverride; 00377 extern bool GLTextureCompressionSupported; 00379 extern bool UseGLTextureCompression; 00380 00382 extern void InitVideo(); 00383 00385 void DeInitVideo(); 00386 00388 extern int VideoValidResolution(int w, int h); 00389 00391 extern int LoadGraphicPNG(CGraphic *g); 00392 00394 extern void MakeTexture(CGraphic *graphic); 00396 extern void MakePlayerColorTexture(CPlayerColorGraphic *graphic, int player); 00397 00399 extern void ValidateOpenGLScreen(); 00400 00402 extern void FreeOpenGLGraphics(); 00404 extern void ReloadGraphics(); 00406 extern void ReloadOpenGL(); 00407 00409 extern void SetVideoSync(); 00410 00412 extern void InitLineDraw(); 00413 00415 extern void Invalidate(); 00416 00419 extern void InvalidateArea(int x, int y, int w, int h); 00420 00423 extern void SetClipping(int left, int top, int right, int bottom); 00424 00426 extern void RealizeVideoMemory(); 00427 00429 extern void SaveScreenshotPNG(const char *name); 00430 00432 extern void SetCallbacks(const EventCallback *callbacks); 00434 extern const EventCallback *GetCallbacks(); 00435 00437 extern void WaitEventsOneFrame(); 00438 00440 extern void ToggleFullScreen(); 00441 00443 extern void PushClipping(); 00444 00446 extern void PopClipping(); 00447 00449 extern unsigned long GetTicks(); 00450 00452 extern const char *SdlKey2Str(int key); 00453 00455 extern bool SdlGetGrabMouse(); 00457 extern void ToggleGrabMouse(int mode); 00458 00459 extern EventCallback GameCallbacks; 00460 extern EventCallback EditorCallbacks; 00461 00462 extern Uint32 ColorBlack; 00463 extern Uint32 ColorDarkGreen; 00464 extern Uint32 ColorBlue; 00465 extern Uint32 ColorOrange; 00466 extern Uint32 ColorWhite; 00467 extern Uint32 ColorGray; 00468 extern Uint32 ColorRed; 00469 extern Uint32 ColorGreen; 00470 extern Uint32 ColorYellow; 00471 00472 void DrawTexture(const CGraphic *g, GLuint *textures, int sx, int sy, 00473 int ex, int ey, int x, int y, int flip); 00474 00475 #ifdef DEBUG 00476 extern void FreeGraphics(); 00477 #endif 00478 00479 00480 // ARB_texture_compression 00481 #ifndef USE_GLES 00482 extern PFNGLCOMPRESSEDTEXIMAGE3DARBPROC glCompressedTexImage3DARB; 00483 extern PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB; 00484 extern PFNGLCOMPRESSEDTEXIMAGE1DARBPROC glCompressedTexImage1DARB; 00485 extern PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3DARB; 00486 extern PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2DARB; 00487 extern PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1DARB; 00488 extern PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB; 00489 #endif 00490 00491 // 00492 // Color Cycling stuff 00493 // 00494 00495 extern void VideoPaletteListAdd(SDL_Surface* surface); 00496 extern void VideoPaletteListRemove(SDL_Surface* surface); 00497 extern void ClearAllColorCyclingRange(); 00498 extern void AddColorCyclingRange(unsigned int begin, unsigned int end); 00499 extern void SetColorCycleAll(bool value); 00500 00502 extern void ColorCycle(); 00503 00505 00506 #endif // !__VIDEO_H__