源代码研究之CIMAGE;我们可以直接使用来创建纹理。
来源:互联网 发布:01年nba总决赛数据 编辑:程序博客网 时间:2024/05/21 19:22
\
biSizeImage=(biWidth*biBitCount+31)/32*4*biHeight
inline void GetColor( unsigned int x, unsigned int y, unsigned char* ucpRed, unsigned char* ucpGreen, unsigned char* ucpBlue )//==============================================================//==============================================================//= image.h ====================================================//= Original coders: Trent Polack (trent@voxelsoft.com) and =//- Evan Pipho (evan@codershq.com) =//==============================================================//= Image/texture loadings ops =//==============================================================//==============================================================#ifndef __IMAGE_H__#define __IMAGE_H__//--------------------------------------------------------------//--------------------------------------------------------------//- HEADERS AND LIBRARIES --------------------------------------//--------------------------------------------------------------//--------------------------------------------------------------#include <windows.h>#include <gl/gl.h>#include <gl/glu.h>//--------------------------------------------------------------//--------------------------------------------------------------//- CONSTANTS --------------------------------------------------//--------------------------------------------------------------//--------------------------------------------------------------#define BITMAP_ID 0x4D42//--------------------------------------------------------------//--------------------------------------------------------------//- STRUCTURES -------------------------------------------------//--------------------------------------------------------------//--------------------------------------------------------------struct TGAInformationHeader{unsigned char m_ucHeader[6];unsigned int m_uiBytesPerPixel;unsigned int m_uiImageSize;unsigned int m_uiTemp;unsigned int m_uiType;unsigned int m_uiHeight;unsigned int m_uiWidth;unsigned int m_uiBPP;};//设置1字节对齐,入栈push1#pragma pack( push, 1 )struct BMPFileHeader{unsigned short usType; //2位 unsigned int uiSize; //4位 unsigned short usReserved1;//2位 unsigned short usReserved2; //2位 unsigned int uiOffBits; //4位};//取消1字节对齐,pop 1..出栈#pragma pack( pop )struct BMPInfoHeader{unsigned int uiSize; long lWidth; long lHeight; unsigned short usPlanes; unsigned short usBitCount; unsigned int uiCompression; unsigned int uiSizeImage; long lXPelsPerMeter; long lYPelsPerMeter; unsigned int uiClrUsed; unsigned int uiClrImportant; };//--------------------------------------------------------------//--------------------------------------------------------------//- GLOBALS ----------------------------------------------------//--------------------------------------------------------------//--------------------------------------------------------------extern unsigned char g_ucUTGAcompare[12];extern unsigned char g_ucCTGAcompare[12];//--------------------------------------------------------------//--------------------------------------------------------------//- CLASS ------------------------------------------------------//--------------------------------------------------------------//--------------------------------------------------------------class CIMAGE{private:unsigned char* m_ucpData;unsigned int m_uiWidth;unsigned int m_uiHeight;unsigned int m_uiBPP;unsigned int m_ID;bool m_bIsLoaded;bool LoadBMP( void );bool SaveBMP( char* szFilename );bool LoadCompressedTGA( void );bool LoadUncompressedTGA( void );public:bool Create( unsigned int uiWidth, unsigned int uiHeight, unsigned int uiBPP );bool LoadData( char* a_szFilename );bool Load( char* a_szFilename, float a_fMinFilter, float a_fMaxFilter, bool a_bMipmap= false );void Unload( void );bool Save( char* szFilename );//--------------------------------------------------------------// Name:CIMAGE::GetColor - public// Description:Get the color (RGB triplet) from a texture pixel// Arguments:-x, y: position to get color from//-ucpRed, ucpGreen, ucpBlue: place to store the RGB// values that are extracted from the texture// Return Value:None//--------------------------------------------------------------inline void GetColor( unsigned int x, unsigned int y, unsigned char* ucpRed, unsigned char* ucpGreen, unsigned char* ucpBlue ){unsigned int uiBPP= m_uiBPP/8;if( ( x<m_uiWidth ) && ( y<m_uiHeight ) ){*ucpRed = m_ucpData[( ( y*m_uiHeight )+x )*uiBPP];*ucpGreen= m_ucpData[( ( y*m_uiHeight )+x )*uiBPP+1];*ucpBlue = m_ucpData[( ( y*m_uiHeight )+x )*uiBPP+2];}}//--------------------------------------------------------------// Name:CIMAGE::SetColor - public// Description:Set the color (RGB triplet) for a texture pixel// Arguments:-x, y: position to set color at//-ucpRed, ucpGreen, ucpBlue: color to set at pixel// Return Value:None//--------------------------------------------------------------inline void SetColor( unsigned int x, unsigned int y, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue ){unsigned int uiBPP= m_uiBPP/8;if( ( x<m_uiWidth ) && ( y<m_uiHeight ) ){m_ucpData[( ( y*m_uiHeight )+x )*uiBPP] = ucRed;m_ucpData[( ( y*m_uiHeight )+x )*uiBPP+1]= ucGreen;m_ucpData[( ( y*m_uiHeight )+x )*uiBPP+2]= ucBlue;}}//--------------------------------------------------------------// Name:CIMAGE::GetData - public// Description:Get a pointer to the image's data buffer// Arguments:None// Return Value:An unsigned char buffer (the texture's data)//--------------------------------------------------------------inline unsigned char* GetData( void ){return m_ucpData;}//--------------------------------------------------------------// Name:CIMAGE::GetWidth - public// Description:Get the texture's width (size along the x-axis)// Arguments:None// Return Value:An unsigned int value: the texture's size along the x-axis//--------------------------------------------------------------inline unsigned int GetWidth( void ){return m_uiWidth;}//--------------------------------------------------------------// Name:CIMAGE::GetHeight - public// Description:Get the texture's height (size along the y-axis)// Arguments:None// Return Value:An unsigned int value: the texture's size along the y-axis//--------------------------------------------------------------inline unsigned int GetHeight( void ){return m_uiHeight;}//--------------------------------------------------------------// Name:CIMAGE::GetBPP - public// Description:Get the texture's number of bits per pixel// Arguments:None// Return Value:An unsigned int value: the texture's bits per pixel//--------------------------------------------------------------inline unsigned int GetBPP( void ){return m_uiBPP;}//--------------------------------------------------------------// Name:CIMAGE::GetID - public// Description:Get the texture's identifying ID (use with OpenGL)// Arguments:None// Return Value:An unsigned int value: the texture's ID//--------------------------------------------------------------inline unsigned int GetID( void ){return m_ID;}//--------------------------------------------------------------// Name:CIMAGE::SetID - public// Description:Set the texture's identifying ID (use with OpenGL)// Arguments:-uiID: the texture's soon-to-be ID// Return Value:None//--------------------------------------------------------------inline void SetID( unsigned int uiID ){m_ID= uiID;}//--------------------------------------------------------------// Name:CIMAGE::IsLoaded - public// Description:Find out if the texture has been loaded or not// Arguments:None// Return Value:A boolean value: -true: a texture has been loaded// -false: a texture hasn't been loaded//--------------------------------------------------------------inline bool IsLoaded( void ){return m_bIsLoaded;}};#endif//__IMAGE_H__
//首先,我们关心的是它的接口:
inline bool IsLoaded( void )
inline void SetID( unsigned int uiID )
inline unsigned int GetID( void )
inline unsigned int GetBPP( void )
inline unsigned int GetHeight( void )
inline unsigned int GetWidth( void )
inline unsigned char* GetData( void )
inline void SetColor( unsigned int x, unsigned int y, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue )
inline void GetColor( unsigned int x, unsigned int y, unsigned char* ucpRed, unsigned char* ucpGreen, unsigned char* ucpBlue )
就这么多。。。。。。。
它对应于一个文件。。
前面n多是GetSet方法。。。。关键是如何实现的Load和LoadData;;
//创建一个新的BMP(在内存中的)『实际上是个二维数组。。。』
bool Create( unsigned int uiWidth, unsigned int uiHeight, unsigned int uiBPP );
//这个函数用指定的filename来保存此对象中的数据。
bool Save( char* szFilename );
//卸载Load进来的数据。
void Unload( void );
//这个函数用来加载BMP文件并且制作纹理,纹理ID可以通过
// inline unsigned int GetID( void ) 得到
//如果用这个函数,那么纹理ID已经设好。。。。。。。。。。。。一定不能再去SetID
bool Load( char* a_szFilename, float a_fMinFilter, float a_fMaxFilter, bool a_bMipmap= false );
//纯粹的把BMP内容加载进来
//下面这个函数没有纹理ID,因此,必须手动设置纹理ID。
bool LoadData( char* a_szFilename );
- 源代码研究之CIMAGE;我们可以直接使用来创建纹理。
- 如何使用CCRenderTexture来创建动态纹理
- 如何使用CCRenderTexture来创建动态纹理
- 使用CCRenderTexture来创建动态纹理
- 如何使用CCRenderTexture来创建动态纹理
- 我们可以使用bordercolorlight与bordercolordark 来设置Table的边框,使之变得漂亮;
- (译)如何使用CCRenderTexture来创建动态纹理
- 20. 如何使用CCRenderTexture来创建动态纹理
- (译)如何使用CCRenderTexture来创建动态纹理
- (译)如何使用CCRenderTexture来创建动态纹理
- (译)如何使用CCRenderTexture来创建动态纹理
- 使用纹理中的透明通道(纹理:透明通道可以用Dx的工具创建)
- 终于可以下载android源代码来开始研究framework层了
- 如何使用CCRenderTexture创建动态纹理 Cocos2d-x 2.1.4 含iOS版源代码
- spring中提供了一个Filter过滤器,我们可以直接拿来使用
- UnityShader之创建动态纹理
- OpenGL源代码之六纹理映射
- 总结一下可以研究的CAD源代码
- 【数论】hdu 6069 Counting Divisors
- activity实现半透明效果
- #pragma pack的作用
- 万维链机会
- hadoop学习路线
- 源代码研究之CIMAGE;我们可以直接使用来创建纹理。
- json.dumps和json.dump方法的比较
- SPringBoot 中 使用JSP页面
- BMP图片格式
- 班级40位同学,随机分配4人一组。
- LOADBMP (RGB) 模式
- 详解Tomcat 配置文件server.xml
- C语言学习琐记一
- 学习原子哥STM32M4(1):GPIO输出配置