From: Andreas Eversberg Date: Fri, 2 Nov 2018 06:30:42 +0000 (+0100) Subject: Stereo Hack X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=mercenary-reloaded.git;a=commitdiff_plain;h=7d8ce1d7d9dfd93eedf2f744a2eebea86f3d70f3 Stereo Hack use --stereo and select --fov as you need. --- diff --git a/src/libopengl/opengl.c b/src/libopengl/opengl.c index d992366..886f1cb 100644 --- a/src/libopengl/opengl.c +++ b/src/libopengl/opengl.c @@ -120,7 +120,7 @@ void opengl_clear(int _flip_y) } /* set viewport for improved rendering */ -void opengl_viewport(int view_width, int view_height, int split, int benson_at_line, double fov, double benson_size) +void opengl_viewport(int view_width, int view_height, int split, int benson_at_line, double fov, double benson_size, int stereo) { int view_x = 0, view_y = 0; double factor_height = 1.0; @@ -149,7 +149,16 @@ void opengl_viewport(int view_width, int view_height, int split, int benson_at_l return; /* projection matrix */ - glViewport((GLsizei)view_x, (GLsizei)view_y, (GLsizei)view_width, (GLsizei)view_height); + switch (stereo) { + case 0: /* left eye */ + glViewport((GLsizei)view_x, (GLsizei)view_y, (GLsizei)view_width / 2, (GLsizei)view_height); + break; + case 1: /* right eye */ + glViewport((GLsizei)view_x + (GLsizei)view_width / 2, (GLsizei)view_y, (GLsizei)view_width / 2, (GLsizei)view_height); + break; + default: + glViewport((GLsizei)view_x, (GLsizei)view_y, (GLsizei)view_width, (GLsizei)view_height); + } glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -162,6 +171,14 @@ void opengl_viewport(int view_width, int view_height, int split, int benson_at_l double top = slope * ((double)image_height - benson_start_at_position) / (double)image_width; double bottom = -slope * ((double)image_height * 2.0 - ((double)image_height - benson_start_at_position)) / (double)image_width; glFrustum(left * factor_width, right * factor_width, bottom * factor_height, top * factor_height, 1.0, 5000000000.0); + switch (stereo) { + case 0: /* left eye */ + glTranslated(2.52 / 2.0, 0, 0); + break; + case 1: /* right eye */ + glTranslated(-2.52 / 2.0, 0, 0); + break; + } glMatrixMode(GL_MODELVIEW); } diff --git a/src/libopengl/opengl.h b/src/libopengl/opengl.h index 786dcc7..287c20a 100644 --- a/src/libopengl/opengl.h +++ b/src/libopengl/opengl.h @@ -2,7 +2,7 @@ int init_opengl_image(int _image_width, int _image_height); int init_opengl_osd(int num, int _osd_width, int _osd_height); void opengl_clear(int flip_y); -void opengl_viewport(int view_width, int view_height, int split, int benson_at_line, double fov, double benson_size); +void opengl_viewport(int view_width, int view_height, int split, int benson_at_line, double fov, double benson_size, int stereo); void opengl_blit_image(uint8_t *rgb, int filter, int benson_at_line, int render_benson_only, double fov, double monitor_distance, double benson_size, int benson_case); void opengl_blit_osd(int num, uint8_t *rgba, int filter, int benson_at_line, double fov, double monitor_distnace, double benson_size, double scale_x, double scale_y, double offset_x, double offset_y); void opengl_render_color(double r, double g, double b, double a); diff --git a/src/mercenary/main.c b/src/mercenary/main.c index e62944b..5d7ea31 100644 --- a/src/mercenary/main.c +++ b/src/mercenary/main.c @@ -67,9 +67,11 @@ static int config_multisampling = 8; #ifdef HAVE_OVR static double config_benson_size = 0.7; static double config_fov = FOV_JOLLY; +static int config_stereo = 1; #else static double config_benson_size = 1.0; static double config_fov = FOV_NOVAGEN; +static int config_stereo = 0; #endif static double config_monitor_distance = 41.5; /* inch */ #ifdef HAVE_OVR @@ -193,6 +195,10 @@ int parse_args(int argc, char *argv[]) print_info(" stretched. This compensates the vertical stretch of NTSC vs PAL video.\n"); print_info(" The original (stretched) sphere makes the game authentic.\n"); print_info(" This option requires OpenGL rendering. (default = %d)\n", config_improve_round_planets); +#ifndef HAVE_OVR + print_info(" --stereo\n"); + print_info(" Render Stereoscopic side-by-side.\n"); +#endif print_info("Debug options:\n"); print_info(" -o --debug-opengl\n"); print_info(" Use split screen to display both Amiga and OpenGL rendering.\n"); @@ -325,6 +331,11 @@ illegal_parameter: goto missing_parameter; config_improve_round_planets = atoi(argv[i]); } else +#ifndef HAVE_OVR + if (!strcmp(argv[i], "--stereo")) { + config_stereo = 1; + } else +#endif if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--debug-opengl")) { config_debug_opengl = 1; } else @@ -691,8 +702,8 @@ static void main_loop(void) uint32_t palette_address; uint16_t palette[16]; int all_white = 0; -#ifdef HAVE_OVR int eye; +#ifdef HAVE_OVR int vr = 1; #else int vr = 0; @@ -772,21 +783,24 @@ static void main_loop(void) /* STEP 2: transfer legacy image (or just benson) in memory to OpenGL texture */ #ifdef HAVE_OVR begin_render_ovr(); +#else + /* clear screen */ + opengl_clear(vr); +#endif - for (eye = 0; eye < 2; eye++) { + for (eye = 0; eye < ((config_stereo) ? 2 : 1); eye++) { +#ifdef HAVE_OVR double camera_x, camera_y, camera_z; /* begin of rendering eye, viewport and frustum is set here */ begin_render_ovr_eye(eye, &camera_x, &camera_y, &camera_z); -#else - { -#endif /* clear screen */ opengl_clear(vr); +#endif /* render benson + osd ontop of improved opengl rendering, if enabled */ if (render_improved) { #ifndef HAVE_OVR /* viewport and frustum is set here */ - opengl_viewport(window_width, window_height, (debug_opengl) ? 2 : 0, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, config_fov, benson_size); + opengl_viewport(window_width, window_height, (debug_opengl) ? 2 : 0, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, config_fov, benson_size, (config_stereo) ? eye : -1); #endif /* render improved graphics, interpolate, if required, * if no item list is available, for legacy rendering @@ -829,7 +843,7 @@ static void main_loop(void) emul_video(image, memory, palette, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_DIWSTART, chipreg, 0, BENSON_AT_LINE, double_pixel_size); #ifndef HAVE_OVR /* viewport and frustum is set here */ - opengl_viewport(window_width, window_height, (debug_opengl) ? 1 : 0, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, FOV_NOVAGEN, 1.0); + opengl_viewport(window_width, window_height, (debug_opengl) ? 1 : 0, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, FOV_NOVAGEN, 1.0, (config_stereo) ? eye : -1); #endif opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 0, FOV_NOVAGEN, config_monitor_distance, 1.0, 0); if (help_view)