Got some geometry up and rotating. It will be pretty trivial to pass in
the camera rotation now and have it follow along.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user