set uniforms and draw a quad
This commit is contained in:
parent
27d9b1535e
commit
872dae3f6e
32
app.cc
32
app.cc
@ -3,12 +3,25 @@
|
|||||||
#include "glcxx.hpp"
|
#include "glcxx.hpp"
|
||||||
#include "GL3/gl3w.h"
|
#include "GL3/gl3w.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
#include "glm/gtc/matrix_transform.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
std::shared_ptr<glcxx::Program> program;
|
std::shared_ptr<glcxx::Program> program;
|
||||||
std::shared_ptr<glcxx::Buffer> cube_buffer;
|
std::shared_ptr<glcxx::Buffer> cube_buffer;
|
||||||
std::shared_ptr<glcxx::Array> cube_array;
|
std::shared_ptr<glcxx::Array> 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 WIDTH 800
|
||||||
#define HEIGHT 800
|
#define HEIGHT 800
|
||||||
@ -26,6 +39,12 @@ bool init(void)
|
|||||||
"position", 0,
|
"position", 0,
|
||||||
"normal", 1,
|
"normal", 1,
|
||||||
"tex_coord", 2);
|
"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,
|
cube_buffer = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW,
|
||||||
{-1, -1, -1, 0, 0, -1, 0, 0,
|
{-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(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(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)));
|
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)
|
catch (glcxx::Error & e)
|
||||||
{
|
{
|
||||||
@ -52,6 +74,16 @@ bool init(void)
|
|||||||
void display(SDL_Window * window)
|
void display(SDL_Window * window)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user