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
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001/2002 The ScummVM project
*
* 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; either version 2
* of the License, or (at your option) any later version.
* 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.
*
* $Header$
*
*/
#include "sdl-common.h"
#include "common/scaler.h"
#include "common/engine.h" // Only #included for error() and warning()
#ifdef WIN32
int glColorTable(int, int, int, int, int, void *) { return 0; }
int glGetColorTable(int, int, int, void *) { return 0; }
/* Use OpenGL 1.1 */
bool OGL_1_1 = true;
#else
bool OGL_1_1 = false;
#endif
#include "fb2opengl.h"
class OSystem_SDL_GL : public OSystem_SDL_Common {
public:
// Set colors of the palette
void set_palette(const byte *colors, uint start, uint num);
// Update the dirty areas of the screen
void update_screen();
// Set a parameter
uint32 property(int param, Property *value);
// Overlay
virtual void show_overlay();
virtual void hide_overlay();
virtual void clear_overlay();
virtual void grab_overlay(int16 *buf, int pitch);
virtual void copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h);
protected:
FB2GL fb2gl;
void load_gfx_mode();
void unload_gfx_mode();
void hotswap_gfx_mode();
};
OSystem_SDL_Common *OSystem_SDL_Common::create() {
return new OSystem_SDL_GL();
}
void OSystem_SDL_GL::set_palette(const byte *colors, uint start, uint num) {
const byte *b = colors;
uint i;
for(i=0;i!=num;i++) {
fb2gl.palette(i+start,b[0],b[1],b[2]);
b += 4;
}
if (start < _palette_changed_first)
_palette_changed_first = start;
if (start + num > _palette_changed_last)
_palette_changed_last = start + num;
}
void OSystem_SDL_GL::load_gfx_mode() {
int gl_flags = FB2GL_320 | FB2GL_PITCH;
force_full = true;
scaling = 2;
_mode_flags = 0;
sdl_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, 8, 0, 0, 0, 0);
if (sdl_screen == NULL)
error("sdl_screen failed failed");
_mode_flags = DF_WANT_RECT_OPTIM;
if (_full_screen) gl_flags |= (FB2GL_FS);
if (OGL_1_1) { // OpenGL 1.1
gl_flags |= (FB2GL_RGBA | FB2GL_EXPAND);
fb2gl.init(640,480,0,70,gl_flags );
}
else { // OpenGL 1.2
if (!fb2gl.init(640,480,0,70,gl_flags)) { // Try to use 8bpp textures
gl_flags |= (FB2GL_RGBA | FB2GL_EXPAND); // using RGBA textures
fb2gl.init(640,480,0,70,gl_flags);
}
}
SDL_SetGamma(1.25,1.25,1.25);
}
void OSystem_SDL_GL::unload_gfx_mode() {
if (sdl_screen) {
SDL_FreeSurface(sdl_screen);
sdl_screen = NULL;
}
}
void OSystem_SDL_GL::update_screen() {
/* First make sure the mouse is drawn, if it should be drawn. */
draw_mouse();
/* If the shake position changed, fill the dirty area with blackness */
if (_current_shake_pos != _new_shake_pos) {
_current_shake_pos = _new_shake_pos;
}
/* Palette update in case we are in "real" 8 bit color mode.
* Must take place after the screen data was updated, since with
* "real" 8bit mode, palatte changes may be visible immediatly,
* and we want to avoid any ugly effects.
*/
if (_palette_changed_last != 0) {
fb2gl.setPalette(_palette_changed_first,
_palette_changed_last - _palette_changed_first);
_palette_changed_last = 0;
}
// FIXME - this seems to be tied to 320x200 - what about Zak256 which needs 320x240 ?
fb2gl.update(sdl_screen->pixels,320,200,320,0,_current_shake_pos);
}
void OSystem_SDL_GL::hotswap_gfx_mode() {
/* hmm, need to allocate a 320x200 bitmap
* which will contain the "backup" of the screen during the change.
* then draw that to the new screen right after it's setup.
*/
byte *bak_mem = (byte*)malloc(SCREEN_WIDTH*SCREEN_HEIGHT);
get_320x200_image(bak_mem);
unload_gfx_mode();
load_gfx_mode();
fb2gl.setPalette(0,256);
fb2gl.update(sdl_screen->pixels,320,200,320,0,_current_shake_pos);
/* blit image */
copy_rect(bak_mem, SCREEN_WIDTH, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
free(bak_mem);
update_screen();
}
uint32 OSystem_SDL_GL::property(int param, Property *value) {
if (param == PROP_TOGGLE_FULLSCREEN) {
_full_screen ^= true;
SDL_WM_ToggleFullScreen(fb2gl.screen);
return 1;
}
return OSystem_SDL_Common::property(param, value);
}
|