--- MaskiNg vs. MultiTexturiNg ---

Started by
14 comments, last by Wickeeed 20 years, 6 months ago
Hi, i got a simply problem witch Multitext. plz tell me what i did wrong !!! glColor3ub(255, 255, 255); glEnable(GL_BLEND); /* THIS WORKS PERFECT (without Mulitext.) glBlendFunc(GL_DST_COLOR,GL_ZERO); glBindTexture(GL_TEXTURE_2D, g_Texture[11]); int sh=30; glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex2f(a-sh-mPos.left, b+sh-mPos.top); glTexCoord2f(0.0f, 0.0f); glVertex2f(a-sh-mPos.left, b-sh-mPos.top); glTexCoord2f(1.0f, 0.0f); glVertex2f(a+sh-mPos.left, b-sh-mPos.top); glTexCoord2f(1.0f, 1.0f); glVertex2f(a+sh-mPos.left, b+sh-mPos.top); glEnd(); glBlendFunc(GL_ONE,GL_ONE); glBindTexture(GL_TEXTURE_2D, g_Texture[12]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex2f(a-sh-mPos.left, b+sh-mPos.top); glTexCoord2f(0.0f, 0.0f); glVertex2f(a-sh-mPos.left, b-sh-mPos.top); glTexCoord2f(1.0f, 0.0f); glVertex2f(a+sh-mPos.left, b-sh-mPos.top); glTexCoord2f(1.0f, 1.0f); glVertex2f(a+sh-mPos.left, b+sh-mPos.top); glEnd(); */ /* THIS WHAT I NEED !!! BUT IT DONT WORKT !!! (with MT) int sh=30; glEnable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glBlendFunc(GL_DST_COLOR,GL_ZERO); glBindTexture(GL_TEXTURE_2D, g_Texture[11]); glEnable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glBlendFunc(GL_ONE,GL_ONE); glBindTexture(GL_TEXTURE_2D, g_Texture[12]); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f); glVertex2f(a-sh-mPos.left, b+sh-mPos.top); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f); glVertex2f(a-sh-mPos.left, b-sh-mPos.top); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f); glVertex2f(a+sh-mPos.left, b-sh-mPos.top); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 1.0f); glVertex2f(a+sh-mPos.left, b+sh-mPos.top); glEnd(); */
Advertisement
Look into GL_ARB_tex_env_combine (if your video card supports it):

http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt


EDIT: Might as well post some more explanation. . . Multitexturing doesn't really do anything unless you set some parameters to determe how the textures are being combined. For example, if you want to modulate two textures with each other:

glActiveTextureARB (GL_TEXTURE0_ARB);glBindTexture (GL_TEXTURE_2D,  tex1)glEnable (GL_TEXTURE_2D);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);glActiveTextureARB (GL_TEXTURE1_ARB);glBindTexture (GL_TEXTURE_2D,  tex2)glEnable (GL_TEXTURE_2D);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);


The first block of code binds TEXTURE0 and basically establishes it as the texture being rendered. The second block takes the results of the previous texture stage and modulates it with TEXTURE1.

EDIT AGAIN: All blending functions do is determine how new, incoming pixels are combined with the existing pixels in the framebuffer. With multitexturing, the incoming pixel is the result of the multitexuring operation. Thus, the second blend function you were setting merely replaced the first as the active blend equation.

[edited by - Ostsol on October 17, 2003 12:45:38 PM]
-Ostsol
So how does that translate to
glBlendFunc(GL_DST_COLOR,GL_ZERO);
glBlendFunc(GL_ONE,GL_ONE);
???????????

Also like to mention I have a GeForce3 with an up to date glEXT.H,
and it''s not seeing any of these tokens...
quote:Original post by Anonymous Poster
So how does that translate to
glBlendFunc(GL_DST_COLOR,GL_ZERO);
glBlendFunc(GL_ONE,GL_ONE);
???????????

I guess you're basing your masking off of the Nehe demo? That demo works by masking out pixels already in the frame buffer before adding the new texture on top. With multitexturing it'll work entirely differently. Actually, if you use TGA files you can potentially avoid even using multitexturing simply by storing the mask in the alpha channel of the texture and using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
quote:Also like to mention I have a GeForce3 with an up to date glEXT.H,
and it's not seeing any of these tokens...

It certainly should. . . I think even a Geforce 2 supports this stuff.

To tell the truth, though, I'm not entirely sure of how to do such masking in multitexturing. . . I've always either put the mask in the alpha component of a TGA or added the mask as the texture's alpha in a fragment program. . .

[edited by - Ostsol on October 17, 2003 6:09:24 PM]
-Ostsol
I guess you''re basing your masking off of the Nehe demo?
nice guess!

"With multitexturing it''ll work entirely differently."
I can see that, it''s something to do with EXT_texture_env_combine and glTexEnvi() blending modes..

"Actually, if you use TGA files"
RGBA willl also work with any format supporting alphas..
I wanted to avoid alpha test altogether and only use GL_BLEND..
(but I suppose I have to make due with what I can comprehend..)

Just to inform people, you need to #define the tokens yourself from the opengl extention specification.. not sure why they wouldn''t just add them to glext.h but I guess that''s how they wanted it.. I did that and now I can play with EXT_texture_env_combine
Just curious, but where did you get your glext.h file? The one at the OpenGL extension registry. . .

http://oss.sgi.com/projects/ogl-sample/registry/

. . . certainly does have GL_ARB_texture_env_combine and even the depreciated GL_EXT_texture_env_combine. It has all but the very newest extensions in it.
-Ostsol
Yes that''s also where I got mine.. (where else?!)
sure it has function protocols and all that, just doesn''t define the tokens. If you don''t want to belive me try this with that file un-modified :

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);

Note what your compiler says about that..
Then try this (from the extention specification):

#define GL_COMBINE_EXT 0x8570

and it will work.. see what I''m saying ?
SGI''s glext.h is a half assed header!!!!
Don''t you mean:

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);

Anyway, using GL_COMBINE_EXT works fine for me, without having to redefine it.
-Ostsol
Weird.. (Maybe I should checksum my glext?! )
OK tell me if this works for you, I get "SRC_COLOR undefined" with this seemingly spec comformant line of code:

glTexEnvi(GL_TEXTURE_ENV, OPERAND0_RGB_EXT, SRC_COLOR);

And from the spec:
"Accepted by the <params> parameter of TexEnvf, TexEnvi, TexEnvfv,
and TexEnviv when the <pname> parameter value is OPERAND0_RGB_EXT or OPERAND1_RGB_EXT

SRC_COLOR,ONE_MINUS_SRC_COLOR,SRC_ALPHA, ONE_MINUS_SRC_ALPHA
"

None of those except ONE_MINUS_SRC_ALPHA works for me.
There aren''t any token values in the specs for these.

All of those work for me, too. . .
-Ostsol

This topic is closed to new replies.

Advertisement