From b63e99efd82d1f4062b294d892fb99bc952b97f3 Mon Sep 17 00:00:00 2001 From: Sryder13 Date: Mon, 7 Apr 2014 17:08:04 +0100 Subject: [PATCH] OpenGL Screen Flip Screen flipping in OpenGL is no longer done by inverting the screen polygons. --- src/hardware/hw_defs.h | 1 + src/hardware/hw_main.c | 45 ++++++++++++++++++++------------ src/hardware/hw_md2.c | 5 ++++ src/hardware/r_opengl/r_opengl.c | 29 ++++++++++++++------ 4 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 98305da6d..70d776d9e 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -108,6 +108,7 @@ typedef struct FLOAT scalex,scaley,scalez; FLOAT fovxangle, fovyangle; INT32 splitscreen; + boolean flip; // screenflip } FTransform; // Transformed vector, as passed to HWR API diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 341845a1d..fcb439645 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4475,6 +4475,12 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) // It should replace all other gr_viewxxx when finished atransform.anglex = (float)(aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + + if (postimgtype == postimg_flip) + atransform.flip = true; + else + atransform.flip = false; + atransform.x = gr_viewx; // FIXED_TO_FLOAT(viewx) atransform.y = gr_viewy; // FIXED_TO_FLOAT(viewy) atransform.z = gr_viewz; // FIXED_TO_FLOAT(viewz) @@ -4488,6 +4494,12 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) // Transform for sprites stransform.anglex = 0.0f; stransform.angley = -270.0f; + + if (postimgtype == postimg_flip) + stransform.flip = true; + else + stransform.flip = false; + stransform.x = 0.0f; stransform.y = 0.0f; stransform.z = 0.0f; @@ -4687,6 +4699,12 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) // It should replace all other gr_viewxxx when finished atransform.anglex = (float)(aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + + if (postimgtype == postimg_flip) + atransform.flip = true; + else + atransform.flip = false; + atransform.x = gr_viewx; // FIXED_TO_FLOAT(viewx) atransform.y = gr_viewy; // FIXED_TO_FLOAT(viewy) atransform.z = gr_viewz; // FIXED_TO_FLOAT(viewz) @@ -4700,6 +4718,12 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) // Transform for sprites stransform.anglex = 0.0f; stransform.angley = -270.0f; + + if (postimgtype == postimg_flip) + stransform.flip = true; + else + stransform.flip = false; + stransform.x = 0.0f; stransform.y = 0.0f; stransform.z = 0.0f; @@ -5312,25 +5336,12 @@ void HWR_DoPostProcessor(player_t *player) } HWD.pfnPostImgRedraw(v); disStart += 1; - } - else if (postimgtype == postimg_flip) //We like our screens inverted. - { - // 10 by 10 grid. 2 coordinates (xy) - float v[SCREENVERTS][SCREENVERTS][2]; - UINT8 x, y; - UINT8 flipy; - for (x = 0; x < SCREENVERTS; x++) - { - for (y = 0, flipy = SCREENVERTS; y < SCREENVERTS; y++, flipy--) - { - // Flip the screen. - v[x][y][0] = (x/((float)(SCREENVERTS-1.0f)/9.0f))-4.5f; - v[x][y][1] = (flipy/((float)(SCREENVERTS-1.0f)/9.0f))-5.5f; - } - } - HWD.pfnPostImgRedraw(v); + // Capture the screen again for screen waving on the intermission + if(gamestate != GS_INTERMISSION) + HWD.pfnMakeScreenTexture(); } + // Flipping of the screen isn't done here anymore #endif // SHUFFLE } diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 1a55c7145..8a2e3a6a0 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1244,6 +1244,11 @@ void HWR_DrawMD2(gr_vissprite_t *spr) // SRB2CBTODO: MD2 scaling support finalscale *= FIXED_TO_FLOAT(spr->mobj->scale); + if (postimgtype == postimg_flip) + p.flip = true; + else + p.flip = false; + HWD.pfnDrawMD2i(buff, curr, durs, tics, next, &p, finalscale, flip, color); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index ded8d0767..731f5bcf3 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -628,9 +628,6 @@ void SetStates(void) #ifdef GL_LIGHT_MODEL_AMBIENT GLfloat LightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; #endif -#ifndef KOS_GL_COMPATIBILITY - GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; -#endif DBG_Printf("SetStates()\n"); @@ -693,9 +690,6 @@ void SetStates(void) pglLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightDiffuse); pglEnable(GL_LIGHT0); #endif -#ifndef KOS_GL_COMPATIBILITY - pglLightfv(GL_LIGHT0, GL_POSITION, LightPos); -#endif // bp : when no t&l :) pglLoadIdentity(); @@ -1720,6 +1714,11 @@ EXPORT void HWRAPI(DrawMD2i) (INT32 *gl_cmd_buffer, md2_frame_t *frame, UINT32 d float scalex, scaley, scalez; scalex = scaley = scalez = scale; + // Because Otherwise, scaling the screen negatively vertically breaks the lighting +#ifndef KOS_GL_COMPATIBILITY + GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; +#endif + if (duration == 0) duration = 1; @@ -1760,10 +1759,19 @@ EXPORT void HWRAPI(DrawMD2i) (INT32 *gl_cmd_buffer, md2_frame_t *frame, UINT32 d pglEnable(GL_CULL_FACE); - if (flipped) + // pos->flip is if the screen is flipped too + if (flipped != pos->flip) // If either are active, but not both, invert the model's culling + { pglCullFace(GL_FRONT); + } else + { pglCullFace(GL_BACK); + } + +#ifndef KOS_GL_COMPATIBILITY + pglLightfv(GL_LIGHT0, GL_POSITION, LightPos); +#endif pglShadeModel(GL_SMOOTH); if (color) @@ -1872,7 +1880,12 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) { // keep a trace of the transformation for md2 memcpy(&md2_transform, stransform, sizeof (md2_transform)); - pglScalef(stransform->scalex, stransform->scaley, -stransform->scalez); + + if (stransform->flip) + pglScalef(stransform->scalex, -stransform->scaley, -stransform->scalez); + else + pglScalef(stransform->scalex, stransform->scaley, -stransform->scalez); + pglRotatef(stransform->anglex , 1.0f, 0.0f, 0.0f); pglRotatef(stransform->angley+270.0f, 0.0f, 1.0f, 0.0f); pglTranslatef(-stransform->x, -stransform->z, -stransform->y);