View Full Version : TGA loading...
04-05-2001, 10:20 PM
I need a sample code of TGA loading to Visual Studio 6.0, I'v tried many codes before and none of them are working.
Please help me!
type "opengl tga loading code" into google
i also have code on my site (profile)
04-06-2001, 03:25 AM
are you looking to add tga images as resources to be included in the exe image or just run time loading?
if the former, I have no idea, so when you find out let us all know http://www.opengl.org/discussion_boards/ubb/smile.gif
if the later, nehe nehe nehe nehe nehe nehe nehe nehe nehe nehe nehe nehe NEHE (http://nehe.gamedev.net)
( i know everyone makes references to this site, but in reality, I think everyone should at least browse all those tutorials as soon as they hear about them. would save a lot of repetative posts )
04-06-2001, 03:28 AM
hum, this an advanced opengl coding forum ... you should post this topic on the beginner forum ...
04-06-2001, 02:52 PM
Try this other thread (http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/002574.html) .
04-07-2001, 06:54 PM
For putting a TGA into an executable as a resource, you can just include it as a custom resource in VC++. To access the data, you use FindResource to get a handle to the resource, Then LoadResource to load the resource, then LockResource to get an LPVOID pointer to the actual data. You can then just read from that data the same as if you had read in a full file before parsing the TGA header, etc...
04-08-2001, 12:07 PM
you know, I've been using VC++ since 4.something and I still don't know how to use all of it's features. I've just gotten used to the fact that it's been easier to do something by hand than getting it working in the IDE. Microsoft makes me lazy, complacent, and unmotivated. Thanks for the eye-opener...
04-08-2001, 09:22 PM
This is the header of a .tga file. If you work with truecolor images exported with photoshop, 3DsMax or a similar program, focus only on those variables:
Ok. If you want to load a .tga:
// Open the .tga file for read
FILE* tgafile = fopen("some.tga","rb");
// Read the header
fread (&tga_header, sizeof(tga_header), 1, tgafile);
The remaining data is the pixel data (again, for truecolor images), so we must determine if it's 16,24 or 32 bits, create a buffer and then copy the pixel data to that buffer..
the buffer must be of size (imageW*imageH*(depth>>3))
fread (pixelBuffer, sizeof(pixelBuffer), 1, tgafile);
** Note that the pixel components are arranged as ARGB data (or RGB on 24 bit)
And that's it.. if you want to read a pixel, you could do something like this:
(I assume 32 bits data and pixelBuffer an array of DWORDs)
A = (BYTE) (pixelBuffer >> 24) & 0xFF;
R = (BYTE) (pixelBuffer >> 16) & 0xFF;
G = (BYTE) (pixelBuffer >> 8) & 0xFF;
B = (BYTE) pixelBuffer & 0xFF;
Sorry if you're looking for a complete .tga reader, I just think that this format is very easy to read and I wanted to show you that..
[This message has been edited by royconejo (edited 04-08-2001).]
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.