opengl – Unable to create Shader Object for Geometry Shader (GL_GEOMETRY_SHADER)


I am just starting with OpenGL using c++ on Ubuntu 18.04. The problem I have is that when I try to link Geometry Shader in my main program, the following function call is unable to create an object (and hence returns 0)

GLuint ShaderObj = glCreateShader(ShaderType);

when ShaderType = GL_GEOMETRY_SHADER.
The error log thrown is: “Error creating shader type 36313”.
Here, 36313 is the enum value for GL_GEOMETRY_SHADER.

NOTE: My program runs successfully (with a differing functionality) when I remove the geometry shader, while keeping the fragment & vertex shaders intact.

The following is the source code for my geometry shader:

#version 130

layout (triangles) in;
layout (triangle_strip, max_vertices = 4) out;

void main() {
    gl_Position = gl_in(0).gl_Position;
    EmitVertex();
    gl_Position = gl_in(1).gl_Position;
    EmitVertex();
    gl_Position = gl_in(2).gl_Position;
    EmitVertex();
    EndPrimitive();
}

The flow of the main code is as follows:

During CompileShaders(), the code calls AddShader(ShaderProgram, gs.c_str(), GL_GEOMETRY_SHADER). The following are the first few lines in this function.

static void AddShader(GLuint ShaderProgram, const char* pShaderText, GLenum ShaderType) {
    GLuint ShaderObj = glCreateShader(ShaderType);
    if (ShaderObj == 0) {
        fprintf(stderr, "Error creating shader type %dn", ShaderType);
        exit(0);
    }
...
}

Here glCreateShader() returns 0 which is why in the following if condition an error is thrown as mentioned previously.

The following are the version details of my setup.

    GLX version: 1.4
        Max core profile version: 4.6
        Max compat profile version: 3.0
        Max GLES1 profile version: 1.1
        Max GLES(23) profile version: 3.1
    OpenGL core profile version string: 4.6 (Core Profile) Mesa 20.0.8
    OpenGL core profile shading language version string: 4.60
    OpenGL version string: 3.0 Mesa 20.0.8
    OpenGL shading language version string: 1.30
    OpenGL ES profile version string: OpenGL ES 3.1 Mesa 20.0.8
    OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

The following is my hardware information.

00:02.0 VGA compatible controller: Intel Corporation HD Graphics 5500 (rev 09)
    Subsystem: Dell HD Graphics 5500
    Kernel driver in use: i915
    Kernel modules: i915
--
08:00.0 3D controller: NVIDIA Corporation GF117M (GeForce 610M/710M/810M/820M / GT 620M/625M/630M/720M) (rev a1)
    Subsystem: Dell GeForce 820M
    Kernel driver in use: nouveau
    Kernel modules: nvidiafb, nouveau

I think this might be some version error. But I am not sure. I would be really, really grateful if someone could help me out with this.