summaryrefslogtreecommitdiff
path: root/gfx/gl
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
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')
-rw-r--r--gfx/gl/shaders/uiShaderFont.fs12
-rw-r--r--gfx/gl/uiShader.cpp30
-rw-r--r--gfx/gl/uiShader.h6
3 files changed, 39 insertions, 9 deletions
diff --git a/gfx/gl/shaders/uiShaderFont.fs b/gfx/gl/shaders/uiShaderFont.fs
new file mode 100644
index 0000000..bee455d
--- /dev/null
+++ b/gfx/gl/shaders/uiShaderFont.fs
@@ -0,0 +1,12 @@
+#version 130
+
+in vec2 texCoord0;
+
+uniform sampler2D sampler;
+uniform vec3 colour;
+
+void
+main()
+{
+ gl_FragColor = vec4(colour, texture(sampler, texCoord0).r);
+}
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));
+ }
}
diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h
index 45ccc23..502ba13 100644
--- a/gfx/gl/uiShader.h
+++ b/gfx/gl/uiShader.h
@@ -4,17 +4,19 @@
#include "programHandle.h"
#include <GL/glew.h>
#include <cstddef>
+#include <glm/glm.hpp>
class UIShader {
public:
UIShader(std::size_t width, std::size_t height);
- void use() const;
+ void useDefault() const;
+ void useText(glm::vec3) const;
private:
class UIProgramHandle : public ProgramHandleBase {
using ProgramHandleBase::ProgramHandleBase;
};
- UIProgramHandle program;
+ UIProgramHandle progDefault, progText;
};
#endif