* * *

Author Topic: Lazarus - OpenGL 3.3 Tutorial (German)  (Read 3251 times)

Mathias

  • New member
  • *
  • Posts: 18
Lazarus - OpenGL 3.3 Tutorial (German)
« on: January 26, 2018, 06:01:23 pm »
I'm building an OpenGL 3.3 tutorial for Lazarus.
The tutorial is completely recorded in German. But I'll announce the link here. Since all sources are available, it should not be such a big problem for the English friends.

https://wiki.delphigl.com/index.php/Lazarus_-_OpenGL_3.3_Tutorial

ChrisR

  • Jr. Member
  • **
  • Posts: 67
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #1 on: January 28, 2018, 09:39:05 pm »
Mathias-
  These tutorials are very nice.
   1.) If you want your programs to work on MacOS, you will want to add in the "IFDEF Darwin" conditionals shown below into the unit oglShader.pas.
  2.) You might want to add a link (or completely integrate) my tutorials from here https://github.com/neurolabusc/OpenGLCoreTutorials
  3.) While dglOpenGL works fine on MacOS, be aware that MacOS only supports the Core features of OpenGL, not the legacy features. Therefore, you may find it easier to develop your projects with glcorearb.pas (which is included with my projects). They ensure a developer does not accidentally include a function/constant not included in the modern core specification.
 4.) I would be happy to help write an English translation for your Wiki, just tell me when you think it is completed.



function FileToStr(Datei: string): ansistring;
var
  sl: TStringList;
  size,
  fh: integer;
  {$IFDEF Darwin} s: string;{$ENDIF}
begin
  {$IFDEF Darwin}
  if not FileExists(Datei) then begin
    s := LeftStr(paramstr(0), Pos('.app/', paramstr(0))-1);
    s := ExtractFilePath(s)+ Datei;
    if FileExists(s) then
       Datei := s;
  end;
  {$ENDIF}

Mathias

  • New member
  • *
  • Posts: 18
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #2 on: January 30, 2018, 08:13:00 pm »
1) I do not know what happened here, but I have changed it. I never had a Mac in my fingers.
Code: Pascal  [Select]
  1. function FileToStr(Datei: string): ansistring;
  2. var
  3.   sl: TStringList;
  4.   size: integer;
  5.   {$IFDEF Darwin} s: string;{$ENDIF}
  6. begin
  7.   if FileExists(Datei) then begin
  8.     {$IFDEF Darwin}
  9.     if not FileExists(Datei) then begin
  10.       s := LeftStr(paramstr(0), Pos('.app/', paramstr(0))-1);
  11.       s := ExtractFilePath(s)+ Datei;
  12.       if FileExists(s) then Datei := s;
  13.     end;
  14.     {$ENDIF}
  15.     sl := TStringList.Create;
  16.     sl.LoadFromFile(Datei);
  17.     Result := sl.Text;
  18.     sl.Free;
  19.   end else begin
  20.     WriteLog('FEHLER: Kann Datei ' + Datei + ' nicht finden');
  21.     Result := '';
  22.   end;
  23. end;  
2) I'll look at your tutorial on occasion, maybe I'll find that one thing and others I do not know. I can link it to my tutorial, for example. as further examples.
3) Is this comparable to OpenGL-ES? There is no glBegin anymore.
4) I will not do an English translation, otherwise I would have to translate the whole tutorial with Google, as well as the whole post here.
I can not say what the tutorial will do, you always find something to complement it. But this should not be a problem if someone else wants to translate this.

PS: As it seems, you're also an OpenGL professional. Can you speak German, or do you have to translate everything with difficulty?

ChrisR

  • Jr. Member
  • **
  • Posts: 67
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #3 on: February 02, 2018, 04:02:59 pm »
1.) "OpenGL ES" is for embedded systems such as phones.
2.) "OpenGL Core" was introduced with OpenGL 3.3 and removes deprecated features like "glBegin" as well as the "glMatrix" functions. Modern Macs support legacy OpenGL up to version 2.1 and OpenGL Core for 3.2 and later. Therefore, if you want your software to run on a Mac, you MUST either stick to legacy features or use the modern core version, you can not mix and match.
3.) Windows and Linux machines provide OpenGL legacy, which allows you to mix and match modern OpenGL with legacy features like glBegin and glMatrix.

Be aware that your OpenGL 3.3 tutorials will crash on a mac if you use any legacy features. For Lazarus' "Write Once Compile Anywhere" to work with Mac, you must target the core profile if you want modern features. The benefit of using "glcorearb" instead of "dglOpenGL" is that it hides all functions and constants that were removed in Core. This makes it easier to develop software on Linux and Windows that will also work on a Mac.

There are three reasons why it is a nice idea to have modern OpenGL tutorials remove any deprecated legacy functions:

1.) Software will work on Windows, Linux and Mac.
2.) The deprecated immediate mode functions (e.g. glBegin) often carry a large performance penalty. Restricting yourself to the  retained mode will provide optimal software.
3.) It is much easier to port a modern OpenGL core application to an embedded device, as OpenGL Core and OpenGL ES are very similar. On the other hand, legacy functions do not exist in OpenGL ES.

ChrisR

  • Jr. Member
  • **
  • Posts: 67
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #4 on: February 02, 2018, 04:09:55 pm »
I am not a OpenGL professional - I do research on the human brain. However, I did create a popular surface rendering https://www.nitrc.org/plugins/mwiki/index.php/surfice:MainPage  and volume rendering https://www.nitrc.org/plugins/mwiki/index.php/mricrogl:MainPage tools using OpenGL and Lazarus. My mother is from Germany and while I only studied spanish in school I think my German comprehension is good enough for basic translations - I visit Germany once  a year or so.

Mathias

  • New member
  • *
  • Posts: 18
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #5 on: February 02, 2018, 05:41:32 pm »
Quote
3.) Windows and Linux machines provide OpenGL legacy, which allows you to mix and match modern OpenGL with legacy features like glBegin and glMatrix.
This is not the case for Linux with my Intel 4000, either I can use OpenGL to 3.2, or I have to take Core, as you described it on the Mac. With a NVidia card it looked different, so I could mix too. Also, the major and minor version of OpenControl is handled differently. At Intel, this is mandatory, NVidia, this did not matter.

Quote
3.) It is much easier to port a modern OpenGL core application to an embedded device, as OpenGL Core and OpenGL ES are very similar. On the other hand, legacy functions do not exist in OpenGL ES.

That's exactly what I meant. I use either the modern or old OpenGL, mixing I want to avoid if possible.
The idea with the slimmed-down dglOpenGL.pas is certainly a good idea.

Incidentally, your query is incorrect, with me the message is called, although my chip / driver OpenGL 4.2 can.
Code: Pascal  [Select]
  1.    if (not Load_GL_version_3_3_CORE) then begin
  2.      ShowMessage ('Unable to load OpenGL 3.3 Core');
  3.      // stop;
  4.    end;

ChrisR

  • Jr. Member
  • **
  • Posts: 67
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #6 on: February 03, 2018, 04:01:02 pm »
I am surprised you get that error.

1.) Could you please tell me if my compiled version of Surfice generates the same error
   https://github.com/neurolabusc/surf-ice/releases
    (The release includes two versions - the "old" version uses OpenGL 2.1 while the regular version requires Core 3.3).

2.) I have updated glcorearb.pas to report errors. Could you run the basic version and if it gives you an error also run it from the command line and tell me what errors the command line reports.
  https://github.com/neurolabusc/OpenGLCoreTutorials

3.) Be aware that having a driver that is OpenGL4.2 compatible does not necessarily ensure that it is 3.3 Core Compatible. Regular OpenGL allows a lot of features to be optional, while Core requires all features of the specification to be enabled. The nice thing with Core is that if your system supports it, you can be confident it supports all the features, whereas in theory different regular OpenGL systems might support some features and not others. In any case, it might be worth seeing if your drivers are up to date.

Mathias

  • New member
  • *
  • Posts: 18
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #7 on: February 03, 2018, 05:40:19 pm »
1) "Unable to load OpenGL". I compile it myself, then it works right away.

2)
Code: Pascal  [Select]
  1.  GLSL error LX_ARB_create_context GLX_ARB_create_context_profile GLX_ARB_create_context_robustness GLX_ARB_fbconfig_float GLX_ARB_framebuffer_sRGB GLX_ARB_get_proc_address GLX_ARB_multisample GLX_EXT_create_context_es2_profile GLX_EXT_create_context_es_profile GLX_EXT_fbconfig_packed_float GLX_EXT_framebuffer_sRGB GLX_EXT_import_context GLX_EXT_texture_from_pixmap GLX_EXT_visual_info GLX_EXT_visual_rating GLX_INTEL_swap_event GLX_MESA_copy_sub_buffer GLX_MESA_multithread_makecurrent GLX_MESA_query_renderer GLX_MESA_swap_control GLX_OML_swap_method GLX_OML_sync_control GLX_SGIS_multisample GLX_SGIX_fbconfig GLX_SGIX_pbuffer GLX_SGIX_visual_select_group GLX_SGI_make_current_read GLX_SGI_swap_control GLX_SGI_video_sync

The rectangle that should appear does not come. I change Load_GL_VERSION_3_3_CORE () to Load_GL_VERSION_3_2_CORE () then it runs. Also, the expected text appears in the caption.
Whatever is funny, I deliberately make a Systax error in the shader code, then not even throwing a mistake.



By the way, I have already broken my head because of the Core, but unfortunately I have not come further, unfortunately you can see that in my tutorial, in context generation.
For this reason, I have outsourced the whole thing in a unit, but if I can manage it, I can only change the unit, instead of the whole tutorial.
I also asked questions in the Maillist of FPC, there was no advice.
« Last Edit: February 03, 2018, 05:44:58 pm by Mathias »

ChrisR

  • Jr. Member
  • **
  • Posts: 67
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #8 on: February 04, 2018, 06:51:00 pm »
Can you tell me which project you were working on that caused these errors, for example
  2_-_Einfachster_Shader/project1.lpi
and I can try to replicate your problems.

Mathias

  • New member
  • *
  • Posts: 18
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #9 on: February 04, 2018, 08:04:10 pm »
Quote
Can you tell me which project you were working on that caused these errors, for example
  2_-_Einfachster_Shader/project1.lpi
and I can try to replicate your problems.
https://delphigl.com/forum/viewtopic.php?f=14&t=11566&hilit=core

Here on page 2 is discussed. But it looks like "Core Profile" with my Intel 4000.

glGetString (GL_VERSION) gives me: "4.2 (Core Profile) Mesa 17.3.0-rc1 - padoka PPA"
I have set Major and Minor version to 3.3 in OpenGLControl.

What NVidia or Windows looks like I can not say because my NVidia is broken. And I do not have Windows anymore.

ChrisR

  • Jr. Member
  • **
  • Posts: 67
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #10 on: February 04, 2018, 08:46:38 pm »
I think I see your problem. I suggest you use "glcorearb" in your "uses" section and make sure NOT to include "gl", "glext" or "dglOpenGL". This ensures that ONLY core definitions and functions are available (so you do not accidentally use deprecated/removed functions). You will use the function "Load_GL_VERSION_3_2_CORE" to enable OpenGL.


For more details on the relative strengths/weaknesses of gl/glext, dglOpenGL and glcorearb please read this:
 https://bugs.freepascal.org/view.php?id=29051

ChrisR

  • Jr. Member
  • **
  • Posts: 67
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #11 on: February 04, 2018, 09:41:58 pm »
I have created a pull request
  https://github.com/sechshelme/Lazarus-OpenGL-3.3-Tutorial/pull/1
this allows the user to choose between dglOpenGL and glcorearb based on the setting in opts.inc. I ported all the projects in the '02_-_Shader' folder and provided instructions for porting the other projects. Please test on your system, but I think you will find this provides OpenGL 3.3 Core compatibility. By providing support for either dglOpenGL and glcorearb we allow users to choose the library they prefer. The glcorearb helps developers restrict themselves to modern, retained OpenGL. Tell me if you want further help converting the rest of the projects.


otoien

  • Jr. Member
  • **
  • Posts: 73
Re: Lazarus - OpenGL 3.3 Tutorial (German)
« Reply #12 on: February 06, 2018, 03:32:58 am »
I am not a OpenGL professional - I do research on the human brain. However, I did create a popular surface rendering https://www.nitrc.org/plugins/mwiki/index.php/surfice:MainPage  and volume rendering https://www.nitrc.org/plugins/mwiki/index.php/mricrogl:MainPage tools using OpenGL and Lazarus. My mother is from Germany and while I only studied spanish in school I think my German comprehension is good enough for basic translations - I visit Germany once  a year or so.

As a side note, MRIcroGL is quite impressive, thanks Chris for creating it! I have had a lot of use for it; the attached image is from an MRI class I participated in to get a better background to also create MRI conditional implantable temperature loggers for my experiments. It was fun to use MRIcroGL to show the other participants how one could use 3D on MRI scans. I need too look into Surfice.
Lazarus 1.8.2 r57369 FPC 3.0.4 x86_64-win64-win32/win64

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus