summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shader.cpp1
-rw-r--r--gfx/gl/shaders/uiShader.fs11
-rw-r--r--gfx/gl/shaders/uiShader.vs13
-rw-r--r--gfx/gl/uiShader.cpp14
-rw-r--r--gfx/gl/uiShader.h18
5 files changed, 56 insertions, 1 deletions
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index 47e08c5..03e7899 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -76,4 +76,3 @@ Shader::setModel(const Location & loc, Program pid) const
glUniformMatrix4fv(prog.model_uniform, 1, GL_FALSE, glm::value_ptr(model));
}
}
-
diff --git a/gfx/gl/shaders/uiShader.fs b/gfx/gl/shaders/uiShader.fs
new file mode 100644
index 0000000..907c4f1
--- /dev/null
+++ b/gfx/gl/shaders/uiShader.fs
@@ -0,0 +1,11 @@
+#version 130
+
+in vec2 texCoord0;
+
+uniform sampler2D sampler;
+
+void
+main()
+{
+ gl_FragColor = texture(sampler, texCoord0);
+}
diff --git a/gfx/gl/shaders/uiShader.vs b/gfx/gl/shaders/uiShader.vs
new file mode 100644
index 0000000..0d00fed
--- /dev/null
+++ b/gfx/gl/shaders/uiShader.vs
@@ -0,0 +1,13 @@
+#version 130
+
+in vec4 position;
+
+out vec2 texCoord0;
+uniform mat4 uiProjection;
+
+void
+main()
+{
+ gl_Position = uiProjection * vec4(position.xy, 0.0, 1.0);
+ texCoord0 = position.zw;
+}
diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp
new file mode 100644
index 0000000..2fbb0d4
--- /dev/null
+++ b/gfx/gl/uiShader.cpp
@@ -0,0 +1,14 @@
+#include "uiShader.h"
+#include <gfx/gl/shaders/fs-uiShader.h>
+#include <gfx/gl/shaders/vs-uiShader.h>
+#include <glm/gtc/type_ptr.hpp>
+#include <glm/gtx/transform.hpp>
+
+UIShader::UIShader(size_t width, size_t height) : program {uiShader_vs.compile(), uiShader_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));
+ }
+}
diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h
new file mode 100644
index 0000000..ff0e96d
--- /dev/null
+++ b/gfx/gl/uiShader.h
@@ -0,0 +1,18 @@
+#ifndef UISHADER_H
+#define UISHADER_H
+
+#include "programHandle.h"
+#include <cstdint>
+
+class UIShader {
+public:
+ UIShader(std::size_t width, std::size_t height);
+
+private:
+ class UIProgramHandle : public ProgramHandleBase {
+ using ProgramHandleBase::ProgramHandleBase;
+ };
+ UIProgramHandle program;
+};
+
+#endif