Search code examples
javaopenglglsllwjgl

LWJGL and GLSL Versions


Recently I've been working on a rendering engine in LWJGL and I've come across numerous issues with versions. So I am after advice on what would be the correct versions to use with this new project.

Firstly, LWJGL 2 or LWJGL 3? Version 2 is still current but version 3 is a complete rewrite and is still missing some utility classes; such as GLU.gluPerspective(...);

After using LWJGL 2 for the compatibility, I have then come across more issues;

As I want to stick with modern OpenGL, I am using VBOs to render my faces. However when using GLSL to do some basic lighting, I have had to use GLSL 140 to ensure compatibility with the functions like normalise() and transform(). Then i had to enable GL_ARB_compatibility to let me access gl_Normal, gl_Vertex and gl_Color, Like so:

#version 140
#extension GL_ARB_compatibility : require

Basically all I'm asking is for some current advice, all the tutorials on the internet are different and outdated.

So, to my questions:

1) What LWJGL version would you recommend? is 3 complete enough to use in production?

2) What GLSL version should I use?

3) What are the replacements for the data I am using the compatibility layer to access?

4) Are there any nice up to date resources or tutorials for Modern OpenGL?

Thanks in advance for clarifying this for me. It's a steep learning curve

EDIT: The reason I am asking this is because of some errors I am receiving the following error when trying to use the GL_ARB_compatibility function on some computers other than mine.

**ERROR** "#extension" : "GL_ARB_compatibility" is not supported

Solution

  • First of all, in LWJGL 3 all math classes were removed in favor of you either implementing your own classes or else using a 3rd party independent library. Apparently you can use the LWJGL2 utilities library to access GLU functions, but it is recommended to just use a 3rd party math library (with matrix methods for perspective etc.) There is a github discussion on the LWJGL page: https://github.com/LWJGL/lwjgl3/issues/19

    To answer the rest of your questions:

    1) I would recommend LWJGL 3 as this is what is currently being developed. For a good list of reasons why you should use LWJGL 3 over 2, see the official LWJGL page: https://github.com/LWJGL/lwjgl3-wiki/wiki/1.2.-Why-a-new-version

    Things like lack of modularity and the static Display class are two reasons cited. LWJGL 3 uses GLFW, which I find the documentation for particular good.

    2) For maximum compatibility, you'd be safest sticking with openGL 2.1. This would mean using GLSL 1.20.

    That said, if you check out the steam dev days 'Moving to OpenGL' presentation, they state that as of Dec '13, 96% of the PC gaming market have OpenGL 3.3+ capability (link: http://media.steampowered.com/apps/steamdevdays/slides/movingtoopengl.pdf). This would mean you could use up to GLSL 3.30.

    Therefore, I would recommend going with 3.3 and the core profile (no fixed-function pipeline)

    3) Alot of the predefined variables were removed from the core profile. In order to use those, you would need to use GL_ARB_compatibility. The alternative to this is to define custom 'in' and 'out' variables and fill them in your vertex and fragment shader code. Here is a small example of a vertex shader:

    out vec4 passColor; // passed out to the frag shader
    out vec2 passTexCoord;  // passed out to the frag shader
    
    void main() {
        // gl_Poisition is still in the core profile
        gl_Position = projectionMatrix * viewMatrix * modelMatrix * inPosition;
    
        // need to be passed
        passColor = inColor;
        passTexCoord  = inTexCoord;
    }
    

    There is a nice answer on SO here: https://stackoverflow.com/a/24425436/1045493

    4) You'd be best just Googling for this and/or checking of the OpenGL forums: https://www.opengl.org/discussion_boards/forumdisplay.php/6-OpenGL-coding-beginners