4
votes

I recently moved a large program from Delphi over to Lazarus. Most of the bugs are sorted out, and I'm thoroughly impressed with Lazarus / FPC. But there's one bug I can't quite figure out.

My application has a main OpenGL window, and a few supplementary forms. Originally, I designed these forms using the Delphi VCL, and now I've moved them over to the Lazarus LCL.

Edit: The OpenGL window is NOT an LCL form at the moment. It is implemented using calls to Win32, and has it's own message loop.

All of the forms are considered children of the main OpenGL Window, as per this line of code:

Form.ParentWindow := OpenGLWindow.h_wnd;

Unfortunately, when the forms are owned by the OpenGL window, they simply disappear. Of course, the OpenGL window gets refreshed at a 30fps framerate, and this is causing a screenbuffer problem. The forms are rendering, and then being rendered on top of by the OpenGL window.

The problem is resolved if the forms are not owned by the main window. Unfortunately, changing the ownership is pretty disruptive to end users (menus get lost behind the program, etc).

So I'm wondering, where do I start with a problem like this? Do I need to ensure that the forms have their own screenbuffers to render inside of, or is that the wrong idea?

To clarify a few things: I'm using the Win32 version of the LCL, not QT or anything like that. Also, I tried setting the forms to be double-buffered, to see if it would help, but it didn't.

1
What about leaving the mainform in LCL, and embed the OpenGL in the mainform?Jeroen Wiert Pluimers
Perhaps. It's one of the things I'm thinking of trying. The opengl window is implemented with win32 calls, and has a custom message loop (I'm really concerned about efficiency here), and I wonder if embedding it in a form would have any effects on it.AudioGL
The OpenGL (main!) window being implemented only by Win32 is an important point! That's probably related to your problem - please edit your question to note it. Secondly, why is a custom message loop more efficient? The VCL has never had a reputation for being slow, even as far back as resource-contrained Windows 3 / Delphi 1 days. Unless there's a good reason, sticking with forms seems a good idea. You can use the known working parenting and mainform system then too, and your problem would probably go away.David
It's food for thought, and I'll update the main question. I made these design decisions when I was a novice programmer. I just wanted to be 100% sure that if there was a weak link in the chain, that I would have control over it, so I implemented everything at the lowest level. The VCL (now LCL) forms were added to the program much later.AudioGL
Fullscreen should be easy - I'm only familiar with the VCL, but you can make a form borderless, on top and the same size and position as the screen easily. I think Windows has some APIs to notify it that it is a game-like fullscreen window, ie to prevent the taskbar appearing etc. I'd suggest searching SO and then asking a question, but it should be pretty simple.David

1 Answers

1
votes

Try to use OpenGlControl that comes with Lazarus. Install the package from componentes folder. This components works like a Tpaint, but is a opengl context. Drop it on any form and this form will be a opengl context, but also a form, can be moved, resize, etc. Take a look of samples that comes with component.

/BlueIcaro