OpenGL not drawing nearest fragment to the camera











up vote
1
down vote

favorite












I have a scene with a teapot mesh in it.
I'm using a framgment shader to light it using a source of light whose value is equal to 10.



When the scene is rendered to the default framebuffer, everything seems to be fine. ok



But, if it's rendered in a custom framebuffer, the result looks like this :ko



OpenGL seems to prefer triangles defined "at the end of" the mesh.



I want the framebuffer to contain 16bits floats so I can store values larger than 1.0.



Sorry for my English.










share|improve this question


















  • 1




    Probably you don't attach a depth buffer to the framebuffer.
    – Rabbid76
    Nov 10 at 20:06










  • Oh. You're probably right. I didn't think of that. I'll do it right now.
    – Elirovi
    Nov 10 at 20:11










  • @Rabbid76, I just added and attached a depth renderBuffer to my framebuffer and now I'm not getting any result
    – Elirovi
    Nov 10 at 20:19










  • Ok I just found out what I did wrong : I forgot to clear the depth buffer in the drawcall using glClear(GL_COLOR_BUFFER_BIT | **GL_DEPTH_BUFFER_BIT**);
    – Elirovi
    Nov 10 at 20:21






  • 1




    Possibly someone would've pointed that out, if you would've added any code to the question. Please read How to create a Minimal, Complete, and Verifiable example.
    – Rabbid76
    Nov 10 at 20:24

















up vote
1
down vote

favorite












I have a scene with a teapot mesh in it.
I'm using a framgment shader to light it using a source of light whose value is equal to 10.



When the scene is rendered to the default framebuffer, everything seems to be fine. ok



But, if it's rendered in a custom framebuffer, the result looks like this :ko



OpenGL seems to prefer triangles defined "at the end of" the mesh.



I want the framebuffer to contain 16bits floats so I can store values larger than 1.0.



Sorry for my English.










share|improve this question


















  • 1




    Probably you don't attach a depth buffer to the framebuffer.
    – Rabbid76
    Nov 10 at 20:06










  • Oh. You're probably right. I didn't think of that. I'll do it right now.
    – Elirovi
    Nov 10 at 20:11










  • @Rabbid76, I just added and attached a depth renderBuffer to my framebuffer and now I'm not getting any result
    – Elirovi
    Nov 10 at 20:19










  • Ok I just found out what I did wrong : I forgot to clear the depth buffer in the drawcall using glClear(GL_COLOR_BUFFER_BIT | **GL_DEPTH_BUFFER_BIT**);
    – Elirovi
    Nov 10 at 20:21






  • 1




    Possibly someone would've pointed that out, if you would've added any code to the question. Please read How to create a Minimal, Complete, and Verifiable example.
    – Rabbid76
    Nov 10 at 20:24















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a scene with a teapot mesh in it.
I'm using a framgment shader to light it using a source of light whose value is equal to 10.



When the scene is rendered to the default framebuffer, everything seems to be fine. ok



But, if it's rendered in a custom framebuffer, the result looks like this :ko



OpenGL seems to prefer triangles defined "at the end of" the mesh.



I want the framebuffer to contain 16bits floats so I can store values larger than 1.0.



Sorry for my English.










share|improve this question













I have a scene with a teapot mesh in it.
I'm using a framgment shader to light it using a source of light whose value is equal to 10.



When the scene is rendered to the default framebuffer, everything seems to be fine. ok



But, if it's rendered in a custom framebuffer, the result looks like this :ko



OpenGL seems to prefer triangles defined "at the end of" the mesh.



I want the framebuffer to contain 16bits floats so I can store values larger than 1.0.



Sorry for my English.







opengl mesh fragment-shader framebuffer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 19:50









Elirovi

1048




1048








  • 1




    Probably you don't attach a depth buffer to the framebuffer.
    – Rabbid76
    Nov 10 at 20:06










  • Oh. You're probably right. I didn't think of that. I'll do it right now.
    – Elirovi
    Nov 10 at 20:11










  • @Rabbid76, I just added and attached a depth renderBuffer to my framebuffer and now I'm not getting any result
    – Elirovi
    Nov 10 at 20:19










  • Ok I just found out what I did wrong : I forgot to clear the depth buffer in the drawcall using glClear(GL_COLOR_BUFFER_BIT | **GL_DEPTH_BUFFER_BIT**);
    – Elirovi
    Nov 10 at 20:21






  • 1




    Possibly someone would've pointed that out, if you would've added any code to the question. Please read How to create a Minimal, Complete, and Verifiable example.
    – Rabbid76
    Nov 10 at 20:24
















  • 1




    Probably you don't attach a depth buffer to the framebuffer.
    – Rabbid76
    Nov 10 at 20:06










  • Oh. You're probably right. I didn't think of that. I'll do it right now.
    – Elirovi
    Nov 10 at 20:11










  • @Rabbid76, I just added and attached a depth renderBuffer to my framebuffer and now I'm not getting any result
    – Elirovi
    Nov 10 at 20:19










  • Ok I just found out what I did wrong : I forgot to clear the depth buffer in the drawcall using glClear(GL_COLOR_BUFFER_BIT | **GL_DEPTH_BUFFER_BIT**);
    – Elirovi
    Nov 10 at 20:21






  • 1




    Possibly someone would've pointed that out, if you would've added any code to the question. Please read How to create a Minimal, Complete, and Verifiable example.
    – Rabbid76
    Nov 10 at 20:24










1




1




Probably you don't attach a depth buffer to the framebuffer.
– Rabbid76
Nov 10 at 20:06




Probably you don't attach a depth buffer to the framebuffer.
– Rabbid76
Nov 10 at 20:06












Oh. You're probably right. I didn't think of that. I'll do it right now.
– Elirovi
Nov 10 at 20:11




Oh. You're probably right. I didn't think of that. I'll do it right now.
– Elirovi
Nov 10 at 20:11












@Rabbid76, I just added and attached a depth renderBuffer to my framebuffer and now I'm not getting any result
– Elirovi
Nov 10 at 20:19




@Rabbid76, I just added and attached a depth renderBuffer to my framebuffer and now I'm not getting any result
– Elirovi
Nov 10 at 20:19












Ok I just found out what I did wrong : I forgot to clear the depth buffer in the drawcall using glClear(GL_COLOR_BUFFER_BIT | **GL_DEPTH_BUFFER_BIT**);
– Elirovi
Nov 10 at 20:21




Ok I just found out what I did wrong : I forgot to clear the depth buffer in the drawcall using glClear(GL_COLOR_BUFFER_BIT | **GL_DEPTH_BUFFER_BIT**);
– Elirovi
Nov 10 at 20:21




1




1




Possibly someone would've pointed that out, if you would've added any code to the question. Please read How to create a Minimal, Complete, and Verifiable example.
– Rabbid76
Nov 10 at 20:24






Possibly someone would've pointed that out, if you would've added any code to the question. Please read How to create a Minimal, Complete, and Verifiable example.
– Rabbid76
Nov 10 at 20:24














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










I forgot to add a depth renderBuffer and clear it using glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



To do so, add :



GLuint rboDepth;
glGenRenderbuffers(1, &rboDepth);
glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width(), height());
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth);


to your framebuffer implementation while it's bound.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242809%2fopengl-not-drawing-nearest-fragment-to-the-camera%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    I forgot to add a depth renderBuffer and clear it using glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



    To do so, add :



    GLuint rboDepth;
    glGenRenderbuffers(1, &rboDepth);
    glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width(), height());
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth);


    to your framebuffer implementation while it's bound.






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      I forgot to add a depth renderBuffer and clear it using glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



      To do so, add :



      GLuint rboDepth;
      glGenRenderbuffers(1, &rboDepth);
      glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
      glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width(), height());
      glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth);


      to your framebuffer implementation while it's bound.






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        I forgot to add a depth renderBuffer and clear it using glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



        To do so, add :



        GLuint rboDepth;
        glGenRenderbuffers(1, &rboDepth);
        glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width(), height());
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth);


        to your framebuffer implementation while it's bound.






        share|improve this answer












        I forgot to add a depth renderBuffer and clear it using glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



        To do so, add :



        GLuint rboDepth;
        glGenRenderbuffers(1, &rboDepth);
        glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width(), height());
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth);


        to your framebuffer implementation while it's bound.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 20:29









        Elirovi

        1048




        1048






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242809%2fopengl-not-drawing-nearest-fragment-to-the-camera%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values