"TextOut" question --

Started by
7 comments, last by IOStream 22 years, 6 months ago
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?
Advertisement
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.
Thanks for the heads up. I am using the DC to draw the text to the screen. So how do i go about creating a Memory DC?
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 itHDC 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 hDCBitBlt( hDC, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, hMemDC, 0, 0, SRCCOPY );// clear all the objects we createdSelectObject( hMemDC, hOldBmp );DeleteObject( hBmp );DeleteDC( hMemDC );  


hope this helps
When I put in the code and ran it, my game started going static. While still being in its playable form. Any ideas?
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...
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 startupvoid 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 itHDC hMemDC = CreateCompatibleDC( hDC );HBITMAP hOldBmp;hOldBmp = (HBITMAP) SelectObject( hMemDC, hBmp ); // ---- draw stuff on hMemDC // copy hMemDC onto hDCBitBlt( hDC, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, hMemDC, 0, 0, SRCCOPY );// clear all the objects we createdSelectObject( hMemDC, hOldBmp );DeleteDC( hMemDC );  

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...
Maybe this can help:

Initialize hbrBackground member of WNDCLASS structure to NULL, before the call to RegisterClass.

This topic is closed to new replies.

Advertisement