Changing Hue of a texture

Started by
17 comments, last by Devil_Inside 18 years, 9 months ago
Ok, that's what i tried:
1. I duplicated my LoadTgaTexture() function and modified it so it doesn't create a texture after it loads the data from the file, but saves the data to a special structure;
2. I created a function that loops through the pixels of the image from the structure and changes their color.
3. I created a function that updates the old data of the texture with the new, modified data (using glTexSubImage2d).

Everything works fine except one thing. glTexSubImage2D aplies my new texture with its width and height smaller than the original texture. This way only a part of the original textures gets updated. And the strange thing is that the updated part contains the whole texture, but in a smaller scale. I don't understand how could this be, if the new texture has the old's texture width and height and the same number of pixels. It should fit just right, but it doesn't. Where could be the problem?
=================* No Brain - No Pain *=================
Advertisement
Post the relevant code. Especially where you upload the image data with glTexSubImage2D
void UpdateTexture(TGADATA *tgafile, int TexId){   glBindTexture(GL_TEXTURE_2D,TextureArray[TexId]);   int format;   if(tgafile->channel==4) format=GL_RGBA; else format=GL_RGB;   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tgafile->width, tgafile->height, format, GL_UNSIGNED_BYTE, tgafile->data);};

Here is the code. The other strange thing is that if i recreate the texture using:

gluBuild2DMipmaps(GL_TEXTURE_2D, tgafile->channel, tgafile->width, tgafile->height, TextureType, GL_UNSIGNED_BYTE, tgafile->data);

for example, it works fine, fullsize.
=================* No Brain - No Pain *=================
I think the ARB_imaging extension can do this. IIRC, You can convolve the colour of a fragment with a matrix. It's not in the OpenGL core specification - at least in 1.2 it's optional, so ideally you'd need a fallback path.
Quote:Original post by Devil_Inside
void UpdateTexture(TGADATA *tgafile, int TexId){   glBindTexture(GL_TEXTURE_2D,TextureArray[TexId]);   int format;   if(tgafile->channel==4) format=GL_RGBA; else format=GL_RGB;   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tgafile->width, tgafile->height, format, GL_UNSIGNED_BYTE, tgafile->data);};

Well, I can't see anything wrong with the code.

Quote:
gluBuild2DMipmaps(GL_TEXTURE_2D, tgafile->channel, tgafile->width, tgafile->height, TextureType, GL_UNSIGNED_BYTE, tgafile->data);

for example, it works fine, fullsize.


Well, then apparently it's got something to do with the mipmapping. I can't tell you exactly what, it's a little strange. Maybe you have to upload the texture data for each of the mipmap leves individually with glTexSubImage2D...
The other thing i noticed today is that i cant use glTexImage2D to create 32bit textures. The 32bit textures created using glTexImage2D are represented as white boxes (24bit textures are ok) while gluBuild2DMipmaps() works fine with both 32 and 24 bit.

That's what works:
glGenTextures(1,&TextureArray[TextureID]);glBindTexture(GL_TEXTURE_2D,TextureArray[TextureID]);int TextureType;if(tgafile->channel==4) TextureType=GL_RGBA; else TextureType=GL_RGB;gluBuild2DMipmaps(GL_TEXTURE_2D, tgafile->channel, tgafile->width, tgafile->height, TextureType, GL_UNSIGNED_BYTE, tgafile->data);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);


And that's what doesn't work:
glGenTextures(1,&TextureArray[TextureID]);glBindTexture(GL_TEXTURE_2D,TextureArray[TextureID]);int TextureType;if(tgafile->channel==4) TextureType=GL_RGBA; else TextureType=GL_RGB;glTexImage2D(GL_TEXTURE_2D,0,tgafile->channel, tgafile->width, tgafile->height, 0, TextureType, GL_UNSIGNED_BYTE, tgafile->data);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);



And about the mipmap levels: how do i know how many levels there are?
=================* No Brain - No Pain *=================
All right!!! I've got the solution to the problem with glTexSubImage2D(). My texture size wasn't "^2", i changed the size and now its updating fullsize.

If i get it right, i don't really need mipmaps if i'm using opengl for 2d games. I can only create level 0 texture and that's all, am i wrong? But the problem with glTexImage2D still exists. Could hardware be the cause of glTexImage2D 32-bit texture creation failure?
=================* No Brain - No Pain *=================
Quote:Original post by Devil_Inside
All right!!! I've got the solution to the problem with glTexSubImage2D(). My texture size wasn't "^2", i changed the size and now its updating fullsize.


Ah! Sure, that makes sense now.

Quote:
If i get it right, i don't really need mipmaps if i'm using opengl for 2d games. I can only create level 0 texture and that's all, am i wrong?


You're entirely right.

Quote:
But the problem with glTexImage2D still exists. Could hardware be the cause of glTexImage2D 32-bit texture creation failure?

You know, I had a similar problem, (might very well have been the exact same one), a little while ago. There was a case in which glTexImage2D should have worked perfectly fine, but for some reason the texture turned up white. I really had checked everything, (all the parameters were correct, glGetError returned GL_NO_ERROR, the texture had power of two dimensions, and everything...) It worked with gluBuild2DMipmaps, though. I didn't actually look into the problem, so I'm afraid I don't have a solution...

Anyway, congratulations on getting it working.
Ok, THANKS A LOT for the help[attention][attention][attention][attention][attention][attention]
=================* No Brain - No Pain *=================

This topic is closed to new replies.

Advertisement