Recent

Author Topic: [SOLVED] Problems with dglOpenGL on Windows  (Read 6859 times)

soerensen3

  • Full Member
  • ***
  • Posts: 213
[SOLVED] Problems with dglOpenGL on Windows
« on: December 05, 2017, 03:47:03 pm »
I have a problem with dglOpenGL on Windows. When I try to initialize it doesn't find some of the functions. I am usually working on Linux, where everything is working fine. It used to work on Windows as well but for some reason it does not work anymore. I have an NVidia discrete display adapter and an Intel adapter which supports GL up to 4.5 so it is not a hardware related issue.

This minimal example fails on Windows but works on Linux:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses dglOpenGL;
  4.  
  5. begin
  6.   InitOpenGL();
  7.   ReadExtensions;
  8.   WriteLn( Assigned( glGenerateMipmap )); // Returns False ..  it is not the only function not working
  9.   ReadLn;
  10. end.
  11.  

I use Lazarus 1.8 RC 5 with FPC 3.0.4 (32 Bit) and the latest dglOpenGL.pas.

Is it a drivers problem, maybe?
« Last Edit: December 05, 2017, 05:55:59 pm by soerensen3 »
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Problems with dglOpenGL on Windows
« Reply #1 on: December 05, 2017, 03:56:51 pm »
Try in a lazarus app, maybe it only works with GUI apps.

soerensen3

  • Full Member
  • ***
  • Posts: 213
Re: Problems with dglOpenGL on Windows
« Reply #2 on: December 05, 2017, 04:08:33 pm »
That didn't help. Besides, I'm not talking about creating a context. InitOpenGL/ReadExtensions just dynamically loads all the pointers to the functions, which in my case does not work. I can however run other programs using OpenGL. It might point to the wrong dll? According to dependency walker "OpenGL32.dll" does indeed not have the functions I was looking for.
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Problems with dglOpenGL on Windows
« Reply #3 on: December 05, 2017, 04:22:33 pm »
Well, my dglopengl apps initialize opengl the same way, but in a lazarus application, and that works fine. Note to reach opengl3+ functions more is needed (see below)

opengl32.dll is afaik a windows DLL, but the driver must provide the relevant implementation.

In the past the windows default driver was sometimes a shell, without much 3d, but afaik that doesn't happen anymore since Windows 8.

My code is like:

Code: Pascal  [Select][+][-]
  1.  
  2.  if FirstTime then
  3.   begin // used to do one time init stuff
  4.     InitOpenGL;
  5.     ReadExtensions;
  6.   end;
  7.  
  8.   OnResize := PanelResize; // let's control our own resize, I have no idea which protected method is below this so...
  9.   FBrightness := 10.0;
  10.  
  11.   FDC := GetDC(Handle);
  12.  
  13.   pfd.nSize := SizeOf(pfd);
  14.   pfd.nVersion := 1;
  15.   pfd.dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
  16.   pfd.iPixelType := PFD_TYPE_RGBA;
  17.   pfd.cColorBits := 32;
  18.  
  19.   pf := ChoosePixelFormat(FDC, @pfd);
  20.   b:=SetPixelFormat(FDC, pf, @pfd);
  21.  
  22.   FRC := wglCreateContext(FDC);
  23.   b:=wglMakeCurrent(FDC, FRC);
  24.  
  25.   if FirstTime then begin // reread for opengl 3+ (?) properties.
  26.     ReadImplementationProperties;
  27.     ReadExtensions;
  28.   end;
  29.   b:=wglMakeCurrent(FDC, FRC);
  30.  
« Last Edit: December 05, 2017, 04:28:16 pm by marcov »

KemBill

  • Jr. Member
  • **
  • Posts: 74
Re: Problems with dglOpenGL on Windows
« Reply #4 on: December 05, 2017, 04:51:18 pm »
I have a problem with dglOpenGL on Windows. When I try to initialize it doesn't find some of the functions. I am usually working on Linux, where everything is working fine. It used to work on Windows as well but for some reason it does not work anymore. I have an NVidia discrete display adapter and an Intel adapter which supports GL up to 4.5 so it is not a hardware related issue.

This minimal example fails on Windows but works on Linux:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses dglOpenGL;
  4.  
  5. begin
  6.   InitOpenGL();
  7.   ReadExtensions;
  8.   WriteLn( Assigned( glGenerateMipmap )); // Returns False ..  it is not the only function not working
  9.   ReadLn;
  10. end.
  11.  

I use Lazarus 1.8 RC 5 with FPC 3.0.4 (32 Bit) and the latest dglOpenGL.pas.

Is it a drivers problem, maybe?

you miss ReadImplementationProperties after ReadExtensions; but glGenerateMipmap  is loaded during the call of ReadExtensions

i'm in the same case, try :
Code: Pascal  [Select][+][-]
  1. WriteLn(  dglCheckExtension('GL_ARB_framebuffer_object') );
« Last Edit: December 05, 2017, 05:33:04 pm by KemBill »

KemBill

  • Jr. Member
  • **
  • Posts: 74
Re: Problems with dglOpenGL on Windows
« Reply #5 on: December 05, 2017, 05:51:42 pm »
this is related to the way you test. In a real window if i check for extension GL_ARB_framebuffer_object, it's loaded

soerensen3

  • Full Member
  • ***
  • Posts: 213
Re: Problems with dglOpenGL on Windows
« Reply #6 on: December 05, 2017, 05:55:35 pm »
Thank you both! It works now!
The solution was to call ReadExtensions again after the Context is initialized!
Quote
if FirstTime then begin // reread for opengl 3+ (?) properties.
    ReadImplementationProperties;
    ReadExtensions;
  end;

So the order is like this.
Code: Pascal  [Select][+][-]
  1. InitOpenGL();
  2. //CreateContext
  3. ReadExtensions(); //Here the order does not seem to matter
  4. ReadImplementationProperties();//This might or might not be necessary, I still have to find out what the procedure does exactly
  5.  
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: [SOLVED] Problems with dglOpenGL on Windows
« Reply #7 on: December 08, 2017, 08:00:12 am »
Your issue is likely related to the fact that there's no actual window present, to be honest. OpenGL isn't a command-line API...

 

TinyPortal © 2005-2018