# HG changeset patch # User Mike Pavone # Date 1383098959 25200 # Node ID 251fe7a75a14ef4990b826ec36cdf4226e837053 # Parent 27345a67225d0009dc46accb4fb22dc20fdc1609 Preserve aspect ratio unless config file says otherwise diff -r 27345a67225d -r 251fe7a75a14 render_sdl.c --- a/render_sdl.c Tue Oct 29 00:03:11 2013 -0700 +++ b/render_sdl.c Tue Oct 29 19:09:19 2013 -0700 @@ -5,6 +5,7 @@ */ #include #include +#include #include "render.h" #include "blastem.h" #include "io.h" @@ -101,7 +102,7 @@ #ifndef DISABLE_OPENGL GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], at_pos; -const GLfloat vertex_data[] = { +GLfloat vertex_data[] = { -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, @@ -259,16 +260,25 @@ if (use_gl) { GLenum res = glewInit(); - if (res != GLEW_OK) - { + if (res != GLEW_OK) { fprintf(stderr, "Initialization of GLEW failed with code %d\n", res); exit(1); } - if (!GLEW_VERSION_2_0) - { + if (!GLEW_VERSION_2_0) { fputs("OpenGL 2.0 is unable, falling back to standard SDL rendering\n", stderr); exit(1); } + float aspect = (float)width / height; + if (fabs(aspect - 4.0/3.0) > 0.01 && strcmp(tern_find_ptr_default(config, "videoaspect", "normal"), "stretch")) { + for (int i = 0; i < 4; i++) + { + if (aspect > 4.0/3.0) { + vertex_data[i*2] *= (4.0/3.0)/aspect; + } else { + vertex_data[i*2+1] *= aspect/(4.0/3.0); + } + } + } } render_gl = use_gl; #endif diff -r 27345a67225d -r 251fe7a75a14 shaders/default.v.glsl --- a/shaders/default.v.glsl Tue Oct 29 00:03:11 2013 -0700 +++ b/shaders/default.v.glsl Tue Oct 29 19:09:19 2013 -0700 @@ -6,5 +6,5 @@ void main() { gl_Position = vec4(pos, 0.0, 1.0); - texcoord = pos * vec2(320.0/1024.0, 240.0/-512.0) + vec2(320.0/1024.0, 240.0/512.0); + texcoord = sign(pos) * vec2(320.0/1024.0, 240.0/-512.0) + vec2(320.0/1024.0, 240.0/512.0); }