亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tgaloader.cpp

?? opengl開發(fā)的 小游戲
?? CPP
字號:
/********************************************************************************
/Name:		TGA.cpp																*
/Header:	tga.h																*
/Purpose:	Load Compressed and Uncompressed TGA files							*
/Functions:	LoadTGA(Texture * texture, char * filename)							*
/			LoadCompressedTGA(Texture * texture, char * filename, FILE * fTGA)	*
/			LoadUncompressedTGA(Texture * texture, char * filename, FILE * fTGA)*	
/*******************************************************************************/
#include "tga.h"


/********************************************************************************
/name :		LoadTGA(Texture * texture, char * filename)							*
/function:  Open and test the file to make sure it is a valid TGA file			*	
/parems:	texture, pointer to a Texture structure								*
/			filename, string pointing to file to open							*
/********************************************************************************/

bool LoadTGA(Texture * texture, char * filename)				// Load a TGA file
{
	FILE * fTGA;												// File pointer to texture file
	fTGA = fopen(filename, "rb");								// Open file for reading

	if(fTGA == NULL)											// If it didn't open....
	{
		MessageBox(NULL, "Could not open texture file", "ERROR", MB_OK);	// Display an error message
		return false;														// Exit function
	}

	if(fread(&tgaheader, sizeof(TGAHeader), 1, fTGA) == 0)					// Attempt to read 12 byte header from file
	{
		MessageBox(NULL, "Could not read file header", "ERROR", MB_OK);		// If it fails, display an error message 
		if(fTGA != NULL)													// Check to seeiffile is still open
		{
			fclose(fTGA);													// If it is, close it
		}
		return false;														// Exit function
	}

	if(memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)				// See if header matches the predefined header of 
	{																		// an Uncompressed TGA image
		LoadUncompressedTGA(texture, filename, fTGA);						// If so, jump to Uncompressed TGA loading code
	}
	else if(memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)		// See if header matches the predefined header of
	{																		// an RLE compressed TGA image
		LoadCompressedTGA(texture, filename, fTGA);							// If so, jump to Compressed TGA loading code
	}
	else																	// If header matches neither type
	{
		MessageBox(NULL, "TGA file be type 2 or type 10 ", "Invalid Image", MB_OK);	// Display an error
		fclose(fTGA);
		return false;																// Exit function
	}
	return true;															// All went well, continue on
}

bool LoadUncompressedTGA(Texture * texture, char * filename, FILE * fTGA)	// Load an uncompressed TGA (note, much of this code is based on NeHe's 
{																			// TGA Loading code nehe.gamedev.net)
	if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)					// Read TGA header
	{										
		MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);		// Display error
		if(fTGA != NULL)													// if file is still open
		{
			fclose(fTGA);													// Close it
		}
		return false;														// Return failular
	}	

	texture->width  = tga.header[1] * 256 + tga.header[0];					// Determine The TGA Width	(highbyte*256+lowbyte)
	texture->height = tga.header[3] * 256 + tga.header[2];					// Determine The TGA Height	(highbyte*256+lowbyte)
	texture->bpp	= tga.header[4];										// Determine the bits per pixel
	tga.Width		= texture->width;										// Copy width into local structure						
	tga.Height		= texture->height;										// Copy height into local structure
	tga.Bpp			= texture->bpp;											// Copy BPP into local structure

	if((texture->width <= 0) || (texture->height <= 0) || ((texture->bpp != 24) && (texture->bpp !=32)))	// Make sure all information is valid
	{
		MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);	// Display Error
		if(fTGA != NULL)													// Check if file is still open
		{
			fclose(fTGA);													// If so, close it
		}
		return false;														// Return failed
	}

	if(texture->bpp == 24)													// If the BPP of the image is 24...
		texture->type	= GL_RGB;											// Set Image type to GL_RGB
	else																	// Else if its 32 BPP
		texture->type	= GL_RGBA;											// Set image type to GL_RGBA

	tga.bytesPerPixel	= (tga.Bpp / 8);									// Compute the number of BYTES per pixel
	tga.imageSize		= (tga.bytesPerPixel * tga.Width * tga.Height);		// Compute the total amout ofmemory needed to store data
	texture->imageData	= (GLubyte *)malloc(tga.imageSize);					// Allocate that much memory

	if(texture->imageData == NULL)											// If no space was allocated
	{
		MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);	// Display Error
		fclose(fTGA);														// Close the file
		return false;														// Return failed
	}

	if(fread(texture->imageData, 1, tga.imageSize, fTGA) != tga.imageSize)	// Attempt to read image data
	{
		MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);		// Display Error
		if(texture->imageData != NULL)										// If imagedata has data in it
		{
			free(texture->imageData);										// Delete data from memory
		}
		fclose(fTGA);														// Close file
		return false;														// Return failed
	}

	// Byte Swapping Optimized By Steve Thomas
	for(GLuint cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel)
	{
		texture->imageData[cswap] ^= texture->imageData[cswap+2] ^=
		texture->imageData[cswap] ^= texture->imageData[cswap+2];
	}

	fclose(fTGA);															// Close file
	return true;															// Return success
}

bool LoadCompressedTGA(Texture * texture, char * filename, FILE * fTGA)		// Load COMPRESSED TGAs
{ 
	if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)					// Attempt to read header
	{
		MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);		// Display Error
		if(fTGA != NULL)													// If file is open
		{
			fclose(fTGA);													// Close it
		}
		return false;														// Return failed
	}

	texture->width  = tga.header[1] * 256 + tga.header[0];					// Determine The TGA Width	(highbyte*256+lowbyte)
	texture->height = tga.header[3] * 256 + tga.header[2];					// Determine The TGA Height	(highbyte*256+lowbyte)
	texture->bpp	= tga.header[4];										// Determine Bits Per Pixel
	tga.Width		= texture->width;										// Copy width to local structure
	tga.Height		= texture->height;										// Copy width to local structure
	tga.Bpp			= texture->bpp;											// Copy width to local structure

	if((texture->width <= 0) || (texture->height <= 0) || ((texture->bpp != 24) && (texture->bpp !=32)))	//Make sure all texture info is ok
	{
		MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);	// If it isnt...Display error
		if(fTGA != NULL)													// Check if file is open
		{
			fclose(fTGA);													// Ifit is, close it
		}
		return false;														// Return failed
	}

	if(texture->bpp == 24)													// If the BPP of the image is 24...
		texture->type	= GL_RGB;											// Set Image type to GL_RGB
	else																	// Else if its 32 BPP
		texture->type	= GL_RGBA;											// Set image type to GL_RGBA

	tga.bytesPerPixel	= (tga.Bpp / 8);									// Compute BYTES per pixel
	tga.imageSize		= (tga.bytesPerPixel * tga.Width * tga.Height);		// Compute amout of memory needed to store image
	texture->imageData	= (GLubyte *)malloc(tga.imageSize);					// Allocate that much memory

	if(texture->imageData == NULL)											// If it wasnt allocated correctly..
	{
		MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);	// Display Error
		fclose(fTGA);														// Close file
		return false;														// Return failed
	}

	GLuint pixelcount	= tga.Height * tga.Width;							// Nuber of pixels in the image
	GLuint currentpixel	= 0;												// Current pixel being read
	GLuint currentbyte	= 0;												// Current byte 
	GLubyte * colorbuffer = (GLubyte *)malloc(tga.bytesPerPixel);			// Storage for 1 pixel

	do
	{
		GLubyte chunkheader = 0;											// Storage for "chunk" header

		if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0)				// Read in the 1 byte header
		{
			MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK);	// Display Error
			if(fTGA != NULL)												// If file is open
			{
				fclose(fTGA);												// Close file
			}
			if(texture->imageData != NULL)									// If there is stored image data
			{
				free(texture->imageData);									// Delete image data
			}
			return false;													// Return failed
		}

		if(chunkheader < 128)												// If the ehader is < 128, it means the that is the number of RAW color packets minus 1
		{																	// that follow the header
			chunkheader++;													// add 1 to get number of following color values
			for(short counter = 0; counter < chunkheader; counter++)		// Read RAW color values
			{
				if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) // Try to read 1 pixel
				{
					MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);		// IF we cant, display an error

					if(fTGA != NULL)													// See if file is open
					{
						fclose(fTGA);													// If so, close file
					}

					if(colorbuffer != NULL)												// See if colorbuffer has data in it
					{
						free(colorbuffer);												// If so, delete it
					}

					if(texture->imageData != NULL)										// See if there is stored Image data
					{
						free(texture->imageData);										// If so, delete it too
					}

					return false;														// Return failed
				}
																						// write to memory
				texture->imageData[currentbyte		] = colorbuffer[2];				    // Flip R and B vcolor values around in the process 
				texture->imageData[currentbyte + 1	] = colorbuffer[1];
				texture->imageData[currentbyte + 2	] = colorbuffer[0];

				if(tga.bytesPerPixel == 4)												// if its a 32 bpp image
				{
					texture->imageData[currentbyte + 3] = colorbuffer[3];				// copy the 4th byte
				}

				currentbyte += tga.bytesPerPixel;										// Increase thecurrent byte by the number of bytes per pixel
				currentpixel++;															// Increase current pixel by 1

				if(currentpixel > pixelcount)											// Make sure we havent read too many pixels
				{
					MessageBox(NULL, "Too many pixels read", "ERROR", NULL);			// if there is too many... Display an error!

					if(fTGA != NULL)													// If there is a file open
					{
						fclose(fTGA);													// Close file
					}	

					if(colorbuffer != NULL)												// If there is data in colorbuffer
					{
						free(colorbuffer);												// Delete it
					}

					if(texture->imageData != NULL)										// If there is Image data
					{
						free(texture->imageData);										// delete it
					}

					return false;														// Return failed
				}
			}
		}
		else																			// chunkheader > 128 RLE data, next color reapeated chunkheader - 127 times
		{
			chunkheader -= 127;															// Subteact 127 to get rid of the ID bit
			if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel)		// Attempt to read following color values
			{	
				MessageBox(NULL, "Could not read from file", "ERROR", MB_OK);			// If attempt fails.. Display error (again)

				if(fTGA != NULL)														// If thereis a file open
				{
					fclose(fTGA);														// Close it
				}

				if(colorbuffer != NULL)													// If there is data in the colorbuffer
				{
					free(colorbuffer);													// delete it
				}

				if(texture->imageData != NULL)											// If thereis image data
				{
					free(texture->imageData);											// delete it
				}

				return false;															// return failed
			}

			for(short counter = 0; counter < chunkheader; counter++)					// copy the color into the image data as many times as dictated 
			{																			// by the header
				texture->imageData[currentbyte		] = colorbuffer[2];					// switch R and B bytes areound while copying
				texture->imageData[currentbyte + 1	] = colorbuffer[1];
				texture->imageData[currentbyte + 2	] = colorbuffer[0];

				if(tga.bytesPerPixel == 4)												// If TGA images is 32 bpp
				{
					texture->imageData[currentbyte + 3] = colorbuffer[3];				// Copy 4th byte
				}

				currentbyte += tga.bytesPerPixel;										// Increase current byte by the number of bytes per pixel
				currentpixel++;															// Increase pixel count by 1

				if(currentpixel > pixelcount)											// Make sure we havent written too many pixels
				{
					MessageBox(NULL, "Too many pixels read", "ERROR", NULL);			// if there is too many... Display an error!

					if(fTGA != NULL)													// If there is a file open
					{
						fclose(fTGA);													// Close file
					}	

					if(colorbuffer != NULL)												// If there is data in colorbuffer
					{
						free(colorbuffer);												// Delete it
					}

					if(texture->imageData != NULL)										// If there is Image data
					{
						free(texture->imageData);										// delete it
					}

					return false;														// Return failed
				}
			}
		}
	}

	while(currentpixel < pixelcount);													// Loop while there are still pixels left
	fclose(fTGA);																		// Close the file
	return true;																		// return success
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲丝袜精品丝袜在线| 日韩亚洲欧美一区| 亚洲免费av高清| 91亚洲精品乱码久久久久久蜜桃 | 欧美亚男人的天堂| 一个色综合av| 欧美精品一级二级| 狠狠色综合日日| 国产免费观看久久| 色av成人天堂桃色av| 日韩国产一二三区| 26uuu亚洲| 91麻豆免费视频| 日韩高清国产一区在线| 337p粉嫩大胆噜噜噜噜噜91av| 不卡视频一二三| 亚洲 欧美综合在线网络| 日韩免费电影一区| 波多野结衣的一区二区三区| 亚洲免费在线播放| 日韩三级在线免费观看| 国产99久久久国产精品免费看| 亚洲欧美日韩国产中文在线| 欧美人动与zoxxxx乱| 国产一区二区三区免费观看| 亚洲女子a中天字幕| 日韩一区二区视频| youjizz久久| 日产国产欧美视频一区精品| 中日韩免费视频中文字幕| 欧美日韩国产综合一区二区三区 | 中文字幕免费在线观看视频一区| 91麻豆精东视频| 久久99精品国产麻豆不卡| 椎名由奈av一区二区三区| 欧美一级欧美一级在线播放| 国产成人精品免费| 日韩在线播放一区二区| 中文字幕一区二区三区蜜月 | 亚洲成人av中文| 国产三级一区二区三区| 欧美老肥妇做.爰bbww视频| 高潮精品一区videoshd| 日韩专区在线视频| 中文字幕色av一区二区三区| 欧美一级黄色片| 欧美在线观看一区二区| 成人黄色一级视频| 国产一区福利在线| 天天av天天翘天天综合网| 亚洲欧洲精品一区二区精品久久久| 欧美一级久久久| 欧美日韩精品电影| 色哟哟一区二区| 成人免费不卡视频| 国产一区欧美一区| 久久成人精品无人区| 一区二区成人在线视频| 国产精品欧美一区二区三区| 欧美不卡一区二区三区四区| 欧美日本一区二区三区四区| 色欧美日韩亚洲| 不卡av在线网| 丰满亚洲少妇av| 国产精品影视在线| 激情小说欧美图片| 麻豆精品一二三| 日av在线不卡| 麻豆精品新av中文字幕| 蜜桃传媒麻豆第一区在线观看| 性做久久久久久免费观看| 亚洲精选视频免费看| 国产精品你懂的在线| 国产欧美日韩不卡| 国产精品网站一区| 国产精品高潮呻吟| 国产精品国产三级国产专播品爱网| 精品99一区二区三区| 欧美成人一区二区三区| 精品理论电影在线| 久久午夜羞羞影院免费观看| 久久久久久电影| 国产精品欧美经典| 亚洲欧洲日韩一区二区三区| 《视频一区视频二区| 亚洲精品国产第一综合99久久| 亚洲日本成人在线观看| 一区二区三区在线视频免费| 亚洲综合在线五月| 欧美a级一区二区| 精品无人区卡一卡二卡三乱码免费卡| 精品在线视频一区| 成人精品视频一区二区三区| 91在线播放网址| 在线播放中文字幕一区| 欧美成人vr18sexvr| 欧美国产一区二区在线观看 | 国产日韩综合av| 国产精品灌醉下药二区| 亚洲国产精品尤物yw在线观看| 日韩精品成人一区二区三区| 韩日av一区二区| 99久久伊人精品| 欧美精品在线观看播放| 久久久久久久av麻豆果冻| 亚洲日本在线a| 美女任你摸久久| 成人黄色国产精品网站大全在线免费观看| 色婷婷综合视频在线观看| 欧美久久久久久蜜桃| 久久久www免费人成精品| 日韩伦理免费电影| 秋霞电影网一区二区| 成人高清视频免费观看| 欧美日韩中字一区| 久久精品水蜜桃av综合天堂| 亚洲青青青在线视频| 美国av一区二区| 一本一道久久a久久精品综合蜜臀| 欧美日韩国产色站一区二区三区| 久久综合九色综合97婷婷女人| 亚洲三级在线观看| 国产剧情一区二区| 欧美日韩国产一区| 中文字幕在线不卡国产视频| 麻豆成人免费电影| 91成人免费在线视频| www国产成人免费观看视频 深夜成人网| 亚洲视频中文字幕| 国产精品资源网站| 在线综合亚洲欧美在线视频| 国产精品素人视频| 久久激五月天综合精品| 在线精品视频免费观看| 国产欧美一区二区精品性色超碰 | 国产黄人亚洲片| 9191精品国产综合久久久久久 | 一区二区欧美视频| 国产成人午夜片在线观看高清观看| 欧美中文字幕亚洲一区二区va在线 | 韩日欧美一区二区三区| 欧美日免费三级在线| 亚洲日本va午夜在线影院| 国产精品影音先锋| 精品美女一区二区| 免费在线观看一区| 欧美午夜精品一区二区蜜桃| 成人免费在线播放视频| 国产麻豆成人精品| 精品日韩欧美在线| 免费观看在线综合色| 欧美人与z0zoxxxx视频| 亚洲综合在线电影| 91丨九色丨尤物| 1024成人网色www| www.欧美精品一二区| 久久精品人人爽人人爽| 久久成人av少妇免费| 欧美电影免费观看高清完整版在| 调教+趴+乳夹+国产+精品| 欧美影视一区在线| 亚洲国产色一区| 欧美色图一区二区三区| 亚洲综合色噜噜狠狠| 色美美综合视频| 亚洲精品成人精品456| av电影一区二区| 成人免费在线视频观看| 欧洲亚洲国产日韩| 亚洲超碰97人人做人人爱| 欧美伊人久久久久久久久影院 | 成人免费看的视频| 中文字幕一区二区在线观看| 91美女在线视频| 亚洲国产精品一区二区久久恐怖片 | 欧美性色黄大片| 日韩精品午夜视频| 在线播放欧美女士性生活| 日本网站在线观看一区二区三区| 69精品人人人人| 卡一卡二国产精品| 国产亚洲自拍一区| 成年人国产精品| 一区二区三区精品视频在线| 日本久久一区二区三区| 亚洲成人免费在线观看| 欧美一区二区女人| 九色综合国产一区二区三区| 久久久久久久综合日本| 成人va在线观看| 亚洲国产精品一区二区www| 欧美高清dvd| 精品一区二区三区免费| 国产精品视频在线看| 欧美三级韩国三级日本三斤| 三级一区在线视频先锋| 欧美精品一区二区三区蜜桃视频| 国产成人av电影| 亚洲资源在线观看| 日韩欧美一级二级|