Compare commits

...

1 Commits

Author SHA1 Message Date
23b5188079 Fix code style project-wide 2023-03-30 19:26:18 +02:00
9 changed files with 499 additions and 462 deletions

View File

@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED true)
include_directories(deps)
include_directories(src/common)
include_directories("${CMAKE_SOURCE_DIR}/src")
file(GLOB_RECURSE Sources "src/**.cpp" "src/**.h")

View File

@@ -12,15 +12,14 @@ namespace polygun::engine {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Blocking3D", NULL, NULL);
if (window == NULL)
{
if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetCursorPosCallback(window, camera.mouse_callback);
glfwSetCursorPosCallback(window, m_camera.mouse_callback);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
if (glewInit() != GLEW_OK) {
@@ -76,10 +75,10 @@ namespace polygun::engine {
-0.1f, 0.1f, -0.1f, 0.0f, 1.0f
};
//32x32x32 chunk | ONLY FOR TEST THIS IS'NT EVEN A CHUNK
glm::vec3 cubePositions[1024];
glm::vec3 cube_positions[1024];
for(int i = 0; i < 1024; i++){
cubePositions[i] = glm::vec3(0.2f * (i % 32), 0.2f * (i / 32), 0.2f * (i / 32));
cube_positions[i] = glm::vec3(0.2f * (i % 32), 0.2f * (i / 32), 0.2f * (i / 32));
}
unsigned int VBO, VAO;
@@ -123,14 +122,16 @@ namespace polygun::engine {
chunk_shader.bind();
chunk_shader.setuniform("texture1", 0);
chunk_shader.set_uniform("texture1", 0);
m_delta_time = 0;
m_last_frame = 0;
while (!glfwWindowShouldClose(window))
{
float currentFrame = static_cast<float>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
float current_frame = static_cast<float>(glfwGetTime());
m_delta_time = current_frame - m_last_frame;
m_last_frame = current_frame;
// input
// -----
@@ -139,20 +140,20 @@ namespace polygun::engine {
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
camera.ProcessMovement(polygun::engine::FORWARD, deltaTime);
m_camera.process_movement(polygun::engine::FORWARD, m_delta_time);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
camera.ProcessMovement(polygun::engine::BACKWARD, deltaTime);
m_camera.process_movement(polygun::engine::BACKWARD, m_delta_time);
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
camera.ProcessMovement(LEFT, deltaTime);
m_camera.process_movement(LEFT, m_delta_time);
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
camera.ProcessMovement(polygun::engine::RIGHT, deltaTime);
m_camera.process_movement(polygun::engine::RIGHT, m_delta_time);
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
camera.ProcessMovement(polygun::engine::UP, deltaTime);
m_camera.process_movement(polygun::engine::UP, m_delta_time);
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
camera.ProcessMovement(polygun::engine::DOWN, deltaTime);
m_camera.process_movement(polygun::engine::DOWN, m_delta_time);
camera.Update();
m_camera.update();
// render
// ------
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
@@ -165,19 +166,19 @@ namespace polygun::engine {
// activate shader
chunk_shader.bind();
glm::mat4 projection = glm::perspective(glm::radians(camera.m_zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
chunk_shader.setuniform("projection", projection);
glm::mat4 projection = glm::perspective(glm::radians(m_camera.m_zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
chunk_shader.set_uniform("projection", projection);
glm::mat4 view = camera.GetViewMatrix();
chunk_shader.setuniform("view", view);
glm::mat4 view = m_camera.get_view_matrix();
chunk_shader.set_uniform("view", view);
glBindVertexArray(VAO);
for (unsigned int i = 0; i < (sizeof(cubePositions)/sizeof(*cubePositions)) ; i++)
for (unsigned int i = 0; i < (sizeof(cube_positions)/sizeof(*cube_positions)) ; i++)
{
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, cubePositions[i]);
model = glm::translate(model, cube_positions[i]);
float angle = 20.0f * i;
chunk_shader.setuniform("model", model);
chunk_shader.set_uniform("model", model);
glDrawArrays(GL_TRIANGLES, 0, 36);
}

View File

@@ -1,18 +1,19 @@
#ifndef POLYGUN_ENGINE_HPP
#define POLYGUN_ENGINE_HPP
#include "../core.hpp"
#include "../renderer/shader.hpp"
#include "player_camera.hpp"
#include "game/core.hpp"
#include "game/renderer/shader.hpp"
#include "game/engine/player_camera.hpp"
namespace polygun::engine {
class Engine {
private:
GLFWwindow* window;
Camera camera;
GLFWwindow* m_window;
Camera m_camera;
float deltaTime = 0.0f;
float lastFrame = 0.0f;
float m_delta_time;
float m_last_frame;
public:
Engine() = default;

View File

@@ -0,0 +1,113 @@
#include "game/engine/player_camera.hpp"
using namespace polygun::engine;
static float mx,my;
Camera::Camera(glm::vec3 position, glm::vec3 up, float yaw, float pitch) :
m_position(position),
m_front(glm::vec3(0.0f, 0.0f, -1.0f)),
m_up(),
m_right(),
m_worldup(up),
m_yaw(yaw),
m_pitch(pitch),
m_movement_speed(SPEED),
m_mouse_sensitivity(SENSITIVITY),
m_zoom(ZOOM),
m_last_x(SCR_WIDTH / 2.0f),
m_last_y(SCR_HEIGHT / 2.0f),
m_first_mouse(true)
{
update_camera_vectors();
}
Camera::Camera(float pos_x, float pos_y, float pos_z, float up_x, float up_y, float up_z, float yaw, float pitch) :
m_position(pos_x, pos_y, pos_z),
m_front(glm::vec3(0.0f, 0.0f, -1.0f)),
m_up(),
m_right(),
m_worldup(up_x, up_y, up_z),
m_yaw(yaw),
m_pitch(pitch),
m_movement_speed(SPEED),
m_mouse_sensitivity(SENSITIVITY),
m_zoom(ZOOM),
m_last_x(SCR_WIDTH / 2.0f),
m_last_y(SCR_HEIGHT / 2.0f),
m_first_mouse(true)
{
update_camera_vectors();
}
void Camera::update() {
if (m_first_mouse) {
m_last_x = mx;
m_last_y = my;
m_first_mouse = false;
}
float x_offset = mx - m_last_x;
float y_offset = m_last_y - my;
m_last_x = mx;
m_last_y = my;
process_mouse_movement(x_offset, y_offset);
}
void Camera::process_movement(camera_movement direction, float delta_time) {
float velocity = m_movement_speed * delta_time;
if (direction == FORWARD)
m_position += m_front * velocity;
if (direction == BACKWARD)
m_position -= m_front * velocity;
if (direction == LEFT)
m_position -= m_right * velocity;
if (direction == RIGHT)
m_position += m_right * velocity;
if (direction == UP)
m_position += glm::vec3(0.0F, 1.0F, 0.0F) * velocity;
if (direction == DOWN)
m_position += glm::vec3(0.0F, -1.0F, 0.0F) * velocity;
}
void Camera::process_mouse_movement(float x_offset, float y_offset, GLboolean constrain_pitch) {
x_offset *= m_mouse_sensitivity;
y_offset *= m_mouse_sensitivity;
m_yaw += x_offset;
m_pitch += y_offset;
if (constrain_pitch) {
if (m_pitch > 89.0f)
m_pitch = 89.0f;
if (m_pitch < -89.0f)
m_pitch = -89.0f;
}
update_camera_vectors();
}
void Camera::process_mouse_scroll(float y_offset) {
m_zoom -= y_offset;
if (m_zoom < 1.0f)
m_zoom = 1.0f;
if (m_zoom > 45.0f)
m_zoom = 45.0f;
}
void Camera::mouse_callback(GLFWwindow* window, double x_pos_in, double y_pos_in) {
mx = static_cast<float>(x_pos_in);
my = static_cast<float>(y_pos_in);
}
void Camera::update_camera_vectors() {
glm::vec3 front;
front.x = cos(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
front.y = sin(glm::radians(m_pitch));
front.z = sin(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
m_front = glm::normalize(front);
m_right = glm::normalize(glm::cross(m_front, m_worldup));
m_up = glm::normalize(glm::cross(m_right, m_front));
}

View File

@@ -1,7 +1,7 @@
#ifndef POLYGUN_ENGINE_CAMERA_H
#define POLYGUN_ENGINE_CAMERA_H
#include "../core.hpp"
#include "game/core.hpp"
namespace polygun::engine {
enum camera_movement {
@@ -19,8 +19,6 @@ namespace polygun::engine{
const float SENSITIVITY = 0.1f;
const float ZOOM = 45.0f;
static float mx,my;
class Camera {
public:
glm::vec3 m_position;
@@ -34,107 +32,26 @@ namespace polygun::engine{
float m_mouse_sensitivity;
float m_zoom;
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH);
Camera(float pos_x, float pos_y, float pos_z, float up_x, float up_y, float up_z, float yaw, float pitch);
Camera(glm::vec3 m_position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH) : m_front(glm::vec3(0.0f, 0.0f, -1.0f)), m_movement_speed(SPEED), m_mouse_sensitivity(SENSITIVITY), m_zoom(ZOOM) {
m_position = m_position;
m_worldup = up;
m_yaw = yaw;
m_pitch = pitch;
updateCameraVectors();
}
Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch) : m_front(glm::vec3(0.0f, 0.0f, -1.0f)), m_movement_speed(SPEED), m_mouse_sensitivity(SENSITIVITY), m_zoom(ZOOM) {
m_position = glm::vec3(posX, posY, posZ);
m_worldup = glm::vec3(upX, upY, upZ);
m_yaw = yaw;
m_pitch = pitch;
updateCameraVectors();
}
glm::mat4 GetViewMatrix() {
glm::mat4 get_view_matrix() const {
return glm::lookAt(m_position, m_position + m_front, m_up);
}
void Update(){
if (firstMouse)
{
lastX = mx;
lastY = my;
firstMouse = false;
}
float xoffset = mx - lastX;
float yoffset = lastY - my;
lastX = mx;
lastY = my;
ProcessMouseMovement(xoffset, yoffset);
}
void ProcessMovement(camera_movement direction, float deltaTime) {
float velocity = m_movement_speed * deltaTime;
if (direction == FORWARD)
m_position += m_front * velocity;
if (direction == BACKWARD)
m_position -= m_front * velocity;
if (direction == LEFT)
m_position -= m_right * velocity;
if (direction == RIGHT)
m_position += m_right * velocity;
if (direction == UP)
m_position += glm::vec3(0.0F, 1.0F, 0.0F) * velocity;
if (direction == DOWN)
m_position += glm::vec3(0.0F, -1.0F, 0.0F) * velocity;
}
void ProcessMouseMovement(float xoffset, float yoffset, GLboolean constrainPitch = true) {
xoffset *= m_mouse_sensitivity;
yoffset *= m_mouse_sensitivity;
m_yaw += xoffset;
m_pitch += yoffset;
if (constrainPitch)
{
if (m_pitch > 89.0f)
m_pitch = 89.0f;
if (m_pitch < -89.0f)
m_pitch = -89.0f;
}
updateCameraVectors();
}
void ProcessMouseScroll(float yoffset) {
m_zoom -= (float)yoffset;
if (m_zoom < 1.0f)
m_zoom = 1.0f;
if (m_zoom > 45.0f)
m_zoom = 45.0f;
}
static void mouse_callback(GLFWwindow* window, double xposIn, double yposIn) {
mx = static_cast<float>(xposIn);
my = static_cast<float>(yposIn);
}
void update();
void process_movement(camera_movement direction, float delta_time);
void process_mouse_movement(float x_offset, float y_offset, GLboolean constrain_pitch = true);
void process_mouse_scroll(float y_offset);
static void mouse_callback(GLFWwindow* window, double x_pos_in, double y_pos_in);
private:
void updateCameraVectors() {
glm::vec3 front;
front.x = cos(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
front.y = sin(glm::radians(m_pitch));
front.z = sin(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
m_front = glm::normalize(front);
m_right = glm::normalize(glm::cross(m_front, m_worldup));
m_up = glm::normalize(glm::cross(m_right, m_front));
}
void update_camera_vectors();
float lastX = SCR_WIDTH / 2.0f;
float lastY = SCR_HEIGHT / 2.0f;
bool firstMouse = true;
float m_last_x;
float m_last_y;
bool m_first_mouse;
};
}

View File

@@ -1,102 +1,130 @@
#include "shader.hpp"
#include "game/renderer/shader.hpp"
namespace polygun::renderer {
Shader::Shader(const char* vertexPath, const char* fragmentPath) {
std::string vertexCode;
std::string fragmentCode;
std::ifstream vShaderFile;
std::ifstream fShaderFile;
vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
try
{
vShaderFile.open(vertexPath);
fShaderFile.open(fragmentPath);
std::stringstream vShaderStream, fShaderStream;
vShaderStream << vShaderFile.rdbuf();
fShaderStream << fShaderFile.rdbuf();
vShaderFile.close();
fShaderFile.close();
vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
Shader::Shader() :
m_program(0)
{}
Shader::Shader(const GLuint id) :
m_program(id)
{}
Shader::Shader(const char* vertex_path, const char* fragment_path) {
std::string vertex_code;
std::string fragment_code;
std::ifstream v_shader_file;
std::ifstream f_shader_file;
v_shader_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
f_shader_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try {
v_shader_file.open(vertex_path);
f_shader_file.open(fragment_path);
std::stringstream v_shader_stream, f_shader_stream;
v_shader_stream << v_shader_file.rdbuf();
f_shader_stream << f_shader_file.rdbuf();
v_shader_file.close();
f_shader_file.close();
vertex_code = v_shader_stream.str();
fragment_code = f_shader_stream.str();
}
catch (std::ifstream::failure& e)
{
catch (std::ifstream::failure& e) {
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ: " << e.what() << std::endl;
}
const char* vShaderCode = vertexCode.c_str();
const char * fShaderCode = fragmentCode.c_str();
const char* v_shader_code = vertex_code.c_str();
const char * f_shader_code = fragment_code.c_str();
unsigned int vertex, fragment;
vertex = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex, 1, &vShaderCode, NULL);
glShaderSource(vertex, 1, &v_shader_code, NULL);
glCompileShader(vertex);
checkCompileErrors(vertex, "VERTEX");
check_compile_errors(vertex, "VERTEX");
fragment = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment, 1, &fShaderCode, NULL);
glShaderSource(fragment, 1, &f_shader_code, NULL);
glCompileShader(fragment);
checkCompileErrors(fragment, "FRAGMENT");
program = glCreateProgram();
glAttachShader(program, vertex);
glAttachShader(program, fragment);
glLinkProgram(program);
checkCompileErrors(program, "PROGRAM");
check_compile_errors(fragment, "FRAGMENT");
m_program = glCreateProgram();
glAttachShader(m_program, vertex);
glAttachShader(m_program, fragment);
glLinkProgram(m_program);
check_compile_errors(m_program, "PROGRAM");
glDeleteShader(vertex);
glDeleteShader(fragment);
}
Shader::~Shader() {
glDeleteProgram(m_program);
}
void Shader::bind() {
glUseProgram(program);
glUseProgram(m_program);
}
void Shader::unbind() {
glUseProgram(0);
}
void Shader::setuniform(const GLchar* uName, unsigned int value){
glUniform1i(glGetUniformLocation(program, uName), value);
void Shader::set_uniform(const GLchar* u_name, unsigned int value) {
glUniform1i(glGetUniformLocation(m_program, u_name), value);
}
void Shader::setuniform(const GLchar* uName, int value){
glUniform1i(glGetUniformLocation(program, uName), value);
void Shader::set_uniform(const GLchar* u_name, int value) {
glUniform1i(glGetUniformLocation(m_program, u_name), value);
}
void Shader::setuniform(const GLchar* uName, GLfloat value){
glUniform1i(glGetUniformLocation(program, uName), value);
void Shader::set_uniform(const GLchar* u_name, GLfloat value) {
glUniform1i(glGetUniformLocation(m_program, u_name), value);
}
void Shader::setuniform(const GLchar* uName, GLfloat x, GLfloat y){
glUniform2f(glGetUniformLocation(program, uName), x, y);
void Shader::set_uniform(const GLchar* u_name, GLfloat x, GLfloat y) {
glUniform2f(glGetUniformLocation(m_program, u_name), x, y);
}
void Shader::setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z){
glUniform3f(glGetUniformLocation(program, uName), x, y, z);
void Shader::set_uniform(const GLchar* u_name, GLfloat x, GLfloat y, GLfloat z) {
glUniform3f(glGetUniformLocation(m_program, u_name), x, y, z);
}
void Shader::setuniform(const GLchar* uName, glm::vec3 vector){
glUniform3f(glGetUniformLocation(program, uName), vector.x, vector.y, vector.z);
void Shader::set_uniform(const GLchar* u_name, const glm::vec3& vector) {
glUniform3f(glGetUniformLocation(m_program, u_name), vector.x, vector.y, vector.z);
}
void Shader::setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z, GLfloat w){
glUniform4f(glGetUniformLocation(program, uName), x, y, z, w);
void Shader::set_uniform(const GLchar* u_name, GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
glUniform4f(glGetUniformLocation(m_program, u_name), x, y, z, w);
}
void Shader::setuniform(const GLchar* name, const glm::mat4 &mat)
{
glUniformMatrix4fv(glGetUniformLocation(program, name), 1, GL_FALSE, &mat[0][0]);
void Shader::set_uniform(const GLchar* name, const glm::mat4 &mat) {
glUniformMatrix4fv(glGetUniformLocation(m_program, name), 1, GL_FALSE, &mat[0][0]);
}
void Shader::setuniform(const GLchar* uName, glm::vec2 vector){
glUniform2f(glGetUniformLocation(program, uName), vector.x, vector.y);
void Shader::set_uniform(const GLchar* u_name, const glm::vec2& vector) {
glUniform2f(glGetUniformLocation(m_program, u_name), vector.x, vector.y);
}
void Shader::setuniform(const GLchar* uName, glm::vec4 vector){
glUniform4f(glGetUniformLocation(program, uName), vector.x, vector.y, vector.z, vector.w);
void Shader::set_uniform(const GLchar* u_name, const glm::vec4& vector){
glUniform4f(glGetUniformLocation(m_program, u_name), vector.x, vector.y, vector.z, vector.w);
}
void Shader::setuniform(const GLchar* uName, GLuint tex2d, GLint unit){ // sample 2d
void Shader::set_uniform(const GLchar* u_name, GLuint tex2d, GLint unit){ // sample 2d
glActiveTexture(GL_TEXTURE0 + unit);
glBindTexture(GL_TEXTURE_2D, tex2d);
glUniform1i(glGetUniformLocation(program, uName), unit);
glUniform1i(glGetUniformLocation(m_program, u_name), unit);
}
void Shader::check_compile_errors(GLuint shader, const std::string& type) {
GLint success;
GLchar info_log[1024];
if(type != "PROGRAM") {
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if(!success) {
glGetShaderInfoLog(shader, 1024, NULL, info_log);
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << info_log << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
else {
glGetProgramiv(shader, GL_LINK_STATUS, &success);
if(!success) {
glGetProgramInfoLog(shader, 1024, NULL, info_log);
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << info_log << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
}
}

View File

@@ -1,60 +1,37 @@
#ifndef POLYGUN_RENDERER_SHADER_H
#define POLYGUN_RENDERER_SHADER_H
#include "../core.hpp"
#include "game/core.hpp"
namespace polygun::renderer {
class Shader {
public:
Shader() : program(0) {}
Shader(const GLuint id) : program(id) {}
Shader(const char* vertexPath, const char* fragmentPath);
~Shader() { glDeleteProgram(program); }
Shader();
Shader(const GLuint id);
Shader(const char* vertex_path, const char* fragment_path);
~Shader();
void bind();
void unbind();
void setuniform(const GLchar* uName, unsigned int value);
void setuniform(const GLchar* uName, int value);
void setuniform(const GLchar* uName, GLfloat value);
void setuniform(const GLchar* uName, GLfloat x, GLfloat y);
void setuniform(const GLchar* uName, glm::vec2 vector);
void setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z);
void setuniform(const GLchar* uName, glm::vec3 vector);
void setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void setuniform(const GLchar* uName, glm::vec4 vector);
void setuniform(const GLchar* uName, const glm::mat4& mtx);
void setuniform(const GLchar* uName, GLuint tex2d, GLint unit); // sample 2d
void set_uniform(const GLchar* u_name, unsigned int value);
void set_uniform(const GLchar* u_name, int value);
void set_uniform(const GLchar* u_name, GLfloat value);
void set_uniform(const GLchar* u_name, GLfloat x, GLfloat y);
void set_uniform(const GLchar* u_name, const glm::vec2& vector);
void set_uniform(const GLchar* u_name, GLfloat x, GLfloat y, GLfloat z);
void set_uniform(const GLchar* u_name, const glm::vec3& vector);
void set_uniform(const GLchar* u_name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void set_uniform(const GLchar* u_name, const glm::vec4& vector);
void set_uniform(const GLchar* u_name, const glm::mat4& mtx);
void set_uniform(const GLchar* u_name, GLuint tex2d, GLint unit); // sample 2d
GLuint getuniform(const char* name);
GLuint getprogram() { return program; }
GLuint get_uniform(const char* name) const;
GLuint get_program() const { return m_program; }
private:
void check_compile_errors(GLuint shader, const std::string& type);
void checkCompileErrors(GLuint shader, std::string type)
{
GLint success;
GLchar infoLog[1024];
if(type != "PROGRAM")
{
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if(!success)
{
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
else
{
glGetProgramiv(shader, GL_LINK_STATUS, &success);
if(!success)
{
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
}
GLuint program;
GLuint m_program;
};
}