# Display multiple images

## Recommended Posts

I am making a generic tetris clone and have tried using BitBlt to display the images in the program, but it clears the screen before drawing a new image every time a new one needs to be displayed (It will, momentarily, display each image, but it will immediately be cleared and the next image will be displayed, until the only image left is the last one displayed, which will be the only one left visible). How can I fix this problem (display more than one image at a time)?

##### Share on other sites
You might want to create a memory DC and blit everything to it, then blit everything on the window DC.
HDC hdc = GetDC(hWnd);HDC memDC = CreateCompatibleDC(hdc);/* ... blit everything on memDC ... */BitBlt(hdc, 0, 0, Width, Height, memDC, 0, 0, SRCCOPY);
Even better, you could make your own Bitmap class that would use the technique I described above and then call a Draw() function that would draw on another memDC and then blit the result on the window DC.
HDC hdc = GetDC(hWnd);HDC memDC = CreateCompatibleDC(hdc);// Both bitmaps will create an internal compatible DC of hdcBitmap blah(hdc, "blah.bmp");Bitmap whoCares(hdc, "whocares.bmp");// Draw everything from internal memory DC to general memory DCblah.Draw(memDC);whoCares.Draw(memDC);// Blit everything on the window DCBitBlt(hdc, 0, 0, Width, Height, memDC, 0, 0, SRCCOPY); // Die flickers !!!
Edit: That last technique is called double-buffering.

[Edited by - White Scorpion on February 14, 2005 6:43:03 AM]

##### Share on other sites
My compiler says the Blit function is undefined. I have been using BitBlt. Can you give me an example for this:

I call one function to blit the background image, which all the other images are displayed on top of. I then call a function repeatedly, sending it (HWND hwnd, unsigned image, unsigned xpos, unsigned ypos) where image is the offset of an array of previously loaded HBITMAPS (value is 0-5). xpos and ypos are the upper-left coordinates of the image to be displayed. I need to call this function repeatedly with different values each time, as in looping through several different images and positions that need to be displayed, and then once the loop is complete, I need to display the compiled image at the end. Also, the background image needs to be visible in the areas where there wasn't another image displayed. Alternatively, the image could be build up one image at a time, either way would work. How can I do this? Here is some pseudocode to help explain what I mean:

Function DisplayBackground(){    Blit BackgroundImage}Function DisplayTiles(){    loop through y_values    loop through x_values    Display(hwnd, image_value, x_values, y_values) //image_value is retrieved //from a vector containing all the tiles that need to be displayed, and is //referenced by the x_values and y_values.  Just assume we already got it.    end loop    end loop}

##### Share on other sites
Blit() was only a typo, I really meant BitBlt(). You may want to take a peek at winprog.org for a detailed explanation on how to display bitmaps. I think they cover the basics of double-buffering (which is what you need)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628275
• Total Posts
2981763

• 10
• 11
• 17
• 10
• 9