5 bool fullscreen_active
;
8 void video_init(void) {
9 SDL_Init(SDL_INIT_VIDEO
);
10 surface
= SDL_SetVideoMode(VMODE_W
, VMODE_H
, 32, SDL_RESIZABLE
| SDL_HWPALETTE
);
11 video
.mem
= surface
->pixels
;
12 video
.pitch
= surface
->pitch
;
13 video
.width
= VMODE_W
;
14 video
.height
= VMODE_H
;
15 fullscreen_active
= 0;
18 void video_cleanup(void) {
19 if(fullscreen_active
) SDL_WM_ToggleFullScreen(surface
);
20 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
23 void video_update_region(int x
, int y
, int w
, int h
) {
24 SDL_UpdateRect(surface
, x
, y
, w
, h
);
27 void video_update(void) {
28 SDL_UpdateRect(surface
, 0, 0, video
.width
, video
.height
);
33 void video_save_rect(int x
, int y
, int w
, int h
, void* buf
) {
34 sdl_rgb_t
*ptr
= (sdl_rgb_t
*) surface
->pixels
;
35 sdl_rgb_t
*out
= (sdl_rgb_t
*) buf
;
36 unsigned pitch
= surface
->pitch
/4;
38 for(iy
= y
; iy
< VMODE_H
&& iy
< y
+h
; iy
++) for (ix
= x
; ix
< VMODE_W
&& ix
< x
+w
; ix
++) {
39 *out
++ = ptr
[iy
*pitch
+ ix
];
43 void video_restore_rect(int x
, int y
, int w
, int h
, const void* buf
) {
44 sdl_rgb_t
*ptr
= (sdl_rgb_t
*) surface
->pixels
;
45 const sdl_rgb_t
*in
= (const sdl_rgb_t
*) buf
;
46 unsigned pitch
= surface
->pitch
/4;
48 for(iy
= y
; iy
< VMODE_H
&& iy
< y
+h
; iy
++) for (ix
= x
; ix
< VMODE_W
&& ix
< x
+w
; ix
++) {
49 ptr
[iy
*pitch
+ ix
] = *in
++;
53 void video_darken_screen(void) {
54 sdl_rgb_t
*ptr
= (sdl_rgb_t
*) surface
->pixels
;
55 unsigned pitch
= surface
->pitch
/4;
57 for(y
= 0; y
< VMODE_H
; y
++) for (x
= 0; x
< VMODE_W
; x
++) {
58 sdl_rgb_t col
= ptr
[y
*pitch
+ x
];
62 ptr
[y
*pitch
+ x
] = col
;
66 void clear_screen(void) {
67 sdl_rgb_t
*ptr
= (sdl_rgb_t
*) surface
->pixels
;
68 unsigned pitch
= surface
->pitch
/4;
70 for(y
= 0; y
< VMODE_H
; y
++) for (x
= 0; x
< VMODE_W
; x
++)
71 ptr
[y
*pitch
+ x
] = SRGB_BLACK
;
74 void toggle_fullscreen(void) {
75 fullscreen_active
= !fullscreen_active
;
76 SDL_WM_ToggleFullScreen(surface
);
79 SDL_UpdateRect(surface
,0,0,VMODE_W
,VMODE_H
);