This function load a *.tga texture file and convert to OpenGL pixel format, uncompress only.

 #pragma pack(1)

 struct TgaHeader
{
unsigned char m_IDLength;
unsigned char m_ColorMapType;
unsigned char m_ImageType;
unsigned short m_CMapStart;
unsigned short m_CMapLength;
unsigned char m_CMapDepth;
unsigned short m_XOffset;
unsigned short m_YOffset;
unsigned short m_Width;
unsigned short m_Height;
unsigned char m_PixelDepth;
unsigned char m_ImageDescriptor;
}; #pragma pack()
 bool LoadTGA(const char *pszFileName, unsigned char *pBuffer, int iBufferSize, int *pInternalFormat, int *pWidth, int *pHeight)
{
FileHandle_t pFile = g_pFileSystem->Open(pszFileName, "rb"); if (!pFile)
return false; TgaHeader Header;
memset(&Header, , sizeof(Header)); g_pFileSystem->Read(&Header, sizeof(Header), pFile); if (Header.m_ImageType != )
{
g_pFileSystem->Close(pFile);
return false;
} if (Header.m_PixelDepth != && Header.m_PixelDepth != )
{
g_pFileSystem->Close(pFile);
return false;
} uint32 iPixelSize, iImageSize; switch (Header.m_PixelDepth)
{
case :
iPixelSize = ;
*pInternalFormat = GL_RGB;
break;
case :
iPixelSize = ;
*pInternalFormat = GL_RGBA;
break;
} iImageSize = Header.m_Width * Header.m_Height * iPixelSize; if (iImageSize > (uint32)iBufferSize)
{
g_pFileSystem->Close(pFile);
return false;
} uint32 iLineSize = Header.m_Width * iPixelSize;
uint32 iLinePos; for (uint32 y = ; y < Header.m_Height; ++y)
{
iLinePos = (Header.m_Height - y - ) * iLineSize;
g_pFileSystem->Read(&pBuffer[iLinePos], iLineSize, pFile);
} for (uint32 i = ; i < iImageSize; i += iPixelSize)
{
pBuffer[i + ] ^= pBuffer[i + ];
pBuffer[i + ] ^= pBuffer[i + ];
pBuffer[i + ] ^= pBuffer[i + ];
} *pWidth = Header.m_Width;
*pHeight = Header.m_Height; g_pFileSystem->Close(pFile);
return true;
}

[MetaHook] Load TGA texture to OpenGL的更多相关文章

  1. [MetaHook] Load DTX texture to OpenGL

    This function load a LithTech *.dtx texture file and convert to OpenGL pixel format, compressed supp ...

  2. [MetaHook] Load large texture from model

    We need hook "GL_LoadTexture" engine function. GL_LOADTEXTURE_SIG from hw.dll(3266) engine ...

  3. OpenGL学习--08--基本渲染(灯光)

    1.tutorial08.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> #inc ...

  4. OpenGL学习--07--模型加载(obj)

    1.tutorial07.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> #inc ...

  5. OpenGL学习--06--键盘与鼠标交互

    1.tutorial06.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> // I ...

  6. OpenGL学习--05--纹理立方体--代码

    1.tutorial05.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> // I ...

  7. 【入门向】使用 MetaHook Plus 绘制 HUD

    MetaHook Plus 是一个GoldSrc引擎(就是的Half-Life.CS1.6的引擎)的客户端插件平台,它可以加载我们自己开发的DLL插件. 首先你需要安装一个 Visual Studio ...

  8. NeHe OpenGL教程 第三十二课:拾取游戏

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  9. Projective Texture的原理与实现

    http://blog.csdn.net/xukunn1226/article/details/775644 Projective Texture是比较常见的一种技术,实现起来代码也就区区的不过百行, ...

随机推荐

  1. windows 注册表编程

    例子:将本地计算机的Monitor ID写入到注册表中 (1)获取MonitorID BOOLEAN DeviceMonitorService::EnumClassDevice(const GUID ...

  2. QA:Failed to deploy artifacts from/to snapshots XX Failed to transfer file Return code is: 405, ReasonPhrase:Method Not Allowed.

    QA: Failed to deploy artifacts from/to snapshots XX Failed to transfer file Return code is: 405, Rea ...

  3. 在Asp.net MVC中使用Authorization Manager (AzMan)进行Windows用户身份认证

    背景 创建需要通过Windows用户进行身份认证的Asp.net MVC应用 要点 在Asp.net MVC应用基于Windows用户进行身份认证的方法有很多,如MVC自带的Windows认证就经常被 ...

  4. 【mysql】关于innodb中MVCC的一些理解

    一.MVCC简介 MVCC (Multiversion Concurrency Control),即多版本并发控制技术,它使得大部分支持行锁的事务引擎,不再单纯的使用行锁来进行数据库的并发控制,取而代 ...

  5. 问题解决——warning C4503 超出修饰名的长度,名称被截断

    ========================声明============================ 本文原创,转载请注明作者和出处,并保证文章的完整性(包括本声明). 本文不定期修改完善,为 ...

  6. linux常用查看日志命令

    转自:http://yinfeifei.iteye.com/blog/779217 1.cat命令: 功能:1)显示整个文件. 示例: $ cat fileName 2)把文件串连接后传到基本输出,如 ...

  7. 烂泥:kickstart无人值守安装CentOS6.5

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 在本次实验进行之前,首先我们要把公司的网络环境进行介绍. 注意这个网络拓扑图,也是生产环境的一个实例.同时服务器192.168.1.214已关闭ipta ...

  8. CentOS 升级内核

    因为要安装go,尝试升级内核到 2.6.32.61,出现了一些问题,参考如下文档,多谢各位 http://liaozy.blog.51cto.com/921527/553921 http://www. ...

  9. C语言的函数

    "函数"在英文的翻译是"function",无论在自然科学还是计算机科学都是这个词,而"function"的本意是"功能" ...

  10. javascript 特效实现(1)——展开选项和收起效果

    知识点:javascript事件:判断当前展开收起状态:延迟执行setTimeout方法. 1.简单的展开和收起效果: 1.1 静态结构HTML代码分析 body包含最外层的div id=" ...