Animation Flicker

I am working on an  MFC Program where i have to display a semi transparent window
with buttons On the top of an OPENGL animation.
So i have coded two different applications one to create a transparent window and the
other a OPENGL animation.These applications runs fine with out any flicker when run
separetely.

But when i overlay the semi transparent window on the top of  openGL Animation window,
The semi transparent window begins to flicker badly. How can i avoid this?
I have tried various methods but with out much success.Can any one Help on this
thanks
skalmariAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

davebytesCommented:
You need to have them be the same application.  You can't separate them and expect clean updates.

You can capture the buttons into a texture and render it over the OpenGL view, or you can render button by button directly individually into the openGL view.  Basically, transform your GUI rendering into OpenGL textures and rendered rectangles.

d

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skalmariAuthor Commented:
Well i need to have two different applications and cannot render the
buttons into a texture.
Because my transparent window is a VB application hosting  a IE Browser control which contains a web page with a green background and some buttons associated with java script events. I am making use of win32 Api call SetWindowLong and SetLayeredWindowAttributes to key out the green background color and making it  transparent and thereby just exposing the buttons on the top of my VC++- OPENGL water effect Animation.So the web buttons on transparent window  cannot be rendered into a texture. Any other suggestions please!
davebytesCommented:
Hmmm... try setting vsync on the OpenGL context.  That may or may not alleviate things.  Once you're in a windowed environment, the windowing system controls things a lot more.

-d
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

skalmariAuthor Commented:
well the vsync needs to have support from extensions available on the graphic card
which i don't have it.So i have come up with my own solution for this problem.
I have resolved this problem making parts of the window transparent using Regions with Win32.The code guru has some nice articles on it
describing the technique of making shaped windows and achieving transparency using bitmap regions.But i have found this technique rather slow when compared to the windows layering technique as it has to perform perpixel operations to find out the transparent regions on the bitmap.So is there any other way to achieve transparency other than layering and region?
davebytesCommented:
VSYNC is available on nearly all modern graphic cards, that is anything in the last say 3-4 years.  What card do you have, what OS?  Are you running latest drivers?

-d
skalmariAuthor Commented:
Well i am running WIndows XP which is having an  integrated video card
INTEL 82865G Graphics Controller
davebytesCommented:
i865 chipset should certainly give you the ability to vsync under OpenGL or DirectX.  Under GL, I don't think you can really query it.  Under DirectX, I believe it is a CAPS flag somewhere, like on the D3D device object.

-d
void_mainCommented:
Maybe you should enable "double buffering". This often is the reason for flickering.
skalmariAuthor Commented:
Hello Mr.Dave
Well Double buffering is enabled in my program.
I am setting up my PIXELFORMATDESCRIPTOR as follows to enable
Double buffering and calling SwapBuffers(wglGetCurrentDC());
in my "OnDraw" function to swap my primary and back buffer.
I have increased the point values,as it seems to be a tough
question to answer.
thanks

static PIXELFORMATDESCRIPTOR pfd =
      {
            sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd
            1,                              // version number
            PFD_DRAW_TO_WINDOW |            // support window
              PFD_SUPPORT_OPENGL |          // support OpenGL
              PFD_DOUBLEBUFFER,             // double buffered
            PFD_TYPE_RGBA,                  // RGBA type
            24,                             // 24-bit color depth
            0, 0, 0, 0, 0, 0,               // color bits ignored
            0,                              // no alpha buffer
            0,                              // shift bit ignored
            0,                              // no accumulation buffer
            0, 0, 0, 0,                     // accum bits ignored
            32,                             // 32-bit z-buffer
            0,                              // no stencil buffer
            0,                              // no auxiliary buffer
            PFD_MAIN_PLANE,                 // main layer
            0,                              // reserved
            0, 0, 0                         // layer masks ignored
      };
izizCommented:
(I'm not sure if this is completely right so I'm sure someone else will correct this if it isn't!)

The window that you create in the background is defining a region with which opengl is allowed to play with.  The actual drawing is done as a hardware overlay which bypasses normal windows GUI calls.

When you put an ordinary opaque window in front of it, the front window isn't being redrawn like your background opengl window is, on a frame by frame basis.  Instead it effectively redefines the drawing area that opengl uses, so as not to include the area covered by your opaque foreground window.  The result of this is that your opaque foreground window does not need to be redrawn until an event occurs on that foreground window.

The problem with your transparent window is that this all no longer applies.  As your window is transparent, it no longer redefines your opengl drawing window and therefore any transparent object placed within your opengl drawing area will get drawn over every time you swap your frame buffer.  The flickering you are seeing is the redrawing of the some of the GUI components on your foreground window when events occur (eg. mouse movements, mouse over etc), which are then drawn over again the next time you draw the next frame in your opengl application.

There are two ways that I can think of to get around this...

1.      The use of 'PostMessage', called after swapping your frame buffers, to force your transparent foreground window to refresh.  This however is not recommended as you cannot guarantee your background and foreground windows to both update in the same screen refresh... ie you are likely to still get flickering. (although it would be the quicker method)

2.      Draw your opengl scene to memory instead of your frame buffer and then draw that image to a standard window with standard GUI components.  This should have the effect of causing windows to update all transparent GUI components that are on top of the GUI drawing surface.  This would require more work though! (and would be a bit slower)  However if you were doing this I wouldn't see the point of having two applications... you could do this directly in your vb application... unless you wanted / needed the transparency for more than your opengl background.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.