Recent

Author Topic: [SOLVED] OpenGL works - does not work  (Read 7168 times)

metis

  • Full Member
  • ***
  • Posts: 171
[SOLVED] OpenGL works - does not work
« on: May 12, 2015, 04:36:20 pm »
Hi to all Lazarus-User. :)

I'm just writing a little App using FFmpeg-DLLs (not FFPlay.exe) to render MediaFiles, see:
http://forum.lazarus.freepascal.org/index.php/topic,26666.0.html

- PC   : INTEL Pentium DualCore 1,60GHz, 2 GB RAM
- OS   : WinXP 32 SP3
- IDE  : Lazarus v1.2.2 + fpc v2.6.4
- DLLs: - the FFmpeg-DLLs required to render a MediaFile
            - SDL.dll
            - opengl32.dll (in C:\WINDOWS\system32)

One of the VideoOutputs is done, using the OpenGLContext-Control, that comes with Lazarus, see:
"LazDIR\components\opengl\lazopenglcontext.pas"

The compiled EXE-File works (almost) perfectly on the PC, where I write the App, and
obviously on other PCs, where Lazarus is installed, see:
http://forum.lazarus.freepascal.org/index.php/topic,26666.15.html
-> Post from April, 22 2015 by aradeonas -> "Yea! it works!",

BUT:

if I put the same EXE-File with the same DLLs on any other PC, where Lazarus is not installed, the
OpenGL-VideoOutput fails with "TApplication.HandleException Access violation", before the first VideoFrame is to be displayed, see Attachment 'ScreenShot.png'.
This Error even occurs on one of my NoteBooks, where the same Win98-Version is installed - one and only Difference: no Lazarus installed.

-> Here my Questions:
    - What are possible Reasons, that OpenGL works on PCs, where Lazarus is installed, whilst
       it fails on PCs, where Lazarus is not installed ?
    - What are possible Reasons for that ErrorMessage ?
« Last Edit: June 16, 2015, 06:17:13 pm by metis »
Life could be so easy, if there weren't those f*** Details.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8222
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: OpenGL works - does not work
« Reply #1 on: May 12, 2015, 05:04:03 pm »
What are possible Reasons, that OpenGL works on PCs, where Lazarus is installed, whilst it fails on PCs, where Lazarus is not installed ?
Using OpenGL functions not exist in the target environment, for instance. Pure FPC/Lazarus programs are statically linked (the RTL, FCL, LCL, all that's pure Pascal and shipped by default), there's no need for either to be installed in order for the compiled program to run. Use of 3rd party libraries is different case. In that case, you have to make sure that all those libraries are compatible with your target environment, including providing their dependencies (C compilers tend to have runtime libraries shipped as dynamic library, such as libgcc or msvcrt). Use dependencywalker on windows and ldd on linux to see what libraries are linked in and need to be provided.

Recompile your program with -gl (NO optimizations, smartlinking or symbol stripping allowed) and rerun on the failed PC, you'll get respective stacktrace where the error comes from.
What are possible Reasons for that ErrorMessage ?
Generic: http://www.ehow.com/about_6113547_eaccess-violation_.html
Object Pascal specific: http://eurekalog.blogspot.com/2009/05/access-violation-in-details_12.html
« Last Edit: May 12, 2015, 05:07:09 pm by Leledumbo »

metis

  • Full Member
  • ***
  • Posts: 171
Re: OpenGL works - does not work
« Reply #2 on: May 12, 2015, 05:50:44 pm »
@Leledumbo

Thanks a lot - I'll check that.
Life could be so easy, if there weren't those f*** Details.

Laksen

  • Hero Member
  • *****
  • Posts: 649
    • J-Software
Re: OpenGL works - does not work
« Reply #3 on: May 12, 2015, 06:34:59 pm »
You aren't copying opengl32.dll, right? That's a file that's installed by the graphics driver, which is specific to whatever hardware you have.

metis

  • Full Member
  • ***
  • Posts: 171
Re: OpenGL works - does not work
« Reply #4 on: May 15, 2015, 05:26:41 pm »
@Laksen
Quote
You aren't copying opengl32.dll, right?
I tried out with some other OpenGL32-DLL-Versions, putting them into the App's Directory -> same Error.
The original OpenGL32-DLL always had stayed in "C:\WINDOWS\system32".


@leledumbo
Quote
Use dependencywalker
I did with 'Dependency Walker v1.0' from VB6.
-> They are o.k.; nothing is missing.

Quote
you'll get respective stacktrace
I wrote some more ErrHandling-Code and added some more ConsoleMessages to encircle the Error:
-> The App already freezes BEFORE the VideoImage is passed to OpenGL:
     Actually it already hangs, when it should be scaled&converted by FFmpeg, see
Attachment "01_ScreenShot_OnLoad.jpg"
 
When I then press a Key, e.g. [Pause], the mentioned Error occurs with the following StackTrace, see
Attachment "02_ScreenShot_AfterPressPause.jpg"

=> For me, it seems as if two Processes try to access the same MemoryArea at the same Time.

But, how is it possible, that this does not occur, when I run the compiled EXE-File, where
Lazarus is installed ?  %)
Life could be so easy, if there weren't those f*** Details.

metis

  • Full Member
  • ***
  • Posts: 171
Re: OpenGL works - does not work
« Reply #5 on: May 21, 2015, 04:47:04 pm »
@leledumbo
@Laksen

Finally I found the Error (had nothing to do with Lazarus):  :)

First here the Error a little more detailed:

Error-Message:
Project FFPlay4Laz raised exception class 'External SIGSEGV'
At address 6D7C785E

Call Stack-Window:
Source  : 6D7C785E
Function: swscale-0!sws_getCoefficients at :0

Assembler-Window:
6D7C785E 8818                     mov    %bl,(%eax)

The reason for this Error is far before, when setting up the OpenGL-VideoTexture with
'glTexImage2D()': Elder GraphicCards only support TextureWidths/-Heights, that are PowerOfTwo.

I can reproduce the Error on my PC, because I'm working with 2 Screens, where:
Screen #1 is connected to the OnBoard-GraphicCard       -> The App works.
Screen #2 is connected via an external USB-GraphicCard -> The App fails with the mentioned Error.

ergo:
This Error has nothing to do with the fact, that Lazarus is installed or not (sorry ::)), but
at least it has something to do with OpenGL.

And now something strange:
When I initialize the Player (and OpenGL) (= [Open]) on Screen #1, then move the App to Screen #2,
and then start the Video (= [Load]), it works.
This even works when only a tiny Part of the App-Window was left on Screen #1, before moving
the App to Screen #2 and starting the Video there.

=> Questions:
- How is this possible ?
- Is there only some Info missing for OpenGL, when it's initialized on an old/weak GraphiCard ?
  If in case, which Info has to be added by Code, when OpenGL starts ? 
- How to rescale a Texture with OpenGL ?
  (Rescaling each VideoFrame with FFmpeg's 'sws_scale()' works, but is too slow.)
Life could be so easy, if there weren't those f*** Details.

Laksen

  • Hero Member
  • *****
  • Posts: 649
    • J-Software
Re: OpenGL works - does not work
« Reply #6 on: May 21, 2015, 09:13:45 pm »
OpenGL requires you to load an extension to handle non-power-of-2 (NPOT) textures. If you try to load it without having a power of two texture most might allow it, but older or more compliant drivers will not allow it. It should report an error if you call glGetError.

If you then try to use the invalid texture then you'll probably get undefined behaviour. It's probably the drivers fault that it crashes but you still need the proper extensions loaded to handle NPOT textures.

Try calling glGetError all over the place and see if you don't get an error after initializing the texture

Edit: You need to use the GL_ARB_texture_rectangle extension or GL verison 3.1
« Last Edit: May 21, 2015, 09:16:55 pm by Laksen »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8458
  • FPC developer.
Re: OpenGL works - does not work
« Reply #7 on: May 22, 2015, 10:16:34 am »

A.S. I don't know mpeg, just a bit about opengl.


I can reproduce the Error on my PC, because I'm working with 2 Screens, where:
Screen #1 is connected to the OnBoard-GraphicCard       -> The App works.
Screen #2 is connected via an external USB-GraphicCard -> The App fails with the mentioned Error.

(afaik Intel integrated cards before HD4500  (so i945,i965) don't support nonpower2 either.

IMHO such cards are nearly worthless for opengl)

 
Quote
And now something strange:
When I initialize the Player (and OpenGL) (= [Open]) on Screen #1, then move the App to Screen #2,
and then start the Video (= [Load]), it works.
This even works when only a tiny Part of the App-Window was left on Screen #1, before moving
the App to Screen #2 and starting the Video there.

=> Questions:
- How is this possible ?

Probably: Opengl/directx and gdi have separate administration and "screen" concepts. This is a wellknown issue, and also visible in many existing programs. (e.g. DVD authoring software)

Quote
- How to rescale a Texture with OpenGL ?

If you have a non power of two texture, you can't simply use textures that are not a power of two. Period. You will have to use either a power of two texture OR recalc using CPU
 

metis

  • Full Member
  • ***
  • Posts: 171
Re: OpenGL works - does not work
« Reply #8 on: May 27, 2015, 05:11:45 pm »
@Laksen
Quote
Try calling glGetError ... get an error after initializing the texture
I already did; the resulting OpenGL-ErrorString is: "invalid value".
(BTW: On SPANISH WinXP it's "valor no válido", so You cannot rely on the ErrorString.)

@markov
Quote
I don't know mpeg, just a bit about opengl.
After Decoding the VideoStream by FFmpeg, the resulting VideoFrames have nothing to do with
the FileFormat. They are pure Graphic, that can be displayed in OpenGL like Textures are.
-> For Outputting the VideoImages ANY Graphics- and/or OpenGL-Knowledge is very welcome.
(BTW: FFmpeg handles a huge amount of Audio- and VideoFormats, not only MPEG.)

Quote
You will have to use either a power of two texture
This is, what e.g. 'UltraStar' does, but maybe there are other (better) Solutions to handle this problem.

Quote
OR recalc using CPU
I already tried out Rescaling the VideoFrames with FFmpeg
-> CPU is too slow  => The GPU must do it.

BTW:
I found a really good OpenGL-Tutorial by DelphiGL. Though it was already mentioned in this Forum,
I put the Link again at this Place, because it explains lots of OpenGL-Issues very comprehensible:
http://wiki.delphigl.com/index.php/Tutorial
(One disadvantage: It's all in German.)
« Last Edit: June 04, 2015, 05:18:04 pm by metis »
Life could be so easy, if there weren't those f*** Details.

metis

  • Full Member
  • ***
  • Posts: 171
Re: OpenGL works - does not work
« Reply #9 on: June 16, 2015, 06:13:40 pm »
Finally got OpenGL working - without Rescaling, and on both Screens.  :D

Thanx to all, who helped me.
« Last Edit: June 16, 2015, 06:18:24 pm by metis »
Life could be so easy, if there weren't those f*** Details.

 

TinyPortal © 2005-2018