#include "GameImage.h"

GameImage::GameImage(void)
{
	m_tex = NULL;
}

GameImage::~GameImage(void)
{
	Destroy();
}

void GameImage::Create(GameGraphics &g, LPCWSTR image)
{
	if(m_tex != NULL) return;

	D3DXIMAGE_INFO info;
	D3DXGetImageInfoFromResource(GetModuleHandle(NULL), image, &info);

	D3DXCreateTextureFromResourceEx(g.m_d3dDevice, GetModuleHandle(NULL), image, info.Width, info.Height,
		1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, -1, -1, 0xffff00ff, &info, NULL, &m_tex);

	m_d3dSprite = g.m_d3dSprite;
}

void GameImage::Destroy()
{
	SAFE_RELEASE(m_tex);
	m_d3dSprite = NULL;
}

void GameImage::Draw(float x, float y, int alpha)
{
	m_d3dSprite->Begin(D3DXSPRITE_ALPHABLEND);
	m_d3dSprite->Draw(m_tex, NULL, NULL, &D3DXVECTOR3(x, y, 0), D3DCOLOR_ARGB(alpha, 255, 255, 255));
	m_d3dSprite->End();
}