Advertisement Jump to content
Sign in to follow this  

TGA texture : again

This topic is 4968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys please bare with me, I am opening a new thread for the same issue that I was asking about on the directx forum: by the way is there a way to upload images to the forum so that one can demonstrate the question ? I am trying to load a TGA file and use it to texture map a cube. No compression nor encoding is used. the TGA color format is 24 bit BGR. what I do is fairly simple: I just load the image data block into memory and convert it to RGB. then I created another memory buffer that has the format of XRGB and copied the image data into the new buffer. the x is filled with 1 and the rgb are filled with the TGA rgb values. I then created an empty DX9 texture of the format xrgb. I used memcpy to copy the image buffer to the texture surface. I had two problems that I can not explain. 1) the texture is dimmed and looks darker than the original picture but it is not distorted. I do not think it is something to do with lighting, blending or materials. I think it is something to do with loading the image in the first place. I am saying that because I used the D3DX function to create the texture using the same render states and it looks bright as expected. somebody told me about gamma correction. I never used but it might be the reason behind that. 2) another weird problem is that I was able to load a picture once. it was not distorted but was dimmed as mentioned earlier. what was surprising is that I loaded another picture using the same code. the loaded picture was dimmed as before but the strange thing is that it was flipped 180 degrees along the vertical direction. I have two questions: I though that just coping the image to the texture row by row is wrong and DX9 stores the image column by column. but still I had the first picture not flipped. what is going on ? is there some field in the tga that says how the pixels are ordered. ?

Share this post

Link to post
Share on other sites
1) To apply gamma to an image, raise each color component to the power of 1/gamma. I'd use a 256-entry table to do this.. or else you'd need a floating-point pow() per component per pixel. If you want more information on gamma, see the colorspace faq

2) The TGA spec is full of all sorts of useful information:
"Image Specification - Field 5 (10 bytes):
Bits 5 & 4: These bits are used to indicate the order in which pixel data is transferred from the file to the screen. Bit 4 is for left-to-right ordering and bit 5 is for top-to-bottom ordering as shown below."

3) I wouldn't use memcpy to copy your whole image into the texture. This blindly assumes width equals pitch, which is up to the driver, and not guaranteed. Instead, memcpy the bits a scanline at a time.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!