|
|
|
@ -32,6 +32,7 @@
@@ -32,6 +32,7 @@
|
|
|
|
|
#include "defaultobjects/cubemap.h" |
|
|
|
|
#include "drawing.h" |
|
|
|
|
#include "level.h" |
|
|
|
|
#include "player.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -47,7 +48,6 @@ class SDLGLGLWindow {
@@ -47,7 +48,6 @@ class SDLGLGLWindow {
|
|
|
|
|
unsigned int texture[2]; |
|
|
|
|
unsigned int cubemap; |
|
|
|
|
|
|
|
|
|
glm::vec3 *translations = new glm::vec3[1000]; |
|
|
|
|
|
|
|
|
|
glm::vec3 cubePositions[10] = { |
|
|
|
|
glm::vec3( 0.0f, 0.0f, 0.0f),
|
|
|
|
@ -64,15 +64,11 @@ class SDLGLGLWindow {
@@ -64,15 +64,11 @@ class SDLGLGLWindow {
|
|
|
|
|
|
|
|
|
|
std::vector<glm::vec3> lightPositions = std::vector<glm::vec3>(); |
|
|
|
|
|
|
|
|
|
glm::mat4 projection; |
|
|
|
|
glm::mat4 model = glm::mat3(1.0f); |
|
|
|
|
glm::mat4 view = glm::mat4(1.0f); |
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
level * running_level; |
|
|
|
|
|
|
|
|
|
Shader *modelShader; |
|
|
|
|
|
|
|
|
|
Shader *skyboxShader; |
|
|
|
|
Shader *texShader; |
|
|
|
@ -87,11 +83,7 @@ class SDLGLGLWindow {
@@ -87,11 +83,7 @@ class SDLGLGLWindow {
|
|
|
|
|
unsigned int screenTexture; |
|
|
|
|
SDL_Window *gWindow; |
|
|
|
|
|
|
|
|
|
glm::vec3 camera_pos = glm::vec3(0.0f, 0.0f, 3.0f); |
|
|
|
|
glm::vec3 camera_front = glm::vec3(0.0f, 0.0f, -1.0f); |
|
|
|
|
glm::vec3 camera_up = glm::vec3(0.0f, 1.0f, 0.0f); |
|
|
|
|
|
|
|
|
|
glm::vec3 camera_direction = glm::vec3(0.f,0.f,0.f); |
|
|
|
|
std::shared_ptr<player::camera> camera; |
|
|
|
|
/* note:
|
|
|
|
|
* |
|
|
|
|
* direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); |
|
|
|
@ -99,8 +91,6 @@ class SDLGLGLWindow {
@@ -99,8 +91,6 @@ class SDLGLGLWindow {
|
|
|
|
|
* direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); |
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
float cam_pitch = 0;
|
|
|
|
|
float cam_yaw = -90; |
|
|
|
|
simple_object_draw_system *objects ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -119,15 +109,7 @@ class SDLGLGLWindow {
@@ -119,15 +109,7 @@ class SDLGLGLWindow {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void update_camera() { |
|
|
|
|
if (cam_pitch > 89.0f)
|
|
|
|
|
cam_pitch = 89.0f; |
|
|
|
|
if (cam_pitch < -89.0f)
|
|
|
|
|
cam_pitch = -89.0f; |
|
|
|
|
|
|
|
|
|
camera_direction.x = cos(glm::radians(cam_yaw)) * cos(glm::radians(cam_pitch)); |
|
|
|
|
camera_direction.y = sin(glm::radians(cam_pitch)); |
|
|
|
|
camera_direction.z = sin(glm::radians(cam_yaw)) * cos(glm::radians(cam_pitch)); |
|
|
|
|
camera_front = glm::normalize(camera_direction); |
|
|
|
|
camera->update(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int create_gl_window() { |
|
|
|
@ -174,22 +156,21 @@ class SDLGLGLWindow {
@@ -174,22 +156,21 @@ class SDLGLGLWindow {
|
|
|
|
|
fmt::print("loading level\n"); |
|
|
|
|
running_level = new level(("data/levels/init.json")); |
|
|
|
|
//Initialize OpenGL
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setup_msaa_framebuffers(); |
|
|
|
|
camera = player::get_camera(); |
|
|
|
|
initGL(); |
|
|
|
|
// init_level();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glEnable(GL_MULTISAMPLE); |
|
|
|
|
glGetError(); |
|
|
|
|
|
|
|
|
|
// shader = &running_level->shaders[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
@ -235,95 +216,11 @@ class SDLGLGLWindow {
@@ -235,95 +216,11 @@ class SDLGLGLWindow {
|
|
|
|
|
std::cout << "ERROR::FRAMEBUFFER:: Intermediate framebuffer is not complete!" << std::endl; |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* 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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int initGL() { |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
float cubeVertices[] = { |
|
|
|
|
// vertices normals textures tangent
|
|
|
|
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, |
|
|
|
@ -472,22 +369,10 @@ class SDLGLGLWindow {
@@ -472,22 +369,10 @@ class SDLGLGLWindow {
|
|
|
|
|
glCheckError(); |
|
|
|
|
//Set vertex data
|
|
|
|
|
|
|
|
|
|
view = glm::lookAt(camera_pos, camera_pos + camera_front, camera_up); |
|
|
|
|
glUniform3f(glGetUniformLocation(shader->program, "cameraPosition"), camera_pos.x, camera_pos.y, camera_pos.z); |
|
|
|
|
glm::mat4 model = glm::mat4(1.0f); |
|
|
|
|
camera->set_camera(shader); |
|
|
|
|
|
|
|
|
|
unsigned int loc = shader->get_uniform("model");
|
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
loc = shader->get_uniform("view");
|
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(view)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
loc = shader->get_uniform("projection"); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
/** draw skybox cubemap */ |
|
|
|
|
|
|
|
|
@ -501,13 +386,14 @@ class SDLGLGLWindow {
@@ -501,13 +386,14 @@ class SDLGLGLWindow {
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
skyboxShader->setInt("skybox", 11); |
|
|
|
|
loc = skyboxShader->get_uniform("view"); |
|
|
|
|
glm::mat4 skybox_view = glm::mat4(glm::mat3(view)); |
|
|
|
|
auto loc = skyboxShader->get_uniform("view"); |
|
|
|
|
|
|
|
|
|
glm::mat4 skybox_view = glm::mat4(glm::mat3(camera->view)); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(skybox_view)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
loc = skyboxShader->get_uniform("projection");
|
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(camera->projection)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glBindVertexArray(gVAO); |
|
|
|
@ -520,7 +406,7 @@ class SDLGLGLWindow {
@@ -520,7 +406,7 @@ class SDLGLGLWindow {
|
|
|
|
|
// draw the level objects
|
|
|
|
|
|
|
|
|
|
running_level->shader->setInt("skybox", 11); |
|
|
|
|
running_level->draw(view, projection); |
|
|
|
|
running_level->draw(camera->view, camera->projection); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. now blit multisampled buffer(s) to normal colorbuffer of intermediate FBO. Image is stored in screenTexture
|
|
|
|
@ -566,6 +452,7 @@ class SDLGLGLWindow {
@@ -566,6 +452,7 @@ class SDLGLGLWindow {
|
|
|
|
|
|
|
|
|
|
delete texShader; |
|
|
|
|
delete skyboxShader; |
|
|
|
|
delete running_level; |
|
|
|
|
|
|
|
|
|
//Quit SDL subsystems
|
|
|
|
|
SDL_Quit(); |
|
|
|
@ -623,24 +510,22 @@ int main(int argc, char **argv) {
@@ -623,24 +510,22 @@ int main(int argc, char **argv) {
|
|
|
|
|
quit = true; |
|
|
|
|
break; |
|
|
|
|
case SDL_SCANCODE_W: |
|
|
|
|
cont.camera_pos += camera_speed * cont.camera_front; |
|
|
|
|
cont.camera->pos += camera_speed * cont.camera->front; |
|
|
|
|
break; |
|
|
|
|
case SDL_SCANCODE_S: |
|
|
|
|
cont.camera_pos -= camera_speed * cont.camera_front; |
|
|
|
|
cont.camera->pos -= camera_speed * cont.camera->front; |
|
|
|
|
break; |
|
|
|
|
case SDL_SCANCODE_A: |
|
|
|
|
cont.camera_pos -= camera_speed * glm::cross(cont.camera_front, cont.camera_up); |
|
|
|
|
cont.camera->pos -= camera_speed * glm::cross(cont.camera->front, cont.camera->up); |
|
|
|
|
break; |
|
|
|
|
case SDL_SCANCODE_D: |
|
|
|
|
cont.camera_pos += camera_speed * glm::cross(cont.camera_front, cont.camera_up); |
|
|
|
|
cont.camera->pos += camera_speed * glm::cross(cont.camera->front, cont.camera->up); |
|
|
|
|
break; |
|
|
|
|
case SDL_SCANCODE_R: |
|
|
|
|
glCheckError(); |
|
|
|
|
cont.running_level->update(); |
|
|
|
|
cont.initGL(); |
|
|
|
|
fmt::print("finished reloading level\n"); |
|
|
|
|
//cont.texShader->reload();
|
|
|
|
|
//cont.skyboxShader->reload();
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} if (e.type == SDL_MOUSEMOTION) { |
|
|
|
@ -652,8 +537,8 @@ int main(int argc, char **argv) {
@@ -652,8 +537,8 @@ int main(int argc, char **argv) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mouse_mode) { |
|
|
|
|
cont.cam_pitch -= e.motion.yrel * 0.1f; |
|
|
|
|
cont.cam_yaw += e.motion.xrel * 0.1f; |
|
|
|
|
cont.camera->pitch -= e.motion.yrel * 0.1f; |
|
|
|
|
cont.camera->yaw += e.motion.xrel * 0.1f; |
|
|
|
|
cont.update_camera(); |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|