Render a case arround Benson
authorAndreas Eversberg <jolly@eversberg.eu>
Sun, 15 Apr 2018 10:55:36 +0000 (12:55 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sun, 22 Apr 2018 10:04:04 +0000 (12:04 +0200)
src/libsdl/opengl.c
src/libsdl/opengl.h
src/mercenary/main.c

index b87e12b..069f877 100644 (file)
@@ -172,7 +172,7 @@ void opengl_viewport(int view_width, int view_height, int split, int benson_at_l
 }
 
 /* render image or only benson */
-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)
+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)
 {
        double texture_left = 0;
        double texture_right = ((double)image_width) / (double)texture_size;
@@ -186,6 +186,13 @@ void opengl_blit_image(uint8_t *rgb, int filter, int benson_at_line, int render_
        double slope = tan(fov / 360 * M_PI) * monitor_distance;
 
        /* render image */
+
+       if (benson_case) {
+               glEnable(GL_CULL_FACE);
+               glFrontFace(GL_CW);
+               glCullFace(GL_BACK);
+       }
+
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, image_name);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);  /* no modulation with color */
@@ -212,6 +219,51 @@ void opengl_blit_image(uint8_t *rgb, int filter, int benson_at_line, int render_
        glVertex3f(-benson_size * slope, image_top * slope, -monitor_distance);
        glEnd();
        glDisable(GL_TEXTURE_2D);
+       /* render benson case */
+       if (benson_case) {
+               double left, right, bottom, top, near, far;
+               left = -benson_size * slope;
+               right = benson_size * slope;
+               bottom = image_bottom * slope;
+               top = image_top * slope;
+               near = -monitor_distance;
+               far = near - benson_size * slope / 3.0;
+               glBegin(GL_QUADS);
+               /* back */
+               glColor4f(0.3, 0.3, 0.3, 1.0);
+               glVertex3f(left, top, far);
+               glVertex3f(right, top, far);
+               glVertex3f(right, bottom, far);
+               glVertex3f(left, bottom, far);
+               /* top */
+               glColor4f(0.2, 0.2, 0.2, 1.0);
+               glVertex3f(left, top, near);
+               glVertex3f(right, top, near);
+               glVertex3f(right, top, far);
+               glVertex3f(left, top, far);
+               /* bottom */
+               glColor4f(0.05, 0.05, 0.05, 1.0);
+               glVertex3f(left, bottom, far);
+               glVertex3f(right, bottom, far);
+               glVertex3f(right, bottom, near);
+               glVertex3f(left, bottom, near);
+               /* left */
+               glColor4f(0.1, 0.1, 0.1, 1.0);
+               glVertex3f(left, bottom, far);
+               glVertex3f(left, bottom, near);
+               glVertex3f(left, top, near);
+               glVertex3f(left, top, far);
+               /* right */
+               glVertex3f(right, top, far);
+               glVertex3f(right, top, near);
+               glVertex3f(right, bottom, near);
+               glVertex3f(right, bottom, far);
+               glEnd();
+       }
+
+       if (benson_case) {
+               glDisable(GL_CULL_FACE);
+       }
 }
 
 /* render osd texture */
index b3834b6..786dcc7 100644 (file)
@@ -3,7 +3,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_blit_image(uint8_t *rgb, int filter, int benson_at_line, int render_benson_only, double fov, double monitor_distance, double benson_size);
+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);
 void opengl_render_polygon(double *x, double *y, double *z, int count, int cull_face);
index aea09f1..526dd06 100644 (file)
@@ -423,7 +423,11 @@ static void main_loop(void)
 #endif
                                if (rc)
                                        goto goto_legacy;
-                               opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 1, config_fov, config_monitor_distance, benson_size);
+#ifdef HAVE_OVR
+                               opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 1, config_fov, config_monitor_distance, benson_size, 1);
+#else
+                               opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 1, config_fov, config_monitor_distance, benson_size, 0);
+#endif
                                if (help_view)
                                        opengl_blit_osd(0, help_osd, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, config_fov, config_monitor_distance, benson_size, 1.0, 1.0, 0.0, 0.0);
                                if (osd_timer) {
@@ -445,7 +449,7 @@ static void main_loop(void)
                                /* 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, config_fov, 1.0);
 #endif
-                               opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 0, config_fov, config_monitor_distance, 1.0);
+                               opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 0, config_fov, config_monitor_distance, 1.0, 0);
                                if (help_view)
                                        opengl_blit_osd(0, help_osd, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, config_fov, config_monitor_distance, 1.0, 1.0, 1.0, 0.0, 0.0);
                                if (osd_timer) {