[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 ...
随机推荐
- C语言指针学习(续)
五.数组和指针的关系 int array[10] = {0,1,2,3,4,5,6,7,8,9},value; ... ... value = array[0];//也可以写成 value = *ar ...
- IIS does not list a website that matches the launch url
233down voteaccepted I hate answering my questions: in my question i stated that i was running VS un ...
- Log4j配置与使用
log4j是Java社区事实上的日志标准解决方案.使用起来比较简单. 一. 简单使用 1.下载jar包放到lib文件夹,并加入到build path中: 2.编写log4j.properties文件, ...
- mysql中出现Incorrect DECIMAL value: '0' for column '' at row -1错误解决方案
本人开发项目时,在从一个服务器导出数据库到另一服务器时,存储过程中,报Incorrect DECIMAL value: '0' for column '' at row -1错误. 原因: 存储过程中 ...
- strcat()函数常见问题
strcat(char *_Destination,const char *_Source)函数的功能是将后一个字符串粘贴到前一个字符串的末尾 原型 char *strcat(char *_Desti ...
- matlab中subplot函数的功能
转载自http://wenku.baidu.com/link?url=UkbSbQd3cxpT7sFrDw7_BO8zJDCUvPKrmsrbITk-7n7fP8g0Vhvq3QTC0DrwwrXfa ...
- 合工大OJ 1331 回文数
Description 一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序数)是一样的,这样的数就叫回文数. 任取一个正整数,如果不是回文数,将该数与他的倒序数相加,若其和不是回文数, ...
- 获取WIN10技术预览版
说明 这是一款预发行软件 在进行商业发行之前,我们可能会对 Windows Technical Preview 进行大量修改. Microsoft 不对此处提供的信息作任何明示或默示的担保. 有些产品 ...
- NGUI Sprite Type(Simple、Sliced、Tiled、Filed、Advanced)
官方文档:http://www.tasharen.com/forum/index.php?topic=6704.0 Sprite Type 下面是UISprite的Type截图,每一种Type都有不同 ...
- Pro Git(中文版)
Pro Git(中文版) 返回 Git @ OSC 目录 1.起步 1.1 关于版本控制 1.2 Git 简史 1.3 Git 基础 1.4 安装 Git 1.5 初次运行 Git 前的配置 1.6 ...