opengl masking
I am trying to achive an effect something similar to the lesson 20: masking. instead of using seperate mask texture, i want to use the alpha channel of my original texture. i''ve tried using glAlphaFunc/GL_ALPHA_TEST but nothing really shows up (i don''t know if this is what i''m suppose to do). i tried a few different blending modes but to no avail.
Thanks in advance,
-Diaconal
If your texture has no alpha mask, you''ll never use the alpha mask with glAlphaFunc/GL_ALPHA_TEST.
Some years ago, I''ve made an example with that but it''s impossible for me to find it.
In fact, you must add an alpha mask to your texture. I did that with Paint Shop Pro.
Next, simply activate the alpha test and in 2 lines it''s done.
Hope this helps you
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
Some years ago, I''ve made an example with that but it''s impossible for me to find it.
In fact, you must add an alpha mask to your texture. I did that with Paint Shop Pro.
Next, simply activate the alpha test and in 2 lines it''s done.
Hope this helps you
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
My texture does have an alpha mask but i still can''t seem to make it work. which func should i use for glAlphaFunc? i tried:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1.0f);
...render my quad with texture;
glDisable(GL_ALPHA_TEST);
but not thing shows up
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1.0f);
...render my quad with texture;
glDisable(GL_ALPHA_TEST);
but not thing shows up

the alpha values in your texture will range from 0 to 255 like any other texture, but the value you pass into glAlphaFunc will be from 0 to 1...
it''s similar in how it works to the stencil test...
if you want only those pixels with an alpha above 128 to be drawn, use glAlphaFunc(GL_GREATER,0.5);
or, I feel the best bet, is simply to draw only those pixels with at least some alpha, ie, not zero.. so, glAlphaFunc(GL_NOTEQUAL,0);
thats how I usually go about it.
| - Project-X - On hold (kindof
).. - | - adDeath - | - email me - |
it''s similar in how it works to the stencil test...
if you want only those pixels with an alpha above 128 to be drawn, use glAlphaFunc(GL_GREATER,0.5);
or, I feel the best bet, is simply to draw only those pixels with at least some alpha, ie, not zero.. so, glAlphaFunc(GL_NOTEQUAL,0);
thats how I usually go about it.
| - Project-X - On hold (kindof

still no luck 
this is my init code:
and then my actual renderign code is:
the sFont->glSoPrint() function just simply renders some quads with the texture that has an alpha mask, where the parts that are no suppose to show up as black.
is there any extra code i need maybe in my init or is my concept wrong?
[edited by - Diaconal on August 30, 2003 4:14:28 PM]
[edited by - Diaconal on August 30, 2003 4:15:30 PM]

this is my init code:
glClearColor (0.0f, 0.0f, 0.0f, 1.0f); glClearDepth (1.0f); glDepthFunc (GL_LEQUAL); glEnable (GL_DEPTH_TEST); glEnable (GL_TEXTURE_2D); glShadeModel (GL_FLAT); glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
and then my actual renderign code is:
//glEnable(GL_BLEND); //glDisable(GL_DEPTH_TEST); //glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_NOTEQUAL, 0.0f); sFont->glSoPrint(0.0f, 0.0f, sCaption); glDisable(GL_ALPHA_TEST); //glEnable(GL_DEPTH_TEST); //glDisable(GL_BLEND);
the sFont->glSoPrint() function just simply renders some quads with the texture that has an alpha mask, where the parts that are no suppose to show up as black.
is there any extra code i need maybe in my init or is my concept wrong?
[edited by - Diaconal on August 30, 2003 4:14:28 PM]
[edited by - Diaconal on August 30, 2003 4:15:30 PM]
PROBLEM SOLVED! :D
well here''s the code:
the the key is the first BlendFunc, source is GL_ZERO and and destination is one minus src color, the reason its one minus is because when masking, its sorta the opposite of alpha values. and also the setting the colour to white
well here''s the code:
glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); //glEnable(GL_ALPHA_TEST); //glAlphaFunc(GL_NOTEQUAL, 0.0f); glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_COLOR); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); sFont->glSoPrint(0.0f, 0.0f, sCaption); glBlendFunc(GL_ONE, GL_ONE); glColor4fv(fForeColor); sFont->glSoPrint(0.0f, 0.0f, sCaption); //glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST);
the the key is the first BlendFunc, source is GL_ZERO and and destination is one minus src color, the reason its one minus is because when masking, its sorta the opposite of alpha values. and also the setting the colour to white
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement