[SOLVED] OpenGL works - does not work lazarus / 70-OpenGL ---------------------------------------------------------------------- metis · 2015-05-12 14:36 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 ? ---------------------------------------------------------------------- Leledumbo · 2015-05-12 15:04 Quote from: metis on May 12, 2015, 04:36:20 pmWhat 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. Quote from: metis on May 12, 2015, 04:36:20 pmWhat 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 ---------------------------------------------------------------------- metis · 2015-05-12 15:50 @Leledumbo Thanks a lot - I'll check that. ---------------------------------------------------------------------- Laksen · 2015-05-12 16:34 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 · 2015-05-15 15:26 @Laksen QuoteYou 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 QuoteUse dependencywalkerI did with 'Dependency Walker v1.0' from VB6. -> They are o.k.; nothing is missing. Quoteyou'll get respective stacktraceI 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 ? ---------------------------------------------------------------------- metis · 2015-05-21 14:47 @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.) ---------------------------------------------------------------------- Laksen · 2015-05-21 19:13 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 ---------------------------------------------------------------------- marcov · 2015-05-22 08:16 A.S. I don't know mpeg, just a bit about opengl. Quote from: metis on May 21, 2015, 04:47:04 pm 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) QuoteAnd 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 · 2015-05-27 15:11 @Laksen QuoteTry calling glGetError ... get an error after initializing the textureI 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 QuoteI 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.) QuoteYou will have to use either a power of two textureThis is, what e.g. 'UltraStar' does, but maybe there are other (better) Solutions to handle this problem. QuoteOR recalc using CPUI 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.) ---------------------------------------------------------------------- metis · 2015-06-16 16:13 Finally got OpenGL working - without Rescaling, and on both Screens.  Thanx to all, who helped me.