Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Depth problem with framebuffer

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    3

    Depth problem with framebuffer

    Hello everybody!

    First I'm french so please don't be hard with my english

    So my problem is when I draw multiple cube in the default framebuffer (so the screen) it render with a good depth testing and when I render in a framebuffer and then i render the texture in witch i have drawn my cubes it render 2D triangles. I really don't understand why :/...

    images are in the third post

    Code :
        GLuint framebuffertest,tex1,tex2;
     
        glGenFramebuffers(1,&framebuffertest);
        glGenTextures(1,&tex1);
        glGenTextures(1,&tex2);
     
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER,framebuffertest);
     
        glBindTexture(GL_TEXTURE_2D,tex1);
        glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,1024,768,0,GL_RGB,GL_FLOAT,NULL);
     
        glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,tex1,0);
     
     
        glBindTexture(GL_TEXTURE_2D,tex2);
        glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,1024,768,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL);
     
        glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,tex2,0);
     
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
     
    -------------------------------------------------------------------------------------------------
     
            //render cube off screen
     
            glBindFramebuffer(GL_DRAW_FRAMEBUFFER,framebuffertest);
            glDrawBuffers(1,buffs);
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     
            mainShader.useShader();
            glBindTexture(GL_TEXTURE_BUFFER,textureBufferModel);
     
            cube.drawInstanced(NB_CUBE,36,GL_TRIANGLES);
     
            /************************************************/
     
            //render the texture
     
            glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D,tex1);
     
            graussianBlurShader.useShader();
     
            drawScreen.draw(4,GL_TRIANGLE_STRIP);
     
            glBindTexture(GL_TEXTURE_2D,0);
     
     
            /************************************************/
     
            //render directly the cube on the screen
     
            /*glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     
            glBindTexture(GL_TEXTURE_BUFFER,textureBufferModel);
     
            mainShader.useShader();
     
            cube.drawInstanced(NB_CUBE,36,GL_TRIANGLES);*/
     
            /************************************************/
     
     
            glFinish();
            window->swapBuffers();

    mainShader :
    Code :
    vertex shader
    #version 330
     
    layout(std140,binding = 0) uniform Matrice
    {
        mat4 projection;
        mat4 view;
     
    }Matrice;
     
    layout(binding = 0) uniform samplerBuffer modelMatrice;
     
     
    in vec4 vertex_vs;
     
    out vec3 color_fs;
     
    void main()
    {
        mat4 model;
        vec3 color;
        int i;
        vec4 tmp[4];
     
        for(i = 0 ; i < 16 ; i++)
        {
            tmp[(i/4)][i%4] = texelFetch(modelMatrice,gl_InstanceID*19 + i).x;
        }
     
        model[0] = tmp[0];
        model[1] = tmp[1];
        model[2] = tmp[2];
        model[3] = tmp[3];
     
        for(i = 0 ; i < 3 ; i++)
        {
            color[i] = texelFetch(modelMatrice,gl_InstanceID*19 + 16 + i).x;
        }
     
     
        color_fs = color;
     
     
        gl_Position = Matrice.projection * Matrice.view * model * vertex_vs;
    }
     
    fragment shader
     
    #version 330
     
    in vec3 color_fs;
     
    out vec3 color_pixel;
     
    void main()
    {
        color_pixel = color_fs;
    }

    graussianblurshader (witch is realy not a graussian blur but it will be int futur )

    Code :
    vertex shader
    #version 330
     
    in vec2 vertex_vs;
    in vec2 coords_vs;
     
    out vec2 coords_fs;
     
    void main()
    {
        coords_fs = coords_vs;
        gl_Position.xy = vertex_vs;
    }
     
    fragment shader
    #version 330
     
    out vec4 color_pixel;
     
    uniform sampler2D textureToBlur;
     
    in vec2 coords_fs;
     
    void main()
    {
       color_pixel = texture2D(textureToBlur,coords_fs);
    }


    I don't give you all my code but if you want it ask and i'll give you.

    Thanks,
    Jedi768

    GPU : ATI HD 6850
    Opengl : 3.3 core
    Last edited by jedi768; 12-15-2013 at 02:33 AM.

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    3
    Can sameone explain me how to do to post an image, please?

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    New users can't post images or links (helps avoid users that subscribe just to post spam).

    Put the link in a post w/o http://, and we'll fix it up for you.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    3
    hello,

    Thanks but i'm not sur to understand you

    So the image directly on the screen:
    http://hpics.li/38ccaed

    And the image first in framebuffer and then render on the screen:
    http://hpics.li/9d81711

    and if i render an other texture with the same code i get good result :
    http://hpics.li/6de5d2a

    thanks for helping
    Last edited by Dark Photon; 12-16-2013 at 01:38 PM.

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    I think you need to provide more information. For instance, why don't the colors of the shapes rendered in your first shot match the relative orders of colors in the second shot.

    The second shot just looks like you're rendering everything in 2D. But I still can't explain everything I'm seeing in the 2nd shot. The area subtended by the cubes doesn't even match. It doesn't look like you're rendering cubes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •