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. iOS 应用架构浅谈

    当我们讨论客户端应用架构的时候,我们在讨论什么? 其实市面上大部分应用不外乎就是颠过来倒过去地做以下这些事情: 简单来说就是调API,展示页面,然后跳转到别的地方再调API,再展示页面. App确实就 ...

  2. du df 查看文件和文件夹大小

    http://www.cnblogs.com/benio/archive/2010/10/13/1849946.html du -h df -h du -h --max-depth=1 //  查看当 ...

  3. Ubuntu 环境 运行Asp.net mvc +EntityFramework+ Mysql

    关键词:ubuntu,mono,.Net framework 4.5,asp.net mvc 4,Entityframework 6,Mysql Mono安装 参考文章: Install Mono o ...

  4. Effective Java 44 Write doc comments for all exposed API elements

    Principle You must precede every exported class, interface, constructor, method, and field declarati ...

  5. window10系统安装oracle11g时遇到INS-13001环境不满足最低要求

    机器安装了window10系统,之前有次安装oracle11g是成功了.但是机器后来固态硬盘坏了,又坏了个后,还是win10系统安装oracle11g时,出现INS-13001环境不满足最低要求,郁闷 ...

  6. 设置自己的RadASM颜色

    在RadASM.ini中的color节添加 4=wls_asm_color,16777215,0,8388608,16777215,15777984,12644544,12632304,1644176 ...

  7. 烂泥:KVM、kickstart与FTP集成

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 在上一篇文章中,我们介绍了有关KVM.kickstart与NFS集成的相关内容.在这节我们将继续介绍FTP与KVM.kickstart集成的相关操作. ...

  8. 仅IE6中链接A的href为javascript协议时不能在当前页面跳转

    切页面时有时用链接A来替代按钮,这样做有几个好处 鼠标放上时默认有手状效果(不用添加cursor:pointer) 可以添加低版本IE都支持的伪类 如果点击时页面要整体刷新,即跳转,这时IE6则不尽人 ...

  9. Semiconnected--强连通缩点

    1451: Semiconnected 时间限制: 1 Sec  内存限制: 32 MB 提交: 79  解决: 20 题目描述 For a directed graph G = (V, E), if ...

  10. python datetime模块参数详解

    Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime.time模块,它提供 的接口与C标准库time.h基本一致.相比于time模块,datetime模块的接 ...