How to dynamic change the transparency of texture?

Hi, guys:

During the implementation, I meet a problem which need to efficiently change the alpha value of texture without using glTexImage2D to reload the image. The texture is attached onto a moving grid (There may be thousands of these moving grids). Could anyone give me some hint about this? And, I am not familiar with glsl. Thanks a lot.

Can you give an images of the effect you’re trying to achieve?
You can try experimenting with the NV_texture_barrier extension. It allows reading from render target textures before writing to them. Although, that might be a bit overboard for what you’re doing. NV_texture_barrier isn’t supported by Intel (yet).

I don’t think NV_texture_barrier is even relevant, without knowing what the poster wants to do.

zoros, what are you trying to achieve? In what way does the alpha value of the texture change? Does the overall transparency of the texture change? In that case, use glColor4f in combination with GL_MODULATE texture environment. Or do the pixels’ alpha component change arbitrarily? In that case you may want to explore render-to-texture options.

Thanks, DarkGNight and remdul!

I want achieve the texture’s gradually appearing after initialization and gradually disappearing after deletion. Many textures may blend with each other due to the movement of local grid.

I try “glColor4f in combination with GL_MODULATE texture environment”. But, it does not work. My code is like this:

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
//    glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.01);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
         
    float alpha = step/total_step; // alpha is [0, 1]
glColor4f(alpha, alpha, alpha,alpha);

//glColor4fv(emi);
glDepthMask(0);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); 
glVertex2f( x-size, y-size);

glTexCoord2f(1.0, 0.0); 
glVertex2f( x+size, y-size);

glTexCoord2f(1.0, 1.0); 
glVertex2f( x+size,  y+size);

glTexCoord2f(0.0, 1.0); 
glVertex2f( x-size,  y+size);
glEnd();
glDepthMask(1);

I want achieve the texture’s gradually appearing after initialization and gradually disappearing after deletion. Many textures may blend with each other due to the movement of local grid.

That’s still rather vague. Are you making a 2d isometric game with sprites fading in and out? Or are you making photo book browser software? Or display satellite imagery? You’ll have to be more specific to give us an idea what the desired behavior should be. There’s an infinite number of purposes for texture transparency, and a large number of ways to achieve it.

What I’m missing in your code is glEnable(GL_BLEND). Also, do you really want to enable GL_ALPHA_TEST? This will give you hard-edge between visible and invisible pixels, no smooth transition.

And perhaps you’ll also want to do this:
glColor4f(1, 1, 1,alpha);
Or the texture will fade to black as it fades away.

Thanks for patient reply.

The thing I am doing is using particles to model the cloud behavior. Each particle carries a small cloud texture. Their overall effect can reflect the cloud movement in the air. There particles move in a specified velocity field. I will seed the particle in some location and delete some particles in some condition. In order to avoid the sudden appear and disappear, I want them to gradually change. Many particles with textures may overlap with each other. I try to blend them together based on their alpha value. About the GL_ALPHA_TEST, you are right, thanks a lot, I will modify it.

About the glEnable(GL_BLEND), I have already added it into the code. However, the texture transparency is still not changed. Therefore, my question can be simplified as (How to make a texture gradually disapear?) Thanks again!