From b6d58f55c44132d37b36b4099374cd6b8286a616 Mon Sep 17 00:00:00 2001 From: Benau Date: Wed, 21 Apr 2021 12:17:45 +0800 Subject: [PATCH] Remove some GL code in race gui --- src/states_screens/race_gui.cpp | 26 +++++++++++++++++--------- src/states_screens/race_gui.hpp | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 33cddadc5..4136932ad 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -29,6 +29,7 @@ using namespace irr; #include "config/user_config.hpp" #include "font/font_drawer.hpp" #include "graphics/camera.hpp" +#include "graphics/central_settings.hpp" #include "graphics/2dutils.hpp" #ifndef SERVER_ONLY #include "graphics/glwrap.hpp" @@ -61,6 +62,8 @@ using namespace irr; #include "utils/string_utils.hpp" #include "utils/translation.hpp" +#include + /** The constructor is called before anything is attached to the scene node. * So rendering to a texture can be done here. But world is not yet fully * created, so only the race manager can be accessed safely. @@ -856,9 +859,9 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart, state, gauge_width, gauge_height, offset); if(kart->getControls().getNitro() || kart->isOnMinNitroTime()) - drawMeterTexture(m_gauge_full_bright, vertices, count); + drawMeterTexture(m_gauge_full_bright, vertices, count, true); else - drawMeterTexture(m_gauge_full, vertices, count); + drawMeterTexture(m_gauge_full, vertices, count, true); } // Target @@ -873,7 +876,7 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart, unsigned int count = computeVerticesForMeter(position, threshold, vertices, vertices_count, coin_target, gauge_width, gauge_height, offset); - drawMeterTexture(m_gauge_goal, vertices, count); + drawMeterTexture(m_gauge_goal, vertices, count, true); } #endif } // drawEnergyMeter @@ -1097,7 +1100,7 @@ void RaceGUI::drawSpeedEnergyRank(const AbstractKart* kart, #endif } // drawSpeedEnergyRank -void RaceGUI::drawMeterTexture(video::ITexture *meter_texture, video::S3DVertex vertices[], unsigned int count) +void RaceGUI::drawMeterTexture(video::ITexture *meter_texture, video::S3DVertex vertices[], unsigned int count, bool reverse) { #ifndef SERVER_ONLY //Should be greater or equal than the greatest vertices_count used by the meter functions @@ -1110,19 +1113,24 @@ void RaceGUI::drawMeterTexture(video::ITexture *meter_texture, video::S3DVertex vertices[i].Color = video::SColor(255, 255, 255, 255); } + if (reverse) + std::reverse(vertices + 1, vertices + count); + video::SMaterial m; m.setTexture(0, meter_texture); m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; irr_driver->getVideoDriver()->setMaterial(m); - glEnable(GL_BLEND); - glDisable(GL_CULL_FACE); - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + if (CVS->isGLSL()) + { + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + } draw2DVertexPrimitiveList(m.getTexture(0), vertices, count, index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN); - glDisable(GL_BLEND); - glEnable(GL_CULL_FACE); + if (CVS->isGLSL()) + glDisable(GL_BLEND); #endif } // drawMeterTexture diff --git a/src/states_screens/race_gui.hpp b/src/states_screens/race_gui.hpp index 0269d2c3a..4fa72905f 100644 --- a/src/states_screens/race_gui.hpp +++ b/src/states_screens/race_gui.hpp @@ -133,7 +133,7 @@ private: /* Helper functions for drawing meters */ - void drawMeterTexture(video::ITexture *meter_texture, video::S3DVertex vertices[], unsigned int count); + void drawMeterTexture(video::ITexture *meter_texture, video::S3DVertex vertices[], unsigned int count, bool reverse = false); unsigned int computeVerticesForMeter(core::vector2df position[], float threshold[], video::S3DVertex vertices[], unsigned int vertices_count, float measure, int gauge_width,