[MetaHook] Load DTX texture to OpenGL
This function load a LithTech *.dtx texture file and convert to OpenGL pixel format, compressed support.
Use FileSystem interface. :D
#pragma pack(1) struct DtxHeader
{
unsigned int iResType;
int iVersion;
unsigned short usWidth;
unsigned short usHeight;
unsigned short usMipmaps;
unsigned short usSections;
int iFlags;
int iUserFlags;
unsigned char ubExtra[];
char szCommandString[];
}; #pragma pack()
bool LoadDTX(const char *pszFileName, unsigned char *pBuffer, int iBufferSize, int *pInternalFormat, int *pWidth, int *pHeight, int *pImageSize)
{
FileHandle_t pFile = g_pFileSystem->Open(pszFileName, "rb"); if (!pFile)
return false; DtxHeader Header;
memset(&Header, , sizeof(Header)); g_pFileSystem->Read(&Header, sizeof(Header), pFile); if (Header.iResType != || Header.iVersion != - || Header.usMipmaps == )
{
g_pFileSystem->Close(pFile);
return false;
} *pWidth = Header.usWidth;
*pHeight = Header.usHeight; int iBpp = Header.ubExtra[];
int iSize; if (iBpp == )
iBpp = ; if (iBpp == )
{
iSize = Header.usWidth * Header.usHeight * ;
*pInternalFormat = GL_RGBA;
}
else if (iBpp == )
{
iSize = (Header.usWidth * Header.usHeight) >> ;
*pInternalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
}
else if (iBpp == )
{
iSize = Header.usWidth * Header.usHeight;
*pInternalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
}
else if (iBpp == )
{
iSize = Header.usWidth * Header.usHeight;
*pInternalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
}
else
{
iSize = ;
} *pImageSize = iSize; if (iSize == || iSize > iBufferSize)
{
g_pFileSystem->Close(pFile);
return false;
} g_pFileSystem->Read(pBuffer, iSize, pFile); if (iBpp == )
{
for (uint32 i = ; i < (uint32)iSize; i += )
{
pBuffer[i + ] ^= pBuffer[i + ];
pBuffer[i + ] ^= pBuffer[i + ];
pBuffer[i + ] ^= pBuffer[i + ];
}
} g_pFileSystem->Close(pFile);
return true;
}
[MetaHook] Load DTX texture to OpenGL的更多相关文章
- [MetaHook] Load TGA texture to OpenGL
This function load a *.tga texture file and convert to OpenGL pixel format, uncompress only. #pragma ...
- [MetaHook] Load large texture from model
We need hook "GL_LoadTexture" engine function. GL_LOADTEXTURE_SIG from hw.dll(3266) engine ...
- Projective Texture的原理与实现
http://blog.csdn.net/xukunn1226/article/details/775644 Projective Texture是比较常见的一种技术,实现起来代码也就区区的不过百行, ...
- SDL OPENGL 在linux ubuntu示例
gl画纹理texture /* * SDL OpenGL Tutorial. * (c) Michael Vance, 2000 * briareos@lokigames.com * * Distri ...
- OpenGL ES 3.0之Texturing纹理详解(一)
本文流程 1.Texturing基础 2.装载Texturing和mipmapping 3.纹理过滤和包装 4.Texture level-of-detail, swizzles, and depth ...
- 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 ...
随机推荐
- win7共享文件夹给局域网
1.设置共享 2.关闭"需要密码访问"
- 记录JVM垃圾回收算法
垃圾回收算法可以分为三类,都基于标记-清除(复制)算法: Serial算法(单线程) 并行算法 并发算法 JVM会根据机器的硬件配置对每个内存代选择适合的回收算法,比如,如果机器多于1个核,会对年轻代 ...
- Java 8 LongAdders:管理并发计数器的正确方式
转自:http://www.importnew.com/11345.html 我只是喜欢新鲜的事物,而Java 8 有很多新东西.这次我想讨论其中我最喜欢的之一:并发加法器.这是一个新的类集合,他们用 ...
- 烂泥:查看服务器的BIOS是否开启CPU虚拟化
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 有关CPU是否支持虚拟化,我们可以通过相关的命令和软件进行查看. 在windows系统下,我们可以使用CPU-Z这个软件,如下图: 在linux系统下, ...
- Linux查看BIOS信息
http://www.linuxde.net/2013/02/12499.html
- A daemon process class in python
In everbright task schedule project, we need some daemon process to do certain work, here is a examp ...
- Mac/Linux 定时运行命令行
想要开机运行的话可以通过 mac 自带的 Automator 将要运行的命令打包成一个app,用后在用户组的“登录时启动”列表里加上那个app. 但是想要定时运行就不能这么做了,要用上一个叫cront ...
- 浅谈Java中的深拷贝和浅拷贝(转载)
浅谈Java中的深拷贝和浅拷贝(转载) 原文链接: http://blog.csdn.net/tounaobun/article/details/8491392 假如说你想复制一个简单变量.很简单: ...
- java 字节流和字符流的区别 转载
转载自:http://blog.csdn.net/cynhafa/article/details/6882061 java 字节流和字符流的区别 字节流与和字符流的使用非常相似,两者除了操作代码上的不 ...
- Expect 入门
一, Expect的作用 Expect广泛应用于交互式操作和自动化测试的场景之中,用来实现自动和交互式任务进行通信,而无需人的干预. 二, Ubuntu安装Expect sudo ...