From 259f6a8488bf1270dedfa90169e172cc00403340 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Tue, 29 Nov 2016 00:31:22 -0800 Subject: [PATCH] Got some geometry up and rotating. It will be pretty trivial to pass in the camera rotation now and have it follow along. --- include/GL_Testing.h | 6 ++++++ shaders/passthrough.frag | 5 ++++- shaders/passthrough.vert | 8 +++++++- src/GL_Testing.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/main.cpp | 8 ++++++-- 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/include/GL_Testing.h b/include/GL_Testing.h index b7dd8cc..e2746d6 100644 --- a/include/GL_Testing.h +++ b/include/GL_Testing.h @@ -15,6 +15,8 @@ public: void compile_shader(std::string file_path, Shader_Type t); void create_program(); void create_buffers(); + void transform(); + void rotate(double delta); void draw(); private: @@ -25,5 +27,9 @@ private: GLuint vertex_shader; GLuint fragment_shader; GLuint shader_program; + + GLfloat *matrix; + + double counter = 0; }; diff --git a/shaders/passthrough.frag b/shaders/passthrough.frag index 1556f46..fdceae4 100644 --- a/shaders/passthrough.frag +++ b/shaders/passthrough.frag @@ -1,8 +1,11 @@ #version 330 core +in vec4 vertexColor; out vec4 color; + + void main() { - color = vec4(0.0f, 0.5f, 0.2f, 1.0f); + color = vertexColor; } \ No newline at end of file diff --git a/shaders/passthrough.vert b/shaders/passthrough.vert index f50985c..9c1013c 100644 --- a/shaders/passthrough.vert +++ b/shaders/passthrough.vert @@ -2,7 +2,13 @@ layout (location = 0) in vec3 position; +uniform mat4 transform; +out vec4 vertexColor; + void main() { - gl_Position = vec4(position.x, position.y, position.z, 1.0); + gl_Position = transform * vec4(position, 1.0f); + + //gl_Position = vec4(position, 1.0); + vertexColor = vec4(0.5f, 0.0f, 0.0f, 1.0f); } \ No newline at end of file diff --git a/src/GL_Testing.cpp b/src/GL_Testing.cpp index c001790..98753f2 100644 --- a/src/GL_Testing.cpp +++ b/src/GL_Testing.cpp @@ -2,6 +2,18 @@ GL_Testing::GL_Testing() { + GLfloat tmp[] = { + + 1, 0, 0, 0, + 0, cos(1), sin(1), 0, + 0, -sin(1), cos(1), 0, + 0, 0, 0, 1 + + }; + + matrix = new GLfloat[16]; + memcpy(matrix, tmp, sizeof(GLfloat) * 16); + GLint err = glewInit(); if (err) { @@ -12,7 +24,6 @@ GL_Testing::GL_Testing() { void GL_Testing::compile_shader(std::string file_path, Shader_Type t) { - // Load in the source and cstring it const char* source; @@ -107,6 +118,31 @@ void GL_Testing::create_buffers() { glBindVertexArray(0); } +void GL_Testing::transform() +{ + GLuint transformLoc = glGetUniformLocation(shader_program, "transform"); + + glUseProgram(shader_program); + glUniformMatrix4fv(transformLoc, 1, GL_FALSE, matrix); +} + +void GL_Testing::rotate(double delta) { + + counter += delta; + + GLfloat tmp[] = { + + 1, 0, 0, 0, + 0, cos(counter), sin(counter), 0, + 0, -sin(counter), cos(counter), 0, + 0, 0, 0, 1 + + }; + + memcpy(matrix, tmp, sizeof(GLfloat) * 16); + +} + void GL_Testing::draw() { glUseProgram(shader_program); diff --git a/src/main.cpp b/src/main.cpp index 942f2f0..2a55ebe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,6 +73,7 @@ int main() { t.compile_shader("../shaders/passthrough.vert", GL_Testing::Shader_Type::VERTEX); t.create_program(); t.create_buffers(); + t.transform(); // Initialize the raycaster hardware, compat, or software RayCaster *rc = new Hardware_Caster(); @@ -231,9 +232,12 @@ int main() { window.popGLStates(); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + t.rotate(delta_time); + t.transform(); t.draw(); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); window.pushGLStates();