OpenGL着色器错误(存储限定符,未声明的标识符和浮点转换)

时间:2013-07-30 01:17:59

标签: java eclipse opengl shader lwjgl

我开始使用OpenGL并制作了我的第一个着色器(在a tutorial之后)。尽管遵循了这封信的教程,但我得到了一些错误(与教程提供者不同)。

尽管有彻底的创造性的谷歌搜索,但我没有找到任何帮助或解释出错的地方。

我的着色器的来源如下:

basicVertex.vs:

#version 330

layout (location = 0) in vec3 position;

void main() 
{
    gl_Position = vec4(position, 1.0);
}



basicFragment.fs:

#version 330

out vec4 fragColor;

void main() 
{
    fragColor = vec4(0.0, 1.0, 1.0); 
}

,错误如下:

Shader could not be run: 
ERROR: 0:? : '' : storage qualifier not valid with layout qualifier id 
ERROR: 0:7: 'gl_Position' : undeclared identifier 
ERROR: 0:7: 'assign' :  cannot convert from '4-component vector of float' to 'float'

(即整个命令行输出)。

这是Shader加载/编译代码:

package uk.co.gossfunkel.citadel3d.shader;

import static org.lwjgl.opengl.GL20。; import static org.lwjgl.opengl.GL32。;

public class Shader {         private int program;

    public Shader() throws ShaderLoadException {
            program = glCreateProgram();

            if (program == 0) {
                    throw new ShaderLoadException();
            }
    }

    public void bind() {
            glUseProgram(program);
    }

    public void addVertexShader(String text) throws ShaderLoadException {
            addProgram(text, GL_VERTEX_SHADER);
    }

    public void addGeometryShader(String text) throws ShaderLoadException {
            addProgram(text, GL_GEOMETRY_SHADER);
    }

    public void addFragmentShader(String text) throws ShaderLoadException {
            addProgram(text, GL_FRAGMENT_SHADER);
    }

    public void compileShader() throws ShaderLoadException {
            glLinkProgram(program);

            if (glGetProgrami(program, GL_LINK_STATUS) == 0) {
                    throw new ShaderLoadException(glGetShaderInfoLog(program, 1024));
            }

            glValidateProgram(program);

            if (glGetProgrami(program, GL_VALIDATE_STATUS) == 0) {
                    throw new ShaderLoadException(glGetShaderInfoLog(program, 1024));
            }
    }

    private void addProgram(String text, int type) throws ShaderLoadException {
            int shader = glCreateShader(type);
            if (shader == 0) {
                    throw new ShaderLoadException();
            }
            glShaderSource(shader, text);
            glCompileShader(shader);

            if (glGetShaderi(shader, GL_COMPILE_STATUS) == 0) {
                    throw new ShaderLoadException(glGetShaderInfoLog(shader, 1024));
            }

            glAttachShader(program, shader);
    }

}

如果有人可以指导我解决方案或建议什么是错的,我很乐意听到。但是,请不要只说“了解更多OpenGL”,因为这没有帮助。谢谢!

0 个答案:

没有答案