From b5984cd10bdf0e33f3bb964f429fc77813f1b6a7 Mon Sep 17 00:00:00 2001 From: Scott Wichser Date: Mon, 23 Dec 2024 08:26:00 -0600 Subject: [PATCH] Wrap glScissor with glPushAttrib/glPopAttrib to fix game/display capture. --- include/SceneRenderer.h | 2 -- src/bzflag/ControlPanel.cxx | 2 ++ src/bzflag/HUDRenderer.cxx | 6 +++++- src/bzflag/RadarRenderer.cxx | 11 +++++++---- src/bzflag/RadarRenderer.h | 17 +++++++++-------- src/bzflag/SceneRenderer.cxx | 12 ++---------- src/bzflag/playing.cxx | 7 ------- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/include/SceneRenderer.h b/include/SceneRenderer.h index a8fceb8d31..9b487dda15 100644 --- a/include/SceneRenderer.h +++ b/include/SceneRenderer.h @@ -103,8 +103,6 @@ class SceneRenderer : public Singleton void setExposed(); - void clearRadar(float opacity); - void getGroundUV(const float p[2], float uv[2]) const; bool getBlank() const; diff --git a/src/bzflag/ControlPanel.cxx b/src/bzflag/ControlPanel.cxx index e097b4e90b..f424b95f69 100644 --- a/src/bzflag/ControlPanel.cxx +++ b/src/bzflag/ControlPanel.cxx @@ -336,6 +336,7 @@ void ControlPanel::render(SceneRenderer& _renderer) glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); + glPushAttrib(GL_SCISSOR_BIT); OpenGLGState::resetState(); FontManager &fm = FontManager::instance(); @@ -646,6 +647,7 @@ void ControlPanel::render(SceneRenderer& _renderer) glColor4f(teamColor[0], teamColor[1], teamColor[2],1.0f ); + glPopAttrib(); glPopMatrix(); fm.setOpacity(1.0f); diff --git a/src/bzflag/HUDRenderer.cxx b/src/bzflag/HUDRenderer.cxx index de2a0bd5e0..507b0028a3 100644 --- a/src/bzflag/HUDRenderer.cxx +++ b/src/bzflag/HUDRenderer.cxx @@ -1451,6 +1451,7 @@ void HUDRenderer::renderBox(SceneRenderer&) if (true /* always draw heading strip */) { // first clip to area + glPushAttrib(GL_SCISSOR_BIT); glScissor(ox + centerx - maxMotionSize, oy + height - viewHeight + centery + maxMotionSize - 5, 2 * maxMotionSize, 25 + (int)(headingFontSize + 0.5f)); @@ -1570,12 +1571,14 @@ void HUDRenderer::renderBox(SceneRenderer&) } markers.clear(); glPopMatrix(); + glPopAttrib(); } // draw altitude strip if (altitudeTape) { // clip to area + glPushAttrib(GL_SCISSOR_BIT); glScissor(ox + centerx + maxMotionSize - 5, oy + height - viewHeight + centery - maxMotionSize, (int)altitudeLabelMaxWidth + 15, 2 * maxMotionSize); @@ -1652,6 +1655,8 @@ void HUDRenderer::renderBox(SceneRenderer&) y += altitudeMarkSpacing; } } + + glPopAttrib(); } } @@ -1705,7 +1710,6 @@ void HUDRenderer::setOneToOnePrj() const int oy = window.getOriginY(); // use one-to-one pixel projection - glScissor(ox, oy + height - viewHeight, width, viewHeight); glMatrixMode(GL_PROJECTION); window.setProjectionHUD(); glMatrixMode(GL_MODELVIEW); diff --git a/src/bzflag/RadarRenderer.cxx b/src/bzflag/RadarRenderer.cxx index 8bd314c0f1..71fa6f1c06 100644 --- a/src/bzflag/RadarRenderer.cxx +++ b/src/bzflag/RadarRenderer.cxx @@ -380,14 +380,15 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer) return; } + glPushAttrib(GL_SCISSOR_BIT); + // render the frame renderFrame(renderer); - if (blank) - return; - - if (!world) + if (blank || !world) { + glPopAttrib(); return; + } smooth = BZDBCache::smooth; const bool fastRadar = ((BZDBCache::radarStyle == 1) || @@ -782,6 +783,8 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer) } triangleCount = RenderNode::getTriangleCount(); + + glPopAttrib(); } diff --git a/src/bzflag/RadarRenderer.h b/src/bzflag/RadarRenderer.h index be7eab9f5e..9d7ddfb266 100644 --- a/src/bzflag/RadarRenderer.h +++ b/src/bzflag/RadarRenderer.h @@ -47,14 +47,6 @@ class RadarRenderer void render(SceneRenderer&, bool blank, bool observer); - void renderFrame(SceneRenderer&); - - void renderObstacles(bool fastRadar, float range); - void renderWalls(); - void renderBoxPyrMesh(); - void renderBoxPyrMeshFast(float range); - void renderBasesAndTeles(); - int getFrameTriangleCount() const; private: @@ -73,6 +65,15 @@ class RadarRenderer static float colorScale(const float z, const float h); static float transScale(const float z, const float h); + void renderFrame(SceneRenderer&); + + void renderObstacles(bool fastRadar, float range); + void renderWalls(); + void renderBoxPyrMesh(); + void renderBoxPyrMeshFast(float range); + void renderBasesAndTeles(); + + private: World* world; int x, y; diff --git a/src/bzflag/SceneRenderer.cxx b/src/bzflag/SceneRenderer.cxx index 28ada97f32..a227064d2b 100644 --- a/src/bzflag/SceneRenderer.cxx +++ b/src/bzflag/SceneRenderer.cxx @@ -468,16 +468,6 @@ void SceneRenderer::setExposed() } -void SceneRenderer::clearRadar(float opacity) -{ - int size = window->getHeight() - window->getViewHeight(); - float op = (opacity > 1.0f) ? 1.0f : (opacity < 0.0f) ? 0.0f : opacity; - glScissor(window->getOriginX(), 0, size, size); - glClearColor(0.0f, 0.0f, 0.0f, op); - glClear(GL_COLOR_BUFFER_BIT); -} - - void SceneRenderer::setSceneDatabase(SceneDatabase* db) { // update the styles @@ -893,6 +883,7 @@ void SceneRenderer::renderScene(bool UNUSED(_lastFrame), bool UNUSED(_sameFrame) } // set scissor + glPushAttrib(GL_SCISSOR_BIT); glScissor(window->getOriginX(), window->getOriginY() + window->getHeight() - window->getViewHeight(), window->getWidth(), window->getViewHeight()); @@ -1054,6 +1045,7 @@ void SceneRenderer::renderScene(bool UNUSED(_lastFrame), bool UNUSED(_sameFrame) // do depth complexity if (useDepthComplexityOn) renderDepthComplexity(); + glPopAttrib(); return; } diff --git a/src/bzflag/playing.cxx b/src/bzflag/playing.cxx index d6212952e4..e691e11a5f 100644 --- a/src/bzflag/playing.cxx +++ b/src/bzflag/playing.cxx @@ -5650,11 +5650,6 @@ static void renderDialog() { if (HUDDialogStack::get()->isActive()) { - const int width = mainWindow->getWidth(); - const int height = mainWindow->getHeight(); - const int ox = mainWindow->getOriginX(); - const int oy = mainWindow->getOriginY(); - glScissor(ox, oy, width, height); glMatrixMode(GL_PROJECTION); mainWindow->setProjectionPlay(); glMatrixMode(GL_MODELVIEW); @@ -5698,7 +5693,6 @@ static void renderRoamMouse() glPushAttrib(GL_ALL_ATTRIB_BITS); - glScissor(ox, oy, sx, sy); glMatrixMode(GL_PROJECTION); glPushMatrix(); mainWindow->setProjectionPlay(); @@ -6546,7 +6540,6 @@ void drawFrame(const float dt) mainWindow->getWindow()->getMouse(mx, my); my = height - my - 1; - glScissor(ox, oy, width, height); glMatrixMode(GL_PROJECTION); mainWindow->setProjectionPlay(); glMatrixMode(GL_MODELVIEW);