it has been days since I'm trying to debug my project that I recently updated from LWJGL2 to LWJGL3. I found some issues, but still it wasn't working so I made a minimal project, like really minimal and compared it to a working project I found online. I came to a point where the 2 projects were absolutely the same, excepted that in the working project I create the vertex shader 2 times and link the 2 in the program, and on the other one I'm linking the correct ones, they both compile but nothing renders.
Here is the Shader class:
private int vertexID, fragmentID, programID;
public Shader(String vertexPath, String fragmentPath) {
vertexID = loadShader(vertexPath,GL20.GL_VERTEX_SHADER);
fragmentID = loadShader(fragmentPath,GL20.GL_FRAGMENT_SHADER); //Not working
//fragmentID = loadShader(vertexPath,GL20.GL_VERTEX_SHADER); // Working ?????
programID = GL20.glCreateProgram();
GL20.glAttachShader(programID, vertexID);
GL20.glAttachShader(programID, fragmentID);
GL20.glLinkProgram(programID);
GL20.glValidateProgram(programID);
}
private int loadShader(String file,int type) {
StringBuilder shaderSource = new StringBuilder();
try{
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while((line = reader.readLine())!=null){
shaderSource.append(line).append("//\n");
}
reader.close();
}catch(IOException e){
e.printStackTrace();
System.exit(-1);
}
int shaderID = GL20.glCreateShader(type);
GL20.glShaderSource(shaderID, shaderSource);
GL20.glCompileShader(shaderID);
if(GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS )== GL11.GL_FALSE){
System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
System.err.println("Could not compile shader!");
System.exit(-1);
}
return shaderID;
}
Here is the fragment shader:
#version 460 core
in vec3 color;
out vec4 outColor;
void main() {
outColor = vec4(color, 1.0);
}
And the vertex shader:
#version 460 core
in vec3 position;
out vec3 color;
void main() {
color = vec3(1,1,1);
}
And here is the line to create the Shader class called right after creating the display:
shader = new Shader("src/mainVertex", "src/mainFragment");
I don't what is going on, maybe the problem is the fragment shader, maybe the reader. Thanks for your help.