View Full Version : Mixing OpenGL and GDI
05-03-2005, 05:12 AM
I don't know whether this is the correct forum but I need some expert help.
I have an application which has some GDI functionality but it uses OpenGL to draw graphics on some of the canvases as GDI is not fast enough to draw the graphics. The OpenGL canvases are 1280x960. I am not using the OpenGL to draw 3D object. Instead I am just using it to draw 2D very quickly!
Are there problems in mixing standard windows controls and OpenGL and if so what are they?
One of the main problems I have is when I drag a windows form around on top of the OpenGL canvas, it flickers like crazy. I have enabled the OpenGL double buffered and it has not affected it.
Is there a special way to initialise OpenGL so that it will work better?
Your help would be greatly appreciated.
05-03-2005, 06:58 AM
It would also flicker if you used GDI to render.
You probably haven't overwritten the WM_ERASEBKGND window message.
Just returning 1 (non-zero) will keep GDI from clearing the background with the workspace color.
That should stop the flickering.
You can also improve the redraw performance if you enable GL_SCISSOR_TEST and set the glScissor to the actual paint region which is newly exposed after the window move.
05-03-2005, 12:19 PM
Thanks for this
05-03-2005, 12:25 PM
I have tried this and things are a bit better.
There is another strange thing happening is that on certain drivers e.g. latest nVidia driver, the windows cursor disappears completely when it is stationary over the OpenGL canvas but if the mouse is moved it appears again.
I have also noticed that on some ATI and nVidia drivers the OpenGL drawing thread just locks up completely.
Do you have any ideas why this might be happening. I have these problems on the target hardware but not on the development machines.
I originally used OpenGL as it would improve performance but I am beginning to find that it only seems to work properly on certain graphics cards with certain versions of the drivers. Somehow I don't think this is really the case and so am trying to track down my problem in my code.
05-03-2005, 10:55 PM
The cursor should be done in hardware and be unaffected by any rendering.
If the cursor can not be done in hardware (too big, too many colors, full hardware acceleration not enabled in the graphics adapter's troubleshoot dialog) the cursor has to be taken away and redrawn on each SwapBuffers (cursor can flicker).
If you have vsync on, this can result in areas on the display where the frequency matches the animation and the cursor seems to vanish.
Use standard black and white cursors and see if the problem goes away.
If your target machines do not handle this correctly, but your development system does, look for differences in the system and display configuration.
Or something in your code is broken and you need to debug on the target machine to find what it is.
Start checking all OpenGL glGetString() parameters and add glGetError calls in critical places.
05-05-2005, 04:38 AM
Thanks for your help.
Things are running better now.
I have also managed to track the machine locking problem to deletion and creation of OpenGL canvases.
Are there any known issues with deleting and re-creating OpenGL canvases? Can different drivers support this in different ways?
The reason why I do this is because the canvas that I draw on can be different sizes depending on the pictures that I am drawing.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.