Problems with passing FBO texture to GLSL shader. Please help

Hi, in the code below, I am trying to create two separate FBO textures, and then pass them to a third FBO where I use them as samplers for my GLSL frag shader. I am getting a black screen. I have been racking my head for days now, I cant figure out what is wrong.

// Create FBO’s

void RayCaster::createRayStartFBO()
{
glGenFramebuffers(1, &fboRayStart);
glBindFramebuffer(GL_FRAMEBUFFER, fboRayStart);

glGenRenderbuffers(1, &colorBufferRayStart);
glBindRenderbuffer(GL_RENDERBUFFER, colorBufferRayStart);


glGenTextures(1, &texRayStart);
glBindTexture(GL_TEXTURE_2D, texRayStart);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_HALF_FLOAT, NULL);


glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texRayStart, 0);


if(GL_FRAMEBUFFER_COMPLETE != glCheckFramebufferStatus(GL_FRAMEBUFFER))
{
	std::cout<<"Unable to create frame buffer..."<<std::endl;
}


glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);


std::cout<<"Ray Start Frame Buffer created..."<<std::endl;

}

void RayCaster::createRayStopFBO()
{
glGenFramebuffers(1, &fboRayStop);
glBindFramebuffer(GL_FRAMEBUFFER, fboRayStop);

glGenRenderbuffers(1, &colorBufferRayStop);
glBindRenderbuffer(GL_RENDERBUFFER, colorBufferRayStop);


glGenTextures(1, &texRayStop);
glBindTexture(GL_TEXTURE_2D, texRayStop);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_HALF_FLOAT, NULL);


glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texRayStop, 0);


if(GL_FRAMEBUFFER_COMPLETE != glCheckFramebufferStatus(GL_FRAMEBUFFER))
{
	std::cout<<"Unable to create frame buffer..."<<std::endl;
}


glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

std::cout<<"Ray Start Frame Buffer created..."<<std::endl;

}

void RayCaster::createResultFBO()
{
glGenFramebuffers(1, &fboResult);
glBindFramebuffer(GL_FRAMEBUFFER, fboResult);

glGenRenderbuffers(1, &colorBufferResult);
glBindRenderbuffer(GL_RENDERBUFFER, colorBufferResult);


glGenTextures(1, &texResult);
glBindTexture(GL_TEXTURE_2D, texResult);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_HALF_FLOAT, NULL);


glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texResult, 0);


if(GL_FRAMEBUFFER_COMPLETE != glCheckFramebufferStatus(GL_FRAMEBUFFER))
{
	std::cout<<"Unable to create frame buffer..."<<std::endl;
}


glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

std::cout<<"Result Frame Buffer created..."<<std::endl;

}

// Render

void RayCaster::renderRayCast()
{
float ratio = float(width)/float(height);

// Fill screen with viewport
glViewport(0, 0, width, height);


// Reset projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Set a 45 degree perspective
gluPerspective(45, ratio, 0.0, 25);


// Reset Modelview matrix      	
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0);


glTranslatef(0.0, 0.0, 0.0);
glRotatef(rotAngle, 0.0, 1.0, 0.0);


glClearColor(0.0, 0.0, 0.0, 0.0); 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


// Ray Start (Render to FBO)
glBindFramebuffer(GL_FRAMEBUFFER, fboRayStart);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glUseProgram(rayVertexProgram);	
drawQuads(1.0, 1.0, 1.0);
glUseProgram(0);
glDisable(GL_CULL_FACE);
glBindTexture(GL_TEXTURE_2D, texRayStart);
glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);


// Ray Stop (Render to FBO)
glBindFramebuffer(GL_FRAMEBUFFER, fboRayStop);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glUseProgram(rayVertexProgram);	
drawQuads(1.0, 1.0, 1.0);
glUseProgram(0);
glDisable(GL_CULL_FACE);
glBindTexture(GL_TEXTURE_2D, texRayStop);	
glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);


// Ray Cast (Render to FBO)
glBindFramebuffer(GL_FRAMEBUFFER, fboResult);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glUseProgram(rayCasterProgram);	
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texRayStart);
utilities.setUniform("RayStart", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texRayStop);
utilities.setUniform("RayStop", 1);
//glActiveTexture(GL_TEXTURE2);
//glBindTexture(GL_TEXTURE_3D, volumeTex);
//utilities.setUniform("Volume", 2);
//glActiveTexture(GL_TEXTURE1);
//glBindTexture(GL_TEXTURE_3D, gradientTex);
//utilities.setUniform("Gradient", 1);
//utilities.setUniform("IsoValue", isoValue);
//utilities.setUniform("Absorption", absorption);
drawQuads(1.0, 1.0, 1.0);
glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, texResult);
glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


// Render to Quad

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texResult);


reshapeOrtho(width, height);
glColor4f(1.0, 1.0, 1.0, 1.0);
drawFullscreenQuad();


glDisable(GL_TEXTURE_2D);

}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.