Recent

Author Topic: [SOLVED] How to prevent jerking of OpenGL texture rendering  (Read 10414 times)

Pascal

  • Hero Member
  • *****
  • Posts: 932
I am actualy implemeting some kind of KenBurns animation.
If i do fast transitions i can see jerking in the movement of the texture.
How can i prevent this?

See example attached. (Copy addition files to project folder)
« Last Edit: July 05, 2017, 09:12:21 pm by Pascal »
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: How to prevent jerking of OpenGL texture rendering
« Reply #1 on: July 05, 2017, 01:59:52 pm »
Addition file:
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: How to prevent jerking of OpenGL texture rendering
« Reply #2 on: July 05, 2017, 02:00:12 pm »
Additional file:
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: How to prevent jerking of OpenGL texture rendering
« Reply #3 on: July 05, 2017, 04:48:17 pm »
I tried your code, but it is not fully cross-platform. I tried to make it to be able to compile on Linux64 but it has too many incompatibilities, I failed.

I heard that dglOpenGL has its own advantages compare to others. But you may try TOpenGLControl. It may not have the latest OpenGL features, but it works on Windows and Linux. It is able to do KenBurns animation, you can see the scaling and sliding effect on my example on glSlideshow posted on:

http://forum.lazarus.freepascal.org/index.php/topic,35313.msg249731.html#msg249731

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: How to prevent jerking of OpenGL texture rendering
« Reply #4 on: July 05, 2017, 06:52:26 pm »
If you want to try out a cross-platform solution using Core OpenGL (instead of Legacy OpenGL) you can try Project 4 from here:
  https://github.com/neurolabusc/OpenGLCoreTutorials
This should provide fluid graphics.

Flaze07

  • New Member
  • *
  • Posts: 36
Re: How to prevent jerking of OpenGL texture rendering
« Reply #5 on: July 05, 2017, 07:01:55 pm »
I tried your code, but it is not fully cross-platform. I tried to make it to be able to compile on Linux64 but it has too many incompatibilities, I failed.

dunno why...but I laughed when I read that
now I feel bad
pascal is good for learning programming language

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: How to prevent jerking of OpenGL texture rendering
« Reply #6 on: July 05, 2017, 07:10:54 pm »
I don't understand. If it has grammar errors, please understand English is not my native language. I can use Pascal better than English.  :D

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: How to prevent jerking of OpenGL texture rendering
« Reply #7 on: July 05, 2017, 07:17:37 pm »
I don't understand. If it has grammar errors, please understand English is not my native language. I can use Pascal better than English.  :D
Me, too. No wonder, if i use dglOpenGL which is not fully cross platform. But i didn't manage to render in a thread to the TOpenGLControl. I couldn't
access the context.
Anyway, many thank for your try!
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: How to prevent jerking of OpenGL texture rendering
« Reply #8 on: July 05, 2017, 07:32:56 pm »
Actually dglOpenGL is okay, you just need to add  "Classes" into the unit clauses (line #174).

The serious problems are in the Texture.pas:
- Remove "Windows" from the unit clause   ... line #30
- Add "LCLType" into the unit clause ... line #30
- "CreateFile" is unknown on my Lazarus Linux   ... line #146
- "ReadFile" is unknown on my Lazarus Linux   ... line #153
- "MessageBox" is unknown on my Lazarus Linux   ... line #148
- "CloseHandle" is unknown on my Lazarus Linux   ... line #178
- "FileExists" is unknown on my Lazarus Linux   ... line #329
- "Uppercase" is unknown on my Lazarus Linux ... line #518
...

Now you can see, too much issues. If only 3 or 4, I am sure I can fix it manually. My guess, the unknown issues is related with Windows unit.

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: How to prevent jerking of OpenGL texture rendering
« Reply #9 on: July 05, 2017, 09:11:33 pm »
The problem was the inaccuracy of GetTickCount64. The values hop and therefore my offsets too.
I used QueryPerfomanceCounter.

Is there a cross platform version of this?
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: [SOLVED] How to prevent jerking of OpenGL texture rendering
« Reply #10 on: July 05, 2017, 10:42:02 pm »
Project 4 (Textures) shows a cross-platform solution using core OpenGL 3.3. This should work on MacOS, Linux and Windows:
  https://github.com/neurolabusc/OpenGLCoreTutorials
If you want a cross-platform solution for legacy OpenGL you need to target 2.1 (the last legacy version supported by MacOS). In sum, if you want to support MacOS you must either support 2.1 or earlier or the Core profile (3.2 or later).

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: [SOLVED] How to prevent jerking of OpenGL texture rendering
« Reply #11 on: July 06, 2017, 06:02:35 pm »
I have added a version of my cross-platform texture demo to github that supports legacy OpenGL 2.1 (project texLegacy.lpr)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: How to prevent jerking of OpenGL texture rendering
« Reply #12 on: July 06, 2017, 11:16:30 pm »
But i didn't manage to render in a thread to the TOpenGLControl. I couldn't
access the context.
OpenGL calls must always be called in sequence. If you have glBegin..glEnd loops simultaneously rendering in 2 threads you are asking for trouble. What you can do in threads is do cpu tasks, such as filling arrays ready to be then called with glDrawArrays or similar. If you have tens/hundreds of thousands or more polygons it can speed things up. But i don't see how TOpenGLContext would give you problems.

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: How to prevent jerking of OpenGL texture rendering
« Reply #13 on: July 07, 2017, 08:31:21 am »
But i didn't manage to render in a thread to the TOpenGLControl. I couldn't
access the context.
OpenGL calls must always be called in sequence. If you have glBegin..glEnd loops simultaneously rendering in 2 threads you are asking for trouble. What you can do in threads is do cpu tasks, such as filling arrays ready to be then called with glDrawArrays or similar. If you have tens/hundreds of thousands or more polygons it can speed things up. But i don't see how TOpenGLContext would give you problems.
It calls MakeCurrent when invalidated (Paint) or resized. The thread doesn't get the context back unless you call ReleaseContext from the main thread.
I allready submitted a patch for this unnecessary behaviour (https://bugs.freepascal.org/view.php?id=32116)

I know that i have to do locking with more than one thread rendering. That's not the problem. I do not do it for speed reasons, i just whant to keep the main thread free for user interaction.
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: [SOLVED] How to prevent jerking of OpenGL texture rendering
« Reply #14 on: July 07, 2017, 09:31:32 am »
Is that mean we will have threadsafe TOpenGLControl? Great. :D

I never program multi-threaded things. But I heard it a lot when in 3D graphics rendering like in LuxRender and Blender3D. Basically OpenGL is fast, may I ask what is the benefit of doing thread for opengl?

 

TinyPortal © 2005-2018