Sign in to follow this  
DaN1maL

Multitexturing with 1 texture unit

Recommended Posts

DaN1maL    136
Is it possible to multi-texture with 1 texture unit? All I want to do is blend the bound texture with whatever is in the frame buffer. code...... glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, nTexID); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); // glvertex,gltexcoord's here ... ... But it doesn't seem to do anything. I'm thinking you have to be using at least 2 texture units for anything to happen? But all I want to do is blend/modulate with frame buffer :( BTW, this works... glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR); But I cannot use that because I need to use.. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ... Because I want alpha blending as well. So I guess what I'm asking is how do i acheive the same results as glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR) but with multi-texturing....

Share this post


Link to post
Share on other sites
zedzeek    529
>>Is it possible to multi-texture with 1 texture unit?<<

yes

>>All I want to do is blend the bound texture with whatever is in the frame buffer.<<

then u want to have blending enabled as well, multitexture does NOT blend with whats in the framebuffer, it just writes all over it unless blending is enabled

Share this post


Link to post
Share on other sites
DaN1maL    136
I do have blending enabled so that I can use GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA to do transparency blending with alpha from the vertex color..

But then I'm using GL_MODULATE for texture unit one (using GL_TEXTURE and GL_PREVIOUS (framebuffer)) to try and "combine" my texture and the frame buffer. GL_MODULATE doesn't seem to do anything (code posted above)... I'm trying to achieve the same effects as glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR) , but I'm not sure what I should be using. I thought modulate would do it, since all I really want is for the pixel in the frame buffer to be multiplied against the color in the texture.. Should I be using interpolate??

Share this post


Link to post
Share on other sites
Brother Bob    10344
Quote:
Original post by DaN1maL
But then I'm using GL_MODULATE for texture unit one (using GL_TEXTURE and GL_PREVIOUS (framebuffer)) to try and "combine" my texture and the frame buffer.

GL_PREVIOUS is the result from the previous texture combiner, not the content of the frame buffer. The frame buffer is accessable only from the blending state (in fixed function pipe at least). You cannot access the frame buffer in the texture combiners. What your code does is multiplying the texture color with the primary color, i.e. the color set by glColor.

Share this post


Link to post
Share on other sites
DaN1maL    136
In the opengl doc it said that GL_PREVIOUS is the same as GL_PRIMARY_COLOR for the first texture stage. And GL_PRIMARY_COLOR is supposed to be the "incomming fragment prior to the first stage", which I thought would be the frame buffer. GL_CONSTANT_COLOR is supposed to use whatever was set with glColor .. right?

Share this post


Link to post
Share on other sites
zedzeek    529
no, fragment is what u get from gl_lighting or gl_color, its not whats already in the framebuffer.

eg say u have a line (triangle whatever)
glColor
(1,0,0)---------(1,1,0)

and GL_SMOOTH is enabled (not GL_FLAT) then the fragemnt at the left is (1,0,0) in the middle (1,0.5,0) and right (1,1,0)

Share this post


Link to post
Share on other sites
Brother Bob    10344
GL_PRIMARY_COLOR is what zedzeek described; basically the color from the lighting equation or the color set by glColor.

GL_CONSTANT_COLOR is a per-texture combiner constant color, which remains constant untill you change it (the primary can change from fragment to fragment as the color is interpolated over the primitive). You set the constant color with glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, <pointer to RGBA color>).

Share this post


Link to post
Share on other sites
DaN1maL    136
Makes sense. One more question... Is it possible to set two blend funcs at the same time?

I want to basically do this...


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);

// draw here

glDisable(GL_BLEND);


You'd think you'd be able to set a color, and an alpha operation. But it doesn't seem to be the case. I swear I could do it in DirectX, but I'm having no luck with OpenGL.

Share this post


Link to post
Share on other sites
DaN1maL    136
I noticed there is a glBlendFuncSeparate function, would I want to use that instead?

I tried this:

glBlendFuncSeparate(GL_DST_COLOR, GL_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

.. But it seemed to only use the first two params I pass in :(

Share this post


Link to post
Share on other sites
DaN1maL    136
when i do

glBlendFuncSeparate(GL_DST_COLOR, GL_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

it modulates the colors properly, but what i draw isn't translucent like it should be. im using values less than 1.0 for my alpha in my vert color.

when i do

glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_COLOR, GL_SRC_COLOR)

it makes whatever i draw translucent properly, but then it doesnt modulate the colors.

like i said in my last post, it seems like its only using the first two params i give it

Share this post


Link to post
Share on other sites
Brother Bob    10344
glBlendFuncSeparate separates the blending function for RGB and alpha so you can combine the two with different functions. The first two parameters defines the blending function for the RGB channels, and the two last parameters the blending function for the alpha channel. Sounds like you want to combine the two blending functions into one function. Or rather, blend the fragments two times.

I think you better describe what exactly you're trying to do, what effect you're trying to achieve, so we can see the whole problem. Describe, in detail, your input data, and what the output should be.

Share this post


Link to post
Share on other sites
DaN1maL    136
i have a quad which i want to blend over something in the frame buffer. i want to modulate my quad with the frame buffer, so thats what the DST_COLOR, SRC_COLOR is for. but the quad verts have values less than 1.0 for their alpha, so i want to have the quad translucent as well.. which is what the SRC_ALPHA, ONE_MINUS_SRC_ALPHA is for.

is this possible?

Share this post


Link to post
Share on other sites
Brother Bob    10344
So basically, you want Csrc*Cdst*Asrc + Cdst*(1-Asrc) as the result from the blending stage? C is means color, A means alpha and subscript src and dst means source and destination fragments.

If so, then the answer is no, it's not possible. At least not using the fixed function pipeline. It's not possible becuase you need two factors for one of the colors (source or destination), and no blending function setup gives you that. It may be possible using fragment programs, assuming you have access to the frame buffer there. But I don't know, never used it.

Maybe multiple passes or some render to texture solution would help. Maybe someone else could come up with a solution.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this