Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LWJGL无法编译着色器_Java_Opengl_Glsl_Shader_Lwjgl - Fatal编程技术网

Java LWJGL无法编译着色器

Java LWJGL无法编译着色器,java,opengl,glsl,shader,lwjgl,Java,Opengl,Glsl,Shader,Lwjgl,我正试图通过LWJGL网站上的“带投影的四边形”教程加载带投影的VBO 下面是我加载着色器的函数 private int loadShader(String filename, int type) { StringBuilder shaderSource = new StringBuilder(); int shaderID = 0; try { try (BufferedReader reader = new BufferedReader(new Fi

我正试图通过LWJGL网站上的“带投影的四边形”教程加载带投影的VBO

下面是我加载着色器的函数

private int loadShader(String filename, int type) {
    StringBuilder shaderSource = new StringBuilder();
    int shaderID = 0;

    try {
        try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
            String line;
            while ((line = reader.readLine()) != null) {
                shaderSource.append(line).append("\n");
            }
        }
    } catch (IOException e) {
        System.err.println("Could not read file.");
        e.printStackTrace();
        System.exit(-1);
    }

    shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, shaderSource);
    GL20.glCompileShader(shaderID);

    if (GL20.glGetShader(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.err.println("Could not compile shader.");
        System.exit(-1);
    }

    this.exitOnGLError("loadShader");

    return shaderID;
}
当我运行程序时,会发生此错误

if (GL20.glGetShader(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
    System.err.println("Could not compile shader.");
    System.exit(-1);
}
以下是我的着色器代码:

顶点:

#version 150 core

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;

in vec4 in_Position;
in vec4 in_Color;
in vec2 in_TextureCoord;

out vec4 pass_Color;
out vec2 pass_TextureCoord;

void main(void) {
    gl_Position = in_Position;
    // Override gl_Position with our new calculated position
    gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_Position;

    pass_Color = in_Color;
    pass_TextureCoord = in_TextureCoord;
}
片段:

#version 150 core

uniform sampler2D texture_diffuse;

in vec4 pass_Color;
in vec2 pass_TextureCoord;

out vec4 out_Color;

void main(void) {
    out_Color = pass_Color;
    // Override out_Color with our texture pixel
    out_Color = texture2D(texture_diffuse, pass_TextureCoord);
}

感谢您的帮助。

您的片段着色器无效,GLSL 1.50 core中没有功能
texture2D
。只要使用这个函数。编译器从调用它时使用的采样器类型派生要采样的纹理类型。

如果着色器未编译,则应检查着色器编译日志。此外,您应该发布着色器代码。我如何获取着色器编译日志?用于此。