Skip to content

Commit

Permalink
Wrap glScissor with glPushAttrib/glPopAttrib to fix game/display capt…
Browse files Browse the repository at this point in the history
…ure.
  • Loading branch information
blast007 committed Dec 23, 2024
1 parent 070d498 commit b5984cd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 32 deletions.
2 changes: 0 additions & 2 deletions include/SceneRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ class SceneRenderer : public Singleton<SceneRenderer>

void setExposed();

void clearRadar(float opacity);

void getGroundUV(const float p[2], float uv[2]) const;

bool getBlank() const;
Expand Down
2 changes: 2 additions & 0 deletions src/bzflag/ControlPanel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ void ControlPanel::render(SceneRenderer& _renderer)
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glPushAttrib(GL_SCISSOR_BIT);
OpenGLGState::resetState();

FontManager &fm = FontManager::instance();
Expand Down Expand Up @@ -646,6 +647,7 @@ void ControlPanel::render(SceneRenderer& _renderer)

glColor4f(teamColor[0], teamColor[1], teamColor[2],1.0f );

glPopAttrib();
glPopMatrix();

fm.setOpacity(1.0f);
Expand Down
6 changes: 5 additions & 1 deletion src/bzflag/HUDRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1652,6 +1655,8 @@ void HUDRenderer::renderBox(SceneRenderer&)
y += altitudeMarkSpacing;
}
}

glPopAttrib();
}
}

Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/bzflag/RadarRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down Expand Up @@ -782,6 +783,8 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer)
}

triangleCount = RenderNode::getTriangleCount();

glPopAttrib();
}


Expand Down
17 changes: 9 additions & 8 deletions src/bzflag/RadarRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
12 changes: 2 additions & 10 deletions src/bzflag/SceneRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -1054,6 +1045,7 @@ void SceneRenderer::renderScene(bool UNUSED(_lastFrame), bool UNUSED(_sameFrame)
// do depth complexity
if (useDepthComplexityOn)
renderDepthComplexity();
glPopAttrib();

return;
}
Expand Down
7 changes: 0 additions & 7 deletions src/bzflag/playing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -5698,7 +5693,6 @@ static void renderRoamMouse()

glPushAttrib(GL_ALL_ATTRIB_BITS);

glScissor(ox, oy, sx, sy);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
mainWindow->setProjectionPlay();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b5984cd

Please sign in to comment.