Click to See Complete Forum and Search --> : Multiple static GIFs in a window


Dispiacere
October 21st, 2009, 04:34 AM
I'm creating a top-down RPG game engine(like Zelda, only tile-based instead of pixel*based) in Windows and would like to know if anyone can direct me to a tutorial or source code for displaying multiple static GIFs in a window. I don't need animation support, but transparency is a must. I don't like using libraries and would strongly prefer to use small routines for loading and displaying them.

The first version of the engine I made only used Bitmaps and I wrote the code based on bmp tutorials from a book. But after creating nearly 60mb worth of bitmaps I realized that they were just too big for the project and I needed some kind of compressed image type.

The second version used GIFView, written by Juan Soulie, which I found on this page:
http://www.cplusplus.com/src/
but the way that program handles gifs is to create a single image window for each gif, and if you want the same gif in two places at once you have to create a whole separate image window. It also didn't handle overlapping images because of the image window approach. My needs call for a simple set of functions that can load the gif, display it on the window at a specified location, and be done with it because there are at least 300 images on the screen at one time, tiles, sprites, and text.

Here's an example of the way I want to set up the function on loading them:

int LoadGIF(int XDest, int YDest, char *FileName, HWND hWnd);

Where I specify the x position, the y position, the file name, and the window to send it to. That's the way I had the bitmap loading set up. I tried to strip Juan's program's gif decompressing and loading routines and writing a program to use them in this way but wasn't able to succeed.

VictorN
October 21st, 2009, 06:40 AM
Did you consider using GDI+?
http://www.codeproject.com/KB/GDI-plus/
http://www.codeguru.com/cpp/g-m/gdi/gdi/

srelu
October 27th, 2009, 07:01 PM
The API only offers support for bmp images. You can handle gifs using the GDI+ as suggested by VictorN.

In order to perform transparency effects, you should draw each gif (or bmp) in a separate DC in the memory, then use TransparentBlt (or MaskBlt) to transfer transparently each bitmap from the memory DCs to the DC of the screen.

I'm not sure what means that the images are too big for the project. If you mean that the resulting bmp files of the application are too big for the available space, you have the option to compress the files using any ordinary file compression utility and expand before loading them in the memory.

hypheni
November 4th, 2009, 10:57 AM
Is there any sample Win32 code for displaying gif file in a window. ?

Dispiacere
November 7th, 2009, 02:40 PM
Thanks for the replies, guys.

When I said the bitmaps were getting too large I meant in size. Each sprite and tile is under 4kb but some of the larger images such as the HUDs and maps range from 500kb to 2mb each, and I ended up with about 60mb of images. That's not so bad and I may just go with bitmaps since they're so easy to work with(and thanks for the tips srelu, great help), but my concerns are speed and memory usage.

When a bitmap is loaded and displayed with the API is it loaded to the memory and does it stay there until the program is closed? Is it ok to keep loading and overlapping images indefinitely or do I need to clean up once it's not used anymore?

Here's the code I'm using for the bitmaps if it helps


int LoadFile(int XDest, int YDest, char *FileName, HWND hWnd)
{

static BITMAPFILEHEADER *pbmfh;
static BITMAPINFO *pbmi;
static BYTE *pBits;
static int cxDib, cyDib;

DWORD dwFileSize, dwHighSize, dwBytesRead;
HANDLE hFile;

char *NameOfFile;
NameOfFile = new char[50];
NameOfFile = FileName;

hFile = CreateFile (NameOfFile, GENERIC_READ,
FILE_SHARE_READ, NULL,
OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN,
NULL);

dwFileSize = GetFileSize (hFile, &dwHighSize);
pbmfh = (BITMAPFILEHEADER *) malloc (dwFileSize);
ReadFile (hFile, pbmfh, dwFileSize, &dwBytesRead, NULL);
pbmi = (BITMAPINFO *) (pbmfh + 1);
pBits = (BYTE *) pbmfh + pbmfh->bfOffBits;
cxDib = pbmi->bmiHeader.biWidth;
cyDib = abs(pbmi->bmiHeader.biHeight);
HDC hdc;
hdc = GetDC (hWnd);

SetDIBitsToDevice (hdc,
XDest,
YDest,
cxDib,
cyDib,
0,
0,
0,
cyDib,
pBits,
pbmi,
DIB_RGB_COLORS);
ReleaseDC (hWnd, hdc);
free (pbmfh);
return 0;
}


LoadFile(0, 0, "Graphics\\TITLE-SCREEN.BMP", hWnd);