Skip to main content
gamedev.net
🔒 Locked

Flickering problem

Started by UriKiller 1 reply 1.2k views
Original Post
UriKiller
UriKiller
I don't know if this thing is called "flickering" or not but here is what happens: I draw a moving picture to my window using BitBlt more than 60 times a second. Inside this picture there are some straight lines. During the movement they turn into something like stairs, I can't quite describe it because it is an illusion of the brain of course. Here are a couple of things I considered trying: 1) I guess the problem is that the drawing is unsynchronized with the screen flyback, so If anyone knows how to check when the flyback occurs? 2) Using double buffering: I saw in MSDN that when creating a window I should specify WS_EX_COMPOSITED as an extended style. Well, that define doesn't exist in winuser.h (some other possibly usefull definitions & functions don't exist as well), I got VC++ 6.0. 3) I don't exactly know if this is openGL or not, but I tried using SwapBuffers. Now, that was quite weird: First of all, That function takes a lot of time (about 15ms) and also didn't make anything look better. Then I learned that I need the Pixel Format of the Device Context (DC) to support double buffering, So I used GetPixelFormat (myhdc) and guess what it retuend? 0. Then I tried setting the Pixel Format to double buffering but then there were too many posibilities to try and at this point I prefer some professional advice. 4) Me and DirectX are enemies. But, If anyone here knows a way to use directX in the simplest way to draw 2D fast and without that flickering, and it could be as easy as using the normal Win32 Api (Device Contexts, BitBlt and all that collection), And without no Vertices, Matrices, Perspectives, Lightnings and Matirials, Then I would happily use it. 5) The same thing for openGL... On I have another question: When not using a fullscreened window, if the user moves the window, all the message loop gets stuck and I can't refresh the window so all the animation is stuck too, Any Ideas? Oh and another one: Is it correct that almost all of the capabilities of hardware accelaration are somehow related to 3D drawing and using hardware accelaration for 2D drawing would be almost as fast as using software accelaration? Thanks for any help for any question!
Colin Jeanne
Colin Jeanne
1. If I understand correctly what you are describing then yes, this is flickering or tearing.

2. WS_EX_COMPOSITED is not the correct thing to do but, first, the reason why you were unable to use it is because it requires Windows XP or later. In order to set your program as being for Windows XP or later you must add this line before including windows.h

#define _WIN32_WINNT 0x0501

Anyway, Winprog has information on double buffering (bottom of tutorial). The idea is that you create a memory DC and paint everything there. When you're ready to display the frame you simply BitBlt() from the memory DC to the window.

3. - 5.
I do not know OpenGL but as for DirectX I believe you can just use ID3DXSprite and not have to worry about vertices.

As for the final question, if you're doing 2D using 3D then you'll get the benefits of hardware acceleration.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.