[MetaHook] Load TGA texture to OpenGL
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的更多相关文章
- [MetaHook] Load DTX texture to OpenGL
This function load a LithTech *.dtx texture file and convert to OpenGL pixel format, compressed supp ...
- [MetaHook] Load large texture from model
We need hook "GL_LoadTexture" engine function. GL_LOADTEXTURE_SIG from hw.dll(3266) engine ...
- OpenGL学习--08--基本渲染(灯光)
1.tutorial08.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> #inc ...
- OpenGL学习--07--模型加载(obj)
1.tutorial07.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> #inc ...
- OpenGL学习--06--键盘与鼠标交互
1.tutorial06.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> // I ...
- OpenGL学习--05--纹理立方体--代码
1.tutorial05.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> // I ...
- 【入门向】使用 MetaHook Plus 绘制 HUD
MetaHook Plus 是一个GoldSrc引擎(就是的Half-Life.CS1.6的引擎)的客户端插件平台,它可以加载我们自己开发的DLL插件. 首先你需要安装一个 Visual Studio ...
- NeHe OpenGL教程 第三十二课:拾取游戏
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- Projective Texture的原理与实现
http://blog.csdn.net/xukunn1226/article/details/775644 Projective Texture是比较常见的一种技术,实现起来代码也就区区的不过百行, ...
随机推荐
- C++中的常量折叠
先看例子: #include <iostream> using namespace std; int main() { ; int * p = (int *)(&a); *p = ...
- ERROR: The partition with /var/lib/mysql is too full! failed!
发现:ERROR: The partition with /var/lib/mysql is too full! failed! 然后df -h 发现硬盘100% 于是分析到底什么占用了这近两百G ...
- Effective Java 01 Consider static factory methods instead of constructors
Advantage Unlike constructors, they have names. (BigInteger.probablePrime vs BigInteger(int, int, Ra ...
- 【mysql】统计库、表大小
1. 查看该数据库实例下所有库大小,得到的结果是以MB为单位 mysql> select table_schema,sum(data_length)/1024/1024 as data_leng ...
- sass+compass+bootstrap三剑合璧高效开发记录
1. 先搭建环境,下载node.js,rubyinstaller,安装, 安装rubyinstaller时,要选上include system path,这样就会自动将node.js执行添加到wind ...
- private成员变量真的私有吗?(用指针刨他祖坟)
今天写程序时突然想到的,为什么不用指针去获取类的成员变量呢.于是做了这个实验.首先定义了一个类: class Test { private: int i; char c; int* p; public ...
- Regarding learning
when you learn something, just like learn computer language. if you just learn some basic usage, not ...
- css中position属性(absolute|relative|static|fixed)概述及应用
position属性的相关定义: static:无特殊定位,对象遵循正常文档流; relative:对象遵循正常文档流; absolute:对象脱离正常文档流 fixed:对象脱离正常文档流 我们先来 ...
- Linux命令学习-mkdir
1. [root@www tmp]# mkdir test <=建立一名为 test 的新目录 2. [root@www tmp]# mkdir -p /opt/tmp/abc < ...
- 并发用户数与TPS之间的关系
1. 背景 在做性能测试的时候,很多人都用并发用户数来衡量系统的性能,觉得系统能支撑的并发用户数越多,系统的性能就越好:对TPS不是非常理解,也根本不知道它们之间的关系,因此非常有必要进行解释. 2 ...