0
votes

I was trying out some code in LWJGL 3, using Eclipse IDE and GitHub to edit the code on 2 computers (My personal PC and my job one). The commiting and pulling of the code seemed to be working fine, until my code stopped working on my personal PC. While trying to understand the reason, I found out it might be some error with my shader class, that strangely doesn't happen at my job's PC. After adjusting my shader class code, putting some validation ( "glValidateProgram" and "GL_LINK_STATUS") as why the shader program wasn't working, the program returned this error:

Exception in thread "main" java.lang.Exception: Error linking Shader code: Fragment info
-------------
0(11) : error C1105: cannot call a non-function
(0) : error C2003: incompatible options for link

    at br.com.renanlima.engineIO.ShaderLoader.<init>(ShaderLoader.java:62)
    at br.com.renanlima.git.main.main(main.java:115)

I really couldn't find what the errors mean, so now I'm asking for help to understand what's wrong.

My Shader Load Class

import static org.lwjgl.opengl.GL30.*;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.FloatBuffer;
import java.util.HashMap;
import java.util.Map;

import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.system.MemoryStack;

public class ShaderLoader {
    
    public int ID;
    public final Map<String, Integer> uniforms;
    
    public ShaderLoader (String vertexFile, String fragmentFile) throws Exception {
        uniforms = new HashMap<>();
        StringBuilder vertShaderSource = new StringBuilder();
        StringBuilder fragShaderSource = new StringBuilder();
        try {
            BufferedReader reader = new BufferedReader(new FileReader(vertexFile));
            String line;
            while((line = reader.readLine()) != null) {
                vertShaderSource.append(line).append("\n");
            }
            reader.close();
            
        } catch (IOException e) {
            throw new IllegalStateException("Failed to load vertex shader");
        }
        try {
            BufferedReader reader = new BufferedReader(new FileReader(fragmentFile));
            String line;
            while((line = reader.readLine()) != null) {
                fragShaderSource.append(line).append("\n");
            }
            reader.close();
            
        } catch (IOException e) {
            throw new IllegalStateException("Failed to load fragment shader");
        }
        
        ID = glCreateProgram();
        int vertexShader = glCreateShader(GL_VERTEX_SHADER);
        int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(vertexShader, vertShaderSource);
        glCompileShader(vertexShader);
        glShaderSource(fragmentShader, fragShaderSource);
        glCompileShader(fragmentShader);
        
        
        glAttachShader(ID, vertexShader);
        glAttachShader(ID, fragmentShader);
        glLinkProgram(ID);
        
        if (glGetProgrami(ID, GL_LINK_STATUS) == 0) {
            throw new Exception("Error linking Shader code: " + glGetProgramInfoLog(ID, 1024));
        }

        if (vertexShader != 0) {
            glDetachShader(ID, vertexShader);
        }
        if (fragmentShader != 0) {
            glDetachShader(ID, fragmentShader);
        }

        glValidateProgram(ID);
        if (glGetProgrami(ID, GL_VALIDATE_STATUS) == 0) {
            System.err.println("Warning validating Shader code: " + glGetProgramInfoLog(ID, 1024));
        }
        
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);
        
    }
    
    public void use() {
        glUseProgram(ID); 
    }

    public int getID() {
        return ID;
    }
    
    public void createUniform(String uniformName) throws Exception {
        int uniformLocation = glGetUniformLocation(ID,
            uniformName);
        if (uniformLocation < 0) {
            throw new Exception("Could not find uniform:" +
                uniformName);
        }
        uniforms.put(uniformName, uniformLocation);
    }
    
    public void setUniformBoolean(String uniformName, boolean value) {
        float toLoad = 0;
        if(value) {
            toLoad = 1;
        }
        glUniform1f(uniforms.get(uniformName), toLoad);
    }
    
    public void setUniformVector(String uniformName, Vector3f vector) {
        glUniform3f(uniforms.get(uniformName), vector.x, vector.y, vector.z);
    }
    
    public void setUniformMatrix(String uniformName, Matrix4f value) {
        // Dump the matrix into a float buffer
        try (MemoryStack stack = MemoryStack.stackPush()) {
            FloatBuffer fb = stack.mallocFloat(16);
            value.get(fb);
            glUniformMatrix4fv(uniforms.get(uniformName), false, fb);
        }
    }
    public void unbind() {
        glUseProgram(0);
    }
    
    public void cleanup() {
        unbind();
        if (ID != 0) {
            glDeleteProgram(ID);
        }
}
}

My Vertex Shader

#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTexCoord;

out vec3 ourColor;
out vec2 TexCoord;

uniform mat4 projectionMatrix;
uniform mat4 transformationMatrix;
uniform mat4 viewMatrix;

void main()
{
    gl_Position = projectionMatrix * viewMatrix * transformationMatrix * vec4(aPos, 1.0);
    ourColor = aColor;
    TexCoord = aTexCoord;
}    

My Fragment Shader

#version 330 core
out vec4 FragColor;
  
in vec3 ourColor;
in vec2 TexCoord;

uniform sampler2D texture;

void main()
{
    FragColor = texture(texture, TexCoord);
}

And the shader loader class call at the main render class (The "new ShaderLoader" line is the one which the error returns to)

public static void main(String[] args) throws Exception {
    
    Render render = new Render();
    window = render.init();
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    
    glfwShowWindow(window);
    
    createCapabilities();
    
    ModelLoader squareModel = new ModelLoader(position, colorPos, texturePos, indices);
    EntityLoader squareEntity = new EntityLoader(squareModel, new Vector3f(0,0,-1),0,0,0,1);
    Camera camera = new Camera();
    
    ShaderLoader shader = new ShaderLoader("game_engine/src/Shaders/vertex.vert", "game_engine/src/Shaders/fragment.frag");
    shader.createUniform("projectionMatrix");
    shader.createUniform("viewMatrix");
    shader.createUniform("transformationMatrix");
    
    while(!glfwWindowShouldClose(window))
    {
        processInput(window); ...

how the program is working at my job's PC