Why do these two irregular regions blink?

They blink. They both show up, but they both blink.

If I comment out either one of them then the other shows up without blinking.

Question:
How do I get these two irregular bitmap regions to show up without blinking?


Using Windows 32bit.
Using CODE::BLOCKS 17.12
Using C++11.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

        case WM_TIMER:
        {
            RECT rcClient;
            HDC hdc = GetDC(hwnd);

            GetClientRect(hwnd, &rcClient);

            UpdateBall(&rcClient);   // Updated for moving it.

            DrawBall(hdc, &rcClient);


            DrawLINES(hdc, &rcClient);


            ReleaseDC(hwnd, hdc);
        }
            break;



Thanks againtry.

Is that better?
Last edited on
As an observation without getting into the weeds of you voluminous and as yet un-tagged post I think that you are going about solving this the wrong way.

Instead of reams of irrelevant code, why not step outside that box and just write a routine to solve the immediate problem. Once you have that (unit) working without blinking put it back into the main code.

Your description of the problem you are experiencing is vague and probably the reason why your program doesn't work

Show your pseudocode or similar clear description of wtf your plan is. If you don't know it is almost impossible for other people to guess.

For code tagging after you have proper/professional indentation, select your code and use the <> on the right.
I don't see it here, but blinking is usually caused by writing the frame to the screen when you did not mean to.
if you had
draw box (draw frame)
erase box(draw frame)
redraw box in new spot (draw frame)
it would flash.
you need
draw box (draw frame)
erase box(draw previous frame)
redraw box in new spot (draw new frame)

and that extends to drawing a bunch of stuff..
draw old frame until you have finished the new frame solves it.
**typically this kind of code has a 'go as fast as you can' thread that is drawing the current frame, and your other thread will swap the current frame out when it is ready to be displayed.

@OP You’ve just been posted another pile of useless crap from jonnin. Do what I said and you might learn something.

If you can’t answer the simple questions I raised then you’re in the wrong business.

Otherwise just green tick the thread and move on. We aren’t interested in being around time-wasters.
Hi Rollerbladegirl,

I'll be the first to admit I don't know much about 3D graphics programming, but from the little I do know, it sounds like your problem might be with either: writing to your buffer when it's being rendered, or possibly not using double-buffering.

In theory (if I understand correctly) setting up double-buffering and a swap chain would minimize any blinking, as the buffer that's being written to is distinctly different than the one being rendered, and only after the one being written to is ready is it then swapped and rendered.

In general, I think blinking or tearing points to an async between your rendering and writing to buffer.

Edit: Incase you're unfamiliar: https://docs.microsoft.com/en-us/windows/win32/direct3d9/what-is-a-swap-chain-

Best!
Last edited on
Well, that’s just more bullshit that goes nowhere.
I apologize for not knowing enough about C++ to ask a simple question.

I am very new at this. I found some working tutorials which I will be studying the code to see if I can learn from them. I did (tried to do) what againtry said, and it looks like I did not correctly learn how to bitblt multiple regions to a back buffer. I think that is one thing that I am having a very tough time understanding.

Thank you againtry. Yes, I was doing too much at once and jumping ahead of my understanding. I apologize for irritating you. I will do as you say. I will break the program into parts and try to make each part work one at a time.

Thank you jonnin. I do not understand what you are saying. I am not sure where to go with it.

Thank you Aaron Vienneau. I will look into writing to a back buffer and then when I have completed the back buffer (not sure how to verify that) then put the result to a front (?) buffer. And, I do not think that I am using any DirectX at all. I am trying to do this in C++11 by itself, maybe.

Thank you each for your offer of help.

graphics isnt c++, really. Keep that in mind... you are fooling around with libraries and tools that sit on top of the language.

Thank you jonnin. I do not understand what you are saying. I am not sure where to go with it.

I was telling you what causes the problem. If you draw something, erase it, and draw it, it will blink if your draw the frame where the thing was erased by mistake. You must only draw the frames where the thing exists. Basically, somewhere, you are drawing a frame where the object is not there, and when you see that displayed, its there-gone-there blinks happen.

Which is really the same thing we all said. Just breaking it down to the beginner level a bit to see if it helps you spot what you did wrong or what is going on.
@rollerbladegirl, I am not irritated by you asking a question at all. There is a famous saying about a moment of (possible) embarrassment in asking a question vs the eternity of stupidity in not asking it.

Any irritation is with the people here who don’t help, have no idea about problem solving, and just dish out the same serially pestilent Readers Digest style nuisance platitudes.

I’m glad you see the sense of what I’m saying. Its standard practice.
You don't have to apologize. It's why this forum exists. Ignore the people who gaslight you. Your question was directed to nobody in particular, and everybody who responds took it upon themselves to answer, so they have no reason to be irritated. They can just as easily keep scrolling.

Sometimes, as you implied, you don't have enough knowledge to ask the right questions in the right ways, and thats OK. You don't know what you don't know.

Hopefully with the suggestions above you can make a bit of progress. Give the double buffering a shot and see if that helps. If not, continue to ask questions. If you have a Github, you might consider posting the code there and linking to it here.

Your problem is that you are trying to draw to the screen within the WM_TIMER message.

The drawing shall happen within the WM_PAINT message. See:

https://docs.microsoft.com/en-us/windows/win32/gdi/using-the-wm-paint-message

When there are changes you need to call InvalidateRect(...) or similar.

Double buffer is ok to avoid flicker but you might first try without.
Thanks againtry.
Is that better?


@rollerbladegirl

In the cut and thrust I missed your comment and substantial change. It's some time since I used a Windows machine, but if that is the code causing the flickering/whatever then it certainly narrows it down.

I hope @coder_numerous_7's advice gives you the solution.

The online Microsoft reference makes a good resource - there's even a section on 'Regions'

:)

Registered users can post here. Sign in or register to post.