Jump to content
  • Advertisement
congard

OpenGL Strange glDrawBuffers behavior

Recommended Posts

Posted (edited)

Hello! Faced a strange problem when I decided to render the background (skybox) after rendering the scene. There are 4 textures attached to the framebuffer. First I fill them out when rendering the scene. After, I fill in the 0th and 2nd during the rendering of the skybox.

uint colorAttachment02[3] = { GL_COLOR_ATTACHMENT0, GL_NONE, GL_COLOR_ATTACHMENT2 };
uint colorAttachment0123[4] = {
    GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3
};
...
    glDrawBuffers(4, colorAttachment0123);
    glUseProgram(cs.programId);

    // sending lamps parameters to fragment shader
	sendLampsData();

    // drawing
    for (size_t i = 0; i < MODELS_COUNT; i++) drawModel(models[i]);
	for (size_t i = 0; i < POINT_LAMPS_COUNT + DIR_LAMPS_COUNT; i++) drawModel(lamps[i]);

    // render skybox
    glDepthFunc(GL_LEQUAL);
    glDrawBuffers(3, colorAttachment02);
    useShaderProgram(skyboxShader.programId);
    glUniformMatrix3fv(skyboxShader.matView, 1, GL_FALSE, glm::value_ptr(glm::mat3(camera.getViewMatrix())));
    setMat4(skyboxShader.matTransform, camera.getProjectionMatrix() * glm::mat4(glm::mat3(camera.getViewMatrix())));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_CUBE_MAP, skybox);
    skyboxRenderer.render();
    glDepthFunc(GL_LESS);
...
    // another fbo...

The strange thing is that if do not reset to the initial buffers (that is, add the line glDrawBuffers(4, colorAttachment0123)), then with a sharp turn of the camera, something like the previous frame will be noticeable...

Spoiler
 
 
 
 
Spoiler

Screenshot_20190811_211803.thumb.png.85da496cb784fe3cc9f316a90980d9ee.pngScreenshot_20190811_211844.thumb.png.12c30a04db00108d10dfbec06ad66dc2.png

Why is this happening? Thank you in advance for your answers.

Edited by congard

Share this post


Link to post
Share on other sites
Advertisement

Hard to tell with that little info. To me it looks like you're simply not clearing a buffer correctly, most likely the one for the lighting.

Share this post


Link to post
Share on other sites
50 minutes ago, Magogan said:

Hard to tell with that little info. To me it looks like you're simply not clearing a buffer correctly, most likely the one for the lighting.

The strange thing is that if I render the skybox before the scene, then this will not happen

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!