Linux build working again, removed the GL_Testing stuff, I'm going to move to Vulkan eventually. Got voxel search working mostly with the new octree changes. Issue with mirroring of voxel data currently
parent
04842dd597
commit
5e9401cd27
@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <util.hpp>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
|
||||
#elif defined TARGET_OS_MAC
|
||||
#include <OpenGL/gl.h>
|
||||
|
||||
#endif
|
||||
|
||||
class GL_Testing
|
||||
{
|
||||
public:
|
||||
GL_Testing();
|
||||
~GL_Testing(){};
|
||||
|
||||
|
||||
enum Shader_Type {VERTEX, FRAGMENT};
|
||||
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:
|
||||
|
||||
GLuint VBO; //raw points
|
||||
GLuint EBO; //link triangles
|
||||
GLuint VAO;
|
||||
GLuint vertex_shader;
|
||||
GLuint fragment_shader;
|
||||
GLuint shader_program;
|
||||
|
||||
GLfloat *matrix;
|
||||
|
||||
double counter = 0;
|
||||
};
|
||||
|
@ -1,199 +0,0 @@
|
||||
#include "GL_Testing.h"
|
||||
|
||||
GL_Testing::GL_Testing() {
|
||||
|
||||
GLfloat tmp[] = {
|
||||
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, static_cast<float>(cos(1.0f)), static_cast<float>(sin(1.0f)), 0.0f,
|
||||
0.0f, static_cast<float>(-sin(1.0f)), static_cast<float>(cos(1.0f)), 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
|
||||
};
|
||||
|
||||
matrix = new GLfloat[16];
|
||||
memcpy(matrix, tmp, sizeof(GLfloat) * 16);
|
||||
|
||||
#ifdef linux
|
||||
GLint err = glewInit();
|
||||
#elif _WIN32
|
||||
GLint err = glewInit();
|
||||
#elif TARGET_OS_MAC
|
||||
GLint err = 0;
|
||||
#endif
|
||||
|
||||
if (err) {
|
||||
std::cout << "error initializing glew" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GL_Testing::compile_shader(std::string file_path, Shader_Type t) {
|
||||
|
||||
|
||||
// Load in the source and cstring it
|
||||
const char* source;
|
||||
std::string tmp;
|
||||
|
||||
tmp = read_file(file_path);
|
||||
source = tmp.c_str();
|
||||
|
||||
GLint success;
|
||||
GLchar log[512];
|
||||
|
||||
if (t == Shader_Type::VERTEX) {
|
||||
|
||||
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, &source, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
|
||||
glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success);
|
||||
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(vertex_shader, 512, NULL, log);
|
||||
std::cout << "Vertex shader failed compilation: " << log << std::endl;
|
||||
}
|
||||
|
||||
} else if (t == Shader_Type::FRAGMENT) {
|
||||
|
||||
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, &source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success);
|
||||
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(fragment_shader, 512, NULL, log);
|
||||
std::cout << "Vertex shader failed compilation: " << log << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GL_Testing::create_program() {
|
||||
|
||||
GLint success;
|
||||
GLchar log[512];
|
||||
|
||||
shader_program = glCreateProgram();
|
||||
glAttachShader(shader_program, vertex_shader);
|
||||
glAttachShader(shader_program, fragment_shader);
|
||||
glLinkProgram(shader_program);
|
||||
|
||||
|
||||
glGetProgramiv(shader_program, GL_LINK_STATUS, &success);
|
||||
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(shader_program, 512, NULL, log);
|
||||
std::cout << "Failed to link shaders into program: " << log << std::endl;
|
||||
}
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
}
|
||||
|
||||
void GL_Testing::create_buffers() {
|
||||
|
||||
GLfloat vertices[] = {
|
||||
0.5f, 0.5f, 0.0f, // Top Right
|
||||
0.5f, -0.5f, 0.0f, // Bottom Right
|
||||
-0.5f, -0.5f, 0.0f, // Bottom Left
|
||||
-0.5f, 0.5f, 0.0f // Top Left
|
||||
};
|
||||
GLuint indices[] = { // Note that we start from 0!
|
||||
0, 1, 3 // First Triangle
|
||||
// Second Triangle
|
||||
};
|
||||
|
||||
#ifdef linux
|
||||
glGenVertexArrays(1, &VAO);
|
||||
#elif defined _WIN32
|
||||
glGenVertexArrays(1, &VAO);
|
||||
#elif defined TARGET_OS_MAC
|
||||
glGenVertexArraysAPPLE(1, &VAO);
|
||||
#endif
|
||||
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenBuffers(1, &EBO);
|
||||
// Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
|
||||
|
||||
#ifdef linux
|
||||
glBindVertexArray(VAO);
|
||||
#elif defined _WIN32
|
||||
glBindVertexArray(VAO);
|
||||
#elif defined TARGET_OS_MAC
|
||||
glBindVertexArrayAPPLE(VAO);
|
||||
#endif
|
||||
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
#ifdef linux
|
||||
glbindvertexarray(0);
|
||||
#elif defined _win32
|
||||
glbindvertexarray(0);
|
||||
#elif defined target_os_mac
|
||||
glbindvertexarrayapple(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
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.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, static_cast<float>(cos(counter)), static_cast<float>(sin(counter)), 0.0f,
|
||||
0.0f, static_cast<float>(-sin(counter)), static_cast<float>(cos(counter)), 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
|
||||
};
|
||||
|
||||
memcpy(matrix, tmp, sizeof(GLfloat) * 16);
|
||||
|
||||
}
|
||||
|
||||
void GL_Testing::draw() {
|
||||
|
||||
glUseProgram(shader_program);
|
||||
|
||||
#ifdef linux
|
||||
glBindVertexArray(VAO);
|
||||
#elif defined _WIN32
|
||||
glBindVertexArray(VAO);
|
||||
#elif defined TARGET_OS_MAC
|
||||
glBindVertexArrayAPPLE(VAO);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
|
||||
|
||||
#ifdef linux
|
||||
glbindVertexArray(0);
|
||||
#elif defined _win32
|
||||
glbindVertexArray(0);
|
||||
#elif defined target_os_mac
|
||||
glbindVertexArrayAPPLE(0);
|
||||
#endif
|
||||
|
||||
}
|
||||
//
|
Loading…
Reference in new issue