View Full Version : texture data manipulation

06-15-2009, 12:01 PM
Hi out there,

Like many others i need your help.
I googled for a couple of hours to solve my texture manipulation problem but i couldn't find anything helpful, so i hope someone here can help me out.

I want to read out the data of a loaded texture (RGB8). In particular i want to read AND write data from and to it - i thought it maybe could be done in one step - but what i'm trying doesn't seem to work. I must admit that i'm not a senior C/C++ programmer so maybe there lies the problem.

I have a terrain mesh which is textured using 2 "ordinary" textures and an "alpha map" which allows me to blend the 2 textures. What i want to do is: click on the terrain and change the alpha texture (value) at that pixel so that the second texture is more and more blended over the first.

06-15-2009, 11:01 PM
Hello TheAtlasProject,

did you come across this thread?


Maybe that might be useful. :)

06-16-2009, 07:28 AM
Thanks matchStickMan,

that's not excatly what i'm looking for but maybe it points me in the right direction :) thx

06-16-2009, 07:48 AM
Create the alpha texture with glTexImage2D, then update its content with glTexSubImage2D specifying the modified alpha texture data.

You can also rely on PBO for better performances concerning the texture data upload.

06-17-2009, 05:43 AM
Thanks for your hint dletozeun. I'll give it a try.

Is this the right way i'm using it?:

unsigned char* pdata = 0;

glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB8, GL_UNSIGNED_BYTE, (GLvoid*)pdata);

glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 16, 16, GL_RGB8, GL_UNSIGNED_BYTE, (GLvoid*)pdata);

06-18-2009, 03:00 AM
You need to allocate enough memory in the pData buffer.