2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023 John Tsiombikas <nuclear@mutantstargoat.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (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, see <https://www.gnu.org/licenses/>.
33 #include "gaw/gaw_sw.h"
36 static void gui_fill(rtk_rect *rect, uint32_t color);
37 static void gui_blit(int x, int y, rtk_icon *icon);
38 static void gui_drawtext(int x, int y, const char *str);
39 static void gui_textrect(const char *str, rtk_rect *rect);
41 int mouse_x, mouse_y, mouse_state[3];
43 int win_width, win_height;
49 struct app_screen *cur_scr;
57 /* available screens */
59 static struct app_screen *screens[MAX_SCREENS];
60 static int num_screens;
67 static rtk_draw_ops guigfx = {gui_fill, gui_blit, gui_drawtext, gui_textrect};
69 #if !defined(NDEBUG) && defined(DBG_FPEXCEPT)
70 infomsg("floating point exceptions enabled\n");
79 load_options("retroray.cfg");
80 app_resize(opt.xres, opt.yres);
86 /*dtx_target_user(txdraw, 0);*/
87 dtx_target_raster((unsigned char*)framebuf, win_width, win_height);
88 dtx_set(DTX_RASTER_THRESHOLD, 127);
90 uifont = malloc_nf(sizeof *uifont);
91 if(load_font(uifont, "data/uifont14.gmp") == -1) {
98 if(!(scn = create_scene())) {
102 /* initialize screens */
103 screens[num_screens++] = &scr_model;
104 screens[num_screens++] = &scr_rend;
106 start_scr_name = getenv("START_SCREEN");
108 for(i=0; i<num_screens; i++) {
109 if(screens[i]->init() == -1) {
114 time_msec = app_getmsec();
116 for(i=0; i<num_screens; i++) {
117 if(screens[i]->name && start_scr_name && strcmp(screens[i]->name, start_scr_name) == 0) {
118 app_chscr(screens[i]);
123 app_chscr(&scr_model);
129 void app_shutdown(void)
135 save_options("retroray.cfg");
137 for(i=0; i<num_screens; i++) {
138 if(screens[i]->destroy) {
139 screens[i]->destroy();
143 destroy_font(uifont);
155 void app_display(void)
157 time_msec = app_getmsec();
162 void app_reshape(int x, int y)
165 int prev_numpix = win_width * win_height;
167 dbgmsg("reshape(%d, %d)\n", x, y);
169 if(!framebuf || numpix > prev_numpix) {
171 if(!(tmp = realloc(framebuf, numpix * sizeof *framebuf))) {
172 errormsg("failed to resize framebuffer to %dx%d\n", x, y);
178 gaw_sw_framebuffer(x, y, framebuf);
180 dtx_target_raster((unsigned char*)framebuf, x, y);
184 win_aspect = (float)x / (float)y;
185 gaw_viewport(0, 0, x, y);
187 if(cur_scr && cur_scr->reshape) {
188 cur_scr->reshape(x, y);
192 void app_keyboard(int key, int press)
203 if(modkeys & KEY_MOD_CTRL) {
211 if(modkeys & KEY_MOD_ALT) {
220 if(cur_scr && cur_scr->keyboard) {
221 cur_scr->keyboard(key, press);
225 void app_mouse(int bn, int st, int x, int y)
230 mouse_state[bn] = st;
233 if(cur_scr && cur_scr->mouse) {
234 cur_scr->mouse(bn, st, x, y);
238 void app_motion(int x, int y)
240 if(cur_scr && cur_scr->motion) {
241 cur_scr->motion(x, y);
247 void app_sball_motion(int x, int y, int z)
249 if(cur_scr->sball_motion) {
250 cur_scr->sball_motion(x, y, z);
254 void app_sball_rotate(int x, int y, int z)
256 if(cur_scr->sball_rotate) {
257 cur_scr->sball_rotate(x, y, z);
261 void app_sball_button(int bn, int st)
263 if(cur_scr->sball_button) {
264 cur_scr->sball_button(bn, st);
268 void app_chscr(struct app_screen *scr)
270 struct app_screen *prev = cur_scr;
274 if(scr->start && scr->start() == -1) {
278 scr->reshape(win_width, win_height);
281 if(prev && prev->stop) {
287 static void gui_fill(rtk_rect *rect, uint32_t color)
290 uint32_t *fb = framebuf + rect->y * win_width + rect->x;
292 for(i=0; i<rect->height; i++) {
293 for(j=0; j<rect->width; j++) {
300 static void gui_blit(int x, int y, rtk_icon *icon)
303 uint32_t *dest, *src;
305 dest = framebuf + y * win_width + x;
308 for(i=0; i<icon->height; i++) {
309 for(j=0; j<icon->width; j++) {
310 int r = src[j] & 0xff;
311 int g = (src[j] >> 8) & 0xff;
312 int b = (src[j] >> 16) & 0xff;
313 dest[j] = 0xff000000 | (r << 16) | (g << 8) | b;
316 src += icon->scanlen;
320 static void gui_drawtext(int x, int y, const char *str)
324 static void gui_textrect(const char *str, rtk_rect *rect)
326 rect->x = rect->y = 0;
328 rect->height = 10;/* TODO */