From 2b4c0d15331a49f96411abe7dfe3f4c6a8e4b170 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 19 Dec 2022 02:34:18 +0200 Subject: [PATCH] Aspect ratio fixes for non-4:3 displays (projection and overlay) --- src/3dengfx/libs/lib3ds/atmosphere.c | 2 -- src/3dengfx/libs/lib3ds/background.c | 2 -- src/3dengfx/src/3dengfx/3denginefx.cpp | 10 ++++------ src/3dengfx/src/3dengfx/ply.cpp | 12 ++++++++++-- src/3dengfx/src/dsys/fx.cpp | 8 +++++--- src/sumhack.cpp | 1 + 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/3dengfx/libs/lib3ds/atmosphere.c b/src/3dengfx/libs/lib3ds/atmosphere.c index e079b9e..a642be4 100644 --- a/src/3dengfx/libs/lib3ds/atmosphere.c +++ b/src/3dengfx/libs/lib3ds/atmosphere.c @@ -79,7 +79,6 @@ layer_fog_read(Lib3dsLayerFog *fog, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; - Lib3dsBool have_lin=LIB3DS_FALSE; if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, io)) { return(LIB3DS_FALSE); @@ -94,7 +93,6 @@ layer_fog_read(Lib3dsLayerFog *fog, Lib3dsIo *io) switch (chunk) { case LIB3DS_LIN_COLOR_F: lib3ds_io_read_rgb(io, fog->col); - have_lin=LIB3DS_TRUE; break; case LIB3DS_COLOR_F: lib3ds_io_read_rgb(io, fog->col); diff --git a/src/3dengfx/libs/lib3ds/background.c b/src/3dengfx/libs/lib3ds/background.c index 4b24223..22656a9 100644 --- a/src/3dengfx/libs/lib3ds/background.c +++ b/src/3dengfx/libs/lib3ds/background.c @@ -39,7 +39,6 @@ solid_bgnd_read(Lib3dsBackground *background, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; - Lib3dsBool have_lin=LIB3DS_FALSE; if (!lib3ds_chunk_read_start(&c, LIB3DS_SOLID_BGND, io)) { return(LIB3DS_FALSE); @@ -49,7 +48,6 @@ solid_bgnd_read(Lib3dsBackground *background, Lib3dsIo *io) switch (chunk) { case LIB3DS_LIN_COLOR_F: lib3ds_io_read_rgb(io, background->solid.col); - have_lin=LIB3DS_TRUE; break; case LIB3DS_COLOR_F: lib3ds_io_read_rgb(io, background->solid.col); diff --git a/src/3dengfx/src/3dengfx/3denginefx.cpp b/src/3dengfx/src/3dengfx/3denginefx.cpp index 97a7dcd..804eb56 100644 --- a/src/3dengfx/src/3dengfx/3denginefx.cpp +++ b/src/3dengfx/src/3dengfx/3denginefx.cpp @@ -1226,14 +1226,12 @@ void set_viewport_norm(float x, float y, float xsize, float ysize) Matrix4x4 create_projection_matrix(scalar_t vfov, scalar_t aspect, scalar_t near_clip, scalar_t far_clip) { #ifdef COORD_LHS - scalar_t hfov = vfov * aspect; - scalar_t w = 1.0f / (scalar_t)tan(hfov * 0.5f); - scalar_t h = 1.0f / (scalar_t)tan(vfov * 0.5f); + scalar_t f = 1.0f / (scalar_t)tan(vfov * 0.5f); scalar_t q = far_clip / (far_clip - near_clip); - + Matrix4x4 mat; - mat[0][0] = w; - mat[1][1] = h; + mat[0][0] = f / aspect; + mat[1][1] = f; mat[2][2] = q; mat[3][2] = 1.0f; mat[2][3] = -q * near_clip; diff --git a/src/3dengfx/src/3dengfx/ply.cpp b/src/3dengfx/src/3dengfx/ply.cpp index 78bdc53..95dbae7 100644 --- a/src/3dengfx/src/3dengfx/ply.cpp +++ b/src/3dengfx/src/3dengfx/ply.cpp @@ -28,7 +28,7 @@ enum PropType { const size_t prop_size[] = {32, 8, 16, 32, 0}; struct PropTypeMatch { - char *symb; + const char *symb; PropType type; } prop_match[] = { {"float", PROP_FLOAT}, @@ -68,6 +68,8 @@ struct Ply { vector elem; FILE *fp; unsigned long header_skip; + + Ply(); }; static Ply *read_header(FILE *fp); @@ -75,6 +77,13 @@ static Element *seek_elem(Ply *ply, ElementType elem_type); static const char *ply_filename = 0; // for error reports +Ply::Ply() +{ + fmt = PLY_ASCII; + fp = 0; + header_skip = 0; +} + bool file_is_ply(FILE *file) { char sig[5] = {0}; @@ -205,7 +214,6 @@ static Ply *read_header(FILE *fp) { fseek(fp, 0, SEEK_SET); Ply *ply = new Ply; - memset(ply, 0, sizeof(Ply)); bool vertex_ok = false, face_ok = false; diff --git a/src/3dengfx/src/dsys/fx.cpp b/src/3dengfx/src/dsys/fx.cpp index c089bd3..c1fd738 100644 --- a/src/3dengfx/src/dsys/fx.cpp +++ b/src/3dengfx/src/dsys/fx.cpp @@ -57,7 +57,7 @@ void dsys::radial_blur(Texture *tex, float ammount, const Vector2 &origin, bool v2 += origin; float alpha = (float)((quad_count-1) - i) / (float)quad_count; - dsys::overlay(tex, v1, v2, Color(1.0f, 1.0f, 1.0f, alpha), false); + dsys::overlay(tex, v1, v2, Color(1.0f, 1.0f, 1.0f, alpha), 0, false); scale += dscale; } @@ -122,11 +122,13 @@ void dsys::overlay(Texture *tex, const Vector2 &corner1, const Vector2 &corner2, glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - + + float aspect = (float)fxwt::screenx / fxwt::screeny; + float offs = (1.333333333f - aspect) / 2.0f; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - glOrtho(0.0, 1.0, 1.0, 0.0, 0.0, 1.0); + glOrtho(offs, 1.0 - offs, 1.0, 0.0, 0.0, 1.0); set_lighting(false); set_zbuffering(false); diff --git a/src/sumhack.cpp b/src/sumhack.cpp index 6f6a8fa..9491e64 100644 --- a/src/sumhack.cpp +++ b/src/sumhack.cpp @@ -102,6 +102,7 @@ bool init() { //dsys::init(); // show loading screen + glClear(GL_COLOR_BUFFER_BIT); dsys::overlay(get_texture("data/img/loading.jpg"), Vector2(0, 0), Vector2(1, 1), 1.0); flip(); -- 1.7.10.4