summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blastem.c13
-rw-r--r--default.cfg3
-rwxr-xr-xrender_sdl.c51
3 files changed, 46 insertions, 21 deletions
diff --git a/blastem.c b/blastem.c
index 9e30461..a53a52f 100644
--- a/blastem.c
+++ b/blastem.c
@@ -357,7 +357,7 @@ int main(int argc, char ** argv)
loaded = 1;
}
- int def_width = 0;
+ int def_width = 0, def_height = 0;
char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval;
if (config_width) {
def_width = atoi(config_width);
@@ -365,8 +365,15 @@ int main(int argc, char ** argv)
if (!def_width) {
def_width = 640;
}
- width = width < 320 ? def_width : width;
- height = height < 240 ? (width/320) * 240 : height;
+ char *config_height = tern_find_path(config, "video\0height\0", TVAL_PTR).ptrval;
+ if (config_height) {
+ def_height = atoi(config_height);
+ }
+ if (!def_height) {
+ def_height = -1;
+ }
+ width = width < 1 ? def_width : width;
+ height = height < 1 ? def_height : height;
char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval;
if (config_fullscreen && !strcmp("on", config_fullscreen)) {
diff --git a/default.cfg b/default.cfg
index 99dd9d6..b636464 100644
--- a/default.cfg
+++ b/default.cfg
@@ -134,6 +134,9 @@ video {
#special value "stretch" will cause aspect to match window aspect ratio
aspect 4:3
width 640
+ #height is normally calculated automatically from width using the aspect setting
+ #if you would like to set it explicitly, uncomment the line below
+ #height 480
vertex_shader default.v.glsl
fragment_shader default.f.glsl
scanlines off
diff --git a/render_sdl.c b/render_sdl.c
index 607a83e..caca0bd 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -276,6 +276,28 @@ static void render_quit()
}
}
+static float config_aspect()
+{
+ static float aspect = 0.0f;
+ if (aspect == 0.0f) {
+ char *config_aspect = tern_find_path_default(config, "video\0aspect\0", (tern_val){.ptrval = "4:3"}, TVAL_PTR).ptrval;
+ if (strcmp("stretch", config_aspect)) {
+ aspect = 4.0f/3.0f;
+ char *end;
+ float aspect_numerator = strtof(config_aspect, &end);
+ if (aspect_numerator > 0.0f && *end == ':') {
+ float aspect_denominator = strtof(end+1, &end);
+ if (aspect_denominator > 0.0f && !*end) {
+ aspect = aspect_numerator / aspect_denominator;
+ }
+ }
+ } else {
+ aspect = -1.0f;
+ }
+ }
+ return aspect;
+}
+
static void update_aspect()
{
//reset default values
@@ -283,20 +305,9 @@ static void update_aspect()
main_clip.w = main_width;
main_clip.h = main_height;
main_clip.x = main_clip.y = 0;
- //calculate configured aspect ratio
- char *config_aspect = tern_find_path_default(config, "video\0aspect\0", (tern_val){.ptrval = "4:3"}, TVAL_PTR).ptrval;
- if (strcmp("stretch", config_aspect)) {
- float src_aspect = 4.0f/3.0f;
- char *end;
- float aspect_numerator = strtof(config_aspect, &end);
- if (aspect_numerator > 0.0f && *end == ':') {
- float aspect_denominator = strtof(end+1, &end);
- if (aspect_denominator > 0.0f && !*end) {
- src_aspect = aspect_numerator / aspect_denominator;
- }
- }
+ if (config_aspect() > 0.0f) {
float aspect = (float)main_width / main_height;
- if (fabs(aspect - src_aspect) < 0.01f) {
+ if (fabs(aspect - config_aspect()) < 0.01f) {
//close enough for government work
return;
}
@@ -304,16 +315,16 @@ static void update_aspect()
if (render_gl) {
for (int i = 0; i < 4; i++)
{
- if (aspect > src_aspect) {
- vertex_data[i*2] *= src_aspect/aspect;
+ if (aspect > config_aspect()) {
+ vertex_data[i*2] *= config_aspect()/aspect;
} else {
- vertex_data[i*2+1] *= aspect/src_aspect;
+ vertex_data[i*2+1] *= aspect/config_aspect();
}
}
} else {
#endif
- main_clip.w = aspect > src_aspect ? src_aspect * (float)main_height : main_width;
- main_clip.h = aspect > src_aspect ? main_height : main_width / src_aspect;
+ main_clip.w = aspect > config_aspect() ? config_aspect() * (float)main_height : main_width;
+ main_clip.h = aspect > config_aspect() ? main_height : main_width / config_aspect();
main_clip.x = (main_width - main_clip.w) / 2;
main_clip.y = (main_height - main_clip.h) / 2;
#ifndef DISABLE_OPENGL
@@ -334,6 +345,10 @@ void render_init(int width, int height, char * title, uint8_t fullscreen)
fatal_error("Unable to init SDL: %s\n", SDL_GetError());
}
atexit(SDL_Quit);
+ if (height <= 0) {
+ float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f;
+ height = ((float)width / aspect) + 0.5f;
+ }
printf("width: %d, height: %d\n", width, height);
windowed_width = width;
windowed_height = height;