testator boob

This commit is contained in:
malloc 2018-08-27 16:45:24 -05:00
parent 5cd9ab1a59
commit f54d0df92e
4 changed files with 46 additions and 20 deletions

View file

@ -1,18 +1,12 @@
#version 330 core #version 330 core
layout (location = 0) in vec2 aScreenCoords; layout (location = 0) in vec4 aScreenCoords;
layout (location = 1) in vec2 aTexCoords; layout (location = 1) in vec2 aTexCoords;
out vec2 texCoords; out vec2 texCoords;
uniform vec2 screenSize; uniform mat4 orthoMatrix;
void main() { void main() {
mat2 scMatrix = mat2(screenSize.x); gl_Position = orthoMatrix * aScreenCoords;
vec2 viewCoords = scMatrix * aScreenCoords;
gl_Position =
vec4((2 * aScreenCoords.x) / screenSize.x - 1,
1 - (2 * aScreenCoords.y) / screenSize.y,
0, 0);
texCoords = aTexCoords; texCoords = aTexCoords;
} }

View file

@ -1,10 +1,11 @@
#include <SDL.h> #include <SDL.h>
#include <glm/vec2.hpp> #include <glm/glm.hpp>
#include <glm/mat2x2.hpp> #include <glm/gtc/matrix_transform.hpp>
#define GL3_PROTOTYPES 1 #define GL3_PROTOTYPES 1
#include <GL/glew.h> #include <GL/glew.h>
#include "shaders/test.hpp"
void setColor(float r, float g, float b, SDL_Window* window) { void setColor(float r, float g, float b, SDL_Window* window) {
glClearColor(r, g, b, 1.0); glClearColor(r, g, b, 1.0);
glClear(GL_COLOR_BUFFER_BIT); 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[]) { int main(int argc, char* argv[]) {
using namespace sosc;
if(SDL_Init(SDL_INIT_VIDEO) < 0) { if(SDL_Init(SDL_INIT_VIDEO) < 0) {
printf(SDL_GetError()); printf(SDL_GetError());
return -1; return -1;
@ -37,6 +40,10 @@ int main(int argc, char* argv[]) {
SDL_GL_SetSwapInterval(1); SDL_GL_SetSwapInterval(1);
shdr::TestShader test;
test.Load();
test.UpdateWindow(window);
#ifndef __APPLE__ #ifndef __APPLE__
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
glewInit(); glewInit();
@ -46,6 +53,8 @@ int main(int argc, char* argv[]) {
while(running) { while(running) {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(window); SDL_GL_SwapWindow(window);
SDL_Event event; SDL_Event event;
@ -56,7 +65,8 @@ int main(int argc, char* argv[]) {
if(event.type == SDL_WINDOWEVENT && if(event.type == SDL_WINDOWEVENT &&
event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{ {
glViewport(0, 0, event.window.data1, event.window.data2);
test.UpdateWindow(window);
} }
if(event.type == SDL_KEYDOWN) { if(event.type == SDL_KEYDOWN) {
@ -71,6 +81,8 @@ int main(int argc, char* argv[]) {
} }
} }
test.Unload();
SDL_GL_DeleteContext(ctx); SDL_GL_DeleteContext(ctx);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);

View file

@ -1,5 +0,0 @@
#include "test.hpp"
void sosc::shdr::TestShader::PrepareLoad() {
}

View file

@ -1,6 +1,9 @@
#ifndef SOSC_SHADER_TEST_H #ifndef SOSC_SHADER_TEST_H
#define SOSC_SHADER_TEST_H #define SOSC_SHADER_TEST_H
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "common.hpp"
#include "_shader.hpp" #include "_shader.hpp"
namespace sosc { namespace sosc {
@ -8,11 +11,33 @@ namespace shdr {
class TestShader : public Shader { class TestShader : public Shader {
public: public:
enum Uniforms { enum Uniforms {
SCREEN_SIZE = 0, ORTHO_MATRIX = 0,
GRAPHIC_SAMPLER 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: 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"
});
}
}; };
}} }}