版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医院《护理安全管理条例》测试题及答案
- 张家口市桥西区2025年社区网格员笔试考试题库及参考答案
- 酒吧店长面试题及答案
- 《说明文顺序|时间空间逻辑顺序》
- 七年级语文上册文言文阅读课|课外拓展
- (安全管理规定)试卷试题
- 七年级劳动教育上册缝纫课|基础针法
- 《2026拯救脓毒症运动国际指南:儿童脓毒症与脓毒性休克管理》解读
- 广东省汕尾市陆丰市2025-2026学年八年级下学期期末考试语文试题(含答案)
- 熔融纺纺丝操作工岗前测试验证考核试卷含答案
- 2025年医疗废物分类收集与转运处置管理制度培训试题及答案
- 2026年建设工程质量检测人员考试(建筑地基与基础检测)题库及答案(安徽)
- 2025年国家故宫博物院应届高校毕业生招聘64人(北京)笔试历年参考题及答案
- 两层停车场施工方案设计
- 2026内蒙古通辽市人民医院招聘备案制编制护理人员50人笔试备考试题及答案解析
- 卧龙包头永磁电机产业园项目环境影响报告书
- 2025中国国新资产管理有限公司相关岗位招聘4人笔试历年常考点试题专练附带答案详解2套试卷
- 2025年发电厂应聘值长面试题库及答案
- 2025年青少年保护海洋环境知识竞赛题库及答案
- 大型机具移动施工方案
- DB11-T 638-2023 房屋修缮工程工程量计算标准
评论
0/150
提交评论