Thread: One file, many images

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    One file, many images

    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?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    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:
    Code:
    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.
    Code:
    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;
    };

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    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.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    ///
    Guest
    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)

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    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 .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM