Have framebuffer mostly working, but light calculations are not there.
This commit is contained in:
parent
ea80851450
commit
27e34a18c9
5 changed files with 50 additions and 19 deletions
|
|
@ -43,6 +43,7 @@ void Scene::render(GLFWwindow* window) {
|
|||
// framebuffer stuff here
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
|
|
|||
|
|
@ -81,22 +81,32 @@ struct Scene {
|
|||
thing.scale);
|
||||
}
|
||||
|
||||
// screen quadVAO
|
||||
glGenVertexArrays(1, &quadVAO);
|
||||
glGenBuffers(1, &quadVBO);
|
||||
glBindVertexArray(quadVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void *)0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||
|
||||
shader.use();
|
||||
shader.setInt("texture1", 0);
|
||||
shader.apply_lighting(light);
|
||||
|
||||
screen_shader.use();
|
||||
screen_shader.setInt("screenTexture", 0);
|
||||
|
||||
// framebuffer config
|
||||
glGenFramebuffers(1, &framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
|
||||
// framebuffer configuration
|
||||
// -------------------------
|
||||
glGenFramebuffers(1, &framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
|
||||
// create a color attachment texture
|
||||
glGenTextures(1, &textureColorBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, textureColorBuffer);
|
||||
|
|
@ -105,22 +115,15 @@ struct Scene {
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColorBuffer, 0);
|
||||
|
||||
// create renderbuffer object for depth and stencil attachment
|
||||
// create a renderbuffer object for depth and stencil attachment (we won't be sampling these)
|
||||
glGenRenderbuffers(1, &rbo);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, SCR_WIDTH, SCR_HEIGHT);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, SCR_WIDTH, SCR_HEIGHT); // use a single renderbuffer object for both a depth AND stencil buffer.
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo); // now actually attach it
|
||||
// now that we actually created the framebuffer and added all attachments we want to check if it is actually complete now
|
||||
|
||||
dbc::check(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "Frame buffer not complete.");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
shader.use();
|
||||
shader.apply_lighting(light);
|
||||
|
||||
screen_shader.use();
|
||||
screen_shader.setInt("screenTexture", 0);
|
||||
}
|
||||
|
||||
void update();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue