Posted by Xerxes Rånby on Dec 13, 2013; 1:02pm URL: https://forum.jogamp.org/Cross-platform-GLSL-ES-tp4030871p4030880.html
In order to create cross platform GLSL shaders the following three points have to be taken into account:
1. GLSL VERSION >= 130 uses in and out keywords instead of attributes and varying. GLSL VERSION >= 130 also require the fragment shader to explicitly define the out variable. GLSL VERSION >= 130 compatibility can be handled by adding some GLSL pre-processor defines at the beginning of the shaders.
Vertex shader:
#if __VERSION__ >= 130
#define attribute in
#define varying out
#endif
Fragment shader:
#if __VERSION__ >= 130
#define varying in
out vec4 mgl_FragColor;
#else
#define mgl_FragColor gl_FragColor
#endif
2. Some OpenGL contexts require the GLSL #version to be explicitly set at the start of the shader or else it will refuse to compile the shader. The GLSL #version must match a version that is compatible with the OpenGL context or else the shader will refuse to compile.
JogAmp JOGL can return the matching String containing the #version you need to add by analysing the context at runtime by using: gl.getContext().getGLSLVersionString()
2 & 3 can be fixed in one go by using the com.jogamp.opengl.util.glsl.ShaderCode class to load your shaders from disk and customize them using defaultShaderCustomization