Forum > OpenGL

Provided GL, GLext librarys vs dglOpenGL

<< < (2/5) > >>

wp:
I'm only an occasional OpenGL user, and so far it has been ok to stick to gl/glext. The OpenGL drawer of TAChart uses them, and my own 3d-Chart experiments (https://github.com/wp-xyz/OpenGLChart) are fine with them, too. But, of course, these are no high-end applications of OpenGL.

ChrisR:
The GL/GLext units are fine as long as you either never target MacOS, or never target MacOS with features that exceed OpenGL 2.1.

As a developer, the challenge for GL/GLext is that it includes both legacy and modern OpenGL calls. While this is fine for Linux and Windows (where you can mix and match legacy OpenGL and modern OpenGL), it does not alert the developer to legacy OpenGL calls that may have poor performance and will crash MacOS if MacOS is requested to use OpenGL version later than 2.1. Using glcorearb only expose modern OpenGL functions, preventing a developer from accidentally using a legacy function.

Here is another Lazarus demo:
  https://github.com/neurolabusc/plyview

Since the original poster mentions wanting to learn modern OpenGL, I would suggest restricting yourself to the modern calls. It will also help if you ever want to target Vulkan, OpenGL ES or Metal, as those shading languages are very similar to OpenGL core and do not include equivalents for most legacy features. A nice example of this are these Lazarus demos that can be compiled for OpenGL Core on Windows, Linux or MacOS as well as targeting Metal for MacOS
  https://github.com/neurolabusc/Metal-Demos

damieiro:
Well, really i'm a really newbie on modern openGL.
Many thanks for your responses. These help me a lot. And I'm reading the ChrisR tutorials and the german ones

And i'm using SDL for making context. I do not know if this is correct in modern OPENGL, but i'm used not to use GUI

For example, this is my own "actual test" of using
https://www.freepascal-meets-sdl.net/chapter-10-sdl-modern-opengl/
with dglopenGL. Only a few changes. As i saw, i can enforce with sdlopenGL only modern calls. I have to try  glcorearb
Actually this code works (it needs the vertexshader.txt and fragmentshader.txt).

I figure I'm starting a loong path to manage it, but i want to test it.

Note: This needs SDL2 headers (i used jedi ones) and SDL2 installed. I do not know if SDL&ModernGL will target more or less. I will read your examples that targets windows, linux & mac (do work with android?)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program openGLModerno; uses Classes, SysUtils, SDL2,  dglOpenGL;  const  vertexShaderFile = 'VertexShader.txt';  fragmentShaderFile = 'FragmentShader.txt';  triangleData: array[0..8] of GLfloat = ( -1.0, -1.0, 0.0,                                            1.0, -1.0, 0.0,                                            0.0,  1.0, 0.0  ); varsdlWindow1: PSDL_Window;sdlGLContext1: TSDL_GLContext;i: Word;VertexArrayID: GLuint;triangleVBO: GLuint; VertexShaderID: GLuint;VertexShaderCode: PGLchar;FragmentShaderID: GLuint;FragmentShaderCode: PGLchar;ShaderCode: TStringList;ProgramID: GLuint;compilationResult: ByteBool;InfoLogLength: GLint;ErrorMessageArray: array of Char;   begin   compilationResult:= GL_FALSE;   if SDL_Init( SDL_INIT_VIDEO ) < 0 then HALT;   //get an OpenGL window and create OpenGL context - INSTEAD of  sdlWindow1 := SDL_CreateWindow( 'OpenGL window', 50, 50, 500, 500, SDL_WINDOW_OPENGL );  if sdlWindow1 = nil then HALT;   sdlGLContext1 := SDL_GL_CreateContext( sdlWindow1 );  if @sdlGLContext1 = nil then HALT;   //init OpenGL and load extensions  InitOpenGL; // Don't forget, or first gl-Call will result in an access violation!  ReadExtensions;    //print out OpenGL vendor, version and shader version  writeln( 'Vendor: ' + glGetString( GL_VENDOR ) );  writeln( 'OpenGL Version: ' + glGetString( GL_VERSION ) );  writeln( 'Shader Version: ' + glGetString( GL_SHADING_LANGUAGE_VERSION ) );   //create Vertex Array Object (VAO)  glGenVertexArrays( 1, @VertexArrayID );  glBindVertexArray( VertexArrayID );   //creating Vertex Buffer Object (VBO)  glGenBuffers( 1, @triangleVBO );  glBindBuffer( GL_ARRAY_BUFFER, triangleVBO );  glBufferData( GL_ARRAY_BUFFER, SizeOf( triangleData ), @triangleData, GL_STATIC_DRAW );   //creating shaders  VertexShaderID := glCreateShader( GL_VERTEX_SHADER );  FragmentShaderID := glCreateShader( GL_FRAGMENT_SHADER );   //load shader code and get PChars  ShaderCode := TStringList.Create;  ShaderCode.LoadFromFile( VertexShaderFile );  VertexShaderCode := ShaderCode.GetText;  if VertexShaderCode = nil then HALT;  ShaderCode.LoadFromFile( FragmentShaderFile );  FragmentShaderCode := ShaderCode.GetText;  if FragmentShaderCode = nil then HALT;  ShaderCode.Free;   //compiling and error checking vertex shader  write('Compiling and error checking Vertex Shader... ' );  glShaderSource( VertexShaderID, 1, @VertexShaderCode, nil );  glCompileShader( VertexShaderID );   glGetShaderiv( VertexShaderID, GL_COMPILE_STATUS, @compilationResult );  glGetShaderiv( VertexShaderID, GL_INFO_LOG_LENGTH, @InfoLogLength );  if compilationResult = GL_FALSE then  begin    writeln( 'failure' );    SetLength( ErrorMessageArray, InfoLogLength+1 );    glGetShaderInfoLog( VertexShaderID, InfoLogLength, nil, @ErrorMessageArray[0] );    for i := 0 to InfoLogLength do write( String( ErrorMessageArray[i] ) );    writeln;  end else writeln( 'success' );   //compiling and error checking fragment shader  write('Compiling and error checking Fragment Shader... ' );  glShaderSource( FragmentShaderID, 1, @FragmentShaderCode, nil );  glCompileShader( FragmentShaderID );   glGetShaderiv( FragmentShaderID, GL_COMPILE_STATUS, @compilationResult );  glGetShaderiv( FragmentShaderID, GL_INFO_LOG_LENGTH, @InfoLogLength );  if compilationResult = GL_FALSE then  begin    writeln( 'failure' );    SetLength( ErrorMessageArray, InfoLogLength+1 );    glGetShaderInfoLog( VertexShaderID, InfoLogLength, nil, @ErrorMessageArray[0] );    for i := 0 to InfoLogLength do write( String( ErrorMessageArray[i] ) );    writeln;  end else writeln( 'success' );   //creating and linking program  write('Creating and linking program... ' );  ProgramID := glCreateProgram();  glAttachShader( ProgramID, VertexShaderID );  glAttachShader( ProgramID, FragmentShaderID );  glLinkProgram( ProgramID );   glGetShaderiv( ProgramID, GL_LINK_STATUS, @compilationResult );  glGetShaderiv( ProgramID, GL_INFO_LOG_LENGTH, @InfoLogLength );  if compilationResult = GL_FALSE then  begin    writeln( 'failure' );    SetLength( ErrorMessageArray, InfoLogLength+1 );    glGetShaderInfoLog( VertexShaderID, InfoLogLength, nil, @ErrorMessageArray[0] );    for i := 0 to InfoLogLength do write( String( ErrorMessageArray[i] ) );    writeln;  end else writeln( 'success' );     for i := 0 to 400 do  begin    glClearColor( 0.0, 1.0-i/400, 0.0+i/400, 1.0 );    glClear( GL_COLOR_BUFFER_BIT );    glUseProgram( ProgramID );    glEnableVertexAttribArray( 0 );    glBindBuffer( GL_ARRAY_BUFFER, triangleVBO );    glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, nil );    glDrawArrays( GL_TRIANGLES, 0, 3 );    glDisableVertexAttribArray( 0 );    SDL_Delay( 20 );    SDL_GL_SwapWindow( sdlWindow1 );  end;   //clean up  glDetachShader( ProgramID, VertexShaderID );  glDetachShader( ProgramID, FragmentShaderID );   glDeleteShader( VertexShaderID );  glDeleteShader( FragmentShaderID );  glDeleteProgram( ProgramID );   StrDispose( VertexShaderCode );  StrDispose( FragmentShaderCode );   glDeleteBuffers( 1, @triangleVBO );  glDeleteVertexArrays( 1, @VertexArrayID );   //SLD_clean  SDL_GL_DeleteContext( sdlGLContext1 );  SDL_DestroyWindow( sdlWindow1 );   SDL_Quit;end.  

marcov:

--- Quote from: damieiro on December 15, 2019, 11:13:00 pm ---Well, really i'm a really newbie on modern openGL.
Many thanks for your responses. These help me a lot. And I'm reading the ChrisR tutorials and the german ones

And i'm using SDL for making context. I do not know if this is correct in modern OPENGL, but i'm used not to use GUI

--- End quote ---

See the first post in this thread: https://forum.lazarus.freepascal.org/index.php/topic,30556.msg194484.html#msg194484

it is an old unit test for signed distance fonts (not so nice back then, before subsampling was implemented), but it does demonstrate creating an canvas with just dglopengl

avra:

--- Quote from: ChrisR on December 15, 2019, 10:16:43 pm ---If you wish to use OpenGL Core specification using Lazarus you have three options:
 2. dglOpenGL
--- End quote ---
You can find it in OPM under the name pl_OpenGL. It is cross platform and has lots of demos. There are also GLScene, pl_OpenGLES, and pl_Vulkan packages.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version