Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Jan 2013
Offline Last Active Feb 20 2013 09:15 PM

Topics I've Started

Framebuffer - render to texture trouble

26 January 2013 - 04:07 PM

Hey everyone! I am working on rendering to textures and am running into some trouble with unbinding the framebuffer object.


Currently, I am generating a framebuffer object, creating two textures (one RGB and one DEPTH_COMPONENT24), attaching the two textures, checking the status which is okay, and then drawing while the framebuffer is bound. Inside of gDEBugger I can see that everything is being drawn to the textures just fine.


However, when I try to bind back to default buffer ( glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) ) the textures get cleared to zero and everything that was drawn to the textures ends up back in the static buffers. Also, I have also tried binding two more empty textures to the framebuffer and everything gets moved to the new textures.


Any ideas why all that data would just jump ship?


I attached a before and after pictures for when I bind the textures to the framebuffer.

Sampling depth texture

21 January 2013 - 11:27 AM

Opengl novice here so sorry ahead of time! Just hoping to get some questions answered about sampling textures. I was messing around with rendering a scene to textures so that they could be used later. I then wanted to make a shader to view a depth texture by linearizing the depth values and then just bliting it on screen using a single quad. I can see that everything is being drawn into the texture correctly through gDEBugger (debugger.png) but am having some trouble sampling it .


First, to render the texture I output a single quad covering the screen. Then in vertex shader I multiply by modelviewproj matrix and save the xy value. My understanding is this should perfectly match the screen coordinates but when I check these values I am only getting the top right corner (output.png). 


Second, I always seem to get values of 0 when sampling my texture. I can see in the debugger data view that (0,0) has a value of like ~.9997. However I sample it, I always seem to get 0s. It is a floating point texture with GL_DEPTH_ATTACHMENT.


Here's the fragment and vertex shader code (my graphics card doesn't have geometry shader):



ShadowVisualDataOutput ShadowVisualVertexMain(ShadowVisualDataInput vdi, uniform float4x4 modelViewProj) {
  ShadowVisualDataOutput ret;
  ret.projv = mul(modelViewProj, vdi.vertex); 
  ret.saved = mul(modelViewProj, vdi.vertex).xy;
  return ret;

ShadowVisualDataPixelOutput ShadowVisualFragmentMain(
	ShadowVisualDataOutput pdi, 
	uniform sampler2D depthTex,
	uniform float camNear, 
	uniform float camFar) {
	ShadowVisualDataPixelOutput ret;	
	if (pdi.saved.x < 0 || pdi.saved.x > 720) {
		ret.color = float4(0,0,1,1);
		return ret;
	if (pdi.saved.y < 0 || pdi.saved.y > 480) {
		ret.color = float4(0,0,1,1);
		return ret;

	float2 lookup = float2(0, 0);
	float depth = tex2D(depthTex, lookup).x;
	if (depth == 0.0f) {
			ret.color = float4(0,0,0,0);
			return ret;

	ret.color = float4(1,1,1,1);
	return ret;




Thanks for any help ahead of time smile.png