From 5eb4b6d8243150765ce93c8b2a9e2215e5c13543 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 17 Dec 2022 23:45:49 +0200 Subject: [PATCH] resolution don't care option, heuristic to avoid multimon sizes --- 3dengfx.conf | 4 +- src/3dengfx/src/3dengfx/3denginefx.cpp | 53 +++++++++++++++----------- src/3dengfx/src/3dengfx/3denginefx_types.hpp | 1 + src/3dengfx/src/fxwt/fxwt.hpp | 5 ++- src/3dengfx/src/fxwt/fxwt_glut.cpp | 5 +++ src/3dengfx/src/fxwt/fxwt_sdl.cpp | 7 +++- src/3dengfx/src/fxwt/init_sdl.cpp | 45 +++++++++++++++++----- src/3dengfx/src/gfx/base_cam.cpp | 7 +++- src/sumhack.cpp | 8 ++-- 9 files changed, 93 insertions(+), 42 deletions(-) diff --git a/3dengfx.conf b/3dengfx.conf index 7b57a19..fa1348c 100644 --- a/3dengfx.conf +++ b/3dengfx.conf @@ -4,8 +4,8 @@ ; tool) so your best bet would be using that tool to configure the demo. ; If that does not work for some reason, modify this file with care... -fullscreen = false -resolution = 1024x768 +fullscreen = true +resolution = dontcare bpp = dontcare zbuffer = dontcare stencil = dontcare diff --git a/src/3dengfx/src/3dengfx/3denginefx.cpp b/src/3dengfx/src/3dengfx/3denginefx.cpp index 9861ab1..97a7dcd 100644 --- a/src/3dengfx/src/3dengfx/3denginefx.cpp +++ b/src/3dengfx/src/3dengfx/3denginefx.cpp @@ -154,7 +154,7 @@ namespace engfx_state { using namespace engfx_state; GraphicsInitParameters *load_graphics_context_config(const char *fname) { - static GraphicsInitParameters gip; + static GraphicsInitParameters gip; gip.x = 640; gip.y = 480; gip.bpp = 16; @@ -166,10 +166,10 @@ GraphicsInitParameters *load_graphics_context_config(const char *fname) { error("%s: could not load config file", __func__); return 0; } - + const ConfigOption *cfgopt; while((cfgopt = get_next_option())) { - + if(!strcmp(cfgopt->option, "fullscreen")) { if(!strcmp(cfgopt->str_value, "true")) { gip.fullscreen = true; @@ -180,20 +180,26 @@ GraphicsInitParameters *load_graphics_context_config(const char *fname) { return 0; } } else if(!strcmp(cfgopt->option, "resolution")) { - if(!isdigit(cfgopt->str_value[0])) { - error("%s: error parsing config file %s", __func__, fname); - return 0; - } - gip.x = atoi(cfgopt->str_value); - - char *ptr = cfgopt->str_value; - while(*ptr && *ptr != 'x') *ptr++; - if(!*ptr || !*(ptr+1) || !isdigit(*(ptr+1))) { - error("%s: error parsing config file %s", __func__, fname); - return 0; + if(!strcmp(cfgopt->str_value, "dontcare")) { + gip.x = 1024; + gip.y = 768; + gip.dont_care_flags |= DONT_CARE_SIZE; + } else { + if(!isdigit(cfgopt->str_value[0])) { + error("%s: error parsing config file %s", __func__, fname); + return 0; + } + gip.x = atoi(cfgopt->str_value); + + char *ptr = cfgopt->str_value; + while(*ptr && *ptr != 'x') ptr++; + if(!*ptr || !*(ptr+1) || !isdigit(*(ptr+1))) { + error("%s: error parsing config file %s", __func__, fname); + return 0; + } + + gip.y = atoi(ptr + 1); } - - gip.y = atoi(ptr + 1); } else if(!strcmp(cfgopt->option, "bpp")) { if(cfgopt->flags & CFGOPT_INT) { gip.bpp = cfgopt->int_value; @@ -203,7 +209,7 @@ GraphicsInitParameters *load_graphics_context_config(const char *fname) { } else { error("%s: error parsing config file %s", __func__, fname); return 0; - } + } } else if(!strcmp(cfgopt->option, "zbuffer")) { if(cfgopt->flags & CFGOPT_INT) { gip.depth_bits = cfgopt->int_value; @@ -1014,7 +1020,7 @@ void use_vertex_colors(bool enable) { void set_render_target(Texture *tex, CubeMapFace cube_map_face) { static std::stack rt_stack; static std::stack face_stack; - + Texture *prev = rt_stack.empty() ? 0 : rt_stack.top(); CubeMapFace prev_face = CUBE_MAP_PX; // just to get rid of the uninitialized var warning if(!face_stack.empty()) prev_face = face_stack.top(); @@ -1025,7 +1031,7 @@ void set_render_target(Texture *tex, CubeMapFace cube_map_face) { set_texture(0, prev); glCopyTexSubImage2D(prev->get_type() == TEX_CUBE ? prev_face : GL_TEXTURE_2D, 0, 0, 0, 0, 0, prev->width, prev->height); } - + if(!tex) { rt_stack.pop(); if(prev->get_type() == TEX_CUBE) { @@ -1193,20 +1199,21 @@ Matrix4x4 get_matrix(TransformType xform_type, int num) { switch(xform_type) { case XFORM_WORLD: return world_matrix; - + case XFORM_VIEW: return view_matrix; - + case XFORM_TEXTURE: return tex_matrix[num]; - + case XFORM_PROJECTION: default: return proj_matrix; } } -void set_viewport(unsigned int x, unsigned int y, unsigned int xsize, unsigned int ysize) { +void set_viewport(unsigned int x, unsigned int y, unsigned int xsize, unsigned int ysize) +{ glViewport(x, y, xsize, ysize); } diff --git a/src/3dengfx/src/3dengfx/3denginefx_types.hpp b/src/3dengfx/src/3dengfx/3denginefx_types.hpp index 4fcdc31..80b1c9e 100644 --- a/src/3dengfx/src/3dengfx/3denginefx_types.hpp +++ b/src/3dengfx/src/3dengfx/3denginefx_types.hpp @@ -139,6 +139,7 @@ class GfxProg; #define DONT_CARE_BPP 1 // 0001 #define DONT_CARE_DEPTH 2 // 0010 #define DONT_CARE_STENCIL 4 // 0100 +#define DONT_CARE_SIZE 8 struct GraphicsInitParameters { int x, y; diff --git a/src/3dengfx/src/fxwt/fxwt.hpp b/src/3dengfx/src/fxwt/fxwt.hpp index b7684c2..84b969e 100644 --- a/src/3dengfx/src/fxwt/fxwt.hpp +++ b/src/3dengfx/src/fxwt/fxwt.hpp @@ -47,7 +47,7 @@ namespace fxwt { extern std::list keyb_handlers; extern std::list motion_handlers; extern std::list button_handlers; - + extern bool button_state[6]; extern int screenx, screeny; @@ -70,8 +70,9 @@ namespace fxwt { Vector2 get_mouse_pos_normalized(); void set_window_title(const char *title); + void show_cursor(bool show); void swap_buffers(); - + int main_loop(); } diff --git a/src/3dengfx/src/fxwt/fxwt_glut.cpp b/src/3dengfx/src/fxwt/fxwt_glut.cpp index eded410..2b2717e 100644 --- a/src/3dengfx/src/fxwt/fxwt_glut.cpp +++ b/src/3dengfx/src/fxwt/fxwt_glut.cpp @@ -64,6 +64,11 @@ void fxwt::set_window_title(const char *title) { glutSetWindowTitle(title); } +void fxwt::show_cursor(bool show) +{ + glutSetCursor(show ? GLUT_CURSOR_LEFT_ARROW : GLUT_CURSOR_NONE); +} + void fxwt::swap_buffers() { glutSetWindow(fxwt_glut_win); glutSwapBuffers(); diff --git a/src/3dengfx/src/fxwt/fxwt_sdl.cpp b/src/3dengfx/src/fxwt/fxwt_sdl.cpp index e0cd95e..d3e1112 100644 --- a/src/3dengfx/src/fxwt/fxwt_sdl.cpp +++ b/src/3dengfx/src/fxwt/fxwt_sdl.cpp @@ -59,6 +59,11 @@ void fxwt::set_window_title(const char *title) { SDL_WM_SetCaption(title, 0); } +void fxwt::show_cursor(bool show) +{ + SDL_ShowCursor(show ? 1 : 0); +} + void fxwt::swap_buffers() { SDL_GL_SwapBuffers(); #if defined(_POSIX_PRIORITY_SCHEDULING) @@ -70,7 +75,7 @@ void fxwt::swap_buffers() { int fxwt::main_loop() { set_verbosity(3); - + SDL_EnableKeyRepeat(300, 20); while(1) { diff --git a/src/3dengfx/src/fxwt/init_sdl.cpp b/src/3dengfx/src/fxwt/init_sdl.cpp index 5f53d86..1d76914 100644 --- a/src/3dengfx/src/fxwt/init_sdl.cpp +++ b/src/3dengfx/src/fxwt/init_sdl.cpp @@ -33,6 +33,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "3dengfx/3denginefx.hpp" #include "common/err_msg.h" +#define GOOD_ASPECT(x) ((x) > 1.1f && (x) < 2.0f) + bool fxwt::init_graphics(GraphicsInitParameters *gparams) { info("Initializing SDL"); @@ -41,24 +43,49 @@ bool fxwt::init_graphics(GraphicsInitParameters *gparams) { return false; } - if(!gparams->fullscreen) { - const SDL_VideoInfo *vid_inf = SDL_GetVideoInfo(); + char driver[128]; + SDL_VideoDriverName(driver, sizeof driver); + info("SDL video driver: %s", driver); + + const SDL_VideoInfo *vid_inf = SDL_GetVideoInfo(); + if(gparams->fullscreen) { + if(gparams->dont_care_flags & DONT_CARE_SIZE) { + int curx = vid_inf->current_w; + int cury = vid_inf->current_h; + float aspect = (float)curx / cury; + + if(!GOOD_ASPECT(aspect)) { + SDL_Rect **modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN); + info("Current mode %dx%d sounds like multi-monitor. Available modes:", curx, cury); + for(int i=0; modes[i]; i++) { + info(" %dx%d", modes[i]->w, modes[i]->h); + aspect = (float)modes[i]->w / modes[i]->h; + if(GOOD_ASPECT(aspect) && (modes[i]->w == vid_inf->current_w || modes[i]->h == vid_inf->current_h)) { + curx = modes[i]->w; + cury = modes[i]->h; + } + } + } + gparams->x = curx; + gparams->y = cury; + } + } else { gparams->bpp = vid_inf->vfmt->BitsPerPixel; } info("Trying to set video mode %dx%dx%d, d:%d s:%d %s", gparams->x, gparams->y, gparams->bpp, gparams->depth_bits, gparams->stencil_bits, gparams->fullscreen ? "fullscreen" : "windowed"); - + int rbits, gbits, bbits; switch(gparams->bpp) { case 32: rbits = gbits = bbits = 8; break; - + case 16: rbits = bbits = 5; gbits = 6; break; - + default: error("%s: Tried to set unsupported pixel format: %d bpp", __func__, gparams->bpp); return false; @@ -76,7 +103,7 @@ bool fxwt::init_graphics(GraphicsInitParameters *gparams) { if(!SDL_SetVideoMode(gparams->x, gparams->y, gparams->bpp, flags)) { if(gparams->depth_bits == 32) gparams->depth_bits = 24; SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, gparams->depth_bits); - + if(!SDL_SetVideoMode(gparams->x, gparams->y, gparams->bpp, flags)) { error("%s: Could not set requested video mode", __func__); } @@ -104,11 +131,11 @@ bool fxwt::init_graphics(GraphicsInitParameters *gparams) { error("%s: Could not set requested exact bpp mode", __func__); return false; } - - // now if we don't have DONT_CARE_DEPTH in the dont_care_flags check for + + // now if we don't have DONT_CARE_DEPTH in the dont_care_flags check for // exact depth buffer format, however consider 24 and 32 bit the same if(!(gparams->dont_care_flags & DONT_CARE_DEPTH) && azbits != gparams->depth_bits) { - if(!(gparams->depth_bits == 32 && azbits == 24 || gparams->depth_bits == 24 && azbits == 32)) { + if(!((gparams->depth_bits == 32 && azbits == 24) || (gparams->depth_bits == 24 && azbits == 32))) { error("%s: Could not set requested exact zbuffer depth", __func__); return false; } diff --git a/src/3dengfx/src/gfx/base_cam.cpp b/src/3dengfx/src/gfx/base_cam.cpp index 2078529..ee89992 100644 --- a/src/3dengfx/src/gfx/base_cam.cpp +++ b/src/3dengfx/src/gfx/base_cam.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #ifdef USING_3DENGFX #include "3dengfx/3denginefx.hpp" +#include "fxwt/fxwt.hpp" #endif // USING_3DENGFX FrustumPlane::FrustumPlane() { @@ -62,7 +63,11 @@ BaseCamera::BaseCamera(const Vector3 &trans, const Quaternion &rot) { fov = quarter_pi; near_clip = 1.0; far_clip = 10000.0; - aspect = 1.33333; +#ifdef USING_3DENGFX + aspect = (float)fxwt::screenx / fxwt::screeny; +#else + aspect = 1.33333333; +#endif flip_view.x = flip_view.y = flip_view.z = false; } diff --git a/src/sumhack.cpp b/src/sumhack.cpp index 9e2a224..6f6a8fa 100644 --- a/src/sumhack.cpp +++ b/src/sumhack.cpp @@ -88,7 +88,7 @@ bool init() { } if(gip->fullscreen) { - SDL_ShowCursor(0); + fxwt::show_cursor(false); } fxwt::set_window_title("The Lab Demos :: Summer Hack (rebuild)"); @@ -145,18 +145,18 @@ bool init() { timer_reset(&timer); timer_start(&timer); - + return true; } void clean_up() { unsigned long time = timer_getmsec(&timer); - + if(music) { sdlvf_done(); } - SDL_ShowCursor(1); + fxwt::show_cursor(true); for(size_t i=0; i