grunge fightr
grunge fightr

Reputation: 1370

combining blits and gdi drawings (do not work, blinks)

I am tryin to combine texture blit with gdi drawing on top of it (by

    void draw()
    {
     StretchDIBits(hdc, 0, 0, CLIENT_X, CLIENT_Y, 0, 0, BUF_X, BUF_Y, buffer, &bmi,    DIB_RGB_COLORS, SRCCOPY);
     TextOut(hdc, 10, 10, "Hello World", 11);
    }

hdc is obrained once at setup time by GetDC but it is probably ok; this above i run both in idle loop 100 times per second and also fron OnPain message; and this is not working good just becouse TextOut result just blinks, the rest is all ok - could someone tell me some advice how to remove this blinking and obtain stable TextOut result ? much tnx

Upvotes: 1

Views: 508

Answers (2)

valdo
valdo

Reputation: 12943

This is natural. You draw a DIB on the DC. And the immediately you draw a text which is (presumably) placed so that its bounding rectangle overlaps with the one used in StretchDIBits.

In simple words: you draw something, then you draw something else on the same place. This will blink. What else did you expect?

In order to avoid blinking you should use so-called double-buffering. This means:

  1. Create a bitmap of the adequate size.
  2. Create a DC (so-called memory DC)
  3. Select this bitmap into it.
  4. Draw your DIB on this DC (not the one that you initially obtained).
  5. Draw your text.
  6. Finally use BitBlt to transfer the image from bitmap to your initial DC.
  7. Don't forget to cleanup things: DeleteObject for the DIB, DeleteDC for memory DC.

Optionally you may keep your bitmap instead of creating it each time you need to draw something. It's better from the performance point of view: Doing StretchXXXX is heavy, plus drawing on the screen from bitmap is much faster that drawing a DIB (assuming the video card supports 2D acceleration).

Upvotes: 1

Maximus
Maximus

Reputation: 10845

You need "double buffer" to avoid blinking.

Create memory DC CreateCompatibleDC select in it bitmap with proper size created with CreateCompatibleBitmap and paint in this memory DC.

When your picture is ready - BitBlt it on your window DC.

Upvotes: 3

Related Questions