⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objecttexture.cpp

📁 一个类似坦克大战的小小游戏
💻 CPP
字号:
// ObjectTexture.cpp: implementation of the CObjectTexture class.
//
//////////////////////////////////////////////////////////////////////

#include "ObjectTexture.h"
#include "GlobalDefs.h"

#include <D3dx9tex.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CObjectTexture::CObjectTexture()
{
	m_pTexture = NULL;
	m_nWidth = 0;
	m_nHeight = 0;
}

CObjectTexture::~CObjectTexture()
{
	Release();
}

// Create texture ////////////////////////////////////////////////////

BOOL CObjectTexture::Create(LPDIRECT3DDEVICE9 &pDevice, LPCTSTR inFileName, DWORD inColorKey)
{
	D3DXIMAGE_INFO imageInfo;
	memset(&imageInfo, 0, sizeof(imageInfo));

	// Release texture first.
	Release();

	// Create texture
	D3DXCreateTextureFromFileEx(pDevice, inFileName, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, 
					D3DFMT_UNKNOWN, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 
					inColorKey, &imageInfo, NULL, &m_pTexture);

	if (NULL == m_pTexture)
	{
		return FALSE;
	}

	// Get the image infos
	m_nWidth = imageInfo.Width;
	m_nHeight = imageInfo.Height;

	return TRUE;
}

// Release ///////////////////////////////////////////////////////////

void CObjectTexture::Release()
{
	if (NULL != m_pTexture)
	{
		SAFE_RELEASE(m_pTexture);
	}
}

// Get the size of texture ///////////////////////////////////////////

int CObjectTexture::GetHeight()
{
	return m_nHeight;
}

int CObjectTexture::GetWidth()
{
	return m_nWidth;
}

// Get texture //////////////////////////////////////////////////////

LPDIRECT3DTEXTURE9 CObjectTexture::GetTexture()
{
	return m_pTexture;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -