Recent

Author Topic: TOpenGLControl lost focus after border style change (Win10)  (Read 4958 times)

pik33

  • Jr. Member
  • **
  • Posts: 76
TOpenGLControl lost focus after border style change (Win10)
« on: November 14, 2019, 12:18:58 pm »
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

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TOpenGLControl lost focus after border style change (Win10)
« Reply #1 on: November 16, 2019, 06:59:03 pm »
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

  • Jr. Member
  • **
  • Posts: 76
Re: TOpenGLControl lost focus after border style change (Win10)
« Reply #2 on: November 20, 2019, 01:55:49 pm »
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

  • Hero Member
  • *****
  • Posts: 11855
Re: TOpenGLControl lost focus after border style change (Win10)
« Reply #3 on: November 20, 2019, 02:19:41 pm »
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

  • Jr. Member
  • **
  • Posts: 76
Re: TOpenGLControl lost focus after border style change (Win10)
« Reply #4 on: November 20, 2019, 09:55:27 pm »
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.
« Last Edit: November 21, 2019, 09:17:57 am by pik33 »

 

TinyPortal © 2005-2018