From f54d0df92ef740157aa69fa23197f55595923077 Mon Sep 17 00:00:00 2001 From: malloc Date: Mon, 27 Aug 2018 16:45:24 -0500 Subject: [PATCH] testator boob --- resources/client/shaders/test.vert | 12 +++--------- src/client/main.cpp | 20 ++++++++++++++++---- src/client/shaders/test.cpp | 5 ----- src/client/shaders/test.hpp | 29 +++++++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 20 deletions(-) delete mode 100644 src/client/shaders/test.cpp diff --git a/resources/client/shaders/test.vert b/resources/client/shaders/test.vert index 7379be4..3ad07a7 100644 --- a/resources/client/shaders/test.vert +++ b/resources/client/shaders/test.vert @@ -1,18 +1,12 @@ #version 330 core -layout (location = 0) in vec2 aScreenCoords; +layout (location = 0) in vec4 aScreenCoords; layout (location = 1) in vec2 aTexCoords; out vec2 texCoords; -uniform vec2 screenSize; +uniform mat4 orthoMatrix; void main() { - mat2 scMatrix = mat2(screenSize.x); - vec2 viewCoords = scMatrix * aScreenCoords; - gl_Position = - vec4((2 * aScreenCoords.x) / screenSize.x - 1, - 1 - (2 * aScreenCoords.y) / screenSize.y, - 0, 0); - + gl_Position = orthoMatrix * aScreenCoords; texCoords = aTexCoords; } \ No newline at end of file diff --git a/src/client/main.cpp b/src/client/main.cpp index 993a177..eade287 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -1,10 +1,11 @@ #include -#include -#include - +#include +#include #define GL3_PROTOTYPES 1 #include +#include "shaders/test.hpp" + void setColor(float r, float g, float b, SDL_Window* window) { glClearColor(r, g, b, 1.0); glClear(GL_COLOR_BUFFER_BIT); @@ -12,6 +13,8 @@ void setColor(float r, float g, float b, SDL_Window* window) { } int main(int argc, char* argv[]) { + using namespace sosc; + if(SDL_Init(SDL_INIT_VIDEO) < 0) { printf(SDL_GetError()); return -1; @@ -37,6 +40,10 @@ int main(int argc, char* argv[]) { SDL_GL_SetSwapInterval(1); + shdr::TestShader test; + test.Load(); + test.UpdateWindow(window); + #ifndef __APPLE__ glewExperimental = GL_TRUE; glewInit(); @@ -46,6 +53,8 @@ int main(int argc, char* argv[]) { while(running) { glClear(GL_COLOR_BUFFER_BIT); + + SDL_GL_SwapWindow(window); SDL_Event event; @@ -56,7 +65,8 @@ int main(int argc, char* argv[]) { if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - + glViewport(0, 0, event.window.data1, event.window.data2); + test.UpdateWindow(window); } if(event.type == SDL_KEYDOWN) { @@ -71,6 +81,8 @@ int main(int argc, char* argv[]) { } } + test.Unload(); + SDL_GL_DeleteContext(ctx); SDL_DestroyWindow(window); diff --git a/src/client/shaders/test.cpp b/src/client/shaders/test.cpp deleted file mode 100644 index 18cc592..0000000 --- a/src/client/shaders/test.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "test.hpp" - -void sosc::shdr::TestShader::PrepareLoad() { - -} \ No newline at end of file diff --git a/src/client/shaders/test.hpp b/src/client/shaders/test.hpp index df1deea..e7101a6 100644 --- a/src/client/shaders/test.hpp +++ b/src/client/shaders/test.hpp @@ -1,6 +1,9 @@ #ifndef SOSC_SHADER_TEST_H #define SOSC_SHADER_TEST_H +#include +#include +#include "common.hpp" #include "_shader.hpp" namespace sosc { @@ -8,11 +11,33 @@ namespace shdr { class TestShader : public Shader { public: enum Uniforms { - SCREEN_SIZE = 0, + ORTHO_MATRIX = 0, GRAPHIC_SAMPLER }; + + void UpdateWindow(SDL_Window* window) { + this->Start(); + + int width, height; + SDL_GetWindowSize(window, &width, &height); + auto orthoMatrix = glm::ortho(0, width, height, 0); + glUniformMatrix4fv( + (*this)[ORTHO_MATRIX], 1, GL_FALSE, glm::value_ptr(orthoMatrix) + ); + + this->Stop(); + } protected: - void PrepareLoad() override; + void PrepareLoad() override { + this->AttachSource(SOSC_RESC("shaders/test.vert"), GL_VERTEX_SHADER); + this->AttachSource(SOSC_RESC("shaders/test.frag"), GL_VERTEX_SHADER); + + this->LinkProgram(); + this->LoadUniforms({ + "orthoMatrix", + "graphicSampler" + }); + } }; }}