1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
// ____ _ __
// / __ )____ _____ | | / /___ ___________
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
// /_____/\____/____/ |__/|__/\__,_/_/ /____/
//
// A futuristic real-time strategy game.
// This file is part of Bos Wars.
//
/**@name video.cpp - The universal video functions. */
//
// (c) Copyright 1999-2008 by Lutz Sammer, Nehal Mistry, and Jimmy Salmon
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; only version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//@{
/**
** @page VideoModule Module - Video
**
** There are lots of video functions available, therefore this
** page tries to summarize these separately.
**
** @note care must be taken what to use, how to use it and where
** put new source-code. So please read the following sections
** first.
**
**
** @section VideoMain Video main initialization
**
** The general setup of platform dependent video and basic video
** functionalities is done with function @see InitVideo
**
** We support (depending on the platform) resolutions:
** 640x480, 800x600, 1024x768, 1600x1200
** with colors 8,15,16,24,32 bit
**
** @see video.h @see video.cpp
**
**
** @section VideoModuleHigh High Level - video dependent functions
**
** These are the video platforms that are supported, any platform
** dependent settings/functionailty are located within each
** separate files:
**
** SDL : Simple Direct Media for Linux,
** Win32 (Windows 95/98/2000), BeOs, MacOS
** (visit http://www.libsdl.org)
**
** @see sdl.cpp
**
**
** @section VideoModuleLow Low Level - draw functions
**
** All direct drawing functions
**
** @note you might need to use Decorations (see above), to prevent
** drawing directly to screen in conflict with the video update.
**
** @see linedraw.cpp
** @see sprite.cpp
*/
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "stratagus.h"
#include <vector>
#include "video.h"
#include "font.h"
#include "ui.h"
#include "cursor.h"
#include "iolib.h"
#include "intern_video.h"
#include "SDL.h"
/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/
/**
** Structure of pushed clippings.
*/
struct Clip {
int X1; /// pushed clipping top left
int Y1; /// pushed clipping top left
int X2; /// pushed clipping bottom right
int Y2; /// pushed clipping bottom right
};
/*----------------------------------------------------------------------------
-- Externals
----------------------------------------------------------------------------*/
extern void InitVideoSdl(void); /// Init SDL video hardware driver
extern void SdlLockScreen(void); /// Do SDL hardware lock
extern void SdlUnlockScreen(void); /// Do SDL hardware unlock
/*----------------------------------------------------------------------------
-- Variables
----------------------------------------------------------------------------*/
CVideo Video;
bool UseOpenGL; /// Use OpenGL
char VideoForceFullScreen; /// fullscreen set from commandline
unsigned long NextFrameTicks; /// Ticks of begin of the next frame
unsigned long FrameCounter; /// Current frame number
int SlowFrameCounter; /// Profile, frames out of sync
int ClipX1; /// current clipping top left
int ClipY1; /// current clipping top left
int ClipX2; /// current clipping bottom right
int ClipY2; /// current clipping bottom right
static std::vector<Clip> Clips;
int VideoSyncSpeed = -100; /// Default value will be set by lua. 0 disable interrupts
int SkipFrames; /// Skip this frames
Uint32 ColorBlack;
Uint32 ColorDarkGreen;
Uint32 ColorDarkBlue;
Uint32 ColorBlue;
Uint32 ColorCyan;
Uint32 ColorOrange;
Uint32 ColorWhite;
Uint32 ColorGray;
Uint32 ColorRed;
Uint32 ColorGreen;
Uint32 ColorYellow;
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
/**
** Set clipping for graphic routines.
**
** @param left Left X screen coordinate.
** @param top Top Y screen coordinate.
** @param right Right X screen coordinate.
** @param bottom Bottom Y screen coordinate.
*/
void SetClipping(int left, int top, int right, int bottom)
{
Assert(left <= right && top <= bottom && left >= 0 && left < Video.Width &&
top >= 0 && top < Video.Height && right >= 0 &&
right < Video.Width && bottom >= 0 && bottom < Video.Height);
ClipX1 = left;
ClipY1 = top;
ClipX2 = right;
ClipY2 = bottom;
}
/**
** Push current clipping.
*/
void PushClipping(void)
{
Clip clip = {ClipX1, ClipY1, ClipX2, ClipY2};
Clips.push_back(clip);
}
/**
** Pop current clipping.
*/
void PopClipping(void)
{
Clip clip = Clips.back();
ClipX1 = clip.X1;
ClipY1 = clip.Y1;
ClipX2 = clip.X2;
ClipY2 = clip.Y2;
Clips.pop_back();
}
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
/**
** Lock the screen for write access.
*/
void CVideo::LockScreen(void)
{
SdlLockScreen();
}
/**
** Unlock the screen for write access.
*/
void CVideo::UnlockScreen(void)
{
SdlUnlockScreen();
}
/**
** Clear the video screen.
*/
void CVideo::ClearScreen(void)
{
FillRectangle(ColorBlack, 0, 0, Video.Width, Video.Height);
}
/**
** Resize the video screen.
**
** @return True if the resolution changed, false otherwise
*/
bool CVideo::ResizeScreen(int w, int h)
{
if (VideoValidResolution(w, h)) {
if (UseOpenGL) {
FreeOpenGLGraphics();
FreeOpenGLFonts();
UI.Minimap.FreeOpenGL();
}
Width = w;
Height = h;
TheScreen = SDL_SetVideoMode(w, h, TheScreen->format->BitsPerPixel,
TheScreen->flags);
SetClipping(0, 0, Video.Width - 1, Video.Height - 1);
if (UseOpenGL) {
ReloadOpenGL();
}
return true;
}
return false;
}
/**
** Return ticks in ms since start.
*/
unsigned long GetTicks(void)
{
return SDL_GetTicks();
}
/**
** Video initialize.
*/
void InitVideo(void)
{
InitVideoSdl();
InitLineDraw();
}
//@}
|