Closed LeeMcQueen closed 3 years ago
GuiTexture.h
class GuiRenderer {
public:
static void initialise();
static void render(std::vector<GuiTexture> guiTextures);
static void cleanUp();
priavte:
static RawModel rawModel_;
static GuiShader guiShader_;
};
GuiShader.h
class GuiShader : public ShaderProgram {
public:
GuiShader();
static const char *GUI_VERTEX_SHADER;
static const char *GUI_FRAGMENT_SHADER;
void loadTransformationMatrix(glm::mat4 matrix);
protected:
void bindAttributes() override;
void getAllUniformLocation() override;
private:
GLuint Location_transformationMatrix;
}
GuiShader.cpp
const char GuiShader::GUI_VERTEX_SHADER = "guiVertexShader.txt"; const char GuiShader::GUI_FRAGMENT_SHADER = "guiFragmentShader.txt";
GuiShader::GuiShader() : ShaderProgram(GUI_VERTEX_SHADER, GUI_FRAGMENT_SHADER){
bindAttributes();
glLinkProgram(programID);
glValidateProgram(programID);
getAllUniformLocations();
}
void GuiShader::bindAttributes(){
bindAttribute(0, "position");
}
void GuiShader::loadTransformationMatrix(glm::mat4 matrix) {
loadMatrix4(Loaction_transformationMatirx, matrix);
}
void GuiShader::getAllUniformLocations() {
Location_transformationMatrix = getUniformLocation("transformationMatrix");
}
GuiRenderer.cpp
RawModel GuiRenderer::rawModel; GuiShader GuiRenderer::guiShader;
void GuiRenderer::initialise(){
GuiShader guiShader;
Loader loader;
std::vector<float> position = { -1, 1, -1, -1, 1, 1, 1, -1 };
guiModel_ = loader.loadToVao(position, 2);
}
void GuiRenderer::render(std::vector
guiShader_.start();
glBindVertexArray(guiModel_.getVaoId());
glEnableVertexAttribArray(0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST)
for(GuiTexture &guiTexture : guiTextures){
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, guiTexture.getTexture());
glm::mat4 transformMatrix = Maths::createTransformationMatrix(guiTexture.getPosition(), guiTexture.getScale());
guiShader_.loadTransformationMatrix(transformMatrix);
glDrawArrays(GL_TRIANGLE_STRIP, 0, rawModel_.getVertexCount());
}
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisableVertexAttribArray(0);
glBindVertexArray(0);
guiShader_.stop();
}
pragma once
include
class GuiTexture {
public: GuiTexture(unsigned int texture, glm::vec2 position, glm::vec2 scale) : texture(texture), position(position), scale_(scale) {}; ~GuiTexture();
private:
};