Archived

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

IOStream

"TextOut" question --

Recommended Posts

IOStream    122
I have this scoring system i have worked out for this game im working on. it works perfectly in keeping score, but the text blinks. i put it in the WinMain part of the program. Does anyone know why it blinks and how to fix it?

Share this post


Link to post
Share on other sites
Gladiator    127
The reason it blinks is because you write straight to VRAM (video ram) memory. Since you said you are using TextOut() which uses HDC as one of the arguments, I would think you are using HDC''s to draw your text and stuff. A way to fix it is to create a memory DC, which will act as a double(back) buffer, so you draw everything on there first, and then just copy that memory DC to the screen DC (the one you are drawing to now).

If you need more help, please ask.

Share this post


Link to post
Share on other sites
Gladiator    127
Here''s how:

hDC - the DC where you''ve been drawing this far
hMemDC - from now on you will draw here and copy this to hDC at end of drawing

  
// created a new memory DC and select a bitmap into it

HDC hMemDC = CreateCompatibleDC( hDC );
HBITMAP hBmp, hOldBmp;

hBmp = CreateCompatibleBitmap( hDC, WINDOW_WIDTH, WINDOW_HEIGHT );
hOldBmp = (HBITMAP) SelectObject( hMemDC, hBmp );

// ---- draw stuff on hMemDC


// copy hMemDC onto hDC

BitBlt( hDC, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, hMemDC, 0, 0, SRCCOPY );

// clear all the objects we created

SelectObject( hMemDC, hOldBmp );
DeleteObject( hBmp );
DeleteDC( hMemDC );


hope this helps

Share this post


Link to post
Share on other sites
Gladiator    127
I can''t help you more without seeing your source code, or executable at that.

Some things to look for:

* Make sure you draw everything before the call to BitBlt()
* Sometimes you need to clear the back buffer with a call to rectangle before drawing anything on the back buffer
- HBRUSH hBrush = (HBRUSH) GetStockObject( BLACK_BRUSH );
RECT rc = { 0, 0, WINDOW_WIDTH-1, WINDOW_HEIGHT-1 };
FillRect( hMemDC, &rc, hBrush );

That''s the best I can do without code...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by IOStream
When I put in the code and ran it, my game started going static. While still being in its playable form. Any ideas?


Make sure you are deleting the bitmap (DeleteObject( hBmp ); statement in Gladiator''s code).

However you can try another approach - make hBmp global and create bitmap only once, not every time you draw to the window.

  
HBITMAP hBmp; // Global variable


//Call this function only once at the program startup

void createBitmap()
{
HDC hdc = CreateCompatibleDC(NULL);
hBmp = CreateCompatibleBitmap(hdc, WINDOW_WIDTH, WINDOW_HEIGHT);
DeleteDC(hdc);
}


//Use the same Gladiator''s code with some modifications


// created a new memory DC and select a bitmap into it

HDC hMemDC = CreateCompatibleDC( hDC );
HBITMAP hOldBmp;
hOldBmp = (HBITMAP) SelectObject( hMemDC, hBmp );

// ---- draw stuff on hMemDC


// copy hMemDC onto hDC

BitBlt( hDC, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, hMemDC, 0, 0, SRCCOPY );
// clear all the objects we created

SelectObject( hMemDC, hOldBmp );
DeleteDC( hMemDC );


Share this post


Link to post
Share on other sites
IOStream    122
When I put in the modified code, nothing happens. But luckily there''s no static. But there are no changes to the previous blinking. I''m not sure whats wrong with it...

Share this post


Link to post
Share on other sites