libgui/source/gui/GameBgImage.cpp

41 lines
1.6 KiB
C++
Raw Normal View History

2018-06-21 20:44:58 +02:00
#include <gui/GameBgImage.h>
2019-08-14 23:24:55 +02:00
#include <gui/video/CVideo.h>
#include <gui/video/shaders/Shader3D.h>
2017-10-29 10:28:14 +01:00
2020-08-13 12:38:07 +02:00
GameBgImage::GameBgImage(const std::string &filename, GuiImageData *preloadImage)
: GuiImageAsync(filename, preloadImage) {
2017-10-29 10:28:14 +01:00
identity = glm::mat4(1.0f);
alphaFadeOut = glm::vec4(1.0f, 0.075f, 5.305f, 2.0f);
}
2018-06-21 20:44:58 +02:00
GameBgImage::~GameBgImage() {
2017-10-29 10:28:14 +01:00
}
2018-06-21 20:44:58 +02:00
void GameBgImage::draw(CVideo *pVideo) {
2020-08-13 12:58:19 +02:00
if (!getImageData() || !getImageData()->getTexture()) {
2017-10-29 10:28:14 +01:00
return;
2020-08-13 12:58:19 +02:00
}
2017-10-29 10:28:14 +01:00
//! first setup 2D GUI positions
2018-06-21 20:44:58 +02:00
float currPosX = getCenterX();
float currPosY = getCenterY();
float currPosZ = getDepth();
2020-08-13 12:38:07 +02:00
float currScaleX = getScaleX() * (float) getWidth() * pVideo->getWidthScaleFactor();
float currScaleY = getScaleY() * (float) getHeight() * pVideo->getHeightScaleFactor();
float currScaleZ = getScaleZ() * (float) getWidth() * pVideo->getDepthScaleFactor();
2017-10-29 10:28:14 +01:00
2020-08-13 12:38:07 +02:00
glm::mat4 m_modelView = glm::translate(identity, glm::vec3(currPosX, currPosY, currPosZ));
2017-10-29 10:28:14 +01:00
m_modelView = glm::scale(m_modelView, glm::vec3(currScaleX, currScaleY, currScaleZ));
Shader3D::instance()->setShaders();
Shader3D::instance()->setProjectionMtx(identity);
Shader3D::instance()->setViewMtx(identity);
Shader3D::instance()->setModelViewMtx(m_modelView);
Shader3D::instance()->setTextureAndSampler(getImageData()->getTexture(), getImageData()->getSampler());
Shader3D::instance()->setAlphaFadeOut(alphaFadeOut);
Shader3D::instance()->setDistanceFadeOut(0.0f);
Shader3D::instance()->setColorIntensity(glm::vec4(1.0f, 1.0f, 1.0f, getAlpha()));
Shader3D::instance()->setAttributeBuffer();
Shader3D::instance()->draw();
}