[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 ...
随机推荐
- 关于手机微网站ICP备案
今天终于拨通了陕西省通信管理局的电话,并告诉对方我们做的是一个化妆品的微网站,会涉及到使用使用支付宝支付. 询问"xxx微网站"网站经营类型,对方告知虽然使用支付宝,但是是微网站, ...
- 整理了一些常用的jQuery动画事件
部分jQuery常用的动画函数,整理了一下,在做交互式页面的时候挺有用的 .css('a','12px');.css({ a:'12px', b:'#fff'}); .show();.hide() ...
- Hadoop Eclipse开发环境搭建
This document is from my evernote, when I was still at baidu, I have a complete hadoop developme ...
- 魔改——MFC SDI程序 转换为 MDI程序
==================================声明================================== 本文原创,转载在正文中显要的注明作者和出处,并保证文章的完 ...
- poj 2195 KM算法
题目链接:http://poj.org/problem?id=2195 KM算法模板~ 代码如下: #include "stdio.h" #include "string ...
- 简单谈谈RAID
RAID是“Redundant Array of Independent Disk”的缩写,翻译过来叫做独立磁盘的冗余阵列,其实就是磁盘的存储.访问.备份技术.在谈RAID之前,先简单学习一下存储器的 ...
- 迅为顶级四核开发板 Exynos4412开发板,仅售560元
业内公认最强四核 藐视一切挑战 ●四核CPU ●四核GPU ●双通道内存 ●HKMG技术 ●超级性能 ●至佳稳定 ●供货周期长 Exynos 4412处理器成功应用于三星GALAXY S3 ...
- js计算系统当前日期是星期几的几种方法
方法一: // 计算系统当前是星期几 var str = "今天是星期" + "日一二三四五六".charat(new date().getday()); 方法 ...
- Cg关键字(keywords)
保留标识符 除了下面列出的,任何以两个的下划线作为前缀(例如,__ newType)的标识符被保留. 注意,矩阵(matrix)和向量类型(vector types)(如half2x3或float4) ...
- css中position属性(absolute|relative|static|fixed)概述及应用
position属性的相关定义: static:无特殊定位,对象遵循正常文档流; relative:对象遵循正常文档流; absolute:对象脱离正常文档流 fixed:对象脱离正常文档流 我们先来 ...