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

 #pragma pack(1)

 struct TgaHeader
{
unsigned char m_IDLength;
unsigned char m_ColorMapType;
unsigned char m_ImageType;
unsigned short m_CMapStart;
unsigned short m_CMapLength;
unsigned char m_CMapDepth;
unsigned short m_XOffset;
unsigned short m_YOffset;
unsigned short m_Width;
unsigned short m_Height;
unsigned char m_PixelDepth;
unsigned char m_ImageDescriptor;
}; #pragma pack()
 bool LoadTGA(const char *pszFileName, unsigned char *pBuffer, int iBufferSize, int *pInternalFormat, int *pWidth, int *pHeight)
{
FileHandle_t pFile = g_pFileSystem->Open(pszFileName, "rb"); if (!pFile)
return false; TgaHeader Header;
memset(&Header, , sizeof(Header)); g_pFileSystem->Read(&Header, sizeof(Header), pFile); if (Header.m_ImageType != )
{
g_pFileSystem->Close(pFile);
return false;
} if (Header.m_PixelDepth != && Header.m_PixelDepth != )
{
g_pFileSystem->Close(pFile);
return false;
} uint32 iPixelSize, iImageSize; switch (Header.m_PixelDepth)
{
case :
iPixelSize = ;
*pInternalFormat = GL_RGB;
break;
case :
iPixelSize = ;
*pInternalFormat = GL_RGBA;
break;
} iImageSize = Header.m_Width * Header.m_Height * iPixelSize; if (iImageSize > (uint32)iBufferSize)
{
g_pFileSystem->Close(pFile);
return false;
} uint32 iLineSize = Header.m_Width * iPixelSize;
uint32 iLinePos; for (uint32 y = ; y < Header.m_Height; ++y)
{
iLinePos = (Header.m_Height - y - ) * iLineSize;
g_pFileSystem->Read(&pBuffer[iLinePos], iLineSize, pFile);
} for (uint32 i = ; i < iImageSize; i += iPixelSize)
{
pBuffer[i + ] ^= pBuffer[i + ];
pBuffer[i + ] ^= pBuffer[i + ];
pBuffer[i + ] ^= pBuffer[i + ];
} *pWidth = Header.m_Width;
*pHeight = Header.m_Height; g_pFileSystem->Close(pFile);
return true;
}

[MetaHook] Load TGA texture to OpenGL的更多相关文章

  1. [MetaHook] Load DTX texture to OpenGL

    This function load a LithTech *.dtx texture file and convert to OpenGL pixel format, compressed supp ...

  2. [MetaHook] Load large texture from model

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

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

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

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

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

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

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

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

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

  7. 【入门向】使用 MetaHook Plus 绘制 HUD

    MetaHook Plus 是一个GoldSrc引擎(就是的Half-Life.CS1.6的引擎)的客户端插件平台,它可以加载我们自己开发的DLL插件. 首先你需要安装一个 Visual Studio ...

  8. NeHe OpenGL教程 第三十二课:拾取游戏

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  9. Projective Texture的原理与实现

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

随机推荐

  1. 20个简化开发任务的 JavaScript库

    所谓JavaScript库就是预先写好的可以简化基于JavaScript的应用程序开发的,尤其是Ajax和其它以web为中心的技术的 JavaScript代码集.JavaScript主要用于写内嵌于H ...

  2. html 关于内部是float元素的外部div高度为0的解决方法!

    最近编写一个页面的时候遇见一个问题,外部div是block的,而内部元素是float的,大家应该都知道float的元素是没有实际高度的,就算你设置了float元素的高度他也不会撑开外部block元素的 ...

  3. Tomcat6环境JBPM4.4报错:java.lang.ClassNotFoundException: de.odysseus.el.util.SimpleResolver

    Tomcat6环境JBPM4.4报错:java.lang.ClassNotFoundException: de.odysseus.el.util.SimpleResolver 报错信息:

  4. 水溶彩铅的特点&技法运用

    工欲善其事必先利其器!亲爱的同学们都准备好画笔了吗?今天,助助为同学们介绍一下水溶性彩色铅笔的特点,技法运用的基本教程,请仔细看哟! [水溶性彩色铅笔的特点] 能够同时画出像铅笔一样的线条和水彩一样的 ...

  5. Github学习之路-初出茅庐,接触Github,了解Github

     一.了解GitHub 作为一个在线协作网站,GitHub允许程序员们分享和协力于开源项目的工作. GitHub不仅是一个分享开源创作并与其它程序员合作的好地方,你也可以从GitHub上收到自己作品的 ...

  6. ubuntu下ROS安装时sudo rosdep init和rosdep update的解决方法

    问题: 在ubuntu上多次安装matlab选择合适的版本来调用摄像头,终于把系统搞坏了,重装系统后,ROS无法安装,每次安装到sudo rosdep init和rosdep update报错的问题, ...

  7. hyperstart 容器创建流程分析

    hyperstart中运行的pod的核心数据结构如下所示: struct hyper_pod { struct hyper_interface *iface; struct hyper_route * ...

  8. 【实践】获取CKEditor的html文本、纯文本、被选中的内容及赋值

      <%=Html.TextAreaFor(Model => Model.WORK_INTRODUCTION)%> <script type="text/javasc ...

  9. Unity Sample Bootcamp

    M4枪 射击特效 Gun.js源码 function GenerateGraphicStuff(hit : RaycastHit) { var hitType : HitType; var body ...

  10. android图片缩小和放大Matrix

    /**Bitmap放大的方法*/ private static Bitmap big(Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.pos ...