View Full Version : One file, many images
lambs4
12-29-2002, 02:00 PM
I'm planning and designing my next project that will use SDL. One difference I want make between my current project and the next is to put all my images into one .bmp file instead separates ones. Right now my big .bmp contain 16 images divded by 1px lines vertically and across. Is this how it is done?
Eibro
12-29-2002, 02:36 PM
Lose the 1px lines... there's no need for them.
I did code for this awhile back in SDL. Basically, Load the whole bitmap into a surface, and when requested via an index number, fill a rect:
SDL_Rect rSrc =
{
((INDEX % ENTRIES_PER_LINE) * TILE_WIDTH),
((INDEX % (TOTAL_HEIGHT/ ENTRIES_PER_LINE)) * TILE_HEIGHT),
TILE_WIDTH,
TILE_HEIGHT};
Then create a new empty surface TILE_WIDTH wide and TILE_HEIGHT high and finally blit from the palette you loaded (huge bitmap) using rSrc as the clipping rect onto your newly created surface.
Here's a copy_surface() function I created, it might help you out.
bool sdlwrap::surface::copy_surface(SDL_Surface *surface, sdlwrap::RECT *clip)
{
m_autofree = 1; // This surface is now ours
m_data = ::SDL_CreateRGBSurface // Create surface using passed surface params
(
surface->flags,
(clip == NULL) ? surface->w : clip->w,
(clip == NULL) ? surface->h : clip->h,
surface->format->BitsPerPixel,
surface->format->Rmask,
surface->format->Gmask,
surface->format->Bmask,
surface->format->Amask
);
if (m_data == NULL)
return 1;
::SDL_BlitSurface(surface, reinterpret_cast<SDL_Rect *>(clip), m_data, NULL);
::SDL_SetColorKey(m_data, sdlwrap::surface::flags::srccolorkey, ::SDL_MapRGB(m_data->format, 0, 0, 255));
return 0;
};
Sang-drax
12-29-2002, 04:51 PM
Originally posted by Eibro
Lose the 1px lines... there's no need for them.
No, but IMO, it makes the bitmap alot easier to create.
its not that im into game programming but if you want a nice example check this game : Recwar
And look into the bmp files (explosions etc)
Flikm
01-04-2003, 02:25 PM
the only problem with adding the 1px lines is that the file is not a power of 2. for some reason, its just eviler that way :).
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.