3 Copyright (C) 2003 Nuno Subtil
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 static const char cvsid
[] =
21 "$Id: screen.c,v 1.7 2003/11/30 17:43:55 nsubtil Exp $";
38 #define GAMMA_DIR_FADEIN 1
39 #define GAMMA_DIR_FADEOUT 2
41 static struct screen scr
;
42 static float cur_gamma
, target_gamma
;
43 static int gamma_direction
;
44 static float last_gamma
;
47 initializes the screen
49 void screen_init(int fullscreen
, int w
, int h
, int bpp
)
51 SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_AUDIO
| SDL_INIT_NOPARACHUTE
);
52 /* XXX - startup resolutions */
58 scr
.fullscreen
= ( fullscreen
? SDL_FULLSCREEN
: 0);
63 scr
.num_viewports
= 1;
65 screen_switch_resolution();
67 SDL_WM_SetCaption("Attac-Man", "Attac-Man");
68 SDL_ShowCursor(SDL_DISABLE
);
70 printf("%s\n", glGetString(GL_RENDERER
));
71 printf("%s\n", glGetString(GL_VENDOR
));
75 attempts to setup the screen according to scr
77 void screen_switch_resolution(void)
80 object_release_dlists();
82 scr
.surface
= SDL_SetVideoMode(scr
.width
, scr
.height
, scr
.bpp
, SDL_OPENGL
| scr
.fullscreen
);
83 if(scr
.surface
== NULL
)
85 printf("screen_switch_resolution: couldn't set mode (%dx%dx%d %s)\n",
86 scr
.width
, scr
.height
, scr
.bpp
, scr
.fullscreen
? "fullscreen" : "windowed");
91 screen_setup_viewports();
94 object_recompile_dlists();
100 void screen_set_resolution(int w
, int h
)
106 void screen_get_resolution(int *w
, int *h
)
115 void screen_set_bpp(int bpp
)
121 toggles full-screen mode
123 void screen_toggle_fullscreen(void)
128 scr
.fullscreen
= SDL_FULLSCREEN
;
130 screen_switch_resolution();
134 sets the number of viewports
136 void screen_set_num_viewports(int n
)
138 scr
.num_viewports
= n
;
139 screen_setup_viewports();
143 sets up viewports for scr
144 XXX - should handle any number of viewports ?
146 void screen_setup_viewports(void)
153 scr
.viewports
= malloc(sizeof(struct viewport
) * scr
.num_viewports
);
155 switch(scr
.num_viewports
)
158 /* one viewport, whole screen */
159 vp
= &scr
.viewports
[0];
164 vp
->width
= scr
.width
;
165 vp
->height
= scr
.height
;
170 /* two viewports, horizontal split */
171 vp
= &scr
.viewports
[0];
173 vp
->ll_y
= scr
.height
/ 2;
174 vp
->width
= scr
.width
;
175 vp
->height
= scr
.height
/ 2;
177 vp
= &scr
.viewports
[1];
180 vp
->width
= scr
.width
;
181 vp
->height
= scr
.height
/ 2;
186 printf("screen_setup_viewports: too many viewports (%d)\n", scr
.num_viewports
);
195 sets the active opengl viewport
197 void screen_set_active_viewport(int vp
)
199 assert(vp
>= 0 && vp
< scr
.num_viewports
);
200 glViewport(scr
.viewports
[vp
].ll_x
, scr
.viewports
[vp
].ll_y
,
201 scr
.viewports
[vp
].width
, scr
.viewports
[vp
].height
);
205 returns a viewport structure
207 struct viewport
*screen_get_viewport(int vp
)
209 assert(vp
>= 0 && vp
< scr
.num_viewports
);
210 return &scr
.viewports
[vp
];
214 fades in for X seconds
216 void screen_set_fadein(float time
)
220 gamma_direction
= GAMMA_DIR_FADEIN
;
224 fades out for X seconds
226 void screen_set_fadeout(float time
)
230 gamma_direction
= GAMMA_DIR_FADEOUT
;
233 void screen_update_gamma(float delta
)
238 if(cur_gamma
> target_gamma
)
239 cur_gamma
= target_gamma
;
241 gamma
= cur_gamma
/ target_gamma
;
242 if(gamma_direction
== GAMMA_DIR_FADEOUT
)
245 if(last_gamma
!= gamma
)
247 SDL_SetGamma(gamma
, gamma
, gamma
);
252 void screen_reset_gamma(void)
254 cur_gamma
= target_gamma
= last_gamma
= 1.0;
255 SDL_SetGamma(cur_gamma
, cur_gamma
, cur_gamma
);