Jump to content
  • Advertisement

andutros

Member
  • Content Count

    12
  • Joined

  • Last visited

Community Reputation

100 Neutral

About andutros

  • Rank
    Member
  1. andutros

    Newbie Bitmap Woes

    Well, I dunno if this helps, but I changed the background and the ball and it's mask to resources. I compiled it and confirmed that I was getting the same results. So I copied the executable to my girlfriend's computer and ran it on there. Unfortunately the window was completely black. Not even the background appeared. I've been working on this program on two different computers (girlfriend's wasn't one of them.) So it seems the images only appear on machines the program was compiled on.
  2. andutros

    Newbie Bitmap Woes

    I've tried using LoadImage() and CreateDIBitmap(). Both successfully return handles. However, selecting them into the device context still fails. I'm about ready to pull my hair out on this thing, lol.
  3. andutros

    Newbie Bitmap Woes

    OK, I tried another bitmap and the same thing is happening, minus that strange error. Does it matter how the bitmap is loaded depending on if it's a top-down or bottom-up?
  4. andutros

    Newbie Bitmap Woes

    Still no good. I'm going to try displaying a random bitmap from my computer. If I still get an error, it's gotta be something in my code.
  5. andutros

    Newbie Bitmap Woes

    Yeah that sounds right. It was just a shot in the dark because you hadn't described the mask yet and it would be an easy thing to mix up. Sorry if I just ended up causing confusion. [/quote] No worries. I did give it a try, but nothing changed. I'm still trying to find some documentation on that error code. What's strange is I created the background as a 24-bit bmp using MSPaint, just like I did for the ball and its mask. This line: hbmpWorld = (HBITMAP)LoadImage(hInst, "simbkg.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); is the line used to load the background, and it works fine. I tried using LoadImage() for the ball and its mask, but I still get that bizarre error.
  6. andutros

    Newbie Bitmap Woes

    Just a random though. I don't suppose you have your mask reversed? Like, black should be white and white should be black? [/quote] In the ball bitmap, the ball itself is red while the surrounding area is black. In the mask, the ball is black and the surrounding area is white. My understanding is the mask needs to be black where you want the image to appear. Am I correct?
  7. andutros

    Newbie Bitmap Woes

    I added error checks when using CreateDIBitmap and LoadBitmap(). The return of GetLastError() in both cases is 2447680, which I can't find any documentation for . Just to be sure, I initialize a DWORD variable named lastError to 0 before it receives the return value of GetLastError(). Endurion, as far as accurately determining the size of the bitmap, what would you recommend?
  8. andutros

    Newbie Bitmap Woes

    I added error checking to the SelectObject() calls and for the ball and its mask. The function is returning null for both of them. I'm thinking it's a problem with how the bitmaps are being loaded. I'm honestly a bit confused about loading bitmaps between DDBs and DIBs. I've read a number of tutorials and I get the conceptual difference between the two, but I'm much less clear when it comes to implementing it. Anyways, here's the code for that: [source lang="cpp"] // Read in the file and convert it into a DDB. FILE * fp = 0; fp = fopen(filename, "rb"); BITMAPFILEHEADER bmpfh; size_t bytesRead; bytesRead = fread(&bmpfh, sizeof(BITMAPFILEHEADER), 1, fp); VOID* restOfFile = 0; DWORD nDIBLength = bmpfh.bfSize - sizeof(BITMAPFILEHEADER); restOfFile = malloc(nDIBLength); fread(restOfFile, nDIBLength, 1, fp); BITMAPINFO &bmInfo = *(LPBITMAPINFO)restOfFile; LPVOID lpDIBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) + ((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0)); if(_character == 0) _character = CreateDIBitmap(GetDC(hWND), &bmInfo.bmiHeader, CBM_INIT, lpDIBits, &bmInfo, DIB_RGB_COLORS); else _characterMask = CreateDIBitmap(GetDC(hWND), &bmInfo.bmiHeader, CBM_INIT, lpDIBits, &bmInfo, DIB_RGB_COLORS); fclose(fp); free(restOfFile); [/source]
  9. andutros

    Newbie Bitmap Woes

    Here's the most recent version of the code: [source lang="cpp"] DWORD lastError = 0; int nclientWidth = clientRect.right - clientRect.left; int nclientHeight = clientRect.bottom - clientRect.top; // Create the bitmap device context, which will handle all bitmaps HDC bitmapDC = CreateCompatibleDC(hDC); HBITMAP oldBitmap = (HBITMAP)SelectObject(bitmapDC, hbmpWorld); if(!BitBlt(hBackDC, 0, 0, nclientWidth, nclientHeight, bitmapDC, 0, 0, SRCCOPY)) { lastError = GetLastError(); printf("Last Error: %u\n", lastError); } //Draw the ball mask SelectObject(bitmapDC, redBall.GetCharacterMask()); if(!BitBlt(hBackDC, (int)(redBall.Position.X + .5), (int)(redBall.Position.Y + .5), redBall.GetCharacterInfo().bmWidth, redBall.GetCharacterInfo().bmHeight, bitmapDC, 0, 0, SRCAND)) { lastError = GetLastError(); printf("Last Error: %u\n", lastError); } // Draw the ball SelectObject(bitmapDC, redBall.GetCharacter()); if(!BitBlt(hBackDC, (int)(redBall.Position.X + .5), (int)(redBall.Position.Y + .5), redBall.GetCharacterInfo().bmWidth, redBall.GetCharacterInfo().bmHeight, bitmapDC, 0, 0, SRCPAINT)) { lastError = GetLastError(); printf("Last Error: %u\n", lastError); } SelectObject(bitmapDC, oldBitmap); DeleteObject(bitmapDC); DeleteObject(oldBitmap); // Draw image bitmap to the screen. if(!BitBlt(hDC, 0, 0, nclientWidth, nclientHeight, hBackDC, 0, 0, SRCCOPY)) lastError = GetLastError(); printf("Last Error: %u\n", lastError); [/source]
  10. andutros

    Newbie Bitmap Woes

    I've replaced all instances of ReleaseDC() with DeleteDC() when a device context is created via CreateCompatibleDC() and I've created a memory DC and memory bitmap that stays throughout the duration of the program. As a result, something's different, lol. The background still shows up, but now a square bitmap the size of my ball bitmap is showing up where the ball starts, except it's filled with part of the background. I had added code where you can move the ball around by clicking and dragging. I decided to click where the ball is supposed to start and dragged the mouse around to see if its position values would change, which is how I noticed a square of the background was moving with it. Any ideas?
  11. andutros

    Newbie Bitmap Woes

    Well, nevermind. I had been using printf() when I had been checking the return value of GetLastError(). It was printing the line saying lastError was 0 because I had completely forgotten to add curly braces to denote that the printf() should run inside the if statement. It seems the error is elsewhere. Edited: curly braces...not brackets.
  12. andutros

    Newbie Bitmap Woes

    Hi, everyone! Over the last week I've been working on a project to familiarize myself with the Windows GDI and game programming in general. I've created a window and I have a bitmap as a background image successfully displaying. However, I'm trying to add a bitmap of a small red ball, along with a mask. I've been messing with it for the past three days and I cannot for the life of me figure out why the ball is not appearing. I created the background, the ball, and its mask in MSPaint and saved the files as 24-bit bitmaps. As I've said, the background appears, but not the ball. I honestly have no clue if it's happening when the scene is being rendered or when the bitmaps are first loaded into memory from the hard drive. Also of note, BitBlt() returns 0 for each image, so I used GetLastError(), but it returns 0 as well. Here's the code that handles the rendering: void Render(HWND hwnd, HDC hdc) { DWORD lastError = 0; int nclientWidth = clientRect.right - clientRect.left; int nclientHeight = clientRect.bottom - clientRect.top; HDC backHDC = CreateCompatibleDC(hdc); HBITMAP backbuff = CreateCompatibleBitmap(hdc, nclientWidth, nclientHeight); HBITMAP hbmpOld = (HBITMAP)SelectObject(backHDC, backbuff); // Draw the background HDC hWorldDC = CreateCompatibleDC(hdc); HBITMAP hbmpItemOld = (HBITMAP)SelectObject(hWorldDC, hbmpWorld); if(!BitBlt(backHDC, 0, 0, nclientWidth, nclientHeight, hWorldDC, 0, 0, SRCCOPY)) lastError = GetLastError(); SelectObject(hWorldDC, hbmpItemOld); ReleaseDC(hwnd, hWorldDC); // Draw the ball mask HDC hballMaskDC = CreateCompatibleDC(hdc); hbmpItemOld = (HBITMAP)SelectObject(hballMaskDC, redBall.GetCharacterMask()); if(!BitBlt(backHDC, (int)redBall.Position.X, (int)redBall.Position.Y, redBall.GetCharacterInfo().bmWidth, redBall.GetCharacterInfo().bmHeight, hballMaskDC, 0, 0, SRCAND)) lastError = GetLastError(); SelectObject(hballMaskDC, hbmpItemOld); ReleaseDC(hwnd, hballMaskDC); // Draw the ball HDC hballHDC = CreateCompatibleDC(hdc); hbmpItemOld = (HBITMAP)SelectObject(hballHDC, redBall.GetCharacter()); if(!BitBlt(backHDC, (int)redBall.Position.X, (int)redBall.Position.Y, redBall.GetCharacterInfo().bmWidth, redBall.GetCharacterInfo().bmHeight, hballHDC, 0, 0, SRCPAINT)) lastError = GetLastError(); SelectObject(hballHDC, hbmpItemOld); ReleaseDC(hwnd, hballHDC); // Draw the debug information if(bDebug == true) { LPCTSTR debugInfo = new char[80]; sprintf((char*)debugInfo, "Position: (%d,%d) Velocity: (%.4f, %.4f) Acceleration: (%.4f, %.4f)", (int)redBall.Position.X, (int)redBall.Position.Y, redBall.Velocity.X, redBall.Velocity.Y, redBall.Acceleration.X, redBall.Acceleration.Y); DrawText(backHDC, debugInfo, strlen(debugInfo), &clientRect, DT_BOTTOM | DT_SINGLELINE | DT_CENTER); } // Draw image bitmap to the screen. if(!BitBlt(hdc, 0, 0, nclientWidth, nclientHeight, backHDC, 0, 0, SRCCOPY)) lastError = GetLastError(); SelectObject(backHDC, hbmpOld); ReleaseDC(hwnd, backHDC); }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!