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 3 of 3

Thread: Problem with 2Dsampler

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    8

    Problem with 2Dsampler

    So I have no idea what I am doing wrong. For some reason my texture when loaded into the second fragment shader is black when it should be white. When I render it right to the screen it is white, but for some reason it is black when I try and read from it.


    Init
    {
    glActiveTexture(GL_TEXTURE0);
    glGenTextures(1, &myTexture);
    glBindTexture(GL_TEXTURE_2D, myTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SHADOW_SIZE, SHADOW_SIZE, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DE CAL);
    glBindTexture(GL_TEXTURE_2D, 0);

    glGenRenderbuffers(1, &RBO);
    glBindRenderbuffer(GL_RENDERBUFFER, RBO);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, SHADOW_SIZE, SHADOW_SIZE);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);

    glGenFramebuffers(1, &myFBO);
    glBindFramebuffer(GL_FRAMEBUFFER, myFBO);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RBO);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }

    Draw
    {
    glBindFramebuffer(GL_FRAMEBUFFER, myFBO);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, myTexture, 0);

    //set the matrices
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    LoadMatrices();

    glShadeModel(GL_FLAT);

    //Use first pass prog
    renderer->FirstPassProg();

    //draw the sceen
    gameObjects->Draw();

    //Back to default fbo
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glShadeModel(GL_SMOOTH);

    //clear the depth buffer --Second pass starts here--
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    //Set camera matrices
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf(renderer->cameraProjectionMatrix);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    Camera();

    //restore the view port
    glViewport(0,0,Width,Height);

    renderer->SeccondPassProg();

    glActiveTextureARB(GL_TEXTURE6);
    glBindTexture(GL_TEXTURE_2D, myTexture);
    glUniform1i(glGetUniformLocation(renderer->pTwo, "TheTexture"), myTexture);

    glLoadIdentity();

    gameObjects->Draw();

    glBindTexture(GL_TEXTURE_2D, 0);
    }

    fshader for first pass

    void main()
    {
    gl_FragColor = vec4(vec3(1.0), 1.0);
    }

    fshader for the second pass

    uniform sampler2D TheTexture;

    void main()
    {
    gl_FragColor = vec4(texture2D(TheTexture,vec2(.5)).rgb, 1.0);
    }


  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    Code :
    glUniform1i(glGetUniformLocation(renderer->pTwo, "TheTexture"), myTexture)

    check that your location is not -1

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    8
    fixed it


    I had

    glActiveTextureARB(GL_TEXTURE6);
    glBindTexture(GL_TEXTURE_2D, myTexture);
    glUniform1i(glGetUniformLocation(renderer->pTwo, "TheTexture"), myTexture);

    where i needed

    glActiveTextureARB(GL_TEXTURE6);
    glBindTexture(GL_TEXTURE_2D, myTexture);
    glUniform1i(glGetUniformLocation(renderer->pTwo, "TheTexture"), 6);

Tags for this Thread

Posting Permissions

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