Archived

This topic is now archived and is closed to further replies.

DeschutesCore

Targa Loader - .tga image issues

Recommended Posts

Does anyone know what editor NeHe uses to create his tga files? I''ve written a TGA image loader for my Delphi OpenGL projects and the .tga files included in his demos load fine. If I create a new tga file in PSP7 or Photoshop, use one from Quake3, or use one from any other source, they appear pure white. Any ideas on this one BTW? Jason

Share this post


Link to post
Share on other sites
It could be your photo program but just for something for you to try. I had that same problem a while back. Where no matter what I did it was pure white. I discovered that I had not enabled textures. I don''t know how you would do it with TGA files. Haven''t done that tutorial yet, but with the way NeHe sets it up to do it with BMP''s do the following in InitGL()
glEnable(GL_TEXTURE_2D);

Hope this helps!

Share this post


Link to post
Share on other sites
No, the issue isn''t texturing.

Nehe''s .tga files display just fine. Other ones display white. I''ve used two different professional packages(3DStudio Max 3.1 and Adobe PhotoShop) in addition to Paint Shop Pro. This isn''t an issue of poor specification support by the programs generating the tga files, it''s my loader and something about nehe''s images.

Nehe''s .tga file texture my quad just fine, as do bitmaps. If I load his font.tga file, it display, if I edit it in all the above programs, it still works, but if I create a new one, it display''s pure white. I''ve even ensured that the Alpha channel names match exactly, even though alpha isn''t even being looked at yet.

I appreciate your time and response Running_Wolf.

Jason

Share this post


Link to post
Share on other sites
Did you save the Alpha channel? Without a aplpha channel, then you can get the white effect you are talking since it has no data...

(Of course, not all .tga files have alpha, but you loader should check for that.)

Share this post


Link to post
Share on other sites
Thanks for the reply Elixer.

I am 100% sure the alpha is there and intact. I make my selection, save it as an alpha channel, then close the image and reload it to make sure. I''ve loaded a new image from the channel to back myself up on this one. Nothing.

This one is baffling me.

Jason

Share this post


Link to post
Share on other sites
Null and Void,
That was it exactly. 256k without compression, 213k with. I noticed the file sizes after you asked me that, and they are indeed working now.

Now that I can create images I can see mself, I just need to figure out why the .tga images are tinted blue.

Thank you!

Share this post


Link to post
Share on other sites
Hiho,
you should not only car about RLE but also about the top-down alignment. Some programs like ACDSee 32 save the TGA from the first line down to the last. Some others do it the other way round. So if your texture is sometimes displayed 180° round then you have to switch the Top-Down-Orientation off.

Share this post


Link to post
Share on other sites
As far as your blue tinting,

Did you remember to flip the blue and red channels??

TGA''s file spec I believe states that they store the image in BGR format, as opposed to the RGB format. Perhaps that is why your images appear blue-tinted?

Hope it helps,

-mihkael

Share this post


Link to post
Share on other sites
Thanks for the reply Mihkael.

I''ve already fixed it and updated my site with the new loader a few days ago. My problem wasn''t an issue of not trying to swap, I wasn''t paying attention to the fact that Targa files are stored BGRA, not just BGR like bitmaps. I had to change the 3 to a 4 and it finally functioned correctly.

// Here''s the code that works, it was I * 3 that caused the problems
for I :=0 to Width * Height - 1 do
begin
Front := Pointer(Cardinal(pData) + I * 4);
Back := Pointer(Cardinal(pData) + I * 4 + 2);
Temp := Front^;
Front^ := Back^;
Back^ := Temp;
end;

I appreciate everyone taking the time to help with my little problem. I''m currently working on a set of decompression functions next. I''m sure I''ll be asking more questions.


Share this post


Link to post
Share on other sites
Thanks for the reply Mihkael.

I''ve already fixed it and updated my site with the new loader a few days ago. My problem wasn''t an issue of not trying to swap, I wasn''t paying attention to the fact that Targa files are stored BGRA, not just BGR like bitmaps. I had to change the 3 to a 4 and it finally functioned correctly.

// Here''s the code that works, it was I * 3 that caused the problems
for I :=0 to Width * Height - 1 do
begin
Front := Pointer(Cardinal(pData) + I * 4);
Back := Pointer(Cardinal(pData) + I * 4 + 2);
Temp := Front^;
Front^ := Back^;
Back^ := Temp;
end;

I appreciate everyone taking the time to help with my little problem. I''m currently working on a set of decompression functions next. I''m sure I''ll be asking more questions.


Share this post


Link to post
Share on other sites
Hi,

With regards to an earlier post about files sometimes being stored upside down. The spec also states that the image may be stored right-to-left instead of the usual left-to-right , although I''ve never actually found a file like this.

If you''re going to write a fully featured tga loader, I found the easiest way to handle this is to write your code to just read it in ignoring orientation, or assuming the most common case (upside down). Then once it''s loaded flip it either horizontally or vertically (or both) to get it the right way up. This saves having to have 4 blocks of special case code or working out some scheme that does it all in one block.

As I mentioned, you''ll probably find most files will be stored upside down, as this was how all .tga files used to be. The other options were put in for future compatibility, as the original Targa video card (which the format was designed for) stored it''s screen upside down compared to how we now expect it to be.

Dan

Share this post


Link to post
Share on other sites
quote:
Original post by DeschutesCore

Thanks for the reply Mihkael.

I''ve already fixed it and updated my site with the new loader a few days ago. My problem wasn''t an issue of not trying to swap, I wasn''t paying attention to the fact that Targa files are stored BGRA, not just BGR like bitmaps. I had to change the 3 to a 4 and it finally functioned correctly.

// Here''s the code that works, it was I * 3 that caused the problems
for I :=0 to Width * Height - 1 do
begin
Front := Pointer(Cardinal(pData) + I * 4);
Back := Pointer(Cardinal(pData) + I * 4 + 2);
Temp := Front^;
Front^ := Back^;
Back^ := Temp;
end;

I appreciate everyone taking the time to help with my little problem. I''m currently working on a set of decompression functions next. I''m sure I''ll be asking more questions.





Only targa''s with an alpha channel are stored BGRA. 24bpp TGA''s are stored BGR and the above loop wouldn''t work on them.

I suggest instead of multiplying by 4, do this
Front := Ptr(Cardinal(pData) + I * (ColorDepth div 8));

Note: you can use Ptr instead of the longer Pointer

This will allow you to use the same loop on 24bpp and 32bpp TGA''s.

Hope this helps,

Jason A.

---
I write code.
DelphiGL (http://delphigl.cfxweb.net)

Share this post


Link to post
Share on other sites