Recent

Author Topic: OpenGL Core Profile Tutorials  (Read 18116 times)

ChrisR

  • Full Member
  • ***
  • Posts: 247
OpenGL Core Profile Tutorials
« on: January 31, 2017, 03:47:36 pm »
I created three sample projects that demonstrate using the Core Profile of OpenGL using Lazarus
 https://github.com/neurolabusc/OpenGLCoreTutorials
In order to achieve the Lazarus goal of "write once/compile anywhere", you need to either target OpenGL 2.1 (the last legacy version supported by MacOS) or the modern Core profile (which drops deprecated legacy functions). I hope others find this useful, and would be grateful for any suggestions to improve these tutorials.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: OpenGL Core Profile Tutorials
« Reply #1 on: January 31, 2017, 04:17:50 pm »
Thank you for writing those tutorials. I'm sure use it. I only have the basic old OpenGL knowledge, wanting to learn the modern OpenGL unfortunately all I found on the web are written on C++. Bookmarked the link, and will visit it later.

Do you know we have a contest for writing graphics programs?
http://forum.lazarus.freepascal.org/index.php/topic,35313.0.html

I'm now writing a simple game and will publish the source code with tutorial about it. I guess you may interested to join in the contest.

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: OpenGL Core Profile Tutorials
« Reply #2 on: February 03, 2017, 07:48:35 pm »
A note: I'm on 64-bit Windows 10, and your "glcorearb" header unit doesn't work for me. When I refactored all the examples and helper units to use dglOpenGL (as is my normal method for using OpenGL with Lazarus) everything worked fine.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: OpenGL Core Profile Tutorials
« Reply #3 on: February 04, 2017, 01:20:28 am »
Any new information on “modern OpenGL” is very much welcomed. So thanks for that, I’ll definitely take a look.

I can add that I found a ton of excellent “modern OpenGL” tutorials on YouTube. A lot of them use LWJGL (Lightweight Java Game Library), but the actual OpenGL code all translates very easily to Object Pascal and SDL2+OpenGL. I’ve had no problems following along with some of those YouTube tutorials.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: OpenGL Core Profile Tutorials
« Reply #4 on: February 07, 2017, 03:21:26 pm »
Any new information on “modern OpenGL” is very much welcomed. So thanks for that, I’ll definitely take a look.

Did you look at my unit test ? I mentioned in a SDL thread, so you might have skipped it.

http://forum.lazarus-ide.org/index.php/topic,30556.msg194484.html#msg194484

It was the development app for our widget that shows some 2D Canvas (texture, circle,lines etc) in a fairly modern style, and upgrade for an older codebase that Ales Katona made for us in the 2007-2008 timeframe.

Specially the fonts still need work, but the codebase has been moved into production last fall.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: OpenGL Core Profile Tutorials
« Reply #5 on: February 07, 2017, 04:33:55 pm »
Did you look at my unit test ? I mentioned in a SDL thread, so you might have skipped it.
http://forum.lazarus-ide.org/index.php/topic,30556.msg194484.html#msg194484
Thanks Marco, I'll definitely take a look at that.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

jacmoe

  • Full Member
  • ***
  • Posts: 249
    • Jacmoe's Cyber SoapBox
Re: OpenGL Core Profile Tutorials
« Reply #6 on: February 12, 2017, 11:59:43 pm »
Really nice tutorial! :D

Unfortunately, since I am using Mesa and non proprietary Nouveau nVidia graphics driver, I can't convince OpenGL that my card is up for profile 3.3.

In C, I use GLEW to make that happen.

Is there a GLEW for Pascal?
more signal - less noise

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: OpenGL Core Profile Tutorials
« Reply #7 on: February 13, 2017, 12:18:44 am »
I'm not sure it has anything to do with your drivers. FPC is just somewhat shaky when it comes to the way the method pointers are being initialized in the "glcorearb" unit he included. (By which I mean declaring the methods as variables and then assigning directly to them, as opposed to declaring them as types and then assigning to variables of those types, which seems to be much more stable.) Try it with dglOpenGL.

https://github.com/SaschaWillems/dglOpenGL
« Last Edit: February 13, 2017, 12:24:07 am by Akira1364 »

jacmoe

  • Full Member
  • ***
  • Posts: 249
    • Jacmoe's Cyber SoapBox
Re: OpenGL Core Profile Tutorials
« Reply #8 on: February 13, 2017, 12:37:17 am »
Thanks! I'll give it a try.

If I am not lucky with that, I will probably have to bite and get my hands dirty with creating a Pascal interface to GLEW.
more signal - less noise

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: OpenGL Core Profile Tutorials
« Reply #9 on: February 13, 2017, 12:49:18 am »
All you need to do is call

Code: Pascal  [Select][+][-]
  1. InitOpenGL;
  2. ReadExtensions;

in the places he was previously calling

Code: Pascal  [Select][+][-]
  1. Load_GL_version_3_3_CORE;

Also I would recommend moving all the stuff he does in FormCreate to FormShow, as doing it in FormCreate can interfere with the creation of TOpenGLControl's context.

jacmoe

  • Full Member
  • ***
  • Posts: 249
    • Jacmoe's Cyber SoapBox
Re: OpenGL Core Profile Tutorials
« Reply #10 on: February 13, 2017, 06:27:10 am »
I did that, but the program died by a segfault, until I left in a call to Load_GL_version_3_2_CORE:

Code: Pascal  [Select][+][-]
  1. procedure  InitGL(var GLcontrol: TOpenGLControl);
  2. begin
  3.   GLcontrol.MakeCurrent();
  4.   InitOpenGL;
  5.   ReadExtensions;
  6.   //ReadImplementationProperties;
  7.   if not Load_GL_version_3_2_CORE() then begin
  8.      GLcontrol.ReleaseContext;
  9.      {$IFNDEF Windows} writeln('Unable to load OpenGL');{$ENDIF}
  10.      showmessage('Unable to load OpenGL 3.2');
  11.      halt();
  12.   end;
  13.   GLForm1.caption := glGetString(GL_VENDOR)+'; OpenGL= '+glGetString(GL_VERSION)+'; Shader='+glGetString(GL_SHADING_LANGUAGE_VERSION);
  14.   gShader.shaderProgram :=  initVertFrag(kVert,  kFrag);
  15.   LoadBufferData;
  16.   GLcontrol.ReleaseContext;
  17.   if GLErrorStr <> '' then begin
  18.      showmessage(GLErrorStr);
  19.      GLErrorStr := '';
  20.   end;
  21. end;
  22.  

There is probably some stuff that gets done in that function that I need to do - but now I get OpenGL 4.3 !  :D

If I try something higher than 3_2, it will fail to find it.
Ironically, because what I am really getting is 4.3 both for core and for the shader.

This is the basic project, btw.
« Last Edit: February 13, 2017, 06:30:57 am by jacmoe »
more signal - less noise

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: OpenGL Core Profile Tutorials
« Reply #11 on: February 13, 2017, 06:44:13 am »
You shouldn't really be using both the glcorearb unit and dglOpenGL at the same time, as they contain identically named functions (for obvious reasons) and will conflict with each other. That is probably what caused the segfault. Did you try it without glcorearb in the uses section? Either way, good to see you've got it working.

jacmoe

  • Full Member
  • ***
  • Posts: 249
    • Jacmoe's Cyber SoapBox
Re: OpenGL Core Profile Tutorials
« Reply #12 on: February 13, 2017, 06:55:04 am »
If I remove glcorearb, still a sigsegv.

Yes, I know it's strange that I have to call that function, but it probably has to do with some shader related stuff that I need to do that somehow gets triggered in the function.

I will compare to see if I can't figure out what else I need to call, in order to get rid of that unnecessary function call.  ;)

The next step is (obviously) to fish out that one function and put it into the main form's unit so that I can get rid of the glcorearb unit.
And then comment out some lines in it ..
And/or read my own C source code - whatever.

But thanks for the pointers!  8)
« Last Edit: February 13, 2017, 06:59:26 am by jacmoe »
more signal - less noise

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: OpenGL Core Profile Tutorials
« Reply #13 on: February 13, 2017, 10:49:51 am »
Thanks! I'll give it a try.
If I am not lucky with that, I will probably have to bite and get my hands dirty with creating a Pascal interface to GLEW.
I'm using the GL and GLext units included with FPC as standard. They are working perfectly for me, and I'm programming and targeting OpenGL 4+ only.

Just curious... Why would I need other OpenGL header translations? ie: dlgOpenGL?
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: OpenGL Core Profile Tutorials
« Reply #14 on: February 13, 2017, 11:33:30 am »

Just curious... Why would I need other OpenGL header translations? ie: dlgOpenGL?

They work in Delphi (the FPC opengl headers have macro support) and are generally more complete on windows and more regularly updated.

IMHO Pascal opengl is too small to fragment.
« Last Edit: February 13, 2017, 11:38:12 am by marcov »

 

TinyPortal © 2005-2018