const int MAXX = 10; // maximum X of game grid
const int MAXY = 15; // maximum Y of game grid
const int WINDOW_WIDTH = 300;
const int WINDOW_HEIGHT = 300;
void DrawScreen()
{
RECT myRect;
RECT myWindowRect;
int drawwidth = WINDOW_WIDTH / MAXX;
int drawheight = WINDOW_HEIGHT / MAXY;
hWindowDC = GetDC(hwndMain);
hMemDC = CreateCompatibleDC(hWindowDC);
GetClientRect(hwndMain, &myWindowRect);
for (int i = 0; i < 4; i++)
{
myRect.left = currentBlock.myPoints[i].x * drawwidth;
myRect.top = currentBlock.myPoints[i].y * drawheight;
myRect.bottom = myRect.top + drawheight;
myRect.right = myRect.left + drawwidth;
FillRect(hMemDC, &myRect, HBRUSH(GetStockObject(BLACK_BRUSH)));
}
BitBlt(hWindowDC, 0, 0, myWindowRect.right, myWindowRect.bottom, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
ReleaseDC(hwndMain, hWindowDC);
}
GDI graphics question
Hi, I'm somewhat new to windows programming, especially graphics programming.
Anyways, I've been working on a game similar to tetris for a while now. I've written this function which should draw to the window the falling block that is currently active (the block is stored in memory as a 4 member array of POINT in a Block structure.)
After running this function I get nothing on screen. Any ideas?
[edited by - Ronin Magus on May 30, 2002 5:02:25 PM]
[edited by - Ronin Magus on May 30, 2002 5:04:57 PM]
Try to change this...
...by this...
I had the same problem as you twice in the past, and this was the only way I found to solve it. Good luck.
theNestruo
Syntax error in 2410
Ok
hMemDC = CreateCompatibleDC(hWindowDC);/* Some code */DeleteObject (hMemDC);
...by this...
HBITMAP hMemBMP;/* Some code */hMemDC= CreateCompatibleDC (NULL);hMemBMP=CreateCompatibleBitmap (hWnd, width, height);SelectObject (hMemDC, hMemBMP);/* Some code */DeleteObject (hMemBMP);DeleteObject (hMemDC);
I had the same problem as you twice in the past, and this was the only way I found to solve it. Good luck.
theNestruo
Syntax error in 2410
Ok
Thank you, that worked well!! So, I assume that with GDI you have to select a bitmap object into a DC before you can draw on it. Correct?
[edited by - Ronin Magus on May 30, 2002 12:10:33 AM]
[edited by - Ronin Magus on May 30, 2002 12:10:33 AM]
quote:Original post by Ronin Magus
Thank you, that worked well!! So, I assume that with GDI you have to select a bitmap object into a DC before you can draw on it. Correct?
[edited by - Ronin Magus on May 30, 2002 12:10:33 AM]
Correct
I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
Windows GDI is quite troublesome at times, but it works so I can''t complain too much. I have just finished to a working extent a tetris clone myself. If you think it''d be helpful, I can send you the code of how I set up my rendering and various things for some ideas.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement