|
|
|
@ -21,259 +21,19 @@
@@ -21,259 +21,19 @@
|
|
|
|
|
#include <stack> |
|
|
|
|
#include <set> |
|
|
|
|
#include <fmt/core.h> |
|
|
|
|
#include <optional> |
|
|
|
|
|
|
|
|
|
#include "shaders.h" |
|
|
|
|
#include "mesh.h" |
|
|
|
|
#include "stb_image.h" |
|
|
|
|
#include "glerror.h" |
|
|
|
|
#include "errors.h" |
|
|
|
|
#include "glutil.h" |
|
|
|
|
#include "defaultobjects/cubemap.h" |
|
|
|
|
#include "drawing.h" |
|
|
|
|
#include "level.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char * DATA_DIR = "data"; |
|
|
|
|
const char * OBJ_DIR = "data/objects"; |
|
|
|
|
const char * SHADER_DIR = "data/shaders"; |
|
|
|
|
const char * SKYBOX_DIR = "data/objects/cubemaps"; |
|
|
|
|
|
|
|
|
|
GLenum glCheckError_(const char *file, int line) |
|
|
|
|
{ |
|
|
|
|
GLenum errorCode; |
|
|
|
|
while ((errorCode = glGetError()) != GL_NO_ERROR) |
|
|
|
|
{ |
|
|
|
|
std::string error; |
|
|
|
|
switch (errorCode) |
|
|
|
|
{ |
|
|
|
|
case GL_INVALID_ENUM: error = "INVALID_ENUM"; break; |
|
|
|
|
case GL_INVALID_VALUE: error = "INVALID_VALUE"; break; |
|
|
|
|
case GL_INVALID_OPERATION: error = "INVALID_OPERATION"; break; |
|
|
|
|
case GL_STACK_OVERFLOW: error = "STACK_OVERFLOW"; break; |
|
|
|
|
case GL_STACK_UNDERFLOW: error = "STACK_UNDERFLOW"; break; |
|
|
|
|
case GL_OUT_OF_MEMORY: error = "OUT_OF_MEMORY"; break; |
|
|
|
|
case GL_INVALID_FRAMEBUFFER_OPERATION: error = "INVALID_FRAMEBUFFER_OPERATION"; break; |
|
|
|
|
} |
|
|
|
|
std::cerr << error << " | " << file << " (" << line << ")" << std::endl; |
|
|
|
|
} |
|
|
|
|
return errorCode; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Cubemap { |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
unsigned int id; |
|
|
|
|
|
|
|
|
|
Cubemap(std::vector<std::string> texture_faces) { |
|
|
|
|
|
|
|
|
|
/* faces must be provided in the order:
|
|
|
|
|
* |
|
|
|
|
* right, left, top, bottom, front, back |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
int width, height, nrChannels; |
|
|
|
|
|
|
|
|
|
stbi_set_flip_vertically_on_load(false); |
|
|
|
|
|
|
|
|
|
glGenTextures(1, &id); |
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, id); |
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < texture_faces.size(); i++) { |
|
|
|
|
unsigned char *data = stbi_load(texture_faces[i].c_str(),
|
|
|
|
|
&width, &height, &nrChannels, 0); |
|
|
|
|
|
|
|
|
|
if (data) { |
|
|
|
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB,
|
|
|
|
|
width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); |
|
|
|
|
glCheckError(); |
|
|
|
|
stbi_image_free(data); |
|
|
|
|
} else { |
|
|
|
|
A_ERROR(fmt::format("Load cubemap face {}\n", texture_faces[i])); |
|
|
|
|
stbi_image_free(data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// handles shaders, models, meshes for drawing a collection of similar objects
|
|
|
|
|
class drawing_object_handle { |
|
|
|
|
public: |
|
|
|
|
virtual void draw(const glm::mat4 view, const glm::mat4 projection) = 0; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class simple_object_draw_system : public drawing_object_handle { |
|
|
|
|
Shader *shader; |
|
|
|
|
|
|
|
|
|
struct object { |
|
|
|
|
glm::vec3 position; |
|
|
|
|
glm::mat4 orientation; |
|
|
|
|
Model model; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::vector<object> objects; |
|
|
|
|
std::set<int> do_not_draw; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
simple_object_draw_system(Shader *shader) : shader(shader) {} |
|
|
|
|
|
|
|
|
|
int add(Model model, glm::vec3 position, glm::mat4 orientation) { |
|
|
|
|
objects.push_back({position, orientation, model}); |
|
|
|
|
return objects.size() - 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void remove(int i) { |
|
|
|
|
do_not_draw.insert(i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void return_to_draw_list(int i) { |
|
|
|
|
do_not_draw.erase(i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void draw(const glm::mat4 view, const glm::mat4 projection) override { |
|
|
|
|
shader->use(); |
|
|
|
|
|
|
|
|
|
int loc = shader->get_uniform("projection"); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
|
|
|
|
|
int i = 0; |
|
|
|
|
for (auto obj: objects) { |
|
|
|
|
if (do_not_draw.count(i++)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int loc = shader->get_uniform("model"); |
|
|
|
|
glCheckError(); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(obj.orientation)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
auto this_view = glm::translate(view, obj.position); |
|
|
|
|
loc = shader->get_uniform("view"); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(this_view)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
obj.model.draw(*shader); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Draw a lot of the same object. */ |
|
|
|
|
class instanced_drawing : public drawing_object_handle { |
|
|
|
|
public: |
|
|
|
|
struct object { |
|
|
|
|
glm::vec3 position; |
|
|
|
|
glm::mat4 model; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
std::vector<object> models; |
|
|
|
|
|
|
|
|
|
Model *model; |
|
|
|
|
Shader *shader; |
|
|
|
|
|
|
|
|
|
unsigned int instance_VBO; |
|
|
|
|
public: |
|
|
|
|
instanced_drawing (Model *model, Shader *shader, std::vector<object> obj_models)
|
|
|
|
|
: models(obj_models), model(model), shader(shader)
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
instanced_drawing (Model *model, Shader *shader) |
|
|
|
|
: model(model), shader(shader)
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
int finalize () { |
|
|
|
|
glGenBuffers(1, &instance_VBO); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, instance_VBO); |
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(object) * models.size(), &models[0], GL_STATIC_DRAW); |
|
|
|
|
glVertexAttribPointer(3,3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), NULL); |
|
|
|
|
glVertexAttribPointer(5,16, GL_FLOAT, GL_FALSE, 16 * sizeof(float), (void *)offsetof(object, model)); |
|
|
|
|
|
|
|
|
|
glVertexAttribDivisor(3,1); |
|
|
|
|
glVertexAttribDivisor(5,1); |
|
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(3); |
|
|
|
|
glEnableVertexAttribArray(5); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int add(glm::vec3 position, glm::mat4 orientation) { |
|
|
|
|
models.push_back({position, orientation}); |
|
|
|
|
return models.size() - 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void draw(const glm::mat4 view, const glm::mat4 projection) override { |
|
|
|
|
shader->use(); |
|
|
|
|
|
|
|
|
|
int loc = shader->get_uniform("projection"); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glDrawArraysInstanced(GL_TRIANGLES, 0,36,1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class drawing_system { |
|
|
|
|
|
|
|
|
|
std::vector<drawing_object_handle *> draw_systems; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
void add_system(drawing_object_handle *obj) { |
|
|
|
|
draw_systems.push_back(obj); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void run (void) { |
|
|
|
|
for (auto a : draw_systems) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void printProgramLog( GLuint program ) |
|
|
|
|
{ |
|
|
|
|
//Make sure name is shader
|
|
|
|
|
if( glIsProgram( program ) ) |
|
|
|
|
{ |
|
|
|
|
//Program loglength
|
|
|
|
|
int infoLogLength = 0; |
|
|
|
|
int maxLength = infoLogLength; |
|
|
|
|
|
|
|
|
|
//Get info string length
|
|
|
|
|
glGetProgramiv( program, GL_INFO_LOG_LENGTH, &maxLength ); |
|
|
|
|
|
|
|
|
|
//Allocate string
|
|
|
|
|
char* infoLog = new char[ maxLength ]; |
|
|
|
|
|
|
|
|
|
//Get info log
|
|
|
|
|
glGetProgramInfoLog( program, maxLength, &infoLogLength, infoLog ); |
|
|
|
|
if( infoLogLength > 0 ) |
|
|
|
|
{ |
|
|
|
|
//Print Log
|
|
|
|
|
printf( "%s\n", infoLog ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Deallocate string
|
|
|
|
|
delete[] infoLog; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
printf( "Name %d is not a program\n", program ); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SDLGLGLWindow { |
|
|
|
@ -312,15 +72,16 @@ class SDLGLGLWindow {
@@ -312,15 +72,16 @@ class SDLGLGLWindow {
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
level * running_level; |
|
|
|
|
|
|
|
|
|
Shader *shader; |
|
|
|
|
Shader *modelShader; |
|
|
|
|
Shader *texShader; |
|
|
|
|
Shader *skyboxShader; |
|
|
|
|
Model *bp_model; |
|
|
|
|
Shader *modelShader; |
|
|
|
|
|
|
|
|
|
Shader *skyboxShader; |
|
|
|
|
Shader *texShader; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int skybox_object; |
|
|
|
|
int screen_width; |
|
|
|
|
int screen_height; |
|
|
|
|
unsigned int framebuffer; |
|
|
|
@ -413,28 +174,114 @@ class SDLGLGLWindow {
@@ -413,28 +174,114 @@ class SDLGLGLWindow {
|
|
|
|
|
std::cerr << "Creating msbuffers"
|
|
|
|
|
<< SDL_GetError() << std::endl ; |
|
|
|
|
|
|
|
|
|
// now we can load level
|
|
|
|
|
fmt::print("loading level\n"); |
|
|
|
|
running_level = new level(("data/levels/init.json")); |
|
|
|
|
//Initialize OpenGL
|
|
|
|
|
if( !initGL() ) |
|
|
|
|
{ |
|
|
|
|
std::cerr << "Unable to initialie OpenGL!" << std::endl; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
shader = &running_level->shaders[0]; |
|
|
|
|
initGL(); |
|
|
|
|
// init_level();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glEnable(GL_MULTISAMPLE); |
|
|
|
|
glGetError(); |
|
|
|
|
|
|
|
|
|
// shader = &running_level->shaders[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* assumes level is loaded */ |
|
|
|
|
int init_level() { |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Basic Shaders |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
texShader = new Shader("data/shaders/screentexture.vert", "data/shaders/screentexture.frag"); |
|
|
|
|
skyboxShader = new Shader("data/shaders/sky.vert", "data/shaders/sky.frag"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool success = true; |
|
|
|
|
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f)); |
|
|
|
|
projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* MSAA FRAMEBUFFERS */ |
|
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &framebuffer); |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
|
|
|
|
// create a multisampled color attachment texture
|
|
|
|
|
glGenTextures(1, &textureColorBufferMultiSampledHDR); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampledHDR); |
|
|
|
|
|
|
|
|
|
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA16F, screen_width, screen_height, GL_TRUE); |
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); |
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampledHDR, 0); |
|
|
|
|
// create a (also multisampled) renderbuffer object for depth and stencil attachments
|
|
|
|
|
glGenRenderbuffers(1, &rbo); |
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
|
|
|
|
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, screen_width, screen_height); |
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, 0); |
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo); |
|
|
|
|
|
|
|
|
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) |
|
|
|
|
std::cout << "ERROR::FRAMEBUFFER:: Framebuffer is not complete!" << std::endl; |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
|
|
|
|
|
|
// configure second post-processing framebuffer
|
|
|
|
|
glGenFramebuffers(1, &intermediateFBO); |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, intermediateFBO); |
|
|
|
|
// create a color attachment texture
|
|
|
|
|
glGenTextures(1, &screenTexture); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, screenTexture); |
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_width, screen_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, screenTexture, 0); // we only need a color buffer
|
|
|
|
|
|
|
|
|
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) |
|
|
|
|
std::cout << "ERROR::FRAMEBUFFER:: Intermediate framebuffer is not complete!" << std::endl; |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
|
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); |
|
|
|
|
glEnable(GL_BLEND); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********** CUBEMAPS ***************/ |
|
|
|
|
|
|
|
|
|
std::vector<std::string> faces { |
|
|
|
|
fmt::format("{}/sky/right.png", SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/left.png",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/up.png",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/down.png",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/front.png",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/back.png",SKYBOX_DIR), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Cubemap c (faces); |
|
|
|
|
cubemap = c.id; |
|
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &lightVAO); |
|
|
|
|
glBindVertexArray(lightVAO); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int initGL() { |
|
|
|
|
//Success flag
|
|
|
|
|
bool success = true; |
|
|
|
|
//Generate program
|
|
|
|
|
shader = new Shader("data/shaders/test.vert", "data/shaders/test.frag"); |
|
|
|
|
modelShader = new Shader("data/shaders/test.vert", "data/shaders/test.frag"); |
|
|
|
|
//shader = new Shader("data/shaders/instanced.vert", "data/shaders/test.frag");
|
|
|
|
|
modelShader = new Shader("data/shaders/instanced.vert", "data/shaders/test.frag"); |
|
|
|
|
texShader = new Shader("data/shaders/screentexture.vert", "data/shaders/screentexture.frag"); |
|
|
|
|
skyboxShader = new Shader("data/shaders/sky.vert", "data/shaders/sky.frag"); |
|
|
|
|
glCheckError(); |
|
|
|
@ -442,17 +289,23 @@ class SDLGLGLWindow {
@@ -442,17 +289,23 @@ class SDLGLGLWindow {
|
|
|
|
|
objects = new simple_object_draw_system(shader); |
|
|
|
|
|
|
|
|
|
//modelShader->use();
|
|
|
|
|
stbi_set_flip_vertically_on_load(true); |
|
|
|
|
objects->add(Model(fmt::format("{}/backpack/backpack.obj", OBJ_DIR)), {0,0,0}, glm::mat4(1.0)); |
|
|
|
|
// objects->add(new Model(fmt::format("{}/backpack/backpack.obj", OBJ_DIR)), {0,0,0}, glm::mat4(1.0));
|
|
|
|
|
|
|
|
|
|
stbi_set_flip_vertically_on_load(false); |
|
|
|
|
// auto un = objects->add(Model(fmt::format("{}/untitled/untitled.obj", OBJ_DIR)), {10,0,0}, glm::mat4(1.0));
|
|
|
|
|
// objects->remove(un);
|
|
|
|
|
// skybox_object = un;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// objects->add(Model(fmt::format("{}/round/round.obj", OBJ_DIR)), {0,-5,0}, glm::mat4(1.0));
|
|
|
|
|
|
|
|
|
|
objects->add(Model(fmt::format("{}/round/round.obj", OBJ_DIR)), {0,-5,0}, glm::mat4(1.0)); |
|
|
|
|
|
|
|
|
|
//Link program
|
|
|
|
|
stbi_set_flip_vertically_on_load(true); |
|
|
|
|
|
|
|
|
|
//modelShader->use();
|
|
|
|
|
bp_model = new Model(fmt::format("{}/backpack/backpack.obj", OBJ_DIR)); |
|
|
|
|
// bp_model = new Model(fmt::format("{}/backpack/backpack.obj", OBJ_DIR));
|
|
|
|
|
glCheckError(); |
|
|
|
|
//shader->use();
|
|
|
|
|
|
|
|
|
@ -708,12 +561,12 @@ class SDLGLGLWindow {
@@ -708,12 +561,12 @@ class SDLGLGLWindow {
|
|
|
|
|
/********** CUBEMAPS ***************/ |
|
|
|
|
|
|
|
|
|
std::vector<std::string> faces { |
|
|
|
|
fmt::format("{}/sky/right.jpg", SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/left.jpg",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/top.jpg",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/bottom.jpg",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/front.jpg",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/back.jpg",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/right.png", SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/left.png",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/up.png",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/down.png",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/front.png",SKYBOX_DIR), |
|
|
|
|
fmt::format("{}/sky/back.png",SKYBOX_DIR), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
stbi_set_flip_vertically_on_load(false); |
|
|
|
@ -755,9 +608,6 @@ class SDLGLGLWindow {
@@ -755,9 +608,6 @@ class SDLGLGLWindow {
|
|
|
|
|
glEnableVertexAttribArray(0); |
|
|
|
|
glBindVertexArray(quadVAO); |
|
|
|
|
glCheckError(); |
|
|
|
|
/*********** LIGHTS ****************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return success; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -783,74 +633,59 @@ class SDLGLGLWindow {
@@ -783,74 +633,59 @@ class SDLGLGLWindow {
|
|
|
|
|
|
|
|
|
|
float timeVal = SDL_GetTicks() / 1000.0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Bind program
|
|
|
|
|
shader->use(); |
|
|
|
|
printProgramLog(shader->program); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
// shader->setInt("num_lights", 1);
|
|
|
|
|
// shader->setInt("lights[0].type", 1);
|
|
|
|
|
// shader->setFloat("lights[0].angle_cutoff", glm::cos(glm::radians(12.5f)));
|
|
|
|
|
// shader->setFloat("lights[0].outer_angle_cutoff", glm::cos(glm::radians(17.5f)));
|
|
|
|
|
//
|
|
|
|
|
// shader->setVec3("lights[0].direction", glm::vec3(0,-1,0));
|
|
|
|
|
/// shader->setVec3("lights[0].position", camera_pos);
|
|
|
|
|
//
|
|
|
|
|
// shader->setVec3("lights[0].position", lightPositions[0]);
|
|
|
|
|
// shader->setVec3("lights[0].ambient", glm::vec3(0.5));
|
|
|
|
|
// shader->setVec3("lights[0].diffuse", glm::vec3(0.9,0.7,1.0) * glm::vec3(10));
|
|
|
|
|
// shader->setVec3("lights[0].specular", glm::vec3(1.0));
|
|
|
|
|
// shader->setBool("lights[0].attenuate", false);
|
|
|
|
|
// shader->setVec3("lights[0].attenuation", glm::vec3(1.0, 0.09, 0.032));
|
|
|
|
|
//
|
|
|
|
|
// shader->setInt("lights[1].type", 1);
|
|
|
|
|
// shader->setVec3("lights[1].position", lightPositions[1]);
|
|
|
|
|
// shader->setVec3("lights[1].ambient", glm::vec3(0.1));
|
|
|
|
|
// shader->setVec3("lights[1].diffuse", glm::vec3(0.6, 0.4, 0.4));
|
|
|
|
|
// shader->setVec3("lights[1].specular", glm::vec3(1.0));
|
|
|
|
|
// shader->setBool("lights[1].attenuate", false);
|
|
|
|
|
// shader->setVec3("lights[1].attenuation", glm::vec3(1.0, 0.09, 0.032));
|
|
|
|
|
//
|
|
|
|
|
// shader->setInt("lights[2].type", 0);
|
|
|
|
|
// shader->setVec3("lights[2].position", lightPositions[1]);
|
|
|
|
|
//
|
|
|
|
|
// shader->setVec3("lights[2].ambient", glm::vec3(0.1));
|
|
|
|
|
// shader->setVec3("lights[2].diffuse", glm::vec3(0.3, 0.4, 0.6));
|
|
|
|
|
// shader->setVec3("lights[2].specular", glm::vec3(0.3, 1.0, 0.5));
|
|
|
|
|
// shader->setBool("lights[2].attenuate", false);
|
|
|
|
|
// shader->setVec3("lights[2].attenuation", glm::vec3(1.0, 0.09, 0.032));
|
|
|
|
|
//
|
|
|
|
|
shader->setVec3("material.specular", glm::vec3(0.7)); |
|
|
|
|
shader->setVec3("material.diffuse", glm::vec3(1.0, 0.7, 0.8)); |
|
|
|
|
shader->setVec3("material.ambient", glm::vec3(0.2)); |
|
|
|
|
shader->setFloat("material.shininess", 32); |
|
|
|
|
glCheckError(); |
|
|
|
|
glUniform3f(glGetUniformLocation(shader->program, "cameraPosition"), camera_pos.x, camera_pos.y, camera_pos.z); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
modelShader->setInt("num_lights", 1); |
|
|
|
|
modelShader->setInt("lights[0].type", 1); |
|
|
|
|
modelShader->setFloat("lights[0].angle_cutoff", glm::cos(glm::radians(12.5f))); |
|
|
|
|
modelShader->setFloat("lights[0].outer_angle_cutoff", glm::cos(glm::radians(17.5f))); |
|
|
|
|
|
|
|
|
|
modelShader->setVec3("lights[0].direction", glm::vec3(0,-1,0)); |
|
|
|
|
modelShader->setVec3("lights[0].position", camera_pos); |
|
|
|
|
|
|
|
|
|
modelShader->setVec3("lights[0].ambient", glm::vec3(0.1)); |
|
|
|
|
modelShader->setVec3("lights[0].diffuse", glm::vec3(0.8,0.7,1.0) * glm::vec3(200)); |
|
|
|
|
modelShader->setVec3("lights[0].specular", glm::vec3(1.0)); |
|
|
|
|
modelShader->setBool("lights[0].attenuate", false); |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
shader->setInt("num_lights", 3); |
|
|
|
|
shader->setInt("lights[0].type", 1); |
|
|
|
|
shader->setFloat("lights[0].angle_cutoff", glm::cos(glm::radians(12.5f))); |
|
|
|
|
shader->setFloat("lights[0].outer_angle_cutoff", glm::cos(glm::radians(17.5f))); |
|
|
|
|
|
|
|
|
|
shader->setVec3("lights[0].direction", glm::vec3(0,-1,0)); |
|
|
|
|
// shader->setVec3("lights[0].position", camera_pos);
|
|
|
|
|
|
|
|
|
|
shader->setVec3("lights[0].position", lightPositions[0]); |
|
|
|
|
shader->setVec3("lights[0].ambient", glm::vec3(0.5)); |
|
|
|
|
shader->setVec3("lights[0].diffuse", glm::vec3(0.9,0.7,1.0) * glm::vec3(10)); |
|
|
|
|
shader->setVec3("lights[0].specular", glm::vec3(1.0)); |
|
|
|
|
shader->setBool("lights[0].attenuate", false); |
|
|
|
|
shader->setVec3("lights[0].attenuation", glm::vec3(1.0, 0.09, 0.032)); |
|
|
|
|
|
|
|
|
|
shader->setInt("lights[1].type", 1); |
|
|
|
|
shader->setVec3("lights[1].position", lightPositions[1]); |
|
|
|
|
shader->setVec3("lights[1].ambient", glm::vec3(0.1)); |
|
|
|
|
shader->setVec3("lights[1].diffuse", glm::vec3(0.6, 0.4, 0.4)); |
|
|
|
|
shader->setVec3("lights[1].specular", glm::vec3(1.0)); |
|
|
|
|
shader->setBool("lights[1].attenuate", false); |
|
|
|
|
shader->setVec3("lights[1].attenuation", glm::vec3(1.0, 0.09, 0.032)); |
|
|
|
|
|
|
|
|
|
shader->setInt("lights[2].type", 0); |
|
|
|
|
shader->setVec3("lights[2].position", lightPositions[1]); |
|
|
|
|
|
|
|
|
|
shader->setVec3("lights[2].ambient", glm::vec3(0.1)); |
|
|
|
|
shader->setVec3("lights[2].diffuse", glm::vec3(0.3, 0.4, 0.6)); |
|
|
|
|
shader->setVec3("lights[2].specular", glm::vec3(0.3, 1.0, 0.5)); |
|
|
|
|
shader->setBool("lights[2].attenuate", false); |
|
|
|
|
shader->setVec3("lights[2].attenuation", glm::vec3(1.0, 0.09, 0.032)); |
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(shader->program, "cameraPosition"), camera_pos.x, camera_pos.y, camera_pos.z); |
|
|
|
|
shader->setVec3("material.specular", glm::vec3(0.7)); |
|
|
|
|
shader->setVec3("material.diffuse", glm::vec3(1.0, 0.7, 0.8)); |
|
|
|
|
shader->setVec3("material.ambient", glm::vec3(0.2)); |
|
|
|
|
shader->setFloat("material.shininess", 32); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
/***** Light Attenuation
|
|
|
|
|
modelShader->setVec3("material.specular", glm::vec3(0.7)); |
|
|
|
|
modelShader->setVec3("material.diffuse", glm::vec3(1.0, 0.7, 0.8)); |
|
|
|
|
modelShader->setVec3("material.ambient", glm::vec3(0.2)); |
|
|
|
|
modelShader->setFloat("material.shininess", 32); |
|
|
|
|
|
|
|
|
|
/***** Light Attenuation
|
|
|
|
|
* |
|
|
|
|
* Constant x, Linear y, Quadratic z |
|
|
|
|
* |
|
|
|
@ -903,6 +738,7 @@ class SDLGLGLWindow {
@@ -903,6 +738,7 @@ class SDLGLGLWindow {
|
|
|
|
|
glCheckError(); |
|
|
|
|
loc = shader->get_uniform("model"); |
|
|
|
|
glCheckError(); |
|
|
|
|
printProgramLog(shader->program); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
@ -913,14 +749,17 @@ class SDLGLGLWindow {
@@ -913,14 +749,17 @@ class SDLGLGLWindow {
|
|
|
|
|
loc = shader->get_uniform("projection"); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap); |
|
|
|
|
running_level->draw_system->draw(view, projection); |
|
|
|
|
|
|
|
|
|
//bp_model->draw(*shader);
|
|
|
|
|
objects->draw(view, projection); |
|
|
|
|
// objects->draw(view, projection);
|
|
|
|
|
// objects->draw(skybox_object, view, projection);
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*** Draw random cubes ****/
|
|
|
|
|
/*** Draw random cubes
|
|
|
|
|
shader->use(); |
|
|
|
|
|
|
|
|
|
glBindVertexArray(gVAO); |
|
|
|
@ -934,6 +773,9 @@ class SDLGLGLWindow {
@@ -934,6 +773,9 @@ class SDLGLGLWindow {
|
|
|
|
|
glDrawArraysInstanced(GL_TRIANGLES, 0,36,1000); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** draw skybox cubemap */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -986,9 +828,6 @@ class SDLGLGLWindow {
@@ -986,9 +828,6 @@ class SDLGLGLWindow {
|
|
|
|
|
printProgramLog(texShader->program); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1069,10 +908,8 @@ int main(int argc, char **argv) {
@@ -1069,10 +908,8 @@ int main(int argc, char **argv) {
|
|
|
|
|
cont.camera_pos += camera_speed * glm::cross(cont.camera_front, cont.camera_up); |
|
|
|
|
break; |
|
|
|
|
case SDL_SCANCODE_R: |
|
|
|
|
cont.shader->reload(); |
|
|
|
|
cont.modelShader->reload(); |
|
|
|
|
glCheckError(); |
|
|
|
|
glCheckError(); |
|
|
|
|
cont.running_level->update(); |
|
|
|
|
//cont.texShader->reload();
|
|
|
|
|
//cont.skyboxShader->reload();
|
|
|
|
|
break; |
|
|
|
|