Hey Asimov!

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Hey Asimov!

Post by chili » August 5th, 2012, 5:23 am

You want this... don't you... >: )
Attachments
ResPNG.zip
(91.11 KiB) Downloaded 323 times
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Hey Asimov!

Post by LuX » August 5th, 2012, 7:23 am

ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hey Asimov!

Post by Asimov » August 5th, 2012, 11:09 pm

HI Chilli,

If I can guess what it is I certainly do. It doesn't load pngs from resources by any chance does it LOL.
Going to get it now and see if i can work out how it works.

Damn I bet this has been here all day and I haven't seen it heh heh.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hey Asimov!

Post by Asimov » August 5th, 2012, 11:15 pm

Hi Chilli,

Damn I am sure there is just an exe in there. Where is all the lovely source code LOL.

This is exactly what I want to do. Does it build on the gdi code that we already have, or does it use totally alien code that I have never seen before?

Did it take you long to work this out?

I have been trawling websites for weeks, and only end up with rubbish MFC or .net code grrr.
A tutorial on this would be just wonderful BTW :)

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Hey Asimov!

Post by chili » August 6th, 2012, 12:12 am

Hehe, I'll get you the code tonight. It wasn't hard, I just mostly copy pasted from a website and then made modified it to load the data into a sprite structure. It took longer to find a way to incorporate the png into the resource script (fucking useless ResEdit D:< ).
Chili

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Hey Asimov!

Post by chili » August 6th, 2012, 1:10 pm

Here you go Asimov.
Attachments
ResPNG.zip
(132.66 KiB) Downloaded 213 times
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Hey Asimov!

Post by LuX » August 6th, 2012, 3:25 pm

Do you happen to have the link to the tutorial/code base from where you took this. I literally searched through the whole google website database in search for an understandable tutorial.

Just interested how the code or any possible explanations of the original source were.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Hey Asimov!

Post by chili » August 6th, 2012, 3:37 pm

Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hey Asimov!

Post by Asimov » August 6th, 2012, 5:17 pm

Hi Chilli,

That is the page I found, but I didn't understand it enough to implement it in my own program. I couldn't understand how to take that code and get GDI to look at it.

Anyway I am going to download your code now. Just hope I can work out how it works heh heh.

Yes ResEdit is rubbish. It wouldn't even load in a PNG. Kept telling me it was the wrong file format, but I found a good resource editor called XN Resource Editor, and it is free. I have attached it to this message for you to try. Much nicer than ResEdit.

Asimov
Attachments
xnresourceeditor.zip
(866.77 KiB) Downloaded 200 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hey Asimov!

Post by Asimov » August 6th, 2012, 6:21 pm

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
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

Post Reply