PDA

View Full Version : texture data manipulation



TheAtlasProject
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.

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

did you come across this thread?

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=256768

Maybe that might be useful. :)

TheAtlasProject
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

dletozeun
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.

TheAtlasProject
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;

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

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

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