szamil's picture

FBO to texture to Shader - Twice

Hi,
I have trubble with sending more than two texture to the fragment shader. I have something like this:

private void Render()//Render!
        {   
            //..some sets 
 
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, textureId1);
            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, textureId2);
 
            //enable shader
            GL.UseProgram(shader_program_pass2);
 
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fboId1);
                GL.PushAttrib(AttribMask.ViewportBit);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);    
 
                //draw something
 
                GL.Uniform1(GL.GetUniformLocation(shader_program_pass1, "text0"), 0);
 
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fboId2);
                GL.PushAttrib(AttribMask.ViewportBit);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
                //draw something again
 
                GL.Uniform1(GL.GetUniformLocation(shader_program_pass1, "text1"), 1);
 
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
 
            GL.UseProgram(shader_program_pass1);
 
            //draw using shader with textures
 
            GL.UseProgram(0);
            //draw with no shader
            //swap
            glControl.SwapBuffers();
        }

Please. help!
Thanks.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Are you getting an error? How does the rendering differ from what you expected?

Try using the debug version of OpenTK.dll, which will inform you of any OpenGL errors as soon as they happen.

It would also help if you posted the shader source.

szamil's picture

Thanks for reply!
What I get is exactly the same textures in both samplers. Sorry for not mention it before. Shaders are as simple as they can be. They map textures from samplers on cube.

the Fiddler's picture
GL.UseProgram(shader_program_pass2);
...
GL.Uniform1(GL.GetUniformLocation(shader_program_pass1, "text0"), 0);

You are binding pass2 but querying the uniforms for pass1. Doesn't look right.

szamil's picture

Its ok, I use one shader to render the texture, then another to work on this texure and mapping. Pass1 is about to work on textures, pass2 is to produce these textures...
Or maybe I cannot work simultonously on two shaders?

the Fiddler's picture

You can only work with a single shader at a time: GL.Uniform*() affects the program that is currently bound with GL.UseProgram().

In other words, you need to bind pass1 before changing its uniforms (and then bind pass2 if you wish to render with that).

szamil's picture

Yeah, that is working now! Thank you very much!

Now I switch shader with GL.UseProgram() before I pass the texture to shader, and after I GL.Uniform*() I switch back. I'll make it more clear (one FBO, one switch at the end) and post it here.

Again thanks for help. I am really appreciate!

the Fiddler's picture

You are welcome. :)