1 #include "renderer_2d.hpp"
4 bool renderer_offscreen::init_video(int w
, int h
) {
5 if (screen
) SDL_FreeSurface(screen
);
6 // Create an offscreen buffer
7 screen
= SDL_CreateRGBSurface(SDL_SWSURFACE
, w
, h
, 32, 0, 0, 0, 0);
12 renderer_offscreen::~renderer_offscreen() {
13 //ASSUMES renderer_offscreen IS NEVER gps_allocate()'d THROUGH reshape()/grid_resize()
14 //to-do: flag for those calls on the renderer to control this behavior?
15 renderer::screen
= NULL
;
16 renderer::screentexpos
= NULL
;
17 renderer::screentexpos_addcolor
= NULL
;
18 renderer::screentexpos_grayscale
= NULL
;
19 renderer::screentexpos_cf
= NULL
;
20 renderer::screentexpos_cbr
= NULL
;
21 renderer::screen_old
= NULL
;
22 renderer::screentexpos_old
= NULL
;
23 renderer::screentexpos_addcolor_old
= NULL
;
24 renderer::screentexpos_grayscale_old
= NULL
;
25 renderer::screentexpos_cf_old
= NULL
;
26 renderer::screentexpos_cbr_old
= NULL
;
28 SDL_FreeSurface(screen
);
31 // Create an offscreen renderer of a given grid-size
32 renderer_offscreen::renderer_offscreen(int grid_x
, int grid_y
) {
34 dispx
= enabler
.is_fullscreen() ?
35 init
.font
.large_font_dispx
:
36 init
.font
.small_font_dispx
;
37 dispy
= enabler
.is_fullscreen() ?
38 init
.font
.large_font_dispy
:
39 init
.font
.small_font_dispy
;
42 origin_x
= origin_y
= 0;
43 zoom_steps
= forced_steps
= 0;
44 natural_w
= dispx
* grid_x
;
45 natural_h
= dispy
* grid_y
;
48 init_video(natural_w
, natural_h
);
49 // Copy the GPS pointers here
50 renderer::screen
= gps
.screen
;
51 renderer::screentexpos
= gps
.screentexpos
;
52 renderer::screentexpos_addcolor
= gps
.screentexpos_addcolor
;
53 renderer::screentexpos_grayscale
= gps
.screentexpos_grayscale
;
54 renderer::screentexpos_cf
= gps
.screentexpos_cf
;
55 renderer::screentexpos_cbr
= gps
.screentexpos_cbr
;
58 // Slurp the entire gps content into the renderer at some given offset
59 void renderer_offscreen::update_all(int offset_x
, int offset_y
) {
60 for (int x
= 0; x
< gps
.dimx
; x
++) {
61 for (int y
= 0; y
< gps
.dimy
; y
++) {
62 // Read tiles from gps, create cached texture
63 Either
<texture_fullid
,texture_ttfid
> id
= screen_to_texid(x
, y
);
64 SDL_Surface
*tex
= id
.isL
?
65 tile_cache_lookup(id
.left
, false) :
66 ttf_manager
.get_texture(id
.right
);
68 tex
= tile_cache_lookup(id
.left
);
70 tex
= enabler
.textures
.get_texture_data(id
.right
);
72 // Figure out where to blit
74 dst
.x
= dispx
* (x
+offset_x
);
75 dst
.y
= dispy
* (y
+offset_y
);
77 SDL_BlitSurface(tex
, NULL
, screen
, &dst
);
82 // Save the image to some file
83 void renderer_offscreen::save_to_file(const string
&file
) {
84 // TODO: Support png, etc.
85 SDL_SaveBMP(screen
, file
.c_str());