GL blending problem
Ok, this is probably something really simple I''ve missed but it''s 22:30 and I''ve already been on it for 3 hours, and its driving me nuts.
Basically I want to know how to blend one texture over another with parts of the overlay not rendered. An example would be the blood splats/explosions from Half-Life, in which there is a greyscale bitmap that has glcolor3f() set for it''s white component (the explosion mark say) and it''s black outline is not rendered.
I''m not sure if I''m making much sense, but any help in the realms of glblendfunc, glalphafunc, the texture parameters or something.
Thanks in advance.
-Mezz
I''m not sure if I''m making much sense, but any help in the realms of glblendfunc, glalphafunc, the texture parameters or something.
Close enough, my friend!
In your initialisation:
Try playing with the values in the glAlphaFunc to get the desired effect - you learn by doing
Also make sure your texture has an alpha channel.
Paul Groves.
http://home.clara.net/paulyg
OpenGL for Beginners
Close enough, my friend!
In your initialisation:
glAlphaFunc ( GL_GREATER, .01 );glEnable ( GL_ALPHA_TEST );glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );glEnable ( GL_BLEND );
Try playing with the values in the glAlphaFunc to get the desired effect - you learn by doing

Also make sure your texture has an alpha channel.
glTexImage2D ( GL_TEXTURE_2D, 0, components, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image );
Paul Groves.
http://home.clara.net/paulyg
OpenGL for Beginners
Paul Grovespauls opengl page
Hey, thanks for the info Pauly, the only problem is:
I''m using a greyscale .bmp
The reason?
I''m damn sure that''s how Valve did it in Half-Life, and since I know it''s possible, I''m trying to do it that way.
Any more help anyone.
I have tried loading the texture with GL_LUMINANCE, but the image appears all screwy, and I''ve also done
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULAE);
I seem to be able to get it to ignore the black backround of the image, but then the rear image renders over the front one. This is really making me crazy,
any other help would be appreciated.
I''ve also looked at other tutorials on the net (one by NeHe and another one at SGI) but I cannot see how they are achieving this, oh well.
-Mezz
I''m using a greyscale .bmp
The reason?
I''m damn sure that''s how Valve did it in Half-Life, and since I know it''s possible, I''m trying to do it that way.
Any more help anyone.
I have tried loading the texture with GL_LUMINANCE, but the image appears all screwy, and I''ve also done
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULAE);
I seem to be able to get it to ignore the black backround of the image, but then the rear image renders over the front one. This is really making me crazy,
any other help would be appreciated.
I''ve also looked at other tutorials on the net (one by NeHe and another one at SGI) but I cannot see how they are achieving this, oh well.
-Mezz
I''m not sure if this is your problem, but you said that the rear image renders over the front one. This might be because you have to draw the world first, then render any blended polygons. So you would render the entire world, then afterwards you would render the explosion marks, with depth testing disabled, by glDisable(GL_DEPTH_TEST).
Also if you wanted to use a greyscale texture, just save your greyscale texture as a 24 bit bmp, load it using:
and then when you draw it call glColor4ub(r,g,b,a), where r,g,b is your color and "a" is your blending component. Note, if you have blending enabled and you use glColor3f() you will get unpredictable results (at least in my experience)
Also if you wanted to use a greyscale texture, just save your greyscale texture as a 24 bit bmp, load it using:
glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,data);
and then when you draw it call glColor4ub(r,g,b,a), where r,g,b is your color and "a" is your blending component. Note, if you have blending enabled and you use glColor3f() you will get unpredictable results (at least in my experience)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement