ADD: Dimming textures + pushing newGameLayer
All checks were successful
Tests / test (push) Successful in 2m36s

This commit is contained in:
Sebastian Böckelmann 2026-04-25 11:18:45 +02:00
parent 8d6a314a3c
commit def763d6ae
9 changed files with 29 additions and 11 deletions

View File

@ -14,6 +14,7 @@ uniform float tintStrength; // 0.0 = aus
uniform bool hasForeground;
uniform bool hasBackground;
uniform float dimFactor;
void main(void) {
vec4 fg = hasForeground ? texture(guiTexture, textureCoords) : vec4(0.0);
@ -28,4 +29,5 @@ void main(void) {
textureColor.rgb = mix(textureColor.rgb, tintColor, tintStrength);
color = textureColor;
color *= dimFactor;
}

View File

@ -7,6 +7,7 @@
#include "SceneManager.h"
#include "../../renderer/loader/AssetManager.h"
#include "../../renderer/GUIRenderer.h"
#include "../../renderer/RenderContext.h"
#include "../gui/uiComponent/UiImage.h"
#include "../gui/uiComponent/UiProgressbar.h"
#include "../gui/uiMain/UiContainer.h"
@ -23,7 +24,8 @@ void SplashScreenLayer::onRender() {
}
auto guis = renderBundle.getGUITextures();
guiRenderer->render(guis);
RenderContext ctx = RenderContext::Default();
guiRenderer->render(guis, ctx);
}
void SplashScreenLayer::onUpdate() {

View File

@ -7,6 +7,7 @@
#include <iostream>
#include <vector>
#include "RenderContext.h"
#include "components/UiRenderBundle.h"
#include "../toolbox/MathUtils.h"
#include "loader/Loader.h"
@ -17,8 +18,9 @@ GUIRenderer::GUIRenderer(Loader &loader) {
rawModel = std::make_unique<RawModel>(model);
}
void GUIRenderer::render(std::vector<std::shared_ptr<GUITexture>>& gui_textures) {
void GUIRenderer::render(std::vector<std::shared_ptr<GUITexture>>& gui_textures, RenderContext& ctx) {
guiShader.start();
guiShader.loadDimFactor(ctx.dimFactor);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);

View File

@ -13,7 +13,7 @@
#include "shaders/GUIShader.h"
struct RenderContext;
class Loader;
class GUIRenderer {
@ -22,7 +22,7 @@ private:
public:
GUIShader guiShader;
explicit GUIRenderer(Loader& loader);
void render(std::vector<std::shared_ptr<GUITexture>> &gui_textures);
void render(std::vector<std::shared_ptr<GUITexture>> &gui_textures, RenderContext& ctx);
void cleanUp();
};

View File

@ -24,6 +24,10 @@ void GUIShader::loadBackgroundTexture(int textureBankIndex, bool useTexture) {
ShaderProgram::loadInt(getUniformLocation("backgroundTexture"), textureBankIndex);
}
void GUIShader::loadDimFactor(float dim_factor) {
ShaderProgram::loadFloat(getUniformLocation("dimFactor"), dim_factor);
}
void GUIShader::bindAttributes() const {
ShaderProgram::bindAttribute(0, "position");
}

View File

@ -18,6 +18,8 @@ public:
void loadForegroundTexture(int textureBankIndex, bool useTexture);
void loadBackgroundTexture(int textureBankIndex, bool useTexture);
void loadDimFactor(float dim_factor);
private:
inline static const std::string VERTEX_FILE = "assets/shaders/guiVertexShader.glsl";
inline static const std::string FRAGMENT_FILE = "assets/shaders/guiFragmentShader.glsl";

View File

@ -156,11 +156,11 @@ void UILayer::onRender() {
if (rootContainer) {
rootContainer->collectRenderData(renderBundle);
}
RenderContext ctx = RenderContext::Default();
auto guis = renderBundle.getGUITextures();
guiRenderer->render(guis);
guiRenderer->render(guis, ctx);
auto renderTexts = renderBundle.getGUITexts();
RenderContext ctx = RenderContext::Default();
textRenderer->renderGuiTexts(renderTexts, Application::getInstance().getWindow().GetWidth(), Application::getInstance().getWindow().GetHeight(), ctx);
}

View File

@ -30,8 +30,15 @@ void MainUiLayer::onAttach() {
btnStyle2.width = SizeValue(350, SizeUnit::Pixels);
btnStyle2.height = SizeValue(90, SizeUnit::Pixels);
rootContainer->addChild<UiButton>(std::make_unique<UiButton>(AssetManager::getTexture("btn_background")->getTextureID(), "New Game",
auto newGameBtn = rootContainer->addChild<UiButton>(std::make_unique<UiButton>(AssetManager::getTexture("btn_background")->getTextureID(), "New Game",
*AssetManager::getUiTheme("default")->large, btnStyle2));
newGameBtn->addMouseListener([this](const MouseEventData& eventData) {
if (eventData.isCompleteClick(MouseButton::LEFT)) {
auto newGameContainer = std::make_unique<UiContainer>();
uiStack->push(std::move(newGameContainer));
}
});
LayoutStyle btnStyle3;
btnStyle3.margin.top = SizeValue(15, SizeUnit::Pixels);
@ -68,7 +75,7 @@ void MainUiLayer::onRender() {
if (uiStack) {
for (const auto& panel : uiStack->getPanels()) {
RenderContext ctx;
if (!uiStack->isTop(panel.get())) {
if (uiStack->isTop(panel.get())) {
ctx = RenderContext::Default();
} else {
ctx = RenderContext::Dimmed(uiConfig.backgroundDim);
@ -78,7 +85,7 @@ void MainUiLayer::onRender() {
panel->collectRenderData(renderBundle);
auto guis = renderBundle.getGUITextures();
guiRenderer->render(guis);
guiRenderer->render(guis, ctx);
const auto renderTexts = renderBundle.getGUITexts();
textRenderer->renderGuiTexts(renderTexts, static_cast<float>(Application::getInstance().getWindow().GetWidth()),

View File

@ -7,7 +7,6 @@
#include "../../../engine/layer/Layer.h"
#include "../../../engine/renderer/GUIRenderer.h"
#include "../../../engine/renderer/loader/Loader.h"
#include "../../../engine/core/gui/uiMain/UiContainer.h"
#include "../../../engine/core/gui/uiMain/UiStack.h"
#include "../../../engine/renderer/TextRenderer.h"