problem with depth buffer while using the FBO

I don’t know why depth test doesn’t work correctly when I use a FBO to render to texture? Note that I have just attached a texture to the color buffer of FBO. I haven’t attached anything to the depth buffer of FBO.

I haven’t attached anything to the depth buffer of FBO.

and that is why the depth test does not work, it needs a depth buffer, i.e. you need to attach one to your FBO.

Thank you. I tried it, but I no longer see anything in my texture!
here’s my code to initialize a texture, FBO and render buffer:


		glGenerateMipmapEXT( GL_TEXTURE_2D );
		glTexImage2D(GL_TEXTURE_2D, 0, channels, size, size, 0, type, GL_UNSIGNED_BYTE, NULL );
		m_fboID[textureID] = g_render.GenerateFBO();
		g_render.BindFBO( m_fboID[textureID] );
		g_render.Attach2DTextureToFBOColor( m_waterTexture[textureID] );
		CUInt renderBuffer = g_render.GenerateRenderBuffer();
		g_render.BindRenderBuffer( renderBuffer );
		g_render.RenderbufferStorage( 256, 256 );
		g_render.AttachDepthToFBO( renderBuffer );
		g_render.BindFBO(0);
		g_render.BindRenderBuffer(0);

Without creating a render buffer and attaching it to the FBO, at least I get some images in my texture. but now the texture is black.
Note that the result of creating my FBO is GL_FRAMEBUFFER_COMPLETE_EXT.

[solved]
I understood that the width and height of my render buffer are not equal with the with and height of my color texture. replacing this part of code:

g_render.RenderbufferStorage( 256, 256 );

with this one:

g_render.RenderbufferStorage( size, size );

solved my problem

Now the water texture looks nice:

Thank you carsten neumann :slight_smile: