// mvx Image file
// all things associated with images
// this is really easy stuff here
// most of the manipulation is inline, see "mvxImage" in mvx.h for more
#include "mvx.h"
mvxImage::mvxImage()
{
mvxImageData = NULL;
mvxTexture = NULL;
// zero out *most* of the paramaters
memset((void*)&mvxRect, 0, sizeof(mvxRect));
memset((void*)&mvxScaling, 0, sizeof(mvxScaling));
memset((void*)&mvxRotationCenter, 0, sizeof(mvxRotationCenter));
memset((void*)&mvxTranslation, 0, sizeof(mvxTranslation));
memset((void*)&mvxRotationAngle, 0, sizeof(mvxRotationAngle));
memset((void*)&mvxColor, 0, sizeof(mvxColor));
mvxScaling.x = 1;
mvxScaling.y = 1;
}
mvxImage::mvxImage(LPDIRECT3DDEVICE8 device, char* imgfilename)
{
mvxImageData = NULL;
mvxTexture = NULL;
D3DXCreateSprite(device, &mvxImageData);
D3DXCreateTextureFromFile(device, imgfilename, &mvxTexture);
}
mvxImage::~mvxImage()
{
mvxDestroy();
}
bool mvxImage::mvxCreate(LPDIRECT3DDEVICE8 device, char* imgfilename)
{
if (mvxImageData)
return false; // already exists
else
D3DXCreateSprite(device, &mvxImageData);
if (mvxTexture)
return false; // already exists
else
D3DXCreateTextureFromFileExA(device,
imgfilename,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_FILTER_NONE, // filters
D3DX_FILTER_NONE,
0xFF000000, // color key
NULL,
NULL,
&mvxTexture );
return true;
}
void mvxImage::mvxInit()
{
mvxDestroy();
mvxImageData = NULL;
mvxTexture = NULL;
}
void mvxImage::mvxDestroy()
{
if (mvxTexture)
{
mvxTexture->Release();
mvxTexture = NULL;
}
if (mvxImageData)
{
mvxImageData->Release();
mvxImageData = NULL;
}
}