【问题标题】:LWJGL Vertex and Fragment Shaders Wont Compile (Error CO206)LWJGL 顶点和片段着色器无法编译(错误 CO206)
【发布时间】: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


【解决方案1】:

基本拼写错误 - 当您阅读每一行时,您附加的是“/n”而不是“\n”。

@Nicol Bolas 提出了一个很好的观点 - 有一个函数 Files.readAllBytes(Path path),如果您使用它而不是重新实现该功能,您将不太容易出现这样的小错误。

【讨论】:

  • 哇,非常感谢。这似乎解决了问题。我已经阅读了一堆其他人的问题,但我从未注意到我使用了错误的字符串......
  • 记得标记为答案,如果这解决了你的问题:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-19
相关资源
最近更新 更多