Sign in to follow this  
silverphyre673

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 this post


Link to post
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 hdc
Bitmap blah(hdc, "blah.bmp");
Bitmap whoCares(hdc, "whocares.bmp");

// Draw everything from internal memory DC to general memory DC
blah.Draw(memDC);
whoCares.Draw(memDC);

// Blit everything on the window DC
BitBlt(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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this