Editing a Alpha texture in realtime

Hi,

I’m working on a terrain editor, and i’m thinking in adding the ability to paint detail textures on the terrain directly from the editor.
Currently the terrain has 4 layers of detail textures, defined by a alpha map (1 for each detail texture).
So, to change the detail maps in realtime, i need to be able to edit the alpha map of the terrain that correspondes to a particular detail texture.
My question is, i load a tga with a alpha map.
Assuming i know where(pixel x,y) i want to change the alpha map in that texture from 0 to 1, or from 1 to 0, or whatever value, how can i do this ??

thanks,
Bruno

I think using glTexSubImage may do the trick.

You could also render to texture (using FBO) with glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);

Thanks, but doing that is not exactly my problem :slight_smile:
My problem is, supose my texture is 512x512
i clicked somewhere on the terrain, and the corresponding pixel coordinate in that texture is (134,450)
Knowing this, i can render the texture to a offscreen buffer and use ReadPixels to get the color information if i want, but how do i change the alpha component of that particular pixel ?
If the pixel (134,450) has a rgba value of (100,100,100,0) how do i change it to (100,100,100,0.5) for example ??
hmm, i just had a ideia of rendering a quad of size 1, using a orthogonal projection to the texture itself using a glcolor(0,0,0,1) or something, but this looks like kind of a hack…
thanks,
Bruno

as satan mentioned (checking out the competition aye!)
use glTexSubImage( … ) to replace the alpha of the terrains texture (u might also have to replace RGB as well)
i have done something similar with terrain, when an explosion happened i would find out where in the texture it happened and alter the terrains bumpmap

No, it’s not a hack. You have two possibilities - to send data from CPU or to render to texture.
If you want to change one texel with glTexSubImage2D, then go ahead - you can keep a copy of texture in an array (in system memory), and whenever you need, update one texel and send it to GPU.
Another way is to render a quad or a point directly to texture. If you use glColorMask, then you can write directly to alpha without modyfying rgb, but you don’t have access to previous value of alpha unless you use two textures (first render fragment of original texture that is about to be modified to second texture and then use that texture when rendering back to original one) - this would be faster for updating more pixels at once (a brush).