第33课加载压缩和未的tga文件_第1页
第33课加载压缩和未的tga文件_第2页
第33课加载压缩和未的tga文件_第3页
第33课加载压缩和未的tga文件_第4页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第三十三加载压缩和未压缩的TGA文:TGARLE开第三十三加载压缩和未压缩的TGA文:TGARLE开#ifndef #define / / / TEXTURE_H 要加入完成每件工作所需的标准头文件。在#define TGA_H #pragma I/OOpenGLibOpenGLOpenGLtypedef GLubyte* / bit要加入完成每件工作所需的标准头文件。在#define TGA_H #pragma I/OOpenGLibOpenGLOpenGLtypedef GLubyte* / bit/ / / glBindTexture/ 在*ImageData TGAtypedef GL

2、ubyte / typedef GLubyte / 6/ 每像素的字节数 (3 或 / / 图像类型 GL_RGB 或 / / / (24 或 TGA / / TGA120 2 0 0 0 0 0 / 图像类型 GL_RGB 或 / / / (24 或 TGA / / TGA120 2 0 0 0 0 0 0 0 0 0RLE010 0 0 0 0 0 0 0 0 0/ TGA/ TGApare12 0,0, pare12 pressedTGA(Texture *, char *, FILE pressedTGA(Texture *, char *, FILE 包含的文件()#include

3、/ 不接下来要做的事情是看看第一个函数,名为LoadTGA()TGAbool LoadTGA(Texture * texture, char * 它(见包含的例子)了一个文件指针,然后打开由“filename”FILE * fTGA 不接下来要做的事情是看看第一个函数,名为LoadTGA()TGAbool LoadTGA(Texture * texture, char * 它(见包含的例子)了一个文件指针,然后打开由“filename”FILE * fTGA = fopen(filename, / if(fTGA = .Error code. return false;/ / 返回 12在fr

4、eadfalseif(fread(&tgaheader, sizeof(TGAHeader), 1, fTGA) = .Error code return 如果失败则返回 memcmp()/ pare, &tgaheader, sizeof(tgaheader) = TGApressedTGA(texture, filename, / pare, &tgaheader, TGApressedTGA(texture, filename, / .Error code memcmp()/ pare, &tgaheader, sizeof(tgaheader) = TGApressedTGA(text

5、ure, filename, / pare, &tgaheader, TGApressedTGA(texture, filename, / .Error code return / 返回 TGApressedTGA(Texture * texture, char * filename, *3LoadTGA没有丢的空间false/ 6if(fread(tga.header, sizeof(tga.header), 1, fTGA) = .Error code return / 返回 BPPtexture-texture-bpp = tga.header1 * 256 + tga.header0;

6、 / = * 256 + tga.header2; /.Error code return / 返回 BPPtexture-texture-bpp = tga.header1 * 256 + tga.header0; / = * 256 + tga.header2; / WidthHeighttga.Width = texture-tga.Height = texture-height; tga.Bpp = texture-bpp;/ Bpp1bpp2432/ if(texture-width height bpp (texture-bpp !=32).Error code &return /

7、 返回 设置图像的类型。bitGL_RGB,32 bit if(texture-bpp = / 24 bittexture-type 24bit,texture-type ixel = (tga.Bpp / / / tga.imageSize = ixel * tga.Width * malloc然确认内存已经分配,并且它不是NULL。如果出现了错误,则运行错误处理代码/ texture-imageData = (GLubyte if(texture-imageData = .Error codeixel = (tga.Bpp / / / tga.imageSize = ixel * tga.

8、Width * malloc然确认内存已经分配,并且它不是NULL。如果出现了错误,则运行错误处理代码/ texture-imageData = (GLubyte if(texture-imageData = .Error code / return / / if(fread(texture-imageData, 1, tga.imageSize, fTGA) != .Error code return / TGAOpenGLBGRRGBSteve ThomasGRRGBcswap = 0; cswap bpp = tga.header1 * 256 + = tga.header3 * 256

9、 + tga.header2; tga.Width = texture-width; tga.Height = texture-height; tga.Bpp = texture-bpp;if(texture-width height bpp != & (texture-bpp !=32)24) code ixel = (tga.Bpp / = ixel * tga.Width * false/ texture-imageData = (GLubyte if(texture-imageData = .Error code / return / 返回 下一需要决定组成图像的像素数它在变量“pix

10、elcount”pixelcount = tga.Height * tga.Width; / currentpixel = currentbyte = / / / GLubyte * colorbuffer = (GLubyte 让RLERAW,127,RAW先1,ata下一需要决定组成图像的像素数它在变量“pixelcount”pixelcount = tga.Height * tga.Width; / currentpixel = currentbyte = / / / GLubyte * colorbuffer = (GLubyte 让RLERAW,127,RAW先1,ata127,/

11、GLubyte kheader = Idkheader, sizeof(GLubyte), 1, fTGA) = 0) / .Error return / If It Fails, Return RAW1kheader / RAWc1RAW和一colorbuffer否为RAW头。如果是需要添加一个到变量之中以获取头之后的像素总数/ for(short counter = 0; counter kheader; / if(fread(colorbuffer, 1, .Error ixel, kheader / RAWc1RAW和一colorbuffer否为RAW头。如果是需要添加一个到变量之中以

12、获取头之后的像素总数/ for(short counter = 0; counter kheader; / if(fread(colorbuffer, 1, .Error ixel, fTGA) != return / colorbufferBGRRGBBGRARGBA,urrentbyte = / 写“R”ixel = +12 = colorbuffer1; /写“G” = colorbuffer0; / 写“B”/ 32texture-urrentbyte + 3 = colorbuffer3; / 写“A”/ currentbyte += / RLEckheader127c/ RLEkh

13、eader -= 127ID Bitif(fread(colorbuffer, 1, .Error ixel, fTGA) != / RLE颜色值拷贝到图像数据中,预处理RB/ for(shortc/ RLEkheader -= 127ID Bitif(fread(colorbuffer, 1, .Error ixel, fTGA) != / RLE颜色值拷贝到图像数据中,预处理RB/ for(short counter = 0; counter / 拷贝“R”kheader; texture-/ 拷贝“G”texture-/ 拷贝“B”texture-urrentbyte = + 1 = + 2 = / 32ixel = / 拷贝“A”t

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论