Original Post
I'm working on a simple console clone - see if you can guess what it is. 8^) I'm working with simple Win32 API - no DirectX here. Here's a basic idea of what I have: Map Object: This contains a maze map that will be drawn to the screen. The map is a text file that defines where the walls are. There is a Draw function that takes an HDC as its parameter. When Draw(HDC dc) is called, I walk through the map and draw a green square to the target DC where there is supposed to be a portion of a wall. Here's the code that does that: World Object: Contains a Map Object. It also has its own DC used as a back buffer. I create the back buffer DC like this: The World Object also has a draw function that takes an HDC parameter: The general flow is this: When WM_PAINT is called, I call the World::Draw function with the window DC as a paramter. Inside World::Draw I call the Map::Draw function using the BackBuffer as a parameter. The Map::Draw function parses the text file and draws green squares in the appropriate locations on the BackBuffer. Back insed World::Draw, after calling Map::Draw, I BitBlt the BackBuffer to the window DC. The assumption is that I'll have green walls drawn to form my maze, but I get this:
It appears that somewhere along the way, I'm getting a monochrome image. I've done a number of tests and found that if I draw to the BackBuffer directly in the Wolrd::Draw function and then BitBlt, I get the monochrome situation. But, if I draw directly to the window DC in World::Draw, I get the correct colors. Any ideas??? -Kirk
long x, y; //loop indices
long TileID; //which tile to draw?
HBRUSH NewBrush = CreateSolidBrush(RGB(25, 250, 5));
HBRUSH OldBrush = (HBRUSH)SelectObject(TargetDC,NewBrush);
//parse through the map and blit the appropriate picture to the targetDC
for (x=0; x<m_Model->Width(); x++)
{
for (y=0; y<m_Model->Height(); y++)
{
TileID = m_Model->GetPosition(x,y);
if (TileID != 0)
{
Rectangle(TargetDC, x*m_TileHeight, y*m_TileWidth,
x*m_TileHeight+16, y*m_TileWidth+16); }
}
}
SelectObject(TargetDC,OldBrush);
DeleteObject(NewBrush);
m_hBackBuffer = CreateCompatibleDC(NULL);
m_hBitmap = CreateCompatibleBitmap(m_hBackBuffer, m_PixelWidth, m_PixelHeight);
m_hOldBitmap = (HBITMAP) SelectObject(m_hBackBuffer, m_hBitmap);
//tell the map to draw to the backbuffer
m_MazeController.Draw(m_hBackBuffer);
//draw the backbuffer to the target
BitBlt( TargetDC,
0,0,
m_PixelWidth, m_PixelHeight,
m_hBackBuffer,
0,0,
SRCCOPY);
It appears that somewhere along the way, I'm getting a monochrome image. I've done a number of tests and found that if I draw to the BackBuffer directly in the Wolrd::Draw function and then BitBlt, I get the monochrome situation. But, if I draw directly to the window DC in World::Draw, I get the correct colors. Any ideas??? -Kirk


