PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

just starting out

Hi,

Just started playing around with PocketFrog. Conan's articles really helped get me up and running.

I'm not at all familiar with GDI yet so I've got a lot of questions.

One thing I tried to do but couldn't figure out: How do I go about copying part of the contents of a Surface to another Surface?

For example, I have a bitmap that contains several sprites and I want to separate them out into individual Surfaces. I tried using BitBlt, but I never ended up with anything in the destination Surface.

Anybody got a simple code snippet they could post?

Thanks,

Pam
Conan · 19 Jun 2002, 15:30 UTC — How to set up the sprites into surfaces
I have not yet looked at moving portions of one surface to another so I will have a look through the source on the train home & post later.

I guess the way I would approach this if there was no way to chop a sprite out of a larger image already on a surface would be to pre-process the sprites into an array. In the BLIT demo it's 4 separate bitmaps loaded into one array but there's no reason why you could not work through one large file taking out the sprites into an array of surfaces. The only problem is that there's no built-in function to take the source rectangle out of the file. I will see how easy this is later.

The DGI stuff seems to work well. I am still figuring out what works but the DrawText function plus the built-in GDI circles & ellipses work fine.
I've been coding a simple keyboard to deal with user input which is a boring but essential requirement.
The Rasterizer's Blit() method will allow you to copy some part of a surface to the rendering surface. For example, if you want to Blit a surface's subrect with coordinate (100,0,110,10) to the backbuffer, you would use:

Code:

Rect r(100,0,110,10);
GetDisplay()->Blit( dx, dy, sourceSurface, &r );

The easiest way to handle multiple sprites coming from the same image file would be to create a single Surface (holding all the image) and keep an array of rectangles that hold the positions of the sprites within.

Code:

// Load the sprites in memory
Surface* sprites = LoadImage( GetDisplay(), "sprites.bmp" );

// Generate an array of rects holding the sprites
Rect spritesPos[MAX_SPRITE] = {...}

// Blit sprite #3 to the display
GetDisplay()->Blit( dx, dy, sprites, &spritesPos[3] );

You could decide to have one surface for each sprite (although I don't recommend it from a memory usage point of view). To do so is more complicated and you will have to use either use a Rasterizer object or change the rendering target:

Code:

// Load the source image
Surface* srcImage = LoadImage( GetDisplay(), "sprites.bmp" );

// Allocate sprite surfaces
Surface* sprites[MAX_SPRITE];

for (int i = 0; i != MAX_SPRITE; ++i)
{
sprites[i] = GetDisplay()->CreateSurface(...);
GetDisplay()->SetRenderTarget( sprites[i] );
Rect r( /*position of sprite*/ );
GetDisplay()->Blit( 0, 0, srcImage, &r );
}

// Reset rasterizer target to backbuffer
GetDisplay()->SetRenderTarget( 0 );

The first way is much more easier, less code to write. In both cases you have to know the coordinates of your sprites. I would definitely go the first way.

Thierry
Thierry,

Thanks. I agree your first method is the easiest and lines up the best with what I was attempting.

I'll give it a shot later today.

Thanks again.

Pam
Yep, that did it. Works great.

Thanks,

Pam

P.S. Conan, your articles helped a lot getting me started. Looking forward to the next one.
Conan · 19 Jun 2002, 22:26 UTC — thanks for the encouragement
Glad my articles are of help.

I've pretty much finished my soft keyboard & from that I learned how little I know about strings in C++ but also picked up quite a bit re: PocketFrog. (I'm fighting to get TrueType fonts to work on a surface at the moment as I don't want to invent my own font system) :lol: Update: I now have TTF working :lol:

re: copying from a surface I did not spot how to do it so the solution helps me as well. I was looking at copying code out of EasyCE but don't need to now.
One of the problems with no docs is you don;t know what's there. I keep finding nice powerful features
PocketFrog definitely needs docs. There is a lot of stuff in there, and even more comming. I'm trying to finish docs before integrating new features... But each time I sit down try to do it, I end up playing Wolfenstein... Argh!

Your contribution in the form of articles is greatly appreciated... It will allow me to concentrate on reference-like documentation while you provide tutorial/sample-like docs. Thanks a bunch!