The MASM Forum

General => The Campus => Topic started by: r0ger on August 27, 2022, 06:22:56 AM

Title: Spinning cube flickering problem
Post by: r0ger on August 27, 2022, 06:22:56 AM
Hi guys,

does anyone know how do i insert another device context for the cube without flickering that much and to make it play more smooth ?
i tried many times to make another one even with PatBlt and doesn't work in any way..

thanks.
Title: Re: Spinning cube flickering problem
Post by: jj2007 on August 27, 2022, 06:39:07 AM
Hi R0ger,

I've no time to study your code right now: do you paint to a memory DC? I.e. double buffering etc?
Title: Re: Spinning cube flickering problem
Post by: r0ger on August 27, 2022, 07:25:22 AM
i've painted the cube to the main device context (the hdc one from the WM_INITDIALOG).
Title: Re: Spinning cube flickering problem
Post by: fearless on August 27, 2022, 08:28:12 AM
I would double buffer everything.
It is an ideal candidate for a custom control, so could create a custom control and have specific 'properties' to set, back color, text color, cube color, speed of animation, animation direction? speed of text scrolling, direction of text scroll: left to right (centered), down to up (centered), or possible others, etc.
Title: Re: Spinning cube flickering problem
Post by: HSE on August 27, 2022, 09:04:03 AM
Reading code, there is double buffering.

Perhaps must be invalidate instead of redraw?

Capture background erase?
Title: Re: Spinning cube flickering problem
Post by: Greenhorn on August 27, 2022, 05:33:58 PM
invoke SetTimer, hWnd, 1, 10, NULL
invoke SetTimer, hWnd, 2, 15, NULL


So, every 30ms the window gets redrawn. 30ms, because of the invoke Sleep, 20 in the WM_PAINT.
Maybe here is the root of the evil ... ?

Quote from: HSE on August 27, 2022, 09:04:03 AM
Capture background erase?
This could also be the cause (and more likely).
Title: Re: Spinning cube flickering problem
Post by: jj2007 on August 27, 2022, 06:42:50 PM
The Sleep 20 seems to be necessary to make the image rotate.

Yours are valid reasons, HSE & Greenhorn, but sometimes there is one more reason: painting is slow. Check the Coloured rounded buttons (http://masm32.com/board/index.php?topic=10292.msg112580#msg112580) example. It's double-buffered, but especially the controls on the left (using images) tend to flicker. And if you resize the whole thing, it becomes obvious that cpu and gpu have to work hard... if you have an example where a dialog with many controls can be flicker-free resized, I'd be curious to see it :cool:
Title: Re: Spinning cube flickering problem
Post by: fearless on August 27, 2022, 10:53:18 PM
Quote from: jj2007 on August 27, 2022, 06:42:50 PM
if you have an example where a dialog with many controls can be flicker-free resized

I normally would set wc.style to 0 or drop shadow style and make sure no CS_HREDRAW or CS_VREDRAW is used:

mov wc.style, CS_DROPSHADOWAnd set WS_CLIPCHILDREN with the dialog style
That seems to allow flicker free resizing of dialog with child controls.
Title: Re: Spinning cube flickering problem
Post by: jj2007 on August 28, 2022, 12:35:54 AM
Quote from: fearless on August 27, 2022, 10:53:18 PMI normally would set wc.style to 0 or drop shadow style and make sure no CS_HREDRAW or CS_VREDRAW is used:

mov wc.style, CS_DROPSHADOWAnd set WS_CLIPCHILDREN with the dialog style
That seems to allow flicker free resizing of dialog with child controls.

Sure. That's what I do. Show me a flicker-free example of a resizable dialog with many resizable controls. Seriously, I am curious - maybe I am really doing something wrong.
Title: Re: Spinning cube flickering problem
Post by: hutch-- on August 28, 2022, 12:47:14 AM
JJ,

    style = CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW

    and

    mrm wc.hbrBackground,  0

Give it a whirl.
Title: Re: Spinning cube flickering problem
Post by: hutch-- on August 28, 2022, 01:35:23 AM
Roger,

I had a quick look at the code you posted and its a dialog, not a CreateWindowEx and I don't know if you can set the styles in a dialog as well as a full window. I would be inclined to set the display in a window where you have the WNDCLASSEX styles that you can set.
Title: Re: Spinning cube flickering problem
Post by: avcaballero on August 28, 2022, 04:38:34 AM
I have seen the code and I have not understand anything. It seems to be some kind of unassembly product.
Title: Re: Spinning cube flickering problem
Post by: jj2007 on August 28, 2022, 06:03:46 AM
Quote from: hutch-- on August 28, 2022, 12:47:14 AM
JJ,

    style = CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW

    and

    mrm wc.hbrBackground,  0

Give it a whirl.

No difference. Btw and wc.hbrBackground, 0 is shorter ;-)
Title: Re: Spinning cube flickering problem
Post by: r0ger on August 28, 2022, 08:04:23 AM
well i have reviewed all your answers.
tried removing the RedrawWindow and starts to overdraw all the cube lines. :P
my concept of this aboutbox is to create a text scroller to draw altogether with the cube animation without flickering or overdrawing on the black background.
Title: Re: Spinning cube flickering problem
Post by: r0ger on August 29, 2022, 08:43:20 AM
well it seems like there is nothing to do with this cube. i've got to say that i will be giving up continuing to fix the Gdi problem. whenever i try to fix every device context value to this cube it kept getting worse for odd reasons.
Title: Re: Spinning cube flickering problem
Post by: hutch-- on August 29, 2022, 06:20:50 PM
Roger,

I suggested that you don't use a dialog but use a CreateWindowEx() as you have more adjustments with a proper window. A dialog is a limited class window for basically simple tasks. Anything serious is best done in a window.
Title: Re: Spinning cube flickering problem
Post by: r0ger on August 29, 2022, 11:54:24 PM
(https://i.imgur.com/tvzx15u.png)

day 9000 of the cube effect - finally got the cube right and without flickering (not rly, but very very less now but it's acceptable) !

the solution was to create a device context for the static control i've inserted (GetDlgItem,xWnd,10), then create the bitmap for the cube, and then apply it with SelectObject.

what i forgot was that the ebp was saved to the rect variable so for that I have applied it with GetClientRect for the window handle to make the cube working without overdrawing.

at the moment i made the cube only if i want to insert it on the main form. i will see what i can do with the vertical scroller one as well.