Recent

Author Topic: LCL + OpenGL.  (Read 2307 times)

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
LCL + OpenGL.
« on: March 11, 2022, 01:18:04 am »
Windows 7 - 32/64.

Я создал LCL-приложение и с помощью dglOpenGL.pas создал контекст на панели формы.
Приложение выводит треугольник на панель (контекст OpenGL).

При запуске приложения, панель очищается, но треугольник не выводится!!! Все события для вывода треугольника прописаны заранее. Буфер VAO уже заполнен и готов к выводу. Но приложение LCL не выводит данные из буфера (помним, код срабатывает, панель очищается).

Если на форму бросить button (я указывал в buttonclick FormPaint), то даже нажимать на кнопку не надо, в течении секунды треугольник будет выведен.

На Delphi 7 работает нормально всё. И сразу.

Приложение прикладываю.

Gogle translate:
I created an LCL application and using dglOpenGL.pas created a context on the form panel.
The application draws a triangle to the panel (OpenGL context).

When the application starts, the panel is cleared, but the triangle is not displayed!!! All events for the output of the triangle are written in advance. The VAO buffer is already full and ready for output. But the LCL application does not output data from the buffer (remember, the code works, the panel is cleared).

If you throw button on the form (I indicated in buttonclick FormPaint), then you don’t even need to click on the button, within a second the triangle will be displayed.

Everything works fine on Delphi 7. And right away.

I am attaching the application.
« Last Edit: March 11, 2022, 01:19:37 am by Seenkao »
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Red_prig

  • Full Member
  • ***
  • Posts: 153
Re: LCL + OpenGL.
« Reply #1 on: March 11, 2022, 07:45:41 am »
Вопрос в том что происходит быстрее очистка окна или событие paint. (Да есть отличия от делфи)
В данном случае работает так:

The question is what happens faster window clearing or the paint event. (Yes, there are differences from Delphi)
In this case it works like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormActivate(Sender: TObject);
  2. begin
  3.  FormResize(Sender);
  4.  FormPaint(Sender);
  5. end;
Кроме того на будущее лафхаки если будете бороться с мерцанием перерисовки:
Отключение двойной буферизации:

In addition, future life hacks if you fight redraw flicker:
Disable double buffering:
Code: Pascal  [Select][+][-]
  1. Form1.DoubleBuffered:=false;    
и отключение закрашивание фона перед рисованием:
and disable erase background before painting:
Code: Pascal  [Select][+][-]
  1. uses
  2.   ...
  3.   LMessages,
  4.   LCLType,
  5.   ...
  6.  
  7. type
  8.  TForm1 = class(TForm)
  9.    ...
  10.    procedure WMEraseBkgnd(var Message:TLMEraseBkgnd); message LM_ERASEBKGND;
  11.    ...
  12.  private
  13.  
  14.  public
  15.  
  16.  end;
  17.  
  18. procedure TForm1.WMEraseBkgnd(var Message:TLMEraseBkgnd);
  19. begin
  20.  Message.Result:=1;
  21. end;  

« Last Edit: March 11, 2022, 07:47:38 am by Red_prig »

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
Re: LCL + OpenGL.
« Reply #2 on: March 11, 2022, 01:23:56 pm »
Я посмотрю ваше решение.
Но это означает, что при работе с LCL: FormResize срабатывает позже FormPaint, что в принципе неправильно. И это означает, что реализация LCL требует корректировки.

google translate:
I will look into your solution.
But this means that when working with LCL: FormResize works later than FormPaint, which is basically wrong. And this means that the implementation of the LCL needs to be adjusted.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Red_prig

  • Full Member
  • ***
  • Posts: 153
Re: LCL + OpenGL.
« Reply #3 on: March 11, 2022, 01:33:35 pm »
Rather, the problem is somewhere in the bowels of the form initialization, since during normal operation the order of calls is correct

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
Re: LCL + OpenGL.
« Reply #4 on: March 12, 2022, 03:33:33 pm »
Я проверил. При запуске LCL-приложения оно проходит два раза через Paint и лишь потом через Resize.

Почему так? Если Resize должно срабатывать до вызова Paint.

Google translate:
I checked. When an LCL application is launched, it goes through Paint twice and only then through Resize.

Why is that? If Resize should fire before calling Paint.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12266
  • FPC developer.
Re: LCL + OpenGL.
« Reply #5 on: March 12, 2022, 04:00:33 pm »
.Invalidate() the relevant components in the resize event?

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
Re: LCL + OpenGL.
« Reply #6 on: March 12, 2022, 04:13:19 pm »
событие Resize приходит после создания формы практически следом. Форма должна изначально получить размеры (изменённые размеры). И после этого только прорисовываться.

Это так происходит, когда пользуешься WinAPI. Про LCL я не знаю. Потому и задаю вопросы.

По сути ответ (вопрос) один, а почему мы должны дополнительно вызывать прорисовку окна, после процедуры, которая отвечает за изменение размеров окна?

Google translate:
event Resize comes after form creation practically next. The form must initially receive dimensions (resized). And after that, just draw.

This is how it happens when you use WinAPI. I don't know about LCL. That's why I'm asking questions.

In fact, there is only one answer (question), why should we additionally call the window drawing after the procedure that is responsible for resizing the window?
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
Re: LCL + OpenGL.
« Reply #7 on: March 12, 2022, 06:25:33 pm »

https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-size


Please read and study.
Благодарю, но для меня это достаточно "бесполезная" информация. Я занимаюсь нативными приложениями, если вы не обратили на это внимание. И ShowWindow отправляет изначально сообщение WM_SIZE окну.

Я задаю вопрос по LCL. Потому что для людей, работающих с окном "вручную", вполне нормально, когда раньше будет запрашиваться событие Resize а не Paint.

google translate:
Thank you, but for me this is quite "useless" information. I'm doing native apps in case you haven't noticed. And ShowWindow initially sends a WM_SIZE message to the window.

I'm asking a question about LCL. Because for people who work with the window "manually", it is quite normal when the Resize event will be requested earlier and not Paint.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
Re: LCL + OpenGL.
« Reply #8 on: March 12, 2022, 11:55:07 pm »
Благодарю за информацию!  :)

Thanks for the information! :)
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

 

TinyPortal © 2005-2018