PDA

View Full Version : use FBO-Texture in FBO



MoeTM
04-02-2011, 02:32 PM
Hello,

is it possible to use a texture in fbo, which the fbo renders in. Here is an example:

FBO::MakeCurrent()

RenderScene() // into 4 textures (colour/depth/position/normal)

FBO::ColourTexture::Bind() // <- does this work?
FBO::PositionTexture::Bind() // <- does this work?
FBO::NormalTexture::Bind() // <- does this work?

FragShader::Bind()

RenderQuad()

FragShader::Unbind()

FBO::ColourTexture::Unbind()
FBO::PositionTexture::Unbind()
FBO::NormalTexture::Unbind()

Device::MakeCurrent()

Alfonse Reinheart
04-02-2011, 02:43 PM
None of those are OpenGL functions. You're not talking about OpenGL; you're talking about some library layered on top of OpenGL. What library are you using?

MoeTM
04-07-2011, 07:58 AM
its pseudo code, I m using opengl

Alfonse Reinheart
04-07-2011, 02:00 PM
You're asking "does this work?" for "pseudo" code. OpenGL doesn't execute "pseudo" code; it executes actual code. So we can't know if your "pseudo" code works unless we can see what the actual code you're intending to call is.

For example:



FBO::ColourTexture::Bind()


What does this do? Does it attach the "ColourTexture" to the FBO (glFramebufferTexture)? Does it bind the "ColourTexture" in the FBO to the OpenGL context (ie: glBindTexture)?

Without knowing what you're talking about, we can't really help.

MoeTM
04-08-2011, 08:21 AM
Ok, I solve the problem myself but I have another one. If I use multitexturing it only works if I activate a texture_unit with the same id as the texture is bound to.

Like this:

glUniform1i(UniformLocation[i], TexturenID[i]); glActiveTexture(GL_TEXTURE0 + TexturenID[i]); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, TexturenID[i]);

So I activate GL_TEXTURE0 + eg. 20 by why does it not work using GL_TEXTURE0 + 0 , GL_TEXTURE0 + 1 for ervery texture?

I hope this question is easier to understand :)

Alfonse Reinheart
04-08-2011, 02:25 PM
glActiveTexture(GL_TEXTURE0 + TexturenID);

Um, no. That's not how you bind textures to the context.

TexturenID[ i] is a texture object you created with glGenTextures. It is not a "number"; it is a handle that represents the texture you created. You should [i]never use it as a number the way you do here.

This (http://www.opengl.org/wiki/GLSL_Sampler#Binding_textures_to_samplers) explains how to bind textures to samplers.

MoeTM
04-09-2011, 02:13 AM
Thx for the link,

but the strange thing is, that the texture is allways black when I m doing it the way your tutorial says. Is there a reason why he activates texture unit 0,2,4 and not 0,1,2?

Alfonse Reinheart
04-09-2011, 02:58 AM
but the strange thing is, that the texture is allways black when I m doing it the way your tutorial says.

Then there is something else wrong. And since I sadly lack the power to read your mind or sufficient clairvoyance to see your code from where I'm sitting, I have no way to know what the problem is unless you post a more complete example.


Is there a reason why he activates texture unit 0,2,4 and not 0,1,2?

To demonstrate that the texture unit indices don't have to be in any particular order.

MoeTM
04-09-2011, 03:31 AM
the problem is my code is very very long and an example is complicated to make. Could the problem be that I m using GL_TEXTURE_RECT and GL_TEXTURE_2D

Alfonse Reinheart
04-09-2011, 03:33 AM
the problem is my code is very very long and an example is complicated to make.

Then your first step needs to be isolating the problem. That is, make a small demo app that just proves whether or not you can get multitexturing to work. Then build back up, slowly figuring out how your code in your main project differs from the code in your demo project.

MoeTM
04-09-2011, 06:05 AM
I guess you are right, thx for a lot for your help