Recent

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

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: OpenGL Core Profile Tutorials
« Reply #15 on: February 13, 2017, 12:08:49 pm »
They work in Delphi

Ah, okay... Not much of a concern for me then.

Quote
... and more regularly updated.
Seeing as they should only be C header translations, backporting anything to the FPC files should be pretty straight forward.

Quote
IMHO Pascal opengl is too small to fragment.
It's just header translations right? In theory they should be pretty similar everywhere,  or even [ideally] auto-generated. As for fragmentation, I can't really see that happening in this case. I've ported tons of C, C+SDL2 and Java OpenGL examples to Free Pascal... all that is required in most cases are minor tweaks to the glXXX API calls, where the parameter types are slightly different (due to programming language). But even for somebody totally new to OpenGL (as myself) it wasn't very hard to figure out how to adjust the code.
--
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 #16 on: February 13, 2017, 12:47:50 pm »
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?

I don't need anything other than a couple helper functions to convince my system that Mesa and Nouveau can deliver OpenGL 4.3.

For that, I use GLEW in C.
more signal - less noise

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: OpenGL Core Profile Tutorials
« Reply #17 on: February 13, 2017, 05:35:51 pm »
The main reason I prefer dglOpenGL is because it only takes two function calls to guarantee that all supported extensions will be loaded, regardless of the computer the software is being run on. Whereas the FPC units have no "load everything" functionality, and you need to call functions for each specific version/extension set/e.t.c. (And as Marco said, they're not 100% complete.) Also, the FPC units have the platform-specific methods spread across different files, whereas dglOpenGL includes all of them and uses IFDEFS to choose the relevant ones.
« Last Edit: February 14, 2017, 12:59:08 am by Akira1364 »

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: OpenGL Core Profile Tutorials
« Reply #18 on: April 02, 2017, 03:01:51 pm »
Jacmoe

Can you help me troubleshoot this? The code works on my MacOS, Windows and Linux machines. It would help my greatly if you could tell me which function(s) in the Load_GL_VERSION_3_3_CORE call cause your program to crash. Simply edit glcorearb.pas and initially comment out HALF of the functions
 glBindFragDataLocationIndexed
 ...
 glVertexAttribP4uiv := getProc('glVertexAttribP4uiv', OK);

If that compiles, one of the functions in the commented half is problematic, if it fails, try commenting out another quarter. Through a process of elimination we should see which are not supported universally. I have tried this on Nvidia, Intel and AMD cards, so I am puzzled by your problems.

//28 procedures for GL_VERSION_3_3
function Load_GL_VERSION_3_3_CORE : boolean;

I did that, but the program died by a segfault, until I left in a call to Load_GL_version_3_2_CORE:

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: OpenGL Core Profile Tutorials
« Reply #19 on: April 02, 2017, 03:08:00 pm »
Akira1364,
  Yes, your method works by using the dglOpenGL library. The issue with this is that it is hard to compile Core code, as all the non-core functions and constants are available. You can easily write an application that compiles nicely on Linux and Windows (which support the compatibility profile) but fail on MacOS. I have just updated my PlyView to show how a couple compiler switches at the top of a program allow you to select between glcorearb (modern OpenGL only), gl/glext (does not support modern OpenGL on MacOS) or dglOpenGL
  https://github.com/neurolabusc/plyview
I think each of these libraries is useful for developers, and as this project shows, you can switch between them seamlessly.

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;


ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: OpenGL Core Profile Tutorials
« Reply #20 on: April 02, 2017, 03:17:09 pm »
I agree, my updated project
 https://github.com/neurolabusc/plyview
shows how you can choose between GL/EXT, dglOpenGL, and glcorearb at the same time. You only use one at a time, but you can choose which one depending on what you want to achieve. The pros and cons of each seem to be:

1.) GL/GLEXT:
 Pro: Comes with FPC as default library.
 Con: Unable to support modern OpenGL on MacOS

2.) dglOpenGL:
 Pro: can run modern OpenGL on all platforms (Windows, MacOS, Linux)
 Con: some have criticized X dependency http://mantis.freepascal.org/view.php?id=29051

3.) glcorearb
 Pro: hides legacy OpenGL functions and constants, ensuring that you do not accidentally include them. This makes it easier to write software that works on all platforms (Windows, MacOS, Linux)
 Pro: can run modern OpenGL on all platforms (Windows, MacOS, Linux)
 Con: Hides legacy functions and constants, so Windows and Linux users can not mix and match old functions (e.g. immediate mode) with modern code. Note that due to the MacOS Core specification, Mac users must choose EITHER legacy or modern versions, they can never mix and match.


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.

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: OpenGL Core Profile Tutorials
« Reply #21 on: April 02, 2017, 03:25:30 pm »
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?

If you only use Windows or Linux, and never plan to support MacOS, there is no need to use any other translation. However, for me the appeal of Lazarus is the "Write Once, Compile Anywhere" nature, and these other libraries support modern OpenGL on MacOS. One other point, in my experience I can get much better performance using only the modern Core features: while the legacy features of immediate mode are supported, they tend to bog down the rendering. So having a library that helps you determine which features are not available in Modern OpenGL is useful for writing optimized code.


1.) GL/GLEXT:
 Pro: Comes with FPC as default library.
 Con: Unable to support modern OpenGL on MacOS

2.) dglOpenGL:
 Pro: can run modern OpenGL on all platforms (Windows, MacOS, Linux)
 Con: some have criticized X dependency http://mantis.freepascal.org/view.php?id=29051

3.) glcorearb
 Pro: hides legacy OpenGL functions and constants, ensuring that you do not accidentally include them. This makes it easier to write software that works on all platforms (Windows, MacOS, Linux)
 Pro: can run modern OpenGL on all platforms (Windows, MacOS, Linux)
 Con: Hides legacy functions and constants, so Windows and Linux users can not mix and match old functions (e.g. immediate mode) with modern code. Note that due to the MacOS Core specification, Mac users must choose EITHER legacy or modern versions, they can never mix and match.
 

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: OpenGL Core Profile Tutorials
« Reply #22 on: April 02, 2017, 03:30:56 pm »
If I remove glcorearb, still a sigsegv.

The reason you get the error is that dglOpenGL returns strings differently from GL/EXT and glcorearb. If you look at my updates to
  https://github.com/neurolabusc/plyview
you will see that by choosing a {$DEFINE *} you can compile to dglOpenGL, GL/EXT, glcorearb (but only one at a time). If you look at the code's "{$IFDEF DGL}" you will see that you can need to make a couple minor adjustments for dglOpenGL. 

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: OpenGL Core Profile Tutorials
« Reply #23 on: April 02, 2017, 06:50:27 pm »
2.) dglOpenGL:
 Pro: can run modern OpenGL on all platforms (Windows, MacOS, Linux)
 Con: some have criticized X dependency http://mantis.freepascal.org/view.php?id=29051
That's a valid criticism: OpenGL is independent of X. The maintainers should correct that. The changes are minor: introduce an opaque instead of a dependency on an X specific structure.
This is - btw - how to conform to the KHRONOS reference code for GL. It is just a small mistake in a header translation. With big consequences: it ties OpenGL to X.
Specialize a type, not a var.

 

TinyPortal © 2005-2018