Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

OverKill

Masking Textures with color

This topic is 6154 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

hi, i''m trying to mask a b&w texture with the help of a mask and the color it. here''s the code i''m using so far: //not optimised glPushMatrix (); glBlendFunc(GL_DST_COLOR,GL_ZERO); glBindTexture (GL_TEXTURE_2D, texture[0]); glTranslatef (STARS.Position.x, STARS[i].Position.y, STARS[i].Position.z); glBegin(GL_QUADS); glTexCoord2f (0.0,0.0); glVertex3f (0.0f,0.0f, 0.0f ); glTexCoord2f (1.0,0.0); glVertex3f (5.0f*STARS[i].Size,0.0f,0.0f ); glTexCoord2f (1.0,1.0); glVertex3f (5.0f*STARS[i].Size,5.0f*STARS[i].Size,0.0f ); glTexCoord2f (0.0,1.0); glVertex3f (0.0f,5.0f*STARS[i].Size,0.0f ); glEnd(); glColor4ub (STARS[i].Color.r, STARS[i].Color.g, STARS[i].Color.b, 150);//won''t work!!!! glBlendFunc(GL_ONE,GL_ONE); glBindTexture (GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); //same as above! glEnd(); glPopMatrix (); what am i doing wrong? thanks

Share this post


Link to post
Share on other sites
Advertisement
not sure I totally follow what you''re trying to do...

I see that the first call to glTranslatef leaves the index off of "STARS", but I would think the compiler would catch that... seeing the "i" index makes me think this is in a loop. Are you setting your color for the first pass correctly? What is already on the screen? The GL_DST_COLOR means multiply the source color by the color that''s already there. Is this part not working or is it the second part? The second part seems pretty bullet-proof assuming your texture is okay...

What the result when this runs?

Share this post


Link to post
Share on other sites
Hi!!

I am not sure if this is totaly correct...but here some ps.code :

Enable Blending (DST, ALPHA, Whatever);
Draw the poly / tris with the mask texture
Disable Blending.
Draw the poly / tris with the color texture!!

All this is right out of my head, and i really haven''t done
this much...but if i am wrong here....someone let me know!!

As a reference you should try NeHe''s tutorials on masking!!
I think he does the same that i was trying to make out here! :

Hope this can help you a little!!

btw : You are refering to a number in an array ("i"), but you
don''t set the value for "i" anywhere......

Take Care!

- -- ---[XaOs]--- -- -

Share this post


Link to post
Share on other sites
Hello and thaks for the help.
yes, "i" refers to a loop.
i did not add it since it doesn''t really have anything to do
with my problem. :-)
what i would like to have is:
mask the negative
and render the original in the color defined.
is that even possible, or would i have to make different
colored originals???

thanks again.

frank

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
As far as I understood, do you want to change the color of the texture you have (b&w) to the color you have given in
glColor4ub(...) right?

You have to call
glEnable(GL_COLOR_MATERIAL); to get the effect you want.

cya
C_L

Share this post


Link to post
Share on other sites
do i have to enable something?
atm i have:
glEnable (GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_COLOR_MATERIAL);
glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_BLEND);

anything else?
do i need any of these?
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_EQUAL);

thanks again

Share this post


Link to post
Share on other sites
another Q:
would i have to do my own depth-sorting?
atm i am just rendering them to the screen.

thanks again

frank

Share this post


Link to post
Share on other sites
You only need GL_COLOR_MATERIAL if lighting is enabled, which it doesn''t appear to be.

Sorry, I still don''t think I fully understand the problem.

If there are overlaps, you''ll have to split up your drawing routines. Given the functions as they are currently, all multiplies can be done at one time, then all adds (ie, the first part for each star, then the second part for each star). This is because multiplies and adds are order independent amongs themselves, but mixed cause problems. by splitting them up, you avoid having to sort.

Share this post


Link to post
Share on other sites
Found my problem:
i was hoping to have the white part of my orig image colored.
stupid me!
is there a way to color textures?
or define transparent area''s?

Share this post


Link to post
Share on other sites
How should i do my blending?
first glBlendFunc(GL_DST_COLOR,GL_ZERO);
then glBlendFunc(GL_ONE,GL_ONE);???
and does anyone have a explanation of the parameters?
glBlendFunc(source, dest); correct
so GL_One means that all of the info from the source is used,
and all the dest info, correct?
GL_DST_COLOR means that the destination info is used
GL_ZERO that that no dest info is used.

any help in clearing this up would be appreciated.
(i have nehe''s tutorials and the red book, but cannot figure it out! :-))

thakns

Share this post


Link to post
Share on other sites

  • 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!