summaryrefslogtreecommitdiff
path: root/gfx/gl/uiShader.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-01-01 13:01:08 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-01-01 14:40:06 +0000
commit1f68fe78e84f25c8ddacdc37a293a5de31725bab (patch)
tree4537db483391b579387c1bcc00c3f1e3b6adc106 /gfx/gl/uiShader.cpp
parentAdd glm::vec concatenation operator|| (diff)
downloadilt-1f68fe78e84f25c8ddacdc37a293a5de31725bab.tar.bz2
ilt-1f68fe78e84f25c8ddacdc37a293a5de31725bab.tar.xz
ilt-1f68fe78e84f25c8ddacdc37a293a5de31725bab.zip
First iteration with font/text support
Diffstat (limited to 'gfx/gl/uiShader.cpp')
-rw-r--r--gfx/gl/uiShader.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp
index 1c2a0e1..fbcdd15 100644
--- a/gfx/gl/uiShader.cpp
+++ b/gfx/gl/uiShader.cpp
@@ -2,20 +2,36 @@
#include <gfx/gl/glSource.h>
#include <gfx/gl/programHandle.h>
#include <gfx/gl/shaders/fs-uiShader.h>
+#include <gfx/gl/shaders/fs-uiShaderFont.h>
#include <gfx/gl/shaders/vs-uiShader.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
+#include <initializer_list>
-UIShader::UIShader(size_t width, size_t height) : program {uiShader_vs.compile(), uiShader_fs.compile()}
+UIShader::UIShader(size_t width, size_t height) :
+ progDefault {uiShader_vs.compile(), uiShader_fs.compile()}, progText {uiShader_vs.compile(),
+ uiShaderFont_fs.compile()}
{
- if (auto loc = glGetUniformLocation(program.m_program, "uiProjection"); loc >= 0) {
- glUseProgram(program.m_program);
- const auto uiProjection = glm::ortho<float>(0, static_cast<float>(width), 0, static_cast<float>(height));
- glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(uiProjection));
+ for (const auto prog : {&progDefault, &progText}) {
+ if (auto loc = glGetUniformLocation(prog->m_program, "uiProjection"); loc >= 0) {
+ glUseProgram(prog->m_program);
+ const auto uiProjection = glm::ortho<float>(0, static_cast<float>(width), 0, static_cast<float>(height));
+ glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(uiProjection));
+ }
}
}
+
+void
+UIShader::useDefault() const
+{
+ glUseProgram(progDefault.m_program);
+}
+
void
-UIShader::use() const
+UIShader::useText(glm::vec3 colour) const
{
- glUseProgram(program.m_program);
+ glUseProgram(progText.m_program);
+ if (auto loc = glGetUniformLocation(progText.m_program, "colour"); loc >= 0) {
+ glUniform3fv(loc, 1, glm::value_ptr(colour));
+ }
}