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. android 进程/线程管理(四)续----消息机制的思考(自定义消息机制)

    继续分析handler 和looper 先看看handler的 public void dispatchMessage(Message msg) { if (msg.callback != null) ...

  2. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has p

    2014-09-16 15:47:51.590:WARN:oejs.ErrorPageErrorHandler:EXCEPTION org.apache.jasper.JasperException: ...

  3. [ASP.NET MVC]: - EF框架学习手记

    1.EF(Entity Framework)实体框架EF是ADO.NET中的一组支持开发面向数据的软件应用程序的技术,是微软的一个ORM框架. 2.什么是ORM?ORM指的是面向对象的对象模型和关系型 ...

  4. celery 快速入门教程 celery 定时器

    当然首先得安装celery和rabbitmq-server,如果有redis需要安装redis 安装Redis $ yum install redis 启动 Redis $redis-server 检 ...

  5. SAM4E单片机之旅——14、LCD之SMC的配置

    在上个例子中,已经在ASF添加了ILI93xx模块,并做好了相关的声明.这次就做好SMC的配置,然后使用ASF提供的API在屏幕上打印出”Hello World!”字样. 一. 电路图 开发板的LCD ...

  6. 在IE8等不支持placeholder属性的浏览器中模拟placeholder效果

    placeholder是一个很有用的属性,可以提示用户在input框中输入正确的内容,但是IE8以及IE8一下的浏览器不支持该属性,我们可以使用js来模拟相似的效果.下面直接上代码: <!doc ...

  7. Swing应用开发实战系列之三:动态信息提示窗口

    这里所说的“动态信息提示窗口”可不同于JOptionPane中的Message窗口和Confirm窗口,它们都是静态的模态的,更重要的是线程阻塞的,迫使你必须选择某个动作才能继续执行.我们接下来要分享 ...

  8. 利用API方式进行数据库的增删改查

    /* 将数据库的增删改查单独放进一个包 */ package com.itheima28.sqlitedemo.dao; import java.util.ArrayList; import java ...

  9. kafka basic commands

    kafka-server-start.sh config/server.properties & kafka-server-stop.sh kafka-topics.sh    --creat ...

  10. Hive UDF 实验1

    项目中使用的hive版本低于0.11,无法使用hive在0.11中新加的开窗分析函数. 在项目中需要使用到row_number()函数的地方,有人写了udf来实现这个功能. new java proj ...