Forum > OpenGL

TOpenGLControl lost focus after border style change (Win10)

(1/1)

pik33:
I have a form and TOpenGLControl on it. Then, an OpenGL procedure draws something on it.

After changing the form border style to BsNone, the GLControl turns black.

How to return the OpenGLControl to the usable state again? MakeCurrent didn't help.

Handoko:
Did you change the border style using code? If yes, please provide the compilable source code. Without inspecting the source code, not much we can say. If you're not willing to publicize the code, you can write a demo project that can show the issue.

Create a new folder, copy and paste all the necessary files except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here.

pik33:
This is nothing but first experiments. Here is the project. When run it displays a shader output on the OpenGL context. Click on it to toggle the border style and then the window goes black. I think the OpenGL context has to be initialized again but I don't know how to do it.

wp:
I am not an OpenGL expert, so this may be wrong. But looking at your example in comparison with the examples provided in the folders components/opengl/example and examples/openglcontrol it is striking that the "official" examples put all the initialization stuff into the OnPaint event of the OpenGLControl (with a state variable to make sure that init is executed only once) while you have it in FormCreate which probably is too early. Please check these sample projects which come with Lazarus.

pik33:
The problem is: it initializes OK, and works, you can resize it, etc, but you cannot do a form borderstyle change. It seems the connection between the form canvas and the OpenGL is then lost while OpenGL still works reporting  valid execution times in the memo1. Maybe in this case I should close all OpenGL stuff, clean up and initialize it again. Or maybe a form create event is called when the border style is changed which causes reinitializing OpenGL...  Now I have some ideas to try.

Edit: worked around.

Before border size change, openglcontrol1.destroy;
After the change, recreate it and reinit opengl.

Ugly, but works.

Navigation

[0] Message Index

Go to full version