Need help rendering scene to a texture and reusing it in a shader

Hey Everyone,

I have a question concerning framebuffers, textures and shaders and if I can get some help here that would be awesome!

So what I want to do is render my scene to a texture the size of my window, and then use that texture to render to the actual window by passing it into my fragment shader and using gl_FragCoord.x/width and gl_FragCoord.y/height as the texture u,v coordinates.

I don’t quite know whats going wrong with my code though. When I try to reuse the texture to draw to the window it comes out completely wrong.

Here is my code. It may be a little long but if you have the patience to read it it would help me out a lot! :stuck_out_tongue: There are 3 parts. a) Setting texture and framebuffer. b) Rendering to framebuffer c) Passing texture into shader to render.

Edit: I tried posting my code here but it wouldn’t let me post. If anyone knows how to post code let me know that as well haha.

till what point do you see your code working?

So if instead of rendering to the framebuffer I render directly to the screen the first time around, the image turns out exactly how I want. However when I render to the framebuffer and then pass that texture into my shader, I’ve been getting a couple of different effects depending on if I pass in the texture first or call glUseProgram(shader) first or glBindFrameBuffer(, 0) first, etc. Sometimes the object I’m shading just comes out black and other times the wrong texture gets applied onto it.

If there’s a way for the site to allow me to post my code here directly I can show you exactly what I’m doing.