Hi Chilli,
I think I can adapt this to my already written sprite routine.
Found this line calls the routine
LoadSpriteAlpha( &alpha,IDR_DICE );
This is the real important line
HRSRC hResource = FindResource( NULL,
MAKEINTRESOURCE( resID ),MAKEINTRESOURCE( RT_RCDATA ) );
if( !hResource )
return false;
as it grabs the resource.
Not sure about all the DWORD stuff. Haven't come across this much.
This sets up your sprite surface
sprite->surface = (D3DCOLOR*)_aligned_malloc(
sizeof( D3DCOLOR ) * sprite->height * sprite->width,16 );
Although my sprite routine uses
surface = new D3DCOLOR[ tWidth * sHeight ];
so I can modify that.
The main loop is exactly the same
Code: Select all
for( unsigned int y = 0; y < pBitmap->GetHeight(); y++ )
{
for( unsigned int x = 0; x < pBitmap->GetWidth(); x++ )
{
pBitmap->GetPixel( x,y,&pixel );
sprite->surface[ x + y * pBitmap->GetWidth() ] =
D3DCOLOR_ARGB( pixel.GetA(),pixel.GetR(),pixel.GetG(),pixel.GetB() );
}
}
Ok I understand about 60% of what the code is doing. I think I could cludge this into my program.
I have a SpriteLoader class already, so I can add this as a new function, and just re-wire it LOL.
I do believe I can make it work.
Just wish I understood about DWORD and HGLOBAL, as I am not exactly sure what they do.
I think the real difference between my sprite routine and yours is that I call a sprite function which calls my PngLoader functon.My Png function is where it does all the gdi stuff. The reason I do this is because I have use the same class for single sprites and animated sprites and I do this as an overload function. One function sets it up for animated sprites and the other function sets it up for single frame sprites.
Might think about rewriting bits of this now
Code: Select all
void SpriteLoader::LoadSprite(const wchar_t* filename, int sWidth,int sHeight,int nFrames,int tWidth )
{
surface = new D3DCOLOR[ tWidth * sHeight ];
LoadPNG(filename);
SpriteHeight=sHeight;
SpriteWidth=sWidth;
Frame=0;
Time=0;
NumberOfFrames=nFrames;
}
void SpriteLoader::LoadSprite(const wchar_t* filename,int sWidth, int sHeight)
{
surface = new D3DCOLOR[ sWidth * sHeight ];
LoadPNG(filename);
SpriteHeight=sHeight;
SpriteWidth=sWidth;
Frame=0;
Time=0;
NumberOfFrames=1;
}
But I see now that there is no reason why I can't add the first line into the gdi function.
I think I am going to get it working so that it can load a png from a file or a resource. Then in the early stages I can load from files, and then change over to resources when the program is nearing completion.
Hmm this is going to be fun LOL. Thanks a lot for being a Rocket scientist LOL
Asimov