🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

TGA files

Started by
3 comments, last by taby 17 years, 1 month ago
In tutorial 32 it explains how to make TGA files. I couldn't follow this expination and was wondering if anyone could explain it a little better for me?
Advertisement
This is a good explanation, very simple:
http://local.wasp.uwa.edu.au/~pbourke/dataformats/tga/
Is there anything specific you had trouble with? I have recently been through that tutorial myself. It's actually number 33, yes?
I can't figure out how to make the image itself. I don't understand the transparency, ect...
Here's some C++ code to output a sample TGA with transparency, using the information on Paul Bourke's website:

#include <fstream>using std::ofstream;using std::endl;#include <ios>using std::ios_base;int main(void){	// Assumes char is 1 byte, short is 2 bytes.	char temp_c = 0;	short temp_s = 0;	ofstream out("test.tga", ios_base::binary);	temp_c = 0;	out.write(&temp_c, sizeof(temp_c)); // idlength	out.write(&temp_c, sizeof(temp_c)); // colourmaptype	temp_c = 2;	out.write(&temp_c, sizeof(temp_c)); // datatypecode (2 == uncompressed RGB(A) data)	temp_s = 0;	out.write(reinterpret_cast<const char *>(&temp_s), sizeof(temp_s)); // colourmaporigin	out.write(reinterpret_cast<const char *>(&temp_s), sizeof(temp_s)); // colourmaplength	temp_c = 0;	out.write(&temp_c, sizeof(temp_c)); // colourmapdepth	temp_s = 0;	out.write(reinterpret_cast<const char *>(&temp_s), sizeof(temp_s)); // x_origin	out.write(reinterpret_cast<const char *>(&temp_s), sizeof(temp_s)); // y_origin	temp_s = 128;	out.write(reinterpret_cast<const char *>(&temp_s), sizeof(temp_s)); // width (128 pixels wide)	temp_s = 64;	out.write(reinterpret_cast<const char *>(&temp_s), sizeof(temp_s)); // height (64 pixels tall)	temp_c = 32;	out.write(&temp_c, sizeof(temp_c)); // bitsperpixel (32 bits per pixel)	temp_c = 0;	out.write(&temp_c, sizeof(temp_c)); // imagedescriptor	unsigned char r = 0;	unsigned char g = 0;	unsigned char b = 128;	unsigned char a = 0;	// output 128*64*4 bytes of data	for(short y = 0; y < 64; y++)	{		// For each line:		r += 2; // Increase red by 2		g = 0; // Reset green to 0		a = 255; // Reset alpha to 255 (fully opaque)		for(short x = 0; x < 128; x++)		{			// For each pixel in each line:			g++; // Increase green by 1			a--; // Decrease alpha by 1			out.write(reinterpret_cast<const char *>(&r), sizeof(r));			out.write(reinterpret_cast<const char *>(&g), sizeof(g));			out.write(reinterpret_cast<const char *>(&b), sizeof(b));			out.write(reinterpret_cast<const char *>(&a), sizeof(a));		}	}	return 0;}

This topic is closed to new replies.

Advertisement