Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Shaders: glLinkProgram() and glValidateProgram() doesn't work

I've been following along with this tutorial, and that particular video is where my problem comes from. At that time in the video, he begins incorporating his Shader class (I copied everything exactly how he did it, by the way). Anyways, when I call the compileShader() method, which looks like this,

public void compileShader()
{
    glLinkProgram(program);

    if(glGetProgrami(program, GL_LINK_STATUS) == GL_FALSE)
    {
        System.err.println(glGetShaderInfoLog(program, 1024));
        System.exit(1);
    }

    glValidateProgram(program);

    if(glGetProgrami(program, GL_VALIDATE_STATUS) == GL_FALSE)
    {
        System.err.println(glGetShaderInfoLog(program, 1024));
        System.exit(1);
    }
} 

My program crashes because the glGetProgrami(program, GL_LINK_STATUS) ALWAYS equals GL_FALSE (GL_FALSE == 0). Same for the glGetProgrami(program, GL_VALIDATE_STATUS), it returns GL_FALSE. By the way, I used glGetProgrami() instead of glGetProgram() because the latter is a deprecated method. Also, System.err.println(glGetShaderInfoLog(program, 1024)) doesn't print ANYTHING.

After a thorough online search of the main problem, this was the only thread I could find that resembled my problem, it actually seems like the exact same problem. His solution is to change the 3D settings of his intel graphics card, but when I try to follow his steps, I don't have the same options he has for configuring 3D settings. As it turns out, the program my laptop has for configuring the intel graphics settings is different from his!

So after spending hours looking online for solutions for getting his control panel, which was just installing drivers, none of which actually worked, I came across this thread. The third post says that those options are obsolete, and that the options I have are the only ones I need. But after messing around with the settings I have, NOTHING CHANGES. The program still crashes.

I don't understand why glLinkProgram(program) isn't linking the program as well as why glGetShaderInfoLog() doesn't return anything.

EDIT:

private void addProgram(String text, int type)
{
    int shader = glCreateShader(type);

    if(shader == 0)
    {
        System.err.println("Shader creation failed: Could not find valid memory location when adding shader");
        System.exit(1);
    }

    glShaderSource(shader, text);
    glCompileShader(shader);

    if(glGetShaderi(shader, GL_COMPILE_STATUS) == GL_FALSE)
    {
        System.err.println(glGetShaderInfoLog(shader, 1024));
        System.exit(1);
    }

    glAttachShader(program, shader);
}

Here is the code that actually calls glCompileShader(). It's called whenever you want to add a shader. This part is successful and is called before the compile() method.

like image 833
hacksoi Avatar asked Dec 26 '22 03:12

hacksoi


1 Answers

Found the REAL problem: I'm just an idiot.

I really doubt anyone is gonna be dumb enough to replicate this, but just in case some someone else was blindly following tutorials until 4am, the problem was this:

    shader.addVertexShader(ResourceLoader.loadShader("basicVertex.vs"));
    shader.addVertexShader(ResourceLoader.loadShader("basicFragment.fs"));

As you can see, I called addVertexShader for the "basicFragment.fs" shader, when it should've been addFragmentShader.

Thank you for your replies, and sorry for wasting your time.

like image 117
hacksoi Avatar answered May 03 '23 23:05

hacksoi