12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #include "client/engine/shader/OverlayShader.h"
- #include "client/engine/Wrapper.h"
- OverlayShader::OverlayShader()
- {
- }
- OverlayShader::~OverlayShader()
- {
- }
- bool OverlayShader::init()
- {
- program.compile("resources/shader/overlayVertex.vs", "resources/shader/overlayFragment.fs");
- if(!program.isValid())
- {
- return false;
- }
-
- // get uniform locations
- unifUseTexture = glGetUniformLocation(program.getProgram(), "useTexture");
- unifUseColor = glGetUniformLocation(program.getProgram(), "useColor");
- unifViewMatrix = glGetUniformLocation(program.getProgram(), "viewMatrix");
- unifModelMatrix = glGetUniformLocation(program.getProgram(), "modelMatrix");
- return true;
- }
- void OverlayShader::preRender()
- {
- // bind overlay shader program
- glUseProgram(program.getProgram());
-
- // reset view and model matrix
- view.setToIdentity();
- glUniformMatrix4fv(unifViewMatrix, 1, 0, view.getValues());
- glUniformMatrix4fv(unifModelMatrix, 1, 0, view.getValues());
-
- // set defaults
- setUseTexture(true);
- setUseColor(false);
-
- // reset to default framebuffer
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
- // clear color buffer
- glClear(GL_COLOR_BUFFER_BIT);
-
- // depth testing is not needed
- glDisable(GL_DEPTH_TEST);
- }
- void OverlayShader::setViewMatrix()
- {
- view.set(0, 0, (2.0f * Engine::getScale()) / Engine::getWidth());
- view.set(0, 1, 0.0f);
- view.set(0, 2, 0.0f);
- view.set(0, 3, -1.0f);
-
- view.set(1, 0, 0.0f);
- view.set(1, 1, (-2.0f * Engine::getScale()) / Engine::getHeight());
- view.set(1, 2, 0.0f);
- view.set(1, 3, 1.0f);
-
- view.set(2, 0, 0.0f);
- view.set(2, 1, 0.0f);
- view.set(2, 2, (-1.0f * Engine::getScale()) / Engine::getHeight());
- view.set(2, 3, 0.5f);
-
- view.set(3, 0, 0.0f);
- view.set(3, 1, 0.0f);
- view.set(3, 0, 0.0f);
- view.set(3, 3, 1.0f);
-
- glUniformMatrix4fv(unifViewMatrix, 1, 0, view.getValues());
- }
- void OverlayShader::setModelMatrix(const float* data)
- {
- glUniformMatrix4fv(unifModelMatrix, 1, 0, data);
- }
- void OverlayShader::setUseTexture(bool use)
- {
- glUniform1i(unifUseTexture, use);
- }
- void OverlayShader::setUseColor(bool use)
- {
- glUniform1i(unifUseColor, use);
- }
|