|
|
|
@ -77,7 +77,7 @@ class Cubemap {
@@ -77,7 +77,7 @@ class Cubemap {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_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); |
|
|
|
@ -129,9 +129,6 @@ class SDLGLGLWindow {
@@ -129,9 +129,6 @@ class SDLGLGLWindow {
|
|
|
|
|
unsigned int instance_VBO; |
|
|
|
|
unsigned int lightVAO; |
|
|
|
|
unsigned int quadVAO; |
|
|
|
|
unsigned int framebuffer; |
|
|
|
|
unsigned int texColourBuffer; |
|
|
|
|
unsigned int rbo; |
|
|
|
|
unsigned int texture[2]; |
|
|
|
|
unsigned int cubemap; |
|
|
|
|
|
|
|
|
@ -164,6 +161,11 @@ class SDLGLGLWindow {
@@ -164,6 +161,11 @@ class SDLGLGLWindow {
|
|
|
|
|
public: |
|
|
|
|
int screen_width; |
|
|
|
|
int screen_height; |
|
|
|
|
unsigned int framebuffer; |
|
|
|
|
unsigned int textureColorBufferMultiSampled; |
|
|
|
|
unsigned int rbo; |
|
|
|
|
unsigned int intermediateFBO; |
|
|
|
|
unsigned int screenTexture; |
|
|
|
|
SDL_Window *gWindow; |
|
|
|
|
|
|
|
|
|
glm::vec3 camera_pos = glm::vec3(0.0f, 0.0f, 3.0f); |
|
|
|
@ -217,6 +219,7 @@ class SDLGLGLWindow {
@@ -217,6 +219,7 @@ class SDLGLGLWindow {
|
|
|
|
|
gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
|
SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height,
|
|
|
|
|
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto gContext = SDL_GL_CreateContext( gWindow ); |
|
|
|
|
if( gContext == NULL ) { |
|
|
|
@ -239,12 +242,26 @@ class SDLGLGLWindow {
@@ -239,12 +242,26 @@ class SDLGLGLWindow {
|
|
|
|
|
<< SDL_GetError() << std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 2);
|
|
|
|
|
std::cerr << "Creating msbuffers"
|
|
|
|
|
<< SDL_GetError() << std::endl ; |
|
|
|
|
// SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
|
|
|
|
|
std::cerr << "Creating msbuffers"
|
|
|
|
|
<< SDL_GetError() << std::endl ; |
|
|
|
|
|
|
|
|
|
//Initialize OpenGL
|
|
|
|
|
if( !initGL() ) |
|
|
|
|
{ |
|
|
|
|
std::cerr << "Unable to initialie OpenGL!" << std::endl; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glEnable(GL_MULTISAMPLE); |
|
|
|
|
glGetError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -267,8 +284,7 @@ class SDLGLGLWindow {
@@ -267,8 +284,7 @@ class SDLGLGLWindow {
|
|
|
|
|
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 */ |
|
|
|
|
/* generate a framebuffer to draw to
|
|
|
|
|
glGenFramebuffers(1, &framebuffer); |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
|
|
|
|
|
|
|
|
@ -294,6 +310,43 @@ class SDLGLGLWindow {
@@ -294,6 +310,43 @@ class SDLGLGLWindow {
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); // unbind
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/* MSAA FRAMEBUFFERS */ |
|
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &framebuffer); |
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
|
|
|
|
// create a multisampled color attachment texture
|
|
|
|
|
glGenTextures(1, &textureColorBufferMultiSampled); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled); |
|
|
|
|
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, screen_width, screen_height, GL_TRUE); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); |
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled, 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); |
|
|
|
|
|
|
|
|
|
std::default_random_engine generator; |
|
|
|
|
std::uniform_real_distribution<float> distribution(-50,50); |
|
|
|
@ -302,9 +355,10 @@ class SDLGLGLWindow {
@@ -302,9 +355,10 @@ class SDLGLGLWindow {
|
|
|
|
|
float x = distribution(generator) ; |
|
|
|
|
float y = distribution(generator) ; |
|
|
|
|
float z = distribution(generator) ; |
|
|
|
|
translations[i] = glm::vec3(i,y,z); |
|
|
|
|
translations[i] = glm::vec3(x,y,z); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
shader->use(); |
|
|
|
|
|
|
|
|
|
glGenBuffers(1, &instance_VBO); |
|
|
|
@ -537,11 +591,13 @@ class SDLGLGLWindow {
@@ -537,11 +591,13 @@ class SDLGLGLWindow {
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
|
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view = glm::lookAt(camera_pos, camera_pos + camera_front, camera_up); |
|
|
|
|
|
|
|
|
|
//Clear color buffer
|
|
|
|
@ -746,31 +802,33 @@ class SDLGLGLWindow {
@@ -746,31 +802,33 @@ class SDLGLGLWindow {
|
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 36); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
printProgramLog(skyboxShader->program); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. now blit multisampled buffer(s) to normal colorbuffer of intermediate FBO. Image is stored in screenTexture
|
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer); |
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, intermediateFBO); |
|
|
|
|
glBlitFramebuffer(0, 0, screen_width, screen_height, 0, 0, screen_width, screen_height, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
|
glClearColor(1.0,1.0,1.0,1.0); |
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
|
glDisable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
|
|
//glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
|
|
|
|
|
|
texShader->use(); |
|
|
|
|
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL); |
|
|
|
|
glBindVertexArray(quadVAO); |
|
|
|
|
|
|
|
|
|
glDisable(GL_DEPTH_TEST); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texColourBuffer); |
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, screenTexture); |
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 6); |
|
|
|
|
|
|
|
|
|
printProgramLog(texShader->program); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -813,6 +871,7 @@ int main(int argc, char **argv) {
@@ -813,6 +871,7 @@ int main(int argc, char **argv) {
|
|
|
|
|
SDL_SetRelativeMouseMode(SDL_TRUE); |
|
|
|
|
bool mouse_mode = true; |
|
|
|
|
|
|
|
|
|
std::cout << "Rendering now\n"; |
|
|
|
|
//While application is running
|
|
|
|
|
while( !quit ) |
|
|
|
|
{ |
|
|
|
|