[MetaHook] Load TGA texture to OpenGL
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的更多相关文章
- [MetaHook] Load DTX texture to OpenGL
This function load a LithTech *.dtx texture file and convert to OpenGL pixel format, compressed supp ...
- [MetaHook] Load large texture from model
We need hook "GL_LoadTexture" engine function. GL_LOADTEXTURE_SIG from hw.dll(3266) engine ...
- 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 ...
- 【入门向】使用 MetaHook Plus 绘制 HUD
MetaHook Plus 是一个GoldSrc引擎(就是的Half-Life.CS1.6的引擎)的客户端插件平台,它可以加载我们自己开发的DLL插件. 首先你需要安装一个 Visual Studio ...
- NeHe OpenGL教程 第三十二课:拾取游戏
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- Projective Texture的原理与实现
http://blog.csdn.net/xukunn1226/article/details/775644 Projective Texture是比较常见的一种技术,实现起来代码也就区区的不过百行, ...
随机推荐
- 敏捷软件开发(1)--- STATE 模式
如果状态在运行过程中,不停的切换和改变,我们怎么办? 状态的迁移是我们生活和工程中非常普遍的一个概念.于是在数学上有一种理论来分析和解决这个问题. 有限状态机理论是一个非常成熟的理论,所有动作和流程的 ...
- 使用Ant构建struts2 web工程,自动编译,打包成war
c&c++语言通常使用make脚本来构建和管理自己的工程,同样java也有自己的构建工具(Ant),使用时需要写一个biuld.xml,有点类似c&c++里的makefile. 一.首 ...
- Effective Java 04 Enforce noninstantiability with a private constructor
A class can be made noninstantiable by including a private constructor. // Noninstantiable utility c ...
- Python2
安装pycharm专业版,不要汉化 要想写的代码支持linux和2.0版本需要在开头加上注释 #/usr/bin/env python #-*- coding:utf-8 -*- 运算符 结果是值 算 ...
- codeforces C. Triangle
C. Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- shell script 学习笔记-----if,for,while,case语句
1.if内的判断条件为逻辑运算: 2.if内的判断条件为目录是否存在,文件是否存在,下图先检验目录/home/monster是否存在,然后再检测/home/monster中的file.txt文件是否存 ...
- 这一路走来,冷暖自知 (附算法demos)
最近半年多,除了“一键修图”算法之外我还做了其他什么算法? 1.实时单图HDR算法(颜色矫正,智能曝光) 2.多图曝光融合HDR算法(最高支持八百万像素左右) 3.模拟热能探测算法 4.防伪探测算法 ...
- Chrome浏览器与常用插件推荐
Chrome浏览器与常用插件推荐 官方chrome下载:http://www.google.cn/chrome/ 提示:需要FQ才能安装. 1,AdBlock 谷歌屏蔽广告: https://chro ...
- JAVA基础之对象的初始化
本文主要记录JAVA中对象的初始化过程,包括实例变量的初始化和类变量的初始化以及 final 关键字对初始化的影响.另外,还讨论了由于继承原因,探讨了引用变量的编译时类型和运行时类型 一,实例变量的初 ...
- Eclipse中的快捷键总结
Eclipse中10个最有用的快捷键组合 一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升. ...