0

In my createShaderProgram method after glLinkProgram(pID) and glValidateProgram(pID) i have some simple error checking.

int errorCheckValue = glGetError();
if(errorCheckValue != GL_NO_ERROR)
{
    System.err.println("Could not create shaders " + GLU.gluErrorString(errorCheckValue));
   //System.exit(-1);
}

This peace of code fire an error message --> Could not create shaders Invalid operation. Because i commented System.exit(-1) everything works fine but i dont know why this error occurs. Is there any way of code some error handling function that is more specific about the error - something more specific than just Invalid operation?

EDIT: Here is the rest of the code

private static int createShader(String source, int shaderType)
{
    int shaderID = 0;
    shaderID = glCreateShader(shaderType);
    glShaderSource(shaderID, source);
    glCompileShader(shaderID);

    if(glGetShaderi(shaderID, GL_COMPILE_STATUS) == GL_FALSE)
    {
        System.err.println("Shader failed to compile!");
        System.err.println(glGetShaderInfoLog(shaderID, 2048));
        System.exit(-1);
    }

    return shaderID;
}

public static int[] createShaderProgram(String vertFilename, String fragFilename, Attribute locations[])
{
    int pID, vertID, fragID = 0;
    pID = glCreateProgram();
    vertID = createShader(FileUtils.loadFileAsString(vertFilename), GL_VERTEX_SHADER);
    fragID = createShader(FileUtils.loadFileAsString(fragFilename), GL_FRAGMENT_SHADER);
    glAttachShader(pID, vertID);
    glAttachShader(pID, fragID);
    for(int i = 0; i < locations.length; i++){locations[i].bindAttribute(pID);}
    glLinkProgram(pID);
    glValidateProgram(pID);
    int errorCheckValue = glGetError();
    if(errorCheckValue != GL_NO_ERROR)
    {
        System.err.println("Could not create shaders " + GLU.gluErrorString(errorCheckValue));
        //System.exit(-1);
    }

    int[] result = new int[] {pID, vertID, fragID};

    return result;
}

1 Answer 1

2

You can check the link/validation status and print the program info log similar to how you are doing it with the shaders.

glLinkProgram(pID);
if (glGetProgrami(pID, GL_LINK_STATUS) == GL_FALSE) {
    System.err.println("Program failed to link");
    System.err.println(glGetProgramInfoLog(pID, glGetProgrami(pID, GL_INFO_LOG_LENGTH)));
}

(And the same with GL_VALIDATE_STATUS.)


If you are using LWJGL 3 (latest nightly build), you can setup an OpenGL debug message callback with

GLUtil.setupDebugMessageCallback();

This will automatically choose the correct OpenGL extension (or core functionality) to setup a callback that prints an error message every time an OpenGL error occurs (so no need to call glGetError() any more).

You can have a look at GLUtil's source code on how to manually setup the debug callbacks if you want more control over the output.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi javac. Thanks for your answer. It accually answer my question but unfortunatelly do not resolve my problem. This functions do not fire any errors but the compile status function fires Invalid operation error. But im going to accept your answer because again it answer my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.