some meshgen and map rendering updates
[voxelands-alt.git] / src / graphics / wm.c
blobcd8628f61d5bd48a18e4f076a0dbc43f22051fd4
1 /************************************************************************
2 * wm.c
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
20 #include "common.h"
21 #define _WM_EXPOSE_ALL
22 #include "wm.h"
23 #include "graphics.h"
25 #include <string.h>
27 wm_t wm_data = {
29 600,
30 1024,
35 30,
36 {30,30,30,30},
38 30,
39 NULL,
40 1000.0,
44 /* command width setter */
45 int wm_width_setter(char* value)
47 int v = strtol(value,NULL,10);
48 if (v > 0) {
49 wm_data.size.width = v;
50 wm_resize();
52 return 0;
55 /* command height setter */
56 int wm_height_setter(char* value)
58 int v = strtol(value,NULL,10);
59 if (v > 0) {
60 wm_data.size.height = v;
61 wm_resize();
63 return 0;
66 /* command frame cap setter */
67 int wm_cap_setter(char* value)
69 int v = strtol(value,NULL,10);
70 if (v > 0)
71 wm_data.frame_cap = v;
72 return 0;
75 /* command fullscreen setter */
76 int wm_fullscreen_setter(char* value)
78 int v = !!strtol(value,NULL,10);
79 wm_toggle_fullscreen(v);
80 return 0;
83 /* screen capture - take a screenshot, save to file */
84 void wm_capture(char* file)
86 char* fmt;
87 image_t *p;
89 p = image_load_fromscreen(0,0,wm_data.size.width,wm_data.size.height,0);
90 if (!p) {
91 vlprintf(CN_ERROR, "Could not grab screen data");
92 return;
95 fmt = config_get("wm.capture_format");
96 if (!fmt || !strcmp(fmt,"png")) {
97 if (!file)
98 file = "screenshot.png";
99 image_save_png(p,file);
100 }else if (!strcmp(fmt,"tga")) {
101 if (!file)
102 file = "screenshot.tga";
103 image_save_tga(p,file);
104 }else if (!strcmp(fmt,"bmp")) {
105 if (!file)
106 file = "screenshot.bmp";
107 image_save_bmp(p,file);
108 }else{
109 vlprintf(CN_WARN, "Unsupported capture format '%s'",fmt);
112 free(p->pixels);
113 free(p);