1 //       _________ __                 __
2 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
3 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
4 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
5 //     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
6 //             \/                  \/          \//_____/            \/
7 //  ______________________                           ______________________
8 //                        T H E   W A R   B E G I N S
9 //         Stratagus - A free fantasy real time strategy game engine
10 //
11 /**@name video.h - The video headerfile. */
12 //
13 //      (c) Copyright 1999-2011 by Lutz Sammer, Nehal Mistry, Jimmy Salmon and
14 //                                 Pali Rohár
15 //
16 //      This program is free software; you can redistribute it and/or modify
17 //      it under the terms of the GNU General Public License as published by
18 //      the Free Software Foundation; only version 2 of the License.
19 //
20 //      This program is distributed in the hope that it will be useful,
21 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
22 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 //      GNU General Public License for more details.
24 //
25 //      You should have received a copy of the GNU General Public License
26 //      along with this program; if not, write to the Free Software
27 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 //      02111-1307, USA.
29 //
30 
31 #ifndef __VIDEO_H__
32 #define __VIDEO_H__
33 
34 //@{
35 
36 #include "SDL.h"
37 
38 #ifdef USE_GLES
39 #include "GLES/gl.h"
40 #endif
41 
42 #ifdef USE_OPENGL
43 #ifdef __APPLE__
44 #define GL_GLEXT_PROTOTYPES 1
45 #endif
46 #include "SDL_opengl.h"
47 #include "shaders.h"
48 #endif
49 
50 #include "guichan.h"
51 
52 #include "color.h"
53 #include "vec2i.h"
54 
55 class CFont;
56 class CMapTemplate;
57 class CTimeOfDay;
58 
59 #if defined(USE_OPENGL) || defined(USE_GLES)
60 extern char ForceUseOpenGL;
61 extern bool UseOpenGL;
62 extern bool ZoomNoResize;
63 extern bool GLShaderPipelineSupported;
64 #endif
65 
66 class CGraphic : public gcn::Image
67 {
68 
69 	struct frame_pos_t {
70 		short int x;
71 		short int y;
72 	};
73 
74 protected:
CGraphic()75 	CGraphic() : Surface(nullptr), SurfaceFlip(nullptr), frame_map(nullptr),
76 		//Wyrmgus start
77 		DawnSurface(nullptr), DawnSurfaceFlip(nullptr), DuskSurface(nullptr), DuskSurfaceFlip(nullptr), NightSurface(nullptr), NightSurfaceFlip(nullptr),
78 		//Wyrmgus end
79 		Width(0), Height(0), NumFrames(1), GraphicWidth(0), GraphicHeight(0),
80 		//Wyrmgus start
81 //		Refs(1), Resized(false)
82 		Refs(1), TimeOfDay(nullptr), Resized(false), Grayscale(false)
83 		//Wyrmgus end
84 #if defined(USE_OPENGL) || defined(USE_GLES)
85 		, TextureWidth(0.f), TextureHeight(0.f), Textures(nullptr), NumTextures(0)
86 #endif
87 	{
88 		frameFlip_map = nullptr;
89 	}
~CGraphic()90 	~CGraphic() {}
91 
92 public:
93 	// Draw
94 	void DrawClip(int x, int y) const;
95 	//Wyrmgus start
96 	/*
97 	void DrawSub(int gx, int gy, int w, int h, int x, int y) const;
98 	void DrawSubClip(int gx, int gy, int w, int h, int x, int y) const;
99 	void DrawSubTrans(int gx, int gy, int w, int h, int x, int y,
100 					  unsigned char alpha) const;
101 	void DrawSubClipTrans(int gx, int gy, int w, int h, int x, int y,
102 						  unsigned char alpha) const;
103 	*/
104 	void DrawSub(int gx, int gy, int w, int h, int x, int y, SDL_Surface *surface = nullptr) const;
105 	void DrawSubClip(int gx, int gy, int w, int h, int x, int y, SDL_Surface *surface = nullptr) const;
106 	void DrawSubTrans(int gx, int gy, int w, int h, int x, int y,
107 					  unsigned char alpha, SDL_Surface *surface = nullptr) const;
108 	void DrawSubClipTrans(int gx, int gy, int w, int h, int x, int y,
109 						  unsigned char alpha, SDL_Surface *surface = nullptr) const;
110 	//Wyrmgus end
111 
112 	// Draw frame
113 	void DrawFrame(unsigned frame, int x, int y) const;
114 #if defined(USE_OPENGL) || defined(USE_GLES)
115 	void DoDrawFrameClip(GLuint *textures, unsigned frame, int x, int y, int show_percent = 100) const;
116 #endif
117 	//Wyrmgus start
118 //	void DrawFrameClip(unsigned frame, int x, int y) const;
119 	void DrawFrameClip(unsigned frame, int x, int y, bool ignore_time_of_day = true, SDL_Surface *surface = nullptr, int show_percent = 100);
120 	//Wyrmgus end
121 	void DrawFrameTrans(unsigned frame, int x, int y, int alpha) const;
122 	//Wyrmgus start
123 //	void DrawFrameClipTrans(unsigned frame, int x, int y, int alpha) const;
124 	void DrawFrameClipTrans(unsigned frame, int x, int y, int alpha, bool ignore_time_of_day = true, SDL_Surface *surface = nullptr, int show_percent = 100);
125 	//Wyrmgus end
126 
127 	// Draw frame flipped horizontally
128 	void DrawFrameX(unsigned frame, int x, int y) const;
129 #if defined(USE_OPENGL) || defined(USE_GLES)
130 	void DoDrawFrameClipX(GLuint *textures, unsigned frame, int x, int y) const;
131 #endif
132 	//Wyrmgus start
133 //	void DrawFrameClipX(unsigned frame, int x, int y) const;
134 	void DrawFrameClipX(unsigned frame, int x, int y, bool ignore_time_of_day = true, SDL_Surface *surface = nullptr);
135 	//Wyrmgus end
136 	void DrawFrameTransX(unsigned frame, int x, int y, int alpha) const;
137 	//Wyrmgus start
138 //	void DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) const;
139 	void DrawFrameClipTransX(unsigned frame, int x, int y, int alpha, bool ignore_time_of_day = true, SDL_Surface *surface = nullptr);
140 	//Wyrmgus end
141 
142 
143 	static CGraphic *New(const std::string &file, int w = 0, int h = 0);
144 	static CGraphic *ForceNew(const std::string &file, int w = 0, int h = 0);
145 	static CGraphic *Get(const std::string &file);
146 
147 	static void Free(CGraphic *g);
148 
149 	void Load(bool grayscale = false);
150 	void Flip();
151 	void UseDisplayFormat();
152 	void Resize(int w, int h);
153 	void SetOriginalSize();
154 	SDL_Surface *SetTimeOfDay(CTimeOfDay *time_of_day, bool flipped = false);
155 	bool TransparentPixel(int x, int y);
156 	void MakeShadow();
157 
IsLoaded()158 	inline bool IsLoaded() const { return Surface != nullptr; }
159 
160 	//guichan
161 	//Wyrmgus start
162 //	virtual void *_getData() const { return Surface; }
163 	virtual void *_getData(int player_color = -1) { return Surface; }
164 	//Wyrmgus end
getWidth()165 	virtual int getWidth() const { return Width; }
getHeight()166 	virtual int getHeight() const { return Height; }
167 	//Wyrmgus start
getFile()168 	virtual std::string getFile() const { return File; }
getGraphicWidth()169 	virtual int getGraphicWidth() const { return GraphicWidth; }
getGraphicHeight()170 	virtual int getGraphicHeight() const { return GraphicHeight; }
171 	//Wyrmgus end
172 
173 	std::string File;          /// Filename
174 	std::string HashFile;      /// Filename used in hash
175 	SDL_Surface *Surface;      /// Surface
176 	SDL_Surface *SurfaceFlip;  /// Flipped surface
177 	//Wyrmgus start
178 	SDL_Surface *DawnSurface;      /// Surface
179 	SDL_Surface *DawnSurfaceFlip;  /// Flipped surface
180 	SDL_Surface *DuskSurface;      /// Surface
181 	SDL_Surface *DuskSurfaceFlip;  /// Flipped surface
182 	SDL_Surface *NightSurface;      /// Surface
183 	SDL_Surface *NightSurfaceFlip;  /// Flipped surface
184 	//Wyrmgus end
185 	frame_pos_t *frame_map;
186 	frame_pos_t *frameFlip_map;
187 	void GenFramesMap();
188 	int Width;					/// Width of a frame
189 	int Height;					/// Height of a frame
190 	int NumFrames;				/// Number of frames
191 	int GraphicWidth;			/// Original graphic width
192 	int GraphicHeight;			/// Original graphic height
193 	int Refs;					/// Uses of this graphic
194 	CTimeOfDay *TimeOfDay;		/// Time of day for this graphic
195 	bool Resized;				/// Image has been resized
196 	//Wyrmgus start
197 	bool Grayscale;
198 	//Wyrmgus end
199 
200 #if defined(USE_OPENGL) || defined(USE_GLES)
201 	GLfloat TextureWidth;      /// Width of the texture
202 	GLfloat TextureHeight;     /// Height of the texture
203 	GLuint *Textures;          /// Texture names
204 	std::map<CColor, GLuint *> TextureColorModifications;	/// Textures with a color modification applied to them
205 	int NumTextures;           /// Number of textures
206 #endif
207 
208 	friend class CFont;
209 };
210 
211 class CPlayerColorGraphic : public CGraphic
212 {
213 protected:
CPlayerColorGraphic()214 	CPlayerColorGraphic()
215 	{
216 		//Wyrmgus start
217 		for (int i = 0; i < PlayerColorMax; ++i) {
218 			PlayerColorSurfaces[i] = nullptr;
219 			PlayerColorSurfacesFlip[i] = nullptr;
220 			PlayerColorSurfacesDawn[i] = nullptr;
221 			PlayerColorSurfacesDawnFlip[i] = nullptr;
222 			PlayerColorSurfacesDusk[i] = nullptr;
223 			PlayerColorSurfacesDuskFlip[i] = nullptr;
224 			PlayerColorSurfacesNight[i] = nullptr;
225 			PlayerColorSurfacesNightFlip[i] = nullptr;
226 		}
227 		//Wyrmgus end
228 
229 #if defined(USE_OPENGL) || defined(USE_GLES)
230 		//Wyrmgus start
231 //		memset(PlayerColorTextures, 0, sizeof(PlayerColorTextures));
232 		for (int i = 0; i < PlayerColorMax; ++i) {
233 			PlayerColorTextures[i] = nullptr;
234 		}
235 		//Wyrmgus end
236 #endif
237 	}
238 
239 public:
240 	//Wyrmgus start
241 	void MakePlayerColorSurface(int player_color, bool flipped = false, CTimeOfDay *time_of_day = nullptr);
242 	//Wyrmgus end
243 	//Wyrmgus start
244 	void DrawPlayerColorSub(int player, int gx, int gy, int w, int h, int x, int y);
245 	void DrawPlayerColorSubClip(int player, int gx, int gy, int w, int h, int x, int y);
246 //	void DrawPlayerColorFrameClipX(int player, unsigned frame, int x, int y);
247 //	void DrawPlayerColorFrameClip(int player, unsigned frame, int x, int y);
248 	void DrawPlayerColorFrameClipX(int player, unsigned frame, int x, int y, bool ignore_time_of_day = true);
249 	void DrawPlayerColorFrameClip(int player, unsigned frame, int x, int y, bool ignore_time_of_day = true, int show_percent = 100);
250 	void DrawPlayerColorFrameClipTransX(int player, unsigned frame, int x, int y, int alpha, bool ignore_time_of_day = true);
251 	void DrawPlayerColorFrameClipTrans(int player, unsigned frame, int x, int y, int alpha, bool ignore_time_of_day = true, int show_percent = 100);
252 	//Wyrmgus end
253 
254 	static CPlayerColorGraphic *New(const std::string &file, int w = 0, int h = 0);
255 	static CPlayerColorGraphic *ForceNew(const std::string &file, int w = 0, int h = 0);
256 	static CPlayerColorGraphic *Get(const std::string &file);
257 
258 	CPlayerColorGraphic *Clone(bool grayscale = false) const;
259 
260 	//Wyrmgus start
261 	virtual void *_getData(int player_color = -1) {
262 		if (player_color == -1) {
263 			return Surface;
264 		}
265 
266 		if (!PlayerColorSurfaces[player_color]) {
267 			MakePlayerColorSurface(player_color, false, nullptr);
268 		}
269 		return PlayerColorSurfaces[player_color];
270 	}
271 	//Wyrmgus end
272 
273 	//Wyrmgus start
274 	SDL_Surface *PlayerColorSurfaces[PlayerColorMax];			/// Surface
275 	SDL_Surface *PlayerColorSurfacesFlip[PlayerColorMax];		/// Flipped surface
276 	SDL_Surface *PlayerColorSurfacesDawn[PlayerColorMax];		/// Surface
277 	SDL_Surface *PlayerColorSurfacesDawnFlip[PlayerColorMax];	/// Flipped surface
278 	SDL_Surface *PlayerColorSurfacesDusk[PlayerColorMax];		/// Surface
279 	SDL_Surface *PlayerColorSurfacesDuskFlip[PlayerColorMax];	/// Flipped surface
280 	SDL_Surface *PlayerColorSurfacesNight[PlayerColorMax];		/// Surface
281 	SDL_Surface *PlayerColorSurfacesNightFlip[PlayerColorMax];	/// Flipped surface
282 	//Wyrmgus end
283 
284 #if defined(USE_OPENGL) || defined(USE_GLES)
285 	GLuint *PlayerColorTextures[PlayerColorMax];				/// Textures with player colors
286 	std::map<int, std::map<CColor, GLuint *>> PlayerColorTextureColorModifications;	/// Player color textures with a color modification applied to them
287 #endif
288 };
289 
290 #ifdef USE_MNG
291 #include <libmng.h>
292 
293 class Mng
294 {
295 public:
296 	Mng();
297 	~Mng();
298 	int Load(const std::string &name);
299 	void Reset();
300 	void Draw(int x, int y);
301 
302 	std::string name;
303 	FILE *fd;
304 	mng_handle handle;
305 	SDL_Surface *surface;
306 	unsigned char *buffer;
307 	unsigned long ticks;
308 	int iteration;
309 #if defined(USE_OPENGL) || defined(USE_GLES)
310 	GLfloat texture_width;   /// Width of the texture
311 	GLfloat texture_height;  /// Height of the texture
312 	GLuint texture_name;     /// Texture name
313 #endif
314 };
315 #endif
316 
317 /**
318 **  Event call back.
319 **
320 **  This is placed in the video part, because it depends on the video
321 **  hardware driver.
322 */
323 struct EventCallback {
324 
325 	/// Callback for mouse button press
326 	void (*ButtonPressed)(unsigned buttons);
327 	/// Callback for mouse button release
328 	void (*ButtonReleased)(unsigned buttons);
329 	/// Callback for mouse move
330 	void (*MouseMoved)(const PixelPos &screenPos);
331 	/// Callback for mouse exit of game window
332 	void (*MouseExit)();
333 
334 	/// Callback for key press
335 	void (*KeyPressed)(unsigned keycode, unsigned keychar);
336 	/// Callback for key release
337 	void (*KeyReleased)(unsigned keycode, unsigned keychar);
338 	/// Callback for key repeated
339 	void (*KeyRepeated)(unsigned keycode, unsigned keychar);
340 
341 	/// Callback for network event
342 	void (*NetworkEvent)();
343 
344 };
345 
346 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
347 #define RSHIFT  0
348 #define GSHIFT  8
349 #define BSHIFT  16
350 #define ASHIFT  24
351 #define RMASK   0x000000ff
352 #define GMASK   0x0000ff00
353 #define BMASK   0x00ff0000
354 #define AMASK   0xff000000
355 #else
356 #define RSHIFT  24
357 #define GSHIFT  16
358 #define BSHIFT  8
359 #define ASHIFT  0
360 #define RMASK   0xff000000
361 #define GMASK   0x00ff0000
362 #define BMASK   0x0000ff00
363 #define AMASK   0x000000ff
364 #endif
365 
366 
367 class CVideo
368 {
369 public:
CVideo()370 	CVideo() : Width(0), Height(0), Depth(0), FullScreen(false) {}
371 
372 	void LockScreen();
373 	void UnlockScreen();
374 
375 	void ClearScreen();
376 	bool ResizeScreen(int width, int height);
377 
378 	void DrawPixelClip(Uint32 color, int x, int y);
379 	void DrawTransPixelClip(Uint32 color, int x, int y, unsigned char alpha);
380 
381 	void DrawVLine(Uint32 color, int x, int y, int height);
382 	void DrawTransVLine(Uint32 color, int x, int y, int height, unsigned char alpha);
383 	void DrawVLineClip(Uint32 color, int x, int y, int height);
384 	void DrawTransVLineClip(Uint32 color, int x, int y, int height, unsigned char alpha);
385 
386 	void DrawHLine(Uint32 color, int x, int y, int width);
387 	void DrawTransHLine(Uint32 color, int x, int y, int width, unsigned char alpha);
388 	void DrawHLineClip(Uint32 color, int x, int y, int width);
389 	void DrawTransHLineClip(Uint32 color, int x, int y, int width, unsigned char alpha);
390 
391 	void DrawLine(Uint32 color, int sx, int sy, int dx, int dy);
392 	void DrawTransLine(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha);
393 	void DrawLineClip(Uint32 color, const PixelPos &pos1, const PixelPos &pos2);
394 	void DrawTransLineClip(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha);
395 
396 	void DrawRectangle(Uint32 color, int x, int y, int w, int h);
397 	void DrawTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha);
398 	void DrawRectangleClip(Uint32 color, int x, int y, int w, int h);
399 	void DrawTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha);
400 
401 	void FillRectangle(Uint32 color, int x, int y, int w, int h);
402 	void FillTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha);
403 	void FillRectangleClip(Uint32 color, int x, int y, int w, int h);
404 	void FillTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha);
405 
406 	void DrawCircle(Uint32 color, int x, int y, int r);
407 	void DrawTransCircle(Uint32 color, int x, int y, int r, unsigned char alpha);
408 	void DrawCircleClip(Uint32 color, int x, int y, int r);
409 	void DrawTransCircleClip(Uint32 color, int x, int y, int r, unsigned char alpha);
410 
411 	void FillCircle(Uint32 color, int x, int y, int radius);
412 	void FillTransCircle(Uint32 color, int x, int y, int radius, unsigned char alpha);
413 	void FillCircleClip(Uint32 color, const PixelPos &screenPos, int radius);
414 	void FillTransCircleClip(Uint32 color, int x, int y, int radius, unsigned char alpha);
415 
MapRGB(SDL_PixelFormat * f,Uint8 r,Uint8 g,Uint8 b)416 	inline Uint32 MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b)
417 	{
418 #if defined(USE_OPENGL) || defined(USE_GLES)
419 		if (UseOpenGL) {
420 			return MapRGBA(f, r, g, b, 0xFF);
421 		} else
422 #endif
423 		{
424 			return SDL_MapRGB(f, r, g, b);
425 		}
426 	}
MapRGB(SDL_PixelFormat * f,const CColor & color)427 	inline Uint32 MapRGB(SDL_PixelFormat *f, const CColor &color)
428 	{
429 		return MapRGB(f, color.R, color.G, color.B);
430 	}
MapRGBA(SDL_PixelFormat * f,Uint8 r,Uint8 g,Uint8 b,Uint8 a)431 	inline Uint32 MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
432 	{
433 #if defined(USE_OPENGL) || defined(USE_GLES)
434 		if (UseOpenGL) {
435 			return ((r << RSHIFT) | (g << GSHIFT) | (b << BSHIFT) | (a << ASHIFT));
436 		} else
437 #endif
438 		{
439 			return SDL_MapRGBA(f, r, g, b, a);
440 		}
441 	}
MapRGBA(SDL_PixelFormat * f,const CColor & color)442 	inline Uint32 MapRGBA(SDL_PixelFormat *f, const CColor &color)
443 	{
444 		return MapRGBA(f, color.R, color.G, color.B, color.A);
445 	}
GetRGB(Uint32 c,SDL_PixelFormat * f,Uint8 * r,Uint8 * g,Uint8 * b)446 	inline void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b)
447 	{
448 #if defined(USE_OPENGL) || defined(USE_GLES)
449 		if (UseOpenGL) {
450 			*r = (c >> RSHIFT) & 0xff;
451 			*g = (c >> GSHIFT) & 0xff;
452 			*b = (c >> BSHIFT) & 0xff;
453 		} else
454 #endif
455 		{
456 			SDL_GetRGB(c, f, r, g, b);
457 		}
458 	}
GetRGBA(Uint32 c,SDL_PixelFormat * f,Uint8 * r,Uint8 * g,Uint8 * b,Uint8 * a)459 	inline void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
460 	{
461 #if defined(USE_OPENGL) || defined(USE_GLES)
462 		if (UseOpenGL) {
463 			*r = (c >> RSHIFT) & 0xff;
464 			*g = (c >> GSHIFT) & 0xff;
465 			*b = (c >> BSHIFT) & 0xff;
466 			*a = (c >> ASHIFT) & 0xff;
467 		} else
468 #endif
469 		{
470 			SDL_GetRGBA(c, f, r, g, b, a);
471 		}
472 	}
473 
474 	int Width;
475 	int Height;
476 #if defined(USE_OPENGL) || defined(USE_GLES)
477 	int ViewportWidth;         /// Actual width of the window
478 	int ViewportHeight;        /// Actual height of the window
479 #endif
480 //Wyrmgus start
481 //#if defined(USE_TOUCHSCREEN) && defined(USE_WIN32)
482 //Wyrmgus end
483 	SDL_Cursor *blankCursor;
484 //Wyrmgus start
485 //#endif
486 //Wyrmgus end
487 	int Depth;
488 	bool FullScreen;
489 };
490 
491 extern CVideo Video;
492 
493 /**
494 **  Video synchronization speed. Synchronization time in percent.
495 **  If =0, video framerate is not synchronized. 100 is exact
496 **  CYCLES_PER_SECOND (30). Game will try to redraw screen within
497 **  intervals of VideoSyncSpeed, not more, not less.
498 **  @see CYCLES_PER_SECOND
499 */
500 extern int VideoSyncSpeed;
501 
502 extern int SkipFrames;
503 
504 /// Fullscreen or windowed set from commandline.
505 extern char VideoForceFullScreen;
506 
507 /// Next frame ticks
508 extern double NextFrameTicks;
509 
510 /// Counts frames
511 extern unsigned long FrameCounter;
512 
513 /// Counts quantity of slow frames
514 extern unsigned long SlowFrameCounter;
515 
516 /// Initialize Pixels[] for all players.
517 /// (bring Players[] in sync with Pixels[])
518 extern void SetPlayersPalette();
519 
520 /// The SDL screen
521 extern SDL_Surface *TheScreen;
522 
523 #if defined(USE_OPENGL) || defined(USE_GLES)
524 /// Max texture size supported on the video card
525 extern GLint GLMaxTextureSize;
526 /// User-specified limit for ::GLMaxTextureSize
527 extern GLint GLMaxTextureSizeOverride;
528 /// Is OpenGL texture compression supported
529 extern bool GLTextureCompressionSupported;
530 /// Use OpenGL texture compression
531 extern bool UseGLTextureCompression;
532 #endif
533 
534 /// register lua function
535 extern void VideoCclRegister();
536 
537 /// initialize the video part
538 extern void InitVideo();
539 
540 /// deinitliaize the video part
541 void DeInitVideo();
542 
543 /// Check if a resolution is valid
544 extern int VideoValidResolution(int w, int h);
545 
546 /// Load graphic from PNG file
547 extern int LoadGraphicPNG(CGraphic *g);
548 
549 #if defined(USE_OPENGL) || defined(USE_GLES)
550 
551 /// Make an OpenGL texture
552 //Wyrmgus start
553 //extern void MakeTexture(CGraphic *graphic);
554 extern void MakeTexture(CGraphic *graphic, CTimeOfDay *time_of_day = nullptr);
555 //Wyrmgus end
556 //Wyrmgus start
557 extern void MakeTextures2(CGraphic *g, GLuint texture, CUnitColors *colors, const int ow, const int oh, const CTimeOfDay *time_of_day = nullptr);
558 //Wyrmgus end
559 /// Make an OpenGL texture of the player color pixels only.
560 //Wyrmgus start
561 //extern void MakePlayerColorTexture(CPlayerColorGraphic *graphic, int player);
562 extern void MakePlayerColorTexture(CPlayerColorGraphic *graphic, int player, CTimeOfDay *time_of_day = nullptr);
563 //Wyrmgus end
564 
565 /// Regenerate Window screen if needed
566 extern void ValidateOpenGLScreen();
567 
568 /// Free OpenGL graphics
569 extern void FreeOpenGLGraphics();
570 /// Reload OpenGL graphics
571 extern void ReloadGraphics();
572 /// Reload OpenGL
573 extern void ReloadOpenGL();
574 
575 #endif
576 
577 /// Initializes video synchronization.
578 extern void SetVideoSync();
579 
580 /// Init line draw
581 extern void InitLineDraw();
582 
583 /// Simply invalidates whole window or screen.
584 extern void Invalidate();
585 
586 /// Invalidates selected area on window or screen. Use for accurate
587 /// redrawing. in so
588 extern void InvalidateArea(int x, int y, int w, int h);
589 
590 /// Set clipping for nearly all vector primitives. Functions which support
591 /// clipping will be marked Clip. Set the system-wide clipping rectangle.
592 extern void SetClipping(int left, int top, int right, int bottom);
593 
594 /// Realize video memory.
595 extern void RealizeVideoMemory();
596 
597 /// Save a screenshot to a PNG file
598 extern void SaveScreenshotPNG(const char *name);
599 
600 /// Save a screenshot to a PNG file
601 extern void SaveMapPNG(const char *name);
602 
603 //Wyrmgus start
604 /// Save a map template's terrain to a PNG file
605 extern void SaveMapTemplatePNG(const char *name, const CMapTemplate *map_template, const bool overlay);
606 //Wyrmgus end
607 
608 /// Set the current callbacks
609 extern void SetCallbacks(const EventCallback *callbacks);
610 /// Get the current callbacks
611 extern const EventCallback *GetCallbacks();
612 
613 /// Process all system events. Returns if the time for a frame is over
614 extern void WaitEventsOneFrame();
615 
616 /// Poll all sdl events
617 extern void PollEvents();
618 
619 /// Toggle full screen mode
620 extern void ToggleFullScreen();
621 
622 /// Push current clipping.
623 extern void PushClipping();
624 
625 /// Pop current clipping.
626 extern void PopClipping();
627 
628 /// Returns the ticks in ms since start
629 extern unsigned long GetTicks();
630 
631 /// Convert a SDLKey to a string
632 extern const char *SdlKey2Str(int key);
633 
634 /// Check if the mouse is grabbed
635 extern bool SdlGetGrabMouse();
636 /// Toggle mouse grab mode
637 extern void ToggleGrabMouse(int mode);
638 
639 extern EventCallback GameCallbacks;   /// Game callbacks
640 extern EventCallback EditorCallbacks; /// Editor callbacks
641 
642 extern Uint32 ColorBlack;
643 extern Uint32 ColorDarkGreen;
644 extern Uint32 ColorLightBlue;
645 extern Uint32 ColorBlue;
646 extern Uint32 ColorOrange;
647 extern Uint32 ColorWhite;
648 extern Uint32 ColorLightGray;
649 extern Uint32 ColorGray;
650 extern Uint32 ColorDarkGray;
651 extern Uint32 ColorRed;
652 extern Uint32 ColorGreen;
653 extern Uint32 ColorYellow;
654 
655 #if defined(USE_OPENGL) || defined(USE_GLES)
656 void DrawTexture(const CGraphic *g, GLuint *textures, int sx, int sy,
657 				 int ex, int ey, int x, int y, int flip);
658 #endif
659 
660 extern void FreeGraphics();
661 
662 
663 // ARB_texture_compression
664 #if defined(USE_OPENGL) && !defined(__APPLE__)
665 extern PFNGLCOMPRESSEDTEXIMAGE3DARBPROC    glCompressedTexImage3DARB;
666 extern PFNGLCOMPRESSEDTEXIMAGE2DARBPROC    glCompressedTexImage2DARB;
667 extern PFNGLCOMPRESSEDTEXIMAGE1DARBPROC    glCompressedTexImage1DARB;
668 extern PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3DARB;
669 extern PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2DARB;
670 extern PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1DARB;
671 extern PFNGLGETCOMPRESSEDTEXIMAGEARBPROC   glGetCompressedTexImageARB;
672 #endif
673 
674 //
675 //  Color Cycling stuff
676 //
677 
678 extern void VideoPaletteListAdd(SDL_Surface *surface);
679 extern void VideoPaletteListRemove(SDL_Surface *surface);
680 extern void ClearAllColorCyclingRange();
681 extern void AddColorCyclingRange(unsigned int begin, unsigned int end);
682 extern void SetColorCycleAll(bool value);
683 extern void RestoreColorCyclingSurface();
684 
685 /// Does ColorCycling..
686 extern void ColorCycle();
687 
688 //@}
689 
690 #endif // !__VIDEO_H__
691