Jump to content
  • Advertisement
Sign in to follow this  
DaN1maL

Multitexturing with 1 texture unit

This topic is 4970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
>>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
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
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
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
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
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!