diff --git a/app.cc b/app.cc index 108c07a..4b348ec 100644 --- a/app.cc +++ b/app.cc @@ -3,12 +3,25 @@ #include "glcxx.hpp" #include "GL3/gl3w.h" #include +#include "glm/glm.hpp" +#include "glm/gtc/matrix_transform.hpp" using namespace std; std::shared_ptr program; std::shared_ptr cube_buffer; std::shared_ptr cube_array; +static struct +{ + GLint ambient; + GLint specular; + GLint shininess; + GLint tex; + GLint projection; + GLint modelview; +} uniforms; +glm::mat4 modelview; +glm::mat4 projection; #define WIDTH 800 #define HEIGHT 800 @@ -26,6 +39,12 @@ bool init(void) "position", 0, "normal", 1, "tex_coord", 2); + uniforms.ambient = program->get_uniform_location("ambient"); + uniforms.specular = program->get_uniform_location("specular"); + uniforms.shininess = program->get_uniform_location("shininess"); + uniforms.tex = program->get_uniform_location("tex"); + uniforms.projection = program->get_uniform_location("projection"); + uniforms.modelview = program->get_uniform_location("modelview"); cube_buffer = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, {-1, -1, -1, 0, 0, -1, 0, 0, @@ -40,6 +59,9 @@ bool init(void) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), NULL); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *)(3 * sizeof(GLfloat))); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *)(6 * sizeof(GLfloat))); + + modelview = glm::translate(glm::mat4(1.0), glm::vec3(0, 0, -3)); + projection = glm::perspective(60.0f, (float)WIDTH / (float)HEIGHT, 0.1f, 1000.0f); } catch (glcxx::Error & e) { @@ -52,6 +74,16 @@ bool init(void) void display(SDL_Window * window) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + program->use(); + cube_array->bind(); + glUniform4f(uniforms.ambient, 1.0, 1.0, 1.0, 1.0); + glUniform4f(uniforms.specular, 1.0, 1.0, 1.0, 1.0); + glUniform1f(uniforms.shininess, 1.0); + glUniformMatrix4fv(uniforms.modelview, 1, GL_FALSE, &modelview[0][0]); + glUniformMatrix4fv(uniforms.projection, 1, GL_FALSE, &projection[0][0]); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + SDL_GL_SwapWindow(window); }