First edit for framebuffers but it's slapped together and doesn't work yet.
This commit is contained in:
parent
c32e7bd00d
commit
ea80851450
8 changed files with 113 additions and 11 deletions
|
|
@ -26,7 +26,7 @@ struct Thing {
|
|||
|
||||
struct Scene {
|
||||
Shader shader;
|
||||
Shader light_shader;
|
||||
Shader screen_shader;
|
||||
|
||||
std::unordered_map<std::string, components::Material> materials;
|
||||
Camera camera;
|
||||
|
|
@ -36,10 +36,27 @@ struct Scene {
|
|||
|
||||
float deltaTime = 0.0f;
|
||||
float lastFrame = 0.0f;
|
||||
unsigned int framebuffer = 0;
|
||||
unsigned int textureColorBuffer = 0;
|
||||
unsigned int quadVAO = 0;
|
||||
unsigned int quadVBO = 0;
|
||||
unsigned int rbo = 0;
|
||||
|
||||
float quadVertices[24] = {
|
||||
// vertex attributes for a quad that fills the entire screen in Normalized Device Coordinates.
|
||||
// positions // texCoords
|
||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||
-1.0f, -1.0f, 0.0f, 0.0f,
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
|
||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
1.0f, 1.0f, 1.0f, 1.0f
|
||||
};
|
||||
|
||||
Scene(components::Scene& config):
|
||||
shader{config.shader.vertex_path, config.shader.frag_path},
|
||||
light_shader{config.light_shader.vertex_path, config.shader.frag_path},
|
||||
screen_shader{config.screen_shader.vertex_path, config.shader.frag_path},
|
||||
materials{config.materials},
|
||||
camera{
|
||||
.position=config.camera.position,
|
||||
|
|
@ -64,8 +81,46 @@ 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);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||
|
||||
|
||||
// framebuffer config
|
||||
glGenFramebuffers(1, &framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
|
||||
// create a color attachment texture
|
||||
glGenTextures(1, &textureColorBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, textureColorBuffer);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCR_WIDTH, SCR_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, textureColorBuffer, 0);
|
||||
|
||||
// create renderbuffer object for depth and stencil attachment
|
||||
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);
|
||||
|
||||
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