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
|
|
@ -1,12 +1,8 @@
|
|||
{
|
||||
"scene": {
|
||||
"shader": {
|
||||
"vertex_path": "shaders/19-vert.glsl",
|
||||
"frag_path": "shaders/19-frag.glsl"
|
||||
},
|
||||
"light_shader": {
|
||||
"vertex_path": "shaders/19-vert.glsl",
|
||||
"frag_path": "shaders/19-lightsource.frag.glsl"
|
||||
"vertex_path": "shaders/21-framebuffers.vert.glsl",
|
||||
"frag_path": "shaders/21-framebuffers.frag.glsl"
|
||||
},
|
||||
"screen_shader": {
|
||||
"vertex_path": "shaders/21-screen.vert.glsl",
|
||||
|
|
|
|||
11
21-framebuffers/shaders/21-framebuffers.frag.glsl
Normal file
11
21-framebuffers/shaders/21-framebuffers.frag.glsl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(texture1, TexCoords);
|
||||
}
|
||||
20
21-framebuffers/shaders/21-framebuffers.vert.glsl
Normal file
20
21-framebuffers/shaders/21-framebuffers.vert.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
|
|
@ -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