Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Screen texture always appear black

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 MrOMGWTF   Members   

444
Like
0Likes
Like

Posted 02 September 2012 - 03:22 AM

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 ;_;

#2 MrOMGWTF   Members   

444
Like
0Likes
Like

Posted 02 September 2012 - 06:10 AM

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...

#3 irreversible   Members   

2806
Like
0Likes
Like

Posted 02 September 2012 - 07:30 AM

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).

#4 MrOMGWTF   Members   

444
Like
0Likes
Like

Posted 02 September 2012 - 08:12 AM

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.

#5 irreversible   Members   

2806
Like
0Likes
Like

Posted 02 September 2012 - 11:23 AM

Did you try disabling mipmaps or generating them every frame? This the more important question.

#6 MrOMGWTF   Members   

444
Like
0Likes
Like

Posted 03 September 2012 - 04:39 AM

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.

Edited by MrOMGWTF, 03 September 2012 - 04:39 AM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.