【发布时间】:2016-02-02 23:38:09
【问题描述】:
我有一段时间对学习 OpenGL 很感兴趣。但是,每次我开始使用它时,我都会在编译着色器时遇到同样的错误。这是吐出的错误代码。
0(1) : 错误 C0206: 版本行中的无效令牌“无效原子 483265304”
我已尝试查找错误,但没有发现任何内容……当然,也没有任何内容可以提供有关如何解决问题的信息。
我不懂 C 或 C++,所以我使用的是 LWJGL。
这是我用来编译着色器的代码:
private static int loadShader(String file, int type){
//System.out.println("Loading Shader.");
StringBuilder shaderSource = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while((line = reader.readLine())!=null){
//System.out.println(line);
shaderSource.append(line).append("/n");
}
reader.close();
//System.out.println("Closed Reader.");
} catch (IOException e) {
System.err.println("Could not read file!");
e.printStackTrace();
System.exit(-1);
}
//System.out.println("Creating Shader ID...");
int shaderID = GL20.glCreateShader(type);
//System.out.println("Created Shader ID, Compiling Shader.");
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. Location: " + file);
System.exit(-1);
}
return shaderID;
}
这是我的顶点着色器:
#version 400 core
in vec3 position;
out vec3 colour;
void main(void){
gl_Position = vec4(position, 1.0);
colour = vec3(position.x+0.5, 1.0, position.y+0.5);
}
这是我的片段着色器:
#version 400 core
in vec3 colour;
out vec4 out_Colour;
void main(void){
out_Colour = vec4(colour, 1.0);
}
如果有人读到这篇文章,请提前感谢您的宝贵时间。
【问题讨论】:
-
你知道你有什么OpenGL驱动吗?
-
while((line = reader.readLine())!=null)好吧,我看到人们逐行阅读文件的瘟疫并不是 C++ 独有的。为什么这么多人这样做而不是looking through SO to find a function that reads the whole file? -
应该是“\n”,而不是“/n”
-
@Nicol Bolas:在我重新阅读规范后删除了我的评论。我以前从未见过这种语法。
标签: java opengl glsl shader lwjgl