PDA

View Full Version : multipile frame buffer rendering



robinvd95
03-09-2016, 05:38 AM
So i am trying to render my scene using frame buffers, but i can't get it to work properly.
I got 2 frame buffers, 1 for the skyBox and another one for the entities.
However when i draw them only the entity buffer is drawn to the screen.
presumebly due to the fact that the clear color is also rendered on the entity frame buffer, therefore i cannot see my skybox i only see the entites and the clear color.
here is my render code:


GL11.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

skyboxBuffer.bindFrameBuffer();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
testScene.renderSkybox();
skyboxBuffer.unbindCurrentFrameBuffer();

frameBuffer.bindFrameBuffer();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
testScene.renderScene();
frameBuffer.unbindCurrentFrameBuffer();

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL30.glBindVertexArray(frameBuffer.getQuadVAO());

screenShader.start();
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);

screenShader.loadGammaCorrection(1.0f);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skyboxBuffer.getColorTexture());
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6);

screenShader.loadGammaCorrection(2.2f);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, frameBuffer.getColorTexture());
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6);

GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
screenShader.stop();

and the vertex/fragment shader:


//Vertex shader
#version 330 core

in vec2 position;
in vec2 texCoords;

out vec2 textureCoords;

void main(void){

gl_Position = vec4(position.x, position.y, 0.0f, 1.0f);
textureCoords = texCoords;
}

// Fragment Shader
#version 330 core

in vec2 textureCoords;

out vec4 color;

uniform sampler2D screenTexture;
uniform sampler2D skyboxTexture;
uniform float gamma;

void main(void){
vec3 hdrColor = texture(screenTexture, textureCoords).rgb;
vec3 mapped = hdrColor / (hdrColor + vec3(1.0));
mapped = pow(mapped, vec3(1.0 / gamma));
color = vec4(mapped, 1.0);
}

anyone knows how to get rid of the clear color, or if its anything else thats messing me up?

Edit: here is my frame buffer class if needed: pastebin.com/r54jPPxH