我在编译着色器时遇到过几次这种错误。
下面是信息日志/错误
Vertex shader failed to compile with the following errors:
ERROR: 0:1: error(#132) Syntax error: "<" parse error
ERROR: error(#273) 1 compilation errors. No code generated
这也会发生在片段着色器上。下面是我的非常非常基本的测试顶点和片段着色器代码:
@version 330
layout (location = 0) in vec3 position;
void main(){
gl_Position = vec4(position, 1.0);
}
这是碎片:
@version 330
out vec4 fragColor;
void main(){
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
以下是具有所有load/compile/link方法的Shader类:
public abstract class Shader {
private int program;
public Shader(){
program = glCreateProgram();
if(program == 0){
System.err.println("Shader creation failed: Could not find valid memory location");
System.exit(1);
}
}
public void bind(){
glUseProgram(program);
}
public 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");
System.exit(1);
}
glShaderSource(shader, text);
glCompileShader(shader);
if(glGetShaderi(shader, GL_COMPILE_STATUS) == 0){
System.err.println("Shader compilation failed");
System.err.println(glGetShaderInfoLog(shader, 1024));
System.exit(1);
}
glAttachShader(program, shader);
}
public String loadShader(String fileName){
StringBuilder shaderSource = new StringBuilder();
BufferedReader shaderReader = null;
try{
shaderReader = new BufferedReader(new FileReader("./res/shaders/" + fileName));
String line;
while((line = shaderReader.readLine()) != null){
shaderSource.append(line).append("\n");
}
shaderReader.close();
}catch(Exception e){
e.printStackTrace();
System.out.println("HERE IT IS!!!!");
System.exit(1);
}
return shaderSource.toString();
}
public void compileShader(){
glLinkProgram(program);
if(glGetProgrami(program, GL_LINK_STATUS) == 0){
System.err.println(glGetShaderInfoLog(program, 1024));
System.exit(1);
}
glValidateProgram(program);
if(glGetProgrami(program, GL_VALIDATE_STATUS) == 0){
System.err.println(glGetShaderInfoLog(program, 1024));
System.exit(1);
}
}
}
我做了很多实验来找出问题出在哪里,我把问题缩小到两件事中的一件。(A)以某种方式从loadShader中的文件加载文本()方法正在返回一串随机符号(注意在infoLog的最上面的解析错误指示字符是“〈”,这显然不是甚至在任何着色器。或者(B)错误是与glCompileShader(shader)在addProgram()方法中调用。我认为选项A更有可能,但正如我所说,fileLoader以前从未这样做过。
1条答案
按热度按时间erhoui1w1#
答案是.......在着色器代码中声明版本时是# not @......