Editing textures in memory?

Say i have loaded a 512*512 32 bit texture into opengl. Say i want to change the red component of about 10 pixels. How would this be done? Could i manipulate the texture in memory? Or would i have to edit the image save it to another texture load that one, and delete the original?

EDIT: Oh by the way, im working with texture objects. I was looking at gltexsubimage2d, but im not sure if that will work with texture objects, i cant figure out how it would.

[This message has been edited by LostInTheWoods (edited 12-19-2002).]

glTexSubImage2D will update your image – if you want to change only the red components of certain texels, you still need to have the right values of the other components.

There’s two things that would make your job easier: (1) there’s no equivalent of ColorMask for texture downloads, so you have to load all the components, (2) there’s no glGetTexSubImage that would allow you to read back just the 10 texels you want to modify. I think SGI did support a texture_color_mask extension on some accelerators, but I don’t think it’s widely available.

Working with texture objects is not a problem. Just make sure the appropriate texture image is bound first. If you want to edit texture object 12, call

glBindTexture(GL_TEXTURE_2D, 12)

before calling glTexSubImage2D.

This is just an idea, don’t know if it works.

If you had hardware that supported fragment programs, you could:

Create a pbuffer and bind the texture(A), you want to change, to the pbuffer.

Put texture coordinates of those texels that you wanted to change in texture B, and bind it to texture unit 0. Bind texture A to unit 1. Use a framgent program that reads texture coordinates from texture unit 0 and checks
if the pixel being rendered have the same coords as anyone in the list. If so, change it using some mechanism(pull values from yet another texture unit, or just static change).

Render texture A using render-to-texture.

The idea is to let the fragment program act as a filter. I dont know if you could “match up” the two textures though. Considering min/mag filters and projection etc. And what happens to a texture when it is bound to a pbuffer,before rendering that is? Cleared? “Locked”?

EDIT: typos

[This message has been edited by roffe (edited 12-19-2002).]