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的更多相关文章

  1. [MetaHook] Load TGA texture to OpenGL

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

  2. [MetaHook] Load large texture from model

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

  3. Projective Texture的原理与实现

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

  4. SDL OPENGL 在linux ubuntu示例

    gl画纹理texture /* * SDL OpenGL Tutorial. * (c) Michael Vance, 2000 * briareos@lokigames.com * * Distri ...

  5. OpenGL ES 3.0之Texturing纹理详解(一)

    本文流程 1.Texturing基础 2.装载Texturing和mipmapping 3.纹理过滤和包装 4.Texture level-of-detail, swizzles, and depth ...

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

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

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

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

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

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

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

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

随机推荐

  1. paas架构之docker——容器进程管理

    1.docker进程管理 docker的进程管理命令ps的用法基本和ubuntu系统的用法一致 1.1. 查看docker进程 sudo docker ps –a 1.2. 附着到容器上 Sudo d ...

  2. Effective Java 27 Favor generic methods

    Static utility methods are particularly good candidates for generification. The type parameter list, ...

  3. 由IP和掩码计算广播地址

    public static IPAddress GetBroadcast(IPAddress ipAddress, IPAddress subnetMask) { var ip = ipAddress ...

  4. PHP笔记(PHP高级篇)

    高级篇中将涉及数据库的使用以及Cookie和Session会话,提高PHP的开发效率和运行效率 PHP程序员需要掌握的MySQL操作 为项目设计表 使用SQL语句 MySQL的目录结构 data目录中 ...

  5. 烂泥:LVM学习之逻辑卷、卷组及物理卷删除

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 上篇文章,我们介绍了有关LVM的逻辑卷及卷组的空间缩小.这次我们来介绍下如何删除一个逻辑卷及卷组. 删除逻辑卷需要以下几个步骤: 1. 卸载已经挂载的逻 ...

  6. 续Gulp使用入门-综合运用>使用Gulp构建一个项目

    这是我的文件目录结构图  下面是我gulpfile.js的配置 'use strict' var gulp=require('gulp'); var gutil=require('gulp-util' ...

  7. hdu 4612 Warm up 双连通+树形dp思想

    Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total S ...

  8. hdu 1003 Max sum(简单DP)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem ...

  9. 原始的2文件的makefile错误

    从来没系统的看过makefile文档,平时属于复制模板,用完即忘,下午尝试按自己的理解写一个最简单的makefile,含2个.c文件,1个.h文件,费了个把小时,参考别人的文章才弄出来,特记录. ma ...

  10. List与Set的使用

    接口Collection: Collection是Java的一个集合框架, 也是一个根接口.JDK中没有提供此接口的任何实现,但是提供了更具体的子接口Set和List接口的实现,所有的Collecti ...