comparison render_sdl.c @ 500:251fe7a75a14

Preserve aspect ratio unless config file says otherwise
author Mike Pavone <pavone@retrodev.com>
date Tue, 29 Oct 2013 19:09:19 -0700
parents 51bf87f76d15
children 7fdfcced65b6
comparison
equal deleted inserted replaced
499:27345a67225d 500:251fe7a75a14
3 This file is part of BlastEm. 3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5 */ 5 */
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <math.h>
8 #include "render.h" 9 #include "render.h"
9 #include "blastem.h" 10 #include "blastem.h"
10 #include "io.h" 11 #include "io.h"
11 #include "util.h" 12 #include "util.h"
12 13
99 } 100 }
100 101
101 #ifndef DISABLE_OPENGL 102 #ifndef DISABLE_OPENGL
102 GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], at_pos; 103 GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], at_pos;
103 104
104 const GLfloat vertex_data[] = { 105 GLfloat vertex_data[] = {
105 -1.0f, -1.0f, 106 -1.0f, -1.0f,
106 1.0f, -1.0f, 107 1.0f, -1.0f,
107 -1.0f, 1.0f, 108 -1.0f, 1.0f,
108 1.0f, 1.0f 109 1.0f, 1.0f
109 }; 110 };
257 #ifndef DISABLE_OPENGL 258 #ifndef DISABLE_OPENGL
258 //TODO: fallback on standard rendering if OpenGL 2.0 is unavailable or if init fails 259 //TODO: fallback on standard rendering if OpenGL 2.0 is unavailable or if init fails
259 if (use_gl) 260 if (use_gl)
260 { 261 {
261 GLenum res = glewInit(); 262 GLenum res = glewInit();
262 if (res != GLEW_OK) 263 if (res != GLEW_OK) {
263 {
264 fprintf(stderr, "Initialization of GLEW failed with code %d\n", res); 264 fprintf(stderr, "Initialization of GLEW failed with code %d\n", res);
265 exit(1); 265 exit(1);
266 } 266 }
267 if (!GLEW_VERSION_2_0) 267 if (!GLEW_VERSION_2_0) {
268 {
269 fputs("OpenGL 2.0 is unable, falling back to standard SDL rendering\n", stderr); 268 fputs("OpenGL 2.0 is unable, falling back to standard SDL rendering\n", stderr);
270 exit(1); 269 exit(1);
270 }
271 float aspect = (float)width / height;
272 if (fabs(aspect - 4.0/3.0) > 0.01 && strcmp(tern_find_ptr_default(config, "videoaspect", "normal"), "stretch")) {
273 for (int i = 0; i < 4; i++)
274 {
275 if (aspect > 4.0/3.0) {
276 vertex_data[i*2] *= (4.0/3.0)/aspect;
277 } else {
278 vertex_data[i*2+1] *= aspect/(4.0/3.0);
279 }
280 }
271 } 281 }
272 } 282 }
273 render_gl = use_gl; 283 render_gl = use_gl;
274 #endif 284 #endif
275 SDL_WM_SetCaption(title, title); 285 SDL_WM_SetCaption(title, title);