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);
}