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
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;
}

View file

@ -1,10 +1,11 @@
#include <SDL.h>
#include <glm/vec2.hpp>
#include <glm/mat2x2.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GL3_PROTOTYPES 1
#include <GL/glew.h>
#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);

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
#define SOSC_SHADER_TEST_H
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#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"
});
}
};
}}