Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About Nanven

  • Rank
  1. Well, I have five different dice images. If I select the "one" dice image into the DC, sure, I wouldn't have to reselect that everytime, but what happens when the next dice I need to draw is something other than one? I need to put that into the DC instead. Unless I create 10 different image DC's? Would you suggest that? I was also trying to set up this application to be loose. I do kind of want it so it has the option to be double buffered, not autmatically set up that way. As such, if there is no back buffer, my code still works.. which is what I was going for and allowed for easy testing to see if the dice worked without the double buffer and it did. As far as Render() being bool, I agree. I threw this thing together and realized after the fact I should probably try to get some coding standards, etc, in. But I didn't want to recode everything, so a lot of the code isn't completely revised yet, but I am trying to figure out this problem before going any farther. Well, anyway, thanks for your comments.. and this thing is still puzzling me! Heh. As a side note, because I am so puzzled by this, here's the complete code, solution, projects and everything I have so far: Code.
  2. Well, i've been able to narrow it down to the fact it's something to do with how my application is double buffered. Here's what it looks like without the double buffer: With: As you can see, the non-colored dice draw just fine, it's just the dice with color fail to work. And it only draws it completely black when I have a double buffer up and running. Here's some code real quick(from different files): class BasicApp { protected: std::string m_appName; int m_height; int m_width; HINSTANCE m_hInstance; HWND m_hWnd; int m_menuID; HDC m_hDC; HDC m_hBackDC; HDC *m_phCurrentDC; HBITMAP m_hBitmap; PAINTSTRUCT m_ps; std::vector<HWND> m_windowObjects; public: BasicApp(std::string n, HINSTANCE hi, int w, int h, int menuID); ~BasicApp(); std::string GetName() { return m_appName; } bool Initialize(); bool AddObject(std::string clName, std::string obName, int id, int x, int y, int w, int h, int style, int flags); void CreateBackBuffer(); void DestroyBackBuffer(); void Run(); virtual void Idle(); void ClearDC(); virtual LRESULT AppWndProc(UINT msg, WPARAM wParam, LPARAM lParam); }; bool BasicApp::Initialize() { WNDCLASSEX wc; // Define the windows class wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = m_hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = MAKEINTRESOURCE(m_menuID); wc.lpszClassName = m_appName.c_str(); // Register it if(!RegisterClassEx(&wc)) return false; // Create the main application window m_hWnd = CreateWindowEx(NULL, m_appName.c_str(), m_appName.c_str(), WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, m_width, m_height, NULL, NULL, m_hInstance, (LPVOID)this); // If the window didn't get created, that's a bad thing if(!m_hWnd) return false; // Get a device context for drawing m_hDC = GetDC(m_hWnd); m_phCurrentDC = &m_hDC; return true; } void BasicApp::CreateBackBuffer() { DestroyBackBuffer(); // Just incase m_hBackDC = CreateCompatibleDC(m_hDC); m_hBitmap = CreateCompatibleBitmap(m_hBackDC, m_width, m_height); SelectObject(m_hBackDC, m_hBitmap); m_phCurrentDC = &m_hBackDC; BitBlt(*m_phCurrentDC, 0, 0, m_width, m_height, NULL, 0, 0, WHITENESS); } void BasicApp::DestroyBackBuffer() { if(m_hBitmap) { DeleteObject(m_hBitmap); m_hBitmap = NULL; } if(m_hBackDC) { DeleteDC(m_hBackDC); m_hBackDC = NULL; } m_phCurrentDC = &m_hDC; } void BasicApp::ClearDC() { BitBlt(*m_phCurrentDC, 0, 0, m_width, m_height, NULL, 0, 0, WHITENESS); } That handles all the BasicApp drawing components. Here's the Yahtzee app: class YahtzeeGame : public BasicApp { private: HANDLE m_diceImages[NUMIMAGES*2]; RECT m_diceDrawRect[NUMIMAGES]; Player m_players[4]; Player *m_pCurrentPlayer; int m_playerIndex; HDC m_hImageDC; public: YahtzeeGame(std::string n, HINSTANCE hi, int w, int h, int menuID):BasicApp(n,hi,w,h,menuID){GameInit();} ~YahtzeeGame(){GameShutdown();} bool GameInit(); void GameShutdown(); void GameLoop(); void Idle(); void Render(); LRESULT AppWndProc(UINT msg, WPARAM wParam, LPARAM lParam); }; bool YahtzeeGame::GameInit() { // Seed the random number generator srand((unsigned)time(NULL)); // Load the bitmaps for unlocked dice m_diceImages[0] = LoadImage(NULL, "dice1.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[1] = LoadImage(NULL, "dice2.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[2] = LoadImage(NULL, "dice3.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[3] = LoadImage(NULL, "dice4.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[4] = LoadImage(NULL, "dice5.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[5] = LoadImage(NULL, "dice6.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); // Load the bitmaps for locked dice m_diceImages[6] = LoadImage(NULL, "dice1locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[7] = LoadImage(NULL, "dice2locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[8] = LoadImage(NULL, "dice3locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[9] = LoadImage(NULL, "dice4locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[10] = LoadImage(NULL, "dice5locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); m_diceImages[11] = LoadImage(NULL, "dice6locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); // Initialize the draw rects for(int i = 0; i < NUMIMAGES; i++) { m_diceDrawRect.left = (50 * i + (20 * i)); m_diceDrawRect.top = 20; m_diceDrawRect.right = (50 * (i + 1) + (20 * i)); m_diceDrawRect.bottom = 70; } // Give player 1 control at the start of the game m_playerIndex = 0; m_pCurrentPlayer = &m_players[m_playerIndex]; m_hImageDC = CreateCompatibleDC(NULL); AddObject("BUTTON", "Roll", 50001, 300, 100, 80, 20, WS_EX_STATICEDGE, WS_CHILD | WS_VISIBLE); return true; } void YahtzeeGame::Render() { ClearDC(); int imageIndex = 0; // Draw the players name TextOut(*m_phCurrentDC, 0, 0, m_pCurrentPlayer->getName().c_str(), (int)m_pCurrentPlayer->getName().length()); // Draw the current players dice if he's taken atleast 1 turn(rolled the dice) if(m_pCurrentPlayer->getTurn() > 0) { for(int i = 0; i < NUMDICE; i++) { if(!m_pCurrentPlayer->getDice(i)->locked()) imageIndex = (m_pCurrentPlayer->getDiceValue(i) - 1); else imageIndex = (m_pCurrentPlayer->getDiceValue(i) + 5); SelectObject(m_hImageDC, m_diceImages[imageIndex]); BitBlt(*m_phCurrentDC, m_diceDrawRect.left, m_diceDrawRect.top, 50, 50, m_hImageDC, 0, 0, SRCCOPY); } } else { TextOut(*m_phCurrentDC, 30, 30, "Press the roll button to roll the dice", 38); } } // and just throwing my WMPAINT message in here just incase it matters case WM_PAINT: { m_hDC = BeginPaint(m_hWnd, &m_ps); // Validate Render(); if(m_hBackDC) BitBlt(m_hDC, 0, 0, m_width, m_height, m_hBackDC, 0, 0, SRCCOPY); EndPaint(m_hWnd, &m_ps); // Release the DC return TRUE; } So is there anything wrong with that code that would cause colored bitmaps to be drawn in black because of how I handled the double buffering(since they only draw black with the double buffer).
  3. Quote:Original post by Sneftel As long as your windowstyle doesn't include anything requiring a title bar (sysmenu or overlapped, for instance) a titlebar won't appear. That's what I thought but here's what I have right now: // The WCEX def WNDCLASSEX wcex; wcex.cbClsExtra = 0; wcex.cbSize = sizeof(WNDCLASSEX); wcex.cbWndExtra = 0; wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hIcon = 0; wcex.hIconSm = 0; wcex.hInstance = hInstance; wcex.lpfnWndProc = WinProc; wcex.lpszClassName = "Fun"; wcex.lpszMenuName = NULL; wcex.style = 0; // and the create window HWND hWnd = CreateWindowEx(NULL, "Fun", "", WS_MAXIMIZE, 0, 0, 1024, 800, NULL, NULL, hInstance, NULL); and it's still showing up... thus my confusion.. however, using WS_POPUP in CreateWindowEx seemed to of do the trick :) Thanks for the help.
  4. Well, I was in the process of changing everything over from global variables to a basic app class so some of the names aren't exactly completely standardized yet. And aye.. the image DC is created like: m_hImageDC = CreateCompatibleDC(NULL); Like I said, the funny thing is, this was WORKING when they were global variables in WinMain. The only thing that should of changed should of been the variables scope. And it *almost* is still working, if it weren't for the fact the DC seems to be on a white/black color scale and not drawing the colors of the bitmap. (Testable by using colors to make a design, when the bitmap is drawn, the shapes are drawn, but in black, but it was doing color before when it was global... really weird) m_hCurrentDC is just my way of coding a basic app that can be either double buffered or not but regardless of that you can still use it's drawing functions. Also did that so I could destroy the buffer after it's been created during runtime and the code would still work, it would probably just start flashing after that ;) So it points to the default HDC or the double buffered one. I'll post some more code if needed (or perhaps i'll just zip the files so it will be more clear) as I feel i'm not explaining the problem that well.
  5. Okay, this is kind of silly but i've done tons of searching and haven't found exactly what I was looking for. Found tons of ways to remove it in VB or MFC applications but when using just the bare bones Win32 API I can't figure out for the life of me how to disable the title bar of a window so it doesn't show up(kind of like full screen mode without actually being full screen or using DirectX) I just don't want the title bar. How do you do this with just the Win32 API?
  6. I'm still kind of new to this but I had an odd problem crop up. Basically, I have an application that is double buffered and I load a few bitmaps as such: diceImages[0] = LoadImage(NULL, "dice1.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[1] = LoadImage(NULL, "dice2.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[2] = LoadImage(NULL, "dice3.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[3] = LoadImage(NULL, "dice4.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[4] = LoadImage(NULL, "dice5.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[5] = LoadImage(NULL, "dice6.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[6] = LoadImage(NULL, "dice1locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[7] = LoadImage(NULL, "dice2locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[8] = LoadImage(NULL, "dice3locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[9] = LoadImage(NULL, "dice4locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[10] = LoadImage(NULL, "dice5locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); diceImages[11] = LoadImage(NULL, "dice6locked.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); The images load fine. The first six have a white background and are black and white BMP's only. The last six are colored bitmaps with a semi-green background. The idea is when a user clicks on the dice it "locks" it so when they roll the dice that one won't be rolled and as such the background color changes to indicate such. I had this working with global variables (with color) and when I started changing it more towards an object oriented approach(an app class) to avoid global variables, I didn't really change any of the underlying logic, just the scope of the variables. However, now the colored dice are entirely black. When it BitBlt's as such: SelectObject(m_hImageDC, diceImages[imageIndex]); BitBlt(*m_hCurrentDC, diceDrawRect.left, diceDrawRect.top, 50, 50, m_hImageDC, 0, 0, SRCCOPY); It does the first six fine(assume because the background is white) but for the colored background(green) it's changing it to black for some reason. So I was wondering if there was anything with the DC that would make all color not white or black to one of those because I really didn't change anything and this is puzzling me. Thanks for any help. [Edited by - Nanven on December 29, 2005 7:55:37 PM]
  7. Nanven

    Rendering problem

    Aye, I tested my classes in a console application first to make sure they all functioned correctly before throwing them into a Win32 app. I wouldn't of posted unless I was sure where the problem was. I was dead on that it was in how I was rendering. I DID, however, find the problem. It was how I was creating the DC in my Render() function. HDC hDC = CreateCompatibleDC(hdcBackBuffer); Was the old DC, as soon as I did this: HDC hDC = CreateCompatibleDC(NULL); everything worked FLAWLESSLY. Not sure why the old creation would work at first then cease to work all together, but oh well. Anyway! Thanks for responding. :)
  8. Well, I have an interesting problem. I am attempting to make a game base that uses GDI for rendering and basically trying to just add five dice that have their own graphic. The BMP's are black/white scale of 50x50 pixels each so 492 bytes per image. When you press "R" it rolls the five dice and depending on the value draws the correct dice. For reference, here's some of the code: WM_PAINT case: case WM_PAINT: { hDC = BeginPaint(hwnd, &ps); // Validate Render(); BitBlt(hDC, 0, 0, WINWIDTH, WINHEIGHT, hdcBackBuffer, 0, 0, SRCCOPY); EndPaint(hwnd, &ps); // Release the DC return 0; } Here's the render function: void Render() { ClearBuffer(); HDC hDC = CreateCompatibleDC(hdcBackBuffer); TextOut(hdcBackBuffer, 0, 0, currentPlayer->getName().c_str(), (int)currentPlayer->getName().length()); // Draw the current players dice if he's taken atleast 1 turn(rolled the dice) if(currentPlayer->getTurn() > 0) { for(int i = 0; i < 5; i++) { int imageIndex = (currentPlayer->getDiceValue(i) - 1); SelectObject(hDC, diceImages[imageIndex]); BitBlt(hdcBackBuffer, (50 * i + (20 * i)), 20, (50 * (i + 1) + (20 * i)), 70, hDC, 0, 0, SRCCOPY); } } ReleaseDC(NULL, hDC); } Now, after you roll the dice 3 times, it changes player, as such: void Player::rollDice() { m_turnNumber++; for(int i = 0; i < 5; i++) { if(!m_dice.locked()) m_dice.roll(); } } void GameLoop() { if(currentPlayer->getTurn() >= 3) { currentPlayer->clearTurn(); if(playerIndex == 3) playerIndex = 0; else playerIndex++; currentPlayer = &players[playerIndex]; } } Here's the variable definitions too just incase you are wondering: HANDLE diceImages[6]; Player players[4]; Player *currentPlayer; int playerIndex = 0; All ClearBuffer() does is: BitBlt(hdcBackBuffer, 0, 0, WINWIDTH, WINHEIGHT, NULL, 0, 0, WHITENESS); for now. Basically the problem is all the dice will render correct the first time through for player 1. Once it gets to player 2 it only renders the last 3, the first two never get drawn. Eventually, no dice ever get drawn, for any player. Even after it goes back to player 1. Anyone see a problem here? Thanks for any help.
  9. Nanven


    Nevermind. I figured it out. I was calling it too soon. =/
  10. I was following the article at http://www.gamedev.net/reference/articles/article1276.asp to use DirectMusic in my game. I'm trying to keep the source files as seperate modules so I made a new file to do all the initializing and loading. However when running it in debug mode I get this error: Unhandled exception at 0x004133ef in Game.exe: 0xC0000005: Access violation reading location 0x00000000. and when I press break it's at this line: hr = loader->SetSearchDirectory ((REFGUID)GUID_DirectMusicAllTypes, w_directory, FALSE); Any idea what is going on?
  11. Well I was wondering what everyone thought. Basically I set up a back buffer at the beginning before I go into my main loop and my WM_PAINT structure just copies over the back buffer when it needs to be redrawn: case WM_PAINT: { hDC = BeginPaint(hwnd, &ps); // validate BitBlt(hDC, 0, 0, WINWIDTH, WINHEIGHT, hdcBackBuffer, 0, 0, SRCCOPY); EndPaint(hwnd, &ps); // release the DC return 0; } I'm doing this so I am not constantly deleting/recreating my back buffer. However, I then thought i'm going to need to clear the back buffer before drawing the next frame because the old frame will still be there. So I can accomplish this one of two ways which is deleting/initializing it again before WM_PAINT gets called(this seems very bad) or just draw a black rectangle from 0, 0 to the winwidth/winheight. Neither of those seem like an ideal solution and I was wondering if there was a better way to clear the back buffer before rendering the next frame into it.
  12. Does anyone know a good tutorial on how to upload files via PHP?
  13. Nanven

    [web] Question

    Actually it does work with CSS, had to do this: <td style="filter:alpha(opacity=60);-moz-opacity:0.6;background:black;color:#000000;" width="700"> However, that affects the text too and makes it hard to see. Any ideas on how to keep text at 100% opacity?
  14. Nanven

    [web] Question

    Like when I do: td {background-color: transparent} it totally ignores the background color, and just meshes with whatever is behind it.
  15. Nanven

    [web] Question

    I tried the CSS, when I used the transparent option it didn't let me select a color to make it transparent with. I am trying to get the PNG idea working, but for some reason the transparency isn't working, it is completely solid on webpages, but transparent in photoshop.
  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!