Only draw portions of BMPs...?

I originally used DirectDraw, and there was strong support for drawing
a portion or ‘box’ from a BMP. For example, if I had a whole set of
tiles in one bitmap, I would want to be able to draw specific tiles,
not the whole darn image. Could someone provide a simple function that
does this? I’ve tried time and time again, but I could never figure it
out. I’m running Windows XP Home, using Visual C++ 6.0.
Thanks,
Colin Hart

void blit_tile(SDL_Surface * tiles,
int tile_x, int tile_y, int tile_width, int tile_height,
SDL_Surface * destination,
int dest_x, int dest_y)
{
SDL_Rect src, dest;

src.x = tile_x;
src.y = tile_y;
src.w = tile_width;
src.h = tile_height;

dest.x = dest_x;
dest.y = dest_y;
dest.w = tile_width; /* Redundant /
dest.h = tile_height; /
Redundant */

SDL_BlitSurface(tiles, &src, destination, &dest);
}

Pretty lamely simple, huh? :slight_smile:

-bill!On Sun, Feb 23, 2003 at 08:03:38PM -0500, Colin Hart wrote:

I originally used DirectDraw, and there was strong support for drawing
a portion or ‘box’ from a BMP. For example, if I had a whole set of
tiles in one bitmap, I would want to be able to draw specific tiles,
not the whole darn image. Could someone provide a simple function that
does this? I’ve tried time and time again, but I could never figure it
out. I’m running Windows XP Home, using Visual C++ 6.0.


bill at newbreedsoftware.com Was I useful? Rate this message!
http://newbreedsoftware.com/bill http://svcs.affero.net/rm.php?r=billkendrick

http://sdldoc.csn.ul.ie/sdlblitsurface.php

Basically: SDL_BlitSurface() takes a source Rect. This Rect describes the
area of the source surface to Blit to the dest surface.

Owen Butler> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Colin Hart
Sent: Monday, 24 February 2003 12:04 PM
To: SDL Message Board
Subject: [SDL] Only draw portions of BMPs…?

I originally used DirectDraw, and there was strong support for drawing
a portion or ‘box’ from a BMP. For example, if I had a whole set of
tiles in one bitmap, I would want to be able to draw specific tiles,
not the whole darn image. Could someone provide a simple function that
does this? I’ve tried time and time again, but I could never figure it
out. I’m running Windows XP Home, using Visual C++ 6.0.
Thanks,
Colin Hart


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

It’s probably a better idea to split tiles into separate surfaces,
though, if you’re doing this often and the rects you’re using are known
in advance. It makes runtime simpler (you only have to deal with this
at load-time), and it’s probably somewhat faster, since the data you’re
blitting will be more tightly-packed.

(Aside, this isn’t the case with OpenGL, where switching textures is more
expensive and you pay a memory penalty due to the ^2 restriction.)On Sun, Feb 23, 2003 at 05:24:57PM -0800, Bill Kendrick wrote:

I originally used DirectDraw, and there was strong support for drawing
a portion or ‘box’ from a BMP. For example, if I had a whole set of
tiles in one bitmap, I would want to be able to draw specific tiles,
not the whole darn image. Could someone provide a simple function that
does this? I’ve tried time and time again, but I could never figure it
out. I’m running Windows XP Home, using Visual C++ 6.0.

SDL_BlitSurface(tiles, &src, destination, &dest);


Glenn Maynard

Hi,

please check this page for your answer:

http://sdldoc.csn.ul.ie/sdlblitsurface.php

:-)> ----- Original Message -----

From: xempest@comcast.net (Colin Hart)
To: “SDL Message Board”
Sent: Monday, February 24, 2003 2:03 AM
Subject: [SDL] Only draw portions of BMPs…?

I originally used DirectDraw, and there was strong support for drawing
a portion or ‘box’ from a BMP. For example, if I had a whole set of
tiles in one bitmap, I would want to be able to draw specific tiles,
not the whole darn image. Could someone provide a simple function that
does this? I’ve tried time and time again, but I could never figure it
out. I’m running Windows XP Home, using Visual C++ 6.0.
Thanks,
Colin Hart


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

It’s probably a better idea to split tiles into separate surfaces,
though, if you’re doing this often and the rects you’re using are
known in advance. It makes runtime simpler (you only have to deal
with this at load-time), and it’s probably somewhat faster, since
the data you’re blitting will be more tightly-packed.

That’s an interesting point that I hadn’t considered before. I wonder
if this would still be true with, say, hundreds of tiles. If the tiles
aren’t particularly large, such as your typical 32x32 size, wouldn’t
the extra overhead of the SDL_Surfaces outweigh the advantages?

Also, you could still get the advantage of tightly-packed data
(however much that may be) if you used a SDL_Surface with dimensions
such as 32x3200 – i.e., only one tile wide.

b

That’s hard to say; you’d have to benchmark it, and memory usage would
probably depend on the allocator. Either way, it may still be simpler.On Mon, Feb 24, 2003 at 03:34:30PM -0800, Brian Raiter wrote:

That’s an interesting point that I hadn’t considered before. I wonder
if this would still be true with, say, hundreds of tiles. If the tiles
aren’t particularly large, such as your typical 32x32 size, wouldn’t
the extra overhead of the SDL_Surfaces outweigh the advantages?


Glenn Maynard

I doubt whether it’s simpler. You obviously don’t save a tileset as seperate
tiles, so you have to write a routine, which loads the tileset and creates
an array of seperate tiles from them.

I don’t think the overhead of the Surfaces is a problem, because you only
pass one Surface to the blitter. But it might be a caching issue. Note that
this is just a thought, it never researched it.

Years ago, I read in an “inside DirectX” book, that it’s better to store
larger surfaces and blit portions of them. But maybe that only counts for
video memory.>On Mon, 24 Feb 2003 18:50:38 -0500 Glenn Maynard <g_sdl at zewt.org> wrote.

On Mon, Feb 24, 2003 at 03:34:30PM -0800, Brian Raiter wrote:

That’s an interesting point that I hadn’t considered before. I wonder
if this would still be true with, say, hundreds of tiles. If the tiles
aren’t particularly large, such as your typical 32x32 size, wouldn’t
the extra overhead of the SDL_Surfaces outweigh the advantages?

That’s hard to say; you’d have to benchmark it, and memory usage would
probably depend on the allocator. Either way, it may still be simpler.


Glenn Maynard


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl