Masking Textures with color
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.Position.y,
STARS.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.Size,0.0f,0.0f );
glTexCoord2f (1.0,1.0);
glVertex3f (5.0f*STARS.Size,5.0f*STARS.Size,0.0f );
glTexCoord2f (0.0,1.0);
glVertex3f (0.0f,5.0f*STARS.Size,0.0f );
glEnd();
glColor4ub (STARS.Color.r,
STARS.Color.g,
STARS.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
</i>
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?
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?
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]--- -- -
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]--- -- -
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
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
July 16, 2001 07:16 AM
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
glColor4ub(...) right?
You have to call
glEnable(GL_COLOR_MATERIAL); to get the effect you want.
cya
C_L
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
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
another Q:
would i have to do my own depth-sorting?
atm i am just rendering them to the screen.
thanks again
frank
would i have to do my own depth-sorting?
atm i am just rendering them to the screen.
thanks again
frank
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.
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.
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?
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?
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement