Screen texture always appear black

Started by
4 comments, last by MrOMGWTF 11 years, 7 months ago
Hey, I'm writing some kind of little engine in OpenGL. Currently I'm adding post processing.
When I started doing it, I was like "meh it's easy". And then I went into this big problem ;_;
Whenever I pass a screen texture into shader, it becomes black!
Here's my shader code:

uniform sampler2D sceneTexture;
varying vec2 uv;
uniform float time;

void main()
{
//gl_FragColor = vec4(uv.xy, 0.0, 1.0);
gl_FragColor = texture(sceneTexture, uv);
}


However, if I uncomment the first line and comment the second one, everything works. I see correct texture coordinates. Here are main files where could be an error:
https://www.dropbox.com/s/dx5e0q6b7lidvup/Some%20of%20source.rar
It's 2nd day of hell ;_;
Advertisement
Ok... I spammed my source with GL.GetError and found like two InvalidOperations.
Some of my functions was unbinding the fbo, so then whatever I tried to do with it I was getting InvalidOperation.
There are no InvalidOperations right now, but the code is still not working...
Have you tested if the texture bound to sceneTexture is valid and contains proper data*? What do you see when you use the uncommented line? Do you see a yellow-greed-red gradient?

*note - based on its name it would seem sceneTexture is a procedural texture/FBO target. Make sure it doesn't contain mipmap data! AFAIR mipmaps need to be generated manually every time you update an FBO target for sampling to work properly, which makes it far easier to make any dynamic targets non-mipmapped in the first place (instead of GL_LINEAR_MIPMAP_LINEAR user GL_LINEAR when setting its properties).

Have you tested if the texture bound to sceneTexture is valid and contains proper data*? What do you see when you use the uncommented line? Do you see a yellow-greed-red gradient?

*note - based on its name it would seem sceneTexture is a procedural texture/FBO target. Make sure it doesn't contain mipmap data! AFAIR mipmaps need to be generated manually every time you update an FBO target for sampling to work properly, which makes it far easier to make any dynamic targets non-mipmapped in the first place (instead of GL_LINEAR_MIPMAP_LINEAR user GL_LINEAR when setting its properties).



Yes, yellow green red gradient. Black in the bottom left.
I tried binding texture loaded from disk and displaying, it works.
Did you try disabling mipmaps or generating them every frame? This the more important question.
This is my render texture creation code:

public void Create()
{
if (ID != -1)
{
Delete();
}
ID = GL.GenTexture();
this.Bind(TextureUnit.Texture0);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
GL.TexImage2D(TextureTarget.Texture2D, 0, PIF, Width, Height, 0, PixelFormat, PixelType.UnsignedByte, IntPtr.Zero);
}

I posted the code in OP, so you can check it out.

This topic is closed to new replies.

Advertisement