|
|
|
@ -74,8 +74,6 @@ class SDLGLGLWindow {
@@ -74,8 +74,6 @@ class SDLGLGLWindow {
|
|
|
|
|
public: |
|
|
|
|
level * running_level; |
|
|
|
|
|
|
|
|
|
Shader *shader; |
|
|
|
|
Model *bp_model; |
|
|
|
|
Shader *modelShader; |
|
|
|
|
|
|
|
|
|
Shader *skyboxShader; |
|
|
|
@ -141,7 +139,7 @@ class SDLGLGLWindow {
@@ -141,7 +139,7 @@ class SDLGLGLWindow {
|
|
|
|
|
SDL_GL_CONTEXT_PROFILE_CORE ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gWindow = SDL_CreateWindow( "𝔭𝔬𝔫𝔡𝔢𝔯 𝔱𝔥𝔢 𝔬𝔯𝔟", SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
|
gWindow = SDL_CreateWindow( "Tutorial", SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
|
SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height,
|
|
|
|
|
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); |
|
|
|
|
|
|
|
|
@ -178,7 +176,13 @@ class SDLGLGLWindow {
@@ -178,7 +176,13 @@ class SDLGLGLWindow {
|
|
|
|
|
fmt::print("loading level\n"); |
|
|
|
|
running_level = new level(("data/levels/init.json")); |
|
|
|
|
//Initialize OpenGL
|
|
|
|
|
shader = &running_level->shaders[0]; |
|
|
|
|
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(); |
|
|
|
|
initGL(); |
|
|
|
|
// init_level();
|
|
|
|
|
|
|
|
|
@ -193,23 +197,8 @@ class SDLGLGLWindow {
@@ -193,23 +197,8 @@ class SDLGLGLWindow {
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setup_msaa_framebuffers() { |
|
|
|
|
/* MSAA FRAMEBUFFERS */ |
|
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &framebuffer); |
|
|
|
@ -248,99 +237,25 @@ class SDLGLGLWindow {
@@ -248,99 +237,25 @@ class SDLGLGLWindow {
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* assumes level is loaded */ |
|
|
|
|
int init_level() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
* Basic Shaders |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
int initGL() { |
|
|
|
|
//Success flag
|
|
|
|
|
bool success = true; |
|
|
|
|
//Generate program
|
|
|
|
|
//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(); |
|
|
|
|
|
|
|
|
|
objects = new simple_object_draw_system(shader); |
|
|
|
|
|
|
|
|
|
//modelShader->use();
|
|
|
|
|
// 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));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Link program
|
|
|
|
|
stbi_set_flip_vertically_on_load(true); |
|
|
|
|
|
|
|
|
|
//modelShader->use();
|
|
|
|
|
// bp_model = new Model(fmt::format("{}/backpack/backpack.obj", OBJ_DIR));
|
|
|
|
|
glCheckError(); |
|
|
|
|
//shader->use();
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* generate a framebuffer to draw to
|
|
|
|
|
glGenFramebuffers(1, &framebuffer); |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
|
|
|
|
|
|
|
|
|
glGenTextures(1, &texColourBuffer); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texColourBuffer); |
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800,600, 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); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0); |
|
|
|
|
|
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texColourBuffer, 0); |
|
|
|
|
|
|
|
|
|
glGenRenderbuffers(1, &rbo); |
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
|
|
|
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800,600); |
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo); |
|
|
|
|
|
|
|
|
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { |
|
|
|
|
std::cout << "ERROR::FRAMEBUFFER:: not complete\n"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); // unbind
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/* MSAA FRAMEBUFFERS */ |
|
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &framebuffer); |
|
|
|
@ -379,87 +294,39 @@ class SDLGLGLWindow {
@@ -379,87 +294,39 @@ class SDLGLGLWindow {
|
|
|
|
|
std::cout << "ERROR::FRAMEBUFFER:: Intermediate framebuffer is not complete!" << std::endl; |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
|
|
|
|
|
|
std::default_random_engine generator; |
|
|
|
|
std::uniform_real_distribution<float> distribution(-50,50); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i ++) { |
|
|
|
|
float x = distribution(generator) ; |
|
|
|
|
float y = distribution(generator) ; |
|
|
|
|
float z = distribution(generator) ; |
|
|
|
|
translations[i] = glm::vec3(x,y,z); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
//shader->use();
|
|
|
|
|
|
|
|
|
|
glGenBuffers(1, &instance_VBO); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, instance_VBO); |
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * 100, &translations[0], GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* textures */ |
|
|
|
|
|
|
|
|
|
int width, height, nrChannels; |
|
|
|
|
stbi_set_flip_vertically_on_load(true); |
|
|
|
|
glGenTextures(2, texture); |
|
|
|
|
unsigned char *data = stbi_load(fmt::format("{}/Tiles01-1k/Tiles01 diffuse 1k.jpg", OBJ_DIR).c_str(), &width, &height, &nrChannels, 0); |
|
|
|
|
unsigned char *datanorm = stbi_load(fmt::format("{}/Tiles01-1k/Tiles01 normal 1k.jpg", OBJ_DIR).c_str(), &width, &height, &nrChannels, 0); |
|
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[0]); |
|
|
|
|
glCheckError(); |
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); |
|
|
|
|
|
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D); |
|
|
|
|
glCheckError(); |
|
|
|
|
stbi_image_free(data); |
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* load normal */ |
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[1]); |
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, datanorm); |
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D); |
|
|
|
|
stbi_image_free(datanorm); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
A_ERROR("Load cubes"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[0]); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
shader->setInt("material.texture_diffuse1", 0); |
|
|
|
|
/********** CUBEMAPS ***************/ |
|
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0 + 1); |
|
|
|
|
shader->setInt("material.texture_normal1", 1); |
|
|
|
|
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), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
Cubemap c (faces); |
|
|
|
|
cubemap = c.id; |
|
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &lightVAO); |
|
|
|
|
glBindVertexArray(lightVAO); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// shader->setInt("material.specularmap", 1);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int initGL() { |
|
|
|
|
bool success = true; |
|
|
|
|
|
|
|
|
|
shader->setBool("lighting_emit", false); |
|
|
|
|
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
|
|
|
|
@ -522,9 +389,6 @@ class SDLGLGLWindow {
@@ -522,9 +389,6 @@ class SDLGLGLWindow {
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
|
//glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
|
|
|
|
|
|
|
|
|
//IBO data
|
|
|
|
|
// GLuint indexData[] = { 0, 1, 2, 3, 0, 2};
|
|
|
|
|
|
|
|
|
|
/*********** CUBES **************/ |
|
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &gVAO); |
|
|
|
@ -592,22 +456,6 @@ class SDLGLGLWindow {
@@ -592,22 +456,6 @@ class SDLGLGLWindow {
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Create IBO
|
|
|
|
|
// glGenBuffers( 1, &gIBO );
|
|
|
|
|
// glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, gIBO );
|
|
|
|
|
// glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof indexData, indexData, GL_STATIC_DRAW );
|
|
|
|
|
|
|
|
|
|
//glBindVertexArray(gVAO);
|
|
|
|
|
|
|
|
|
|
/*********** LIGHTS ****************/ |
|
|
|
|
glGenVertexArrays(1, &lightVAO); |
|
|
|
|
glBindVertexArray(lightVAO); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, gVBO); |
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)0); |
|
|
|
|
glBufferData( GL_ARRAY_BUFFER, sizeof cubeVertices, cubeVertices, GL_STATIC_DRAW ); |
|
|
|
|
glEnableVertexAttribArray(0); |
|
|
|
|
glBindVertexArray(quadVAO); |
|
|
|
|
glCheckError(); |
|
|
|
|
return success; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -615,107 +463,28 @@ class SDLGLGLWindow {
@@ -615,107 +463,28 @@ class SDLGLGLWindow {
|
|
|
|
|
void render() |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
auto shader = &running_level->shaders[0]; |
|
|
|
|
shader->use(); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
|
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view = glm::lookAt(camera_pos, camera_pos + camera_front, camera_up); |
|
|
|
|
|
|
|
|
|
//Clear color buffer
|
|
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
/***** 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); |
|
|
|
|
|
|
|
|
|
* |
|
|
|
|
* Constant x, Linear y, Quadratic z |
|
|
|
|
* |
|
|
|
|
* Distance Constant Linear Quadratic |
|
|
|
|
* 7 1.0 0.7 1.8
|
|
|
|
|
* 13 1.0 0.35 0.44
|
|
|
|
|
* 20 1.0 0.22 0.20
|
|
|
|
|
* 32 1.0 0.14 0.07
|
|
|
|
|
* 50 1.0 0.09 0.032
|
|
|
|
|
* 65 1.0 0.07 0.017
|
|
|
|
|
* 100 1.0 0.045 0.0075
|
|
|
|
|
* 160 1.0 0.027 0.0028
|
|
|
|
|
* 200 1.0 0.022 0.0019
|
|
|
|
|
* 325 1.0 0.014 0.0007
|
|
|
|
|
* 600 1.0 0.007 0.0002
|
|
|
|
|
* 3250 1.0 0.0014 0.000007 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
//Set vertex data
|
|
|
|
|
shader->use(); |
|
|
|
|
|
|
|
|
|
/* set phong values */ |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int loc = shader->get_uniform("model");
|
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
|
glCheckError(); |
|
|
|
@ -729,57 +498,11 @@ class SDLGLGLWindow {
@@ -729,57 +498,11 @@ class SDLGLGLWindow {
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
/** Draw guitar backpack **/ |
|
|
|
|
shader->use(); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
model = glm::mat4(1.0); |
|
|
|
|
// model = glm::rotate(model, glm::radians( 20.0f + 160.0f *(float)SDL_GetTicks() / 1000.0f), glm::vec3(0.6, 0.3, 1.0));
|
|
|
|
|
glCheckError(); |
|
|
|
|
loc = shader->get_uniform("model"); |
|
|
|
|
glCheckError(); |
|
|
|
|
printProgramLog(shader->program); |
|
|
|
|
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)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//bp_model->draw(*shader);
|
|
|
|
|
// objects->draw(view, projection);
|
|
|
|
|
// objects->draw(skybox_object, view, projection);
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** Draw random cubes
|
|
|
|
|
shader->use(); |
|
|
|
|
|
|
|
|
|
glBindVertexArray(gVAO); |
|
|
|
|
glActiveTexture(GL_TEXTURE0); // activate proper texture unit before binding
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[0]); |
|
|
|
|
shader->setInt("material.texture_diffuse1", 0); |
|
|
|
|
glActiveTexture(GL_TEXTURE0 + 1); // activate proper texture unit before binding
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[1]); |
|
|
|
|
shader->setInt("material.texture_normal1", 1); |
|
|
|
|
glCheckError(); |
|
|
|
|
glDrawArraysInstanced(GL_TRIANGLES, 0,36,1000); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** draw skybox cubemap */ |
|
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE11); |
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
skyboxShader->use(); |
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
@ -803,12 +526,10 @@ class SDLGLGLWindow {
@@ -803,12 +526,10 @@ class SDLGLGLWindow {
|
|
|
|
|
|
|
|
|
|
printProgramLog(skyboxShader->program); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
|
|
|
|
|
running_level->draw_system->draw(view, projection); |
|
|
|
|
// draw the level objects
|
|
|
|
|
|
|
|
|
|
running_level->shader->setInt("skybox", 11); |
|
|
|
|
|
|
|
|
|
running_level->draw(view, projection); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. now blit multisampled buffer(s) to normal colorbuffer of intermediate FBO. Image is stored in screenTexture
|
|
|
|
@ -852,9 +573,7 @@ class SDLGLGLWindow {
@@ -852,9 +573,7 @@ class SDLGLGLWindow {
|
|
|
|
|
SDL_DestroyWindow( gWindow ); |
|
|
|
|
gWindow = NULL; |
|
|
|
|
|
|
|
|
|
delete shader; |
|
|
|
|
delete texShader; |
|
|
|
|
delete bp_model; |
|
|
|
|
delete skyboxShader; |
|
|
|
|
|
|
|
|
|
//Quit SDL subsystems
|
|
|
|
@ -927,6 +646,8 @@ int main(int argc, char **argv) {
@@ -927,6 +646,8 @@ int main(int argc, char **argv) {
|
|
|
|
|
case SDL_SCANCODE_R: |
|
|
|
|
glCheckError(); |
|
|
|
|
cont.running_level->update(); |
|
|
|
|
cont.initGL(); |
|
|
|
|
fmt::print("finished reloading level\n"); |
|
|
|
|
//cont.texShader->reload();
|
|
|
|
|
//cont.skyboxShader->reload();
|
|
|
|
|
break; |
|
|
|
@ -948,11 +669,8 @@ int main(int argc, char **argv) {
@@ -948,11 +669,8 @@ int main(int argc, char **argv) {
|
|
|
|
|
} |
|
|
|
|
cont.update_camera(); |
|
|
|
|
|
|
|
|
|
//Render quad
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cont.render(); |
|
|
|
|
//Update screen
|
|
|
|
|
cont.swap_window(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|