Hey guys, I've been working with my software rasterizer but stuck with painting hand made bitmap onto the screen. The idea is:
1. Create compatible DC and bitmap with current DC
2. Set up BITMAPINFO struct
3. Set the buffer for pixel
4. SetDIBits with the BITMAPINFO and buffer into the compatible DC
5. BitBlt compatible DC to current DC

Am I wrong with all these steps? Here is part of the code: (32 bits)

HDC hdcReal, hdcMem;
HBITMAP hBitmap;
BITMAPINFO bitmapInfo;
BITMAPINFOHEADER *pHeader;
BYTE *buffer;
RECT rect;

buffer = (BYTE *)malloc(SCREEN_WIDTH * SCREEN_HEIGHT * COLOR_BYTES)
hdcReal = GetDC(hwnd);
hdcMem = GetCompatibleDC(hdcReal);
hBitmap = GetCompatibleBitmap(hdcReal, SCREEN_WIDTH, SCREEN_HEIGHT);

memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
pHeader = &(bitmapInfo.bmiHeader);
pHeader->biSize = sizeof(BITMAPINFOHEADER);
pHeader->biWidth = SCREEN_WIDTH;
pHeader->biHeight = SCREEN_HEIGHT;
pHeader->biPlanes = 1;
pHeader->biBitCount = 32;
pHeader->biCompression = BI_RGB;
/* copy it from msdn, deal with alignment */
pHeader->biSizeImage = ((pHeader->biWidth * 32 + 31) & ~31) / 8 * pHeader->biHeight;

menset(buffer, 255, SCREEN_WIDTH * SCREEN_HEIGHT * COLOR_BYTES);

SetDIBits(hdcMem, hBitmap, 0, SCREEN_HEIGHT, buffer, &bitmapInfo, DIB_RGB_COLORS);
BitBlt(hdcReal, 0, 0, SCREEN_WIDHT, SCREEN_HEIGHT, hdcMem, 0, 0, SRCCOPY);

GetClientRect(hwnd, &rect);
ValidateRect(hwnd, &rect);

DeleteObject(hBitmap);
DeleteDC(hdcMem);
ReleaseDC(hwnd, hdcReal);

I suppose it would display a white screen, cause the buffer is fill with 255, but what I got is just a blank black screen, what's wrong with my code? Any reply would be appreciated!