Skip to main content
gamedev.net
🔒 Locked

Modifying a texture

Started by Enjoy Mar 2, 2008 at 9:29 AM 3 replies 2.5k views
Original Post
Enjoy
Enjoy
Hello, I am loading texture from TGA file. How can I modify a loaded texture? And how can I generate a texture on my own? For example if I want to generate a cloud texture and after this to attach this to a billboard. I am storing Image data like this: unsigned char *data Thank you in advance.
polymorphed
polymorphed
Assuming that your .TGA loader loads the image into a bitmap array in the RGB (or RGBA) format, it should be as easy as just changing the colors yourself:

unsigned char* image;image[0] = Red of #1 pixelimage[1] = Green of #1pixelimage[2] = Blue of #1 pixelimage[3] = Alpha of #1 pixelimage[4] = Red of #2 pixelimage[5] = Green of #2pixelimage[6] = Blue of #2 pixelimage[7] = Alpha of #2 pixelimage[8] = Red of #3 pixel// Etc..


And generating your own texture is just as easy

int width = 256;int height = 256;int format = 3; // 3 bytes per pixel, RGBunsigned char* texture = new unsigned char[width*height*format];for (int x = 0; x < width; x++){    for (int y = 0; y < height; y++)    {        texture[((y*width) + x)*format]   = Red;        texture[((y*width) + x)*format+1] = Green;        texture[((y*width) + x)*format+2] = Blue;    }}glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);


I hope this helps.
while (tired) DrinkCoffee();
Lord_Evil
Lord_Evil
Like polymorphed showed, modifying a texture when loading it is as easy as changing individual pixels. This way you can also generate textures - the only thing you need is some algorithm for generating procedural textures.

Updating a texture that is loaded to video memory can be done via glTexSubImage2D. This function let's you update a rectangular region of the texture with new data.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Enjoy
Enjoy
Many thanks,
I just didn't know how to write pixel data.

I will try if it is working for me.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.