Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ronin Magus

GDI graphics question

This topic is 5923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?
      

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);
}
    
[edited by - Ronin Magus on May 30, 2002 5:02:25 PM] [edited by - Ronin Magus on May 30, 2002 5:04:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
Try to change this...

  
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • 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!