尝试使用jogl加载和初始化着色器

时间:2015-03-31 23:39:00

标签: java opengl shader jogl

尝试在JOGL中初始化一些着色器。

为什么错误为空的任何想法?我检查它的大小,它看起来大于0,因为没有打印"Unknown"

vertexShaderProgram = gl.glCreateShader(GL2.GL_VERTEX_SHADER);
fragmentShaderProgram = gl.glCreateShader(GL2.GL_FRAGMENT_SHADER);
gl.glShaderSource(vertexShaderProgram, 1, vsrc, null, 0);
gl.glCompileShader(vertexShaderProgram);
gl.glShaderSource(fragmentShaderProgram, 1, fsrc, null, 0);
gl.glCompileShader(fragmentShaderProgram);
shaderprogram = gl.glCreateProgram();

gl.glAttachShader(shaderprogram, vertexShaderProgram);
gl.glAttachShader(shaderprogram, fragmentShaderProgram);
gl.glLinkProgram(shaderprogram);
gl.glValidateProgram(shaderprogram);
IntBuffer intBuffer = IntBuffer.allocate(1);
gl.glGetProgramiv(shaderprogram, GL2.GL_LINK_STATUS, intBuffer);

System.out.println("got link status");

if (intBuffer.get(0) != 1) {
    gl.glGetProgramiv(shaderprogram, GL2.GL_INFO_LOG_LENGTH, intBuffer);
    int size = intBuffer.get(0);
    System.err.println("Program link error: ");
    if (size > 0) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(size);
        gl.glGetProgramInfoLog(shaderprogram, size, intBuffer, byteBuffer);
        for (byte b: byteBuffer.array()) {
            System.err.print((char) b);
        }
    } else {
        System.out.println("Unknown");
    }
    System.exit(1);
}

我在控制台上收到错误,但不包含数据..

got link status
Program link error: 

这是我的片段着色器..

< FILE :: fragmentShader.txt >
uniform sampler2D fish_y_offset;
uniform float alphavalue;
void main()
{
    gl_FragColor = texture2D(fish_y_offset, gl_TexCoord[0].st);
    gl_FragColor.a=alphavalue;

}

这是我的顶点着色器..

< FILE :: vertextShader.txt >
uniform float waveTime;
uniform float waveWidth;
uniform float waveHeight;
void main(void)
{
    vec4 v = vec4(gl_Vertex);
    v.y = 11 + sin(waveWidth * v.x + waveTime) * cos(waveWidth * v.z + waveTime) * waveHeight;
    gl_Position = gl_ModelViewProjectionMatrix * v;
    gl_TexCoord[0] = gl_MultiTexCoord0;
}

1 个答案:

答案 0 :(得分:2)

在每次着色器编译后检查着色器日志。

https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetShaderInfoLog.xml