Now, I’m using 2 texture units - texture 1 is a heightfield map, used to displace the mesh (greyscale, but stored as RGBA) the second texture is a repeated brick texture. Combined they look nice - but I want both culled when the alpha on the first texture is zero (see screenshot). At present, the first texture is removed but the brick texture remains.
I’ve tried setting the brick alpha to 255, so that a1*a2 = 0 where a1 = 0 (obviously). But (as shot shows), this hasn’t worked. My vertex alpha is 1.0 (so 1.0 * 0.0 * 1.0 should = 0.0!). I’m using GL_REPLACE, GL_MODULATE - I want modulate to get a nice `shaded’ effect on the mesh.
Any further ideas here?
Thanks.
[This message has been edited by Robbo (edited 04-16-2002).]
You need to try and ensure your final alpha fragment is from the first texture, then you can use glAlphaFunc. Try and pass the alpha fragment through the final stage, or use a modulate operation. Maybe reversing the texture operations would do it for you.
You certainly have enough control with newer extensions but I’m not sure if you want to use them.
I’m not using a blend function at all - I figured I could get away with just the alpha test. With a blend function, I have to enable blending and then some bits of my texture will become transparent, surely?
Erm - can anyone spot the deliberate mistakes? Sometimes when I post questions, what I’m really after is a way to fix a bug in my code! Anyway, I fixed it and it works fine - alpha test is blinding and everything looks great. Thanks anyway!!!?!
(below is the stupid, broken version)
void CTextureMaps :: Use ( const tstring& Name1, const tstring& Name2, const bool Swap, const int Mode1, const int Mode2 )
{
//
// Get the texture.
//
CTextureMap& Texture1 = Get ( Name1 ), &Texture2 = Get ( Name2 );
//
// This is a multi-texture blend function (2 units only).
//
if ( glActiveTextureARB )
{
glActiveTextureARB(GL_TEXTURE0_ARB);
//
// Enable texture unit 1
//
pGetState ()->m_Enabler.glEnableTextureUnit1 ();
//
// Bind in texture 1.
//
if ( Texture1.bIsBindable () )
{
glBindTexture ( GL_TEXTURE_2D, Texture1.GetHandle () );
}
//
// Enable texture unit 2
//
pGetState ()->m_Enabler.glEnableTextureUnit2 ();
//
// Set texture environment mode for second texture unit.
//
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
//
// and use the second texture ( although not its material ).
//
if ( Texture2.bIsBindable () )
{
glBindTexture ( GL_TEXTURE_2D, Texture2.GetHandle () );
}
}
else
{
Use ( Name1, Mode1 );
}
What’s all this getting textures from strings about? I saw someone else doing this in another post too…why?
You’re doing strcmp’s every frame for every texture?
Well I don’t really need to use strings now, but thats how I implemented it originally. I’m using stl maps\vectors\lists - textures are added and deleted - so all objects using textures would have to be updated with new pointers\indices every time one was removed. I’m sure there is a more efficient way - but, well I’m not writing a game so I’m not too fussed about the extra cycles I’ll get from not doing this. At least thats an idea for future optimisation!
[This message has been edited by Robbo (edited 04-17-2002).]