From dbe159fcd090ca605fe8a45dea714760f430e237 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 3 Jul 2023 21:42:41 +0300 Subject: [PATCH] heed resolution options, and cross-version resizing --- src/app.c | 6 ++---- src/app.h | 2 ++ src/dos/main.c | 16 +++++++++------- src/modern/main.c | 22 +++++++++++++++++++--- src/options.c | 5 ++++- src/options.h | 2 +- src/rtk.c | 1 - src/scene.c | 22 +++++++++++++++------- src/scene.h | 2 ++ src/scr_mod.c | 7 +++++++ 10 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/app.c b/src/app.c index 92759f6..d62ef60 100644 --- a/src/app.c +++ b/src/app.c @@ -77,8 +77,6 @@ int app_init(void) #endif rend_init(); - load_options("retroray.cfg"); - app_resize(opt.xres, opt.yres); app_vsync(opt.vsync); if(opt.fullscreen) { app_fullscreen(1); @@ -165,8 +163,6 @@ void app_reshape(int x, int y) int numpix = x * y; int prev_numpix = win_width * win_height; - dbgmsg("reshape(%d, %d)\n", x, y); - if(!framebuf || numpix > prev_numpix) { void *tmp; if(!(tmp = realloc(framebuf, numpix * sizeof *framebuf))) { @@ -188,6 +184,8 @@ void app_reshape(int x, int y) if(cur_scr && cur_scr->reshape) { cur_scr->reshape(x, y); } + + app_redisplay(0, 0, 0, 0); } void app_keyboard(int key, int press) diff --git a/src/app.h b/src/app.h index 6073261..4cc9b3a 100644 --- a/src/app.h +++ b/src/app.h @@ -22,6 +22,8 @@ along with this program. If not, see . #include "logger.h" #include "scene.h" +#define CFGFILE "retroray.cfg" + enum { KEY_BACKSP = 8, KEY_ESC = 27, diff --git a/src/dos/main.c b/src/dos/main.c index e26d2b6..e3242f1 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -61,6 +61,11 @@ int main(int argc, char **argv) __djgpp_nearptr_enable(); #endif + if(!have_mouse()) { + fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n"); + return 1; + } + init_logger(); if(read_cpuid(&cpuid) == 0) { @@ -70,10 +75,7 @@ int main(int argc, char **argv) init_timer(0); kb_init(); - if(!have_mouse()) { - fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n"); - return 1; - } + load_options(CFGFILE); if((env = getenv("RRLOG"))) { if(tolower(env[0]) == 'c' && tolower(env[1]) == 'o' && tolower(env[2]) == 'm' @@ -88,15 +90,15 @@ int main(int argc, char **argv) return 1; } - if((vmidx = vid_findmode(640, 480, 32)) == -1) { + if((vmidx = vid_findmode(opt.xres, opt.yres, opt.bpp)) == -1) { return 1; } if(!(vmem = vid_setmode(vmidx))) { return 1; } - win_width = 640; - win_height = 480; + win_width = opt.xres; + win_height = opt.yres; win_aspect = (float)win_width / (float)win_height; if(app_init() == -1) { diff --git a/src/modern/main.c b/src/modern/main.c index 601b2ef..4115d5f 100644 --- a/src/modern/main.c +++ b/src/modern/main.c @@ -20,6 +20,7 @@ along with this program. If not, see . #include #include "miniglut.h" #include "app.h" +#include "options.h" #include "rtk.h" #include "logger.h" @@ -52,7 +53,10 @@ static rtk_rect rband; int main(int argc, char **argv) { glutInit(&argc, argv); - glutInitWindowSize(640, 480); + + load_options(CFGFILE); + + glutInitWindowSize(opt.xres, opt.yres); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("RetroRay"); @@ -109,21 +113,33 @@ void app_redisplay(int x, int y, int w, int h) void app_swap_buffers(void) { + glViewport(0, 0, win_width, win_height); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); + glOrtho(0, win_width, win_height, 0, -1, 1); - glRasterPos2i(-1, 1); + glRasterPos2i(0, 0); glPixelZoom(1, -1); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f); glDrawPixels(win_width, win_height, GL_BGRA, GL_UNSIGNED_BYTE, framebuf); glDisable(GL_ALPHA_TEST); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glBegin(GL_LINE_LOOP); + glColor3f(1, 0, 0); + glVertex2f(0, 0); + glVertex2f(win_width, 0); + glVertex2f(win_width, win_height); + glVertex2f(0, win_height); + glEnd(); + if(rband.width | rband.height) { - glOrtho(0, win_width, win_height, 0, -1, 1); glPushAttrib(GL_ENABLE_BIT); glDisable(GL_DEPTH_TEST); diff --git a/src/options.c b/src/options.c index b9c8e51..2c3db78 100644 --- a/src/options.c +++ b/src/options.c @@ -24,6 +24,7 @@ along with this program. If not, see . #define DEF_XRES 640 #define DEF_YRES 480 +#define DEF_BPP 32 #define DEF_VSYNC 1 #define DEF_FULLSCR 0 #define DEF_MOUSE_SPEED 50 @@ -31,7 +32,7 @@ along with this program. If not, see . struct options opt = { - DEF_XRES, DEF_YRES, + DEF_XRES, DEF_YRES, DEF_BPP, DEF_VSYNC, DEF_FULLSCR, DEF_MOUSE_SPEED, DEF_SBALL_SPEED, @@ -48,6 +49,7 @@ int load_options(const char *fname) opt.xres = ts_lookup_int(cfg, "options.video.xres", DEF_XRES); opt.yres = ts_lookup_int(cfg, "options.video.yres", DEF_YRES); + opt.bpp = ts_lookup_int(cfg, "options.video.bpp", DEF_BPP); opt.vsync = ts_lookup_int(cfg, "options.video.vsync", DEF_VSYNC); opt.fullscreen = ts_lookup_int(cfg, "options.video.fullscreen", DEF_FULLSCR); @@ -79,6 +81,7 @@ int save_options(const char *fname) fprintf(fp, "\tvideo {\n"); WROPT(2, "xres = %d", opt.xres, DEF_XRES); WROPT(2, "yres = %d", opt.yres, DEF_YRES); + WROPT(2, "bpp = %d", opt.bpp, DEF_BPP); WROPT(2, "vsync = %d", opt.vsync, DEF_VSYNC); WROPT(2, "fullscreen = %d", opt.fullscreen, DEF_FULLSCR); fprintf(fp, "\t}\n"); diff --git a/src/options.h b/src/options.h index 0a97cc1..9f0140f 100644 --- a/src/options.h +++ b/src/options.h @@ -19,7 +19,7 @@ along with this program. If not, see . #define OPTIONS_H_ struct options { - int xres, yres; + int xres, yres, bpp; int vsync; int fullscreen; diff --git a/src/rtk.c b/src/rtk.c index 2ed29e9..95ad604 100644 --- a/src/rtk.c +++ b/src/rtk.c @@ -497,7 +497,6 @@ void rtk_draw_widget(rtk_widget *w) int dirty; if(need_relayout(w)) { - dbgmsg("calc layout %s\n", w->any.text ? w->any.text : "?"); calc_layout(w); } diff --git a/src/scene.c b/src/scene.c index 36c9fba..fdde15c 100644 --- a/src/scene.c +++ b/src/scene.c @@ -40,27 +40,35 @@ struct scene *create_scene(void) void free_scene(struct scene *scn) { - int i; - if(!scn) return; + scn_clear(scn); + + darr_free(scn->objects); + darr_free(scn->lights); + darr_free(scn->mtl); + free(scn); +} + +void scn_clear(struct scene *scn) +{ + int i; + for(i=0; iobjects); i++) { free_object(scn->objects[i]); } - darr_free(scn->objects); + darr_clear(scn->objects); for(i=0; ilights); i++) { free_light(scn->lights[i]); } - darr_free(scn->lights); + darr_clear(scn->lights); for(i=0; imtl); i++) { mtl_destroy(scn->mtl[i]); free(scn->mtl[i]); } - darr_free(scn->mtl); - - free(scn); + darr_clear(scn->mtl); } int scn_add_object(struct scene *scn, struct object *obj) diff --git a/src/scene.h b/src/scene.h index ce11dd5..de0e3cd 100644 --- a/src/scene.h +++ b/src/scene.h @@ -69,6 +69,8 @@ struct rayhit; /* declared in rt.h */ struct scene *create_scene(void); void free_scene(struct scene *scn); +void scn_clear(struct scene *scn); + int scn_add_object(struct scene *scn, struct object *obj); int scn_rm_object(struct scene *scn, int idx); int scn_num_objects(const struct scene *scn); diff --git a/src/scr_mod.c b/src/scr_mod.c index ef1c920..834c1c0 100644 --- a/src/scr_mod.c +++ b/src/scr_mod.c @@ -330,6 +330,8 @@ static void mdl_reshape(int x, int y) cgm_minverse(proj_matrix_inv); rtk_resize(toolbar, win_width, TOOLBAR_HEIGHT); + + inval_vport(); } static void mdl_keyb(int key, int press) @@ -491,6 +493,11 @@ static void tbn_callback(rtk_widget *w, void *cls) int id = (intptr_t)cls; switch(id) { + case TBN_NEW: + scn_clear(scn); + inval_vport(); + break; + case TBN_SEL: case TBN_MOVE: case TBN_ROT: -- 1.7.10.4