使用NVIDIA Geforce 9800显卡在Windows Vista上不会编译GLSL着色器并且不会显示错误消息

时间:2016-11-26 22:27:15

标签: java eclipse opengl shader lwjgl

这是问题所在源代码的一部分:

GL.createCapabilities();            
// Define the viewport dimensions
glViewport(0, 0, 300, 300);

int shaderProgram;
final String vertexShader = "#version 330 core\n in vec3 position; // The position variable has attribute position 0\n out vec4 vertexColor; // Specify a color output to the fragment shader\n void main()\n {\n gl_Position = vec4(position, 1.0); // See how we directly give a vec3 to vec4's constructor\n vertexColor = vec4(0.5f, 0.0f, 0.0f, 1.0f); // Set the output variable to a dark-red color\n }";

String fragmentShader = "#version 330 core\n in vec3 ourColor;\n"
                + "in vec2 TexCoord;\n"
                + "out vec4 color;\n"
                + "uniform sampler2D ourTexture1;\n"
                + "void main()\n"
                + "{\n"
                + "color = vec4(ourColor, 1.0f);\n"
                + "}";

int vertex, fragment;
// Vertex Shader
vertex = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
GL20.glShaderSource(vertex, vertexShader);
GL20.glCompileShader(vertex);
// Fragment Shader
fragment = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
GL20.glShaderSource(fragment, fragmentShader);
GL20.glCompileShader(fragment);

//create program and bind shaders to program
shaderProgram = GL20.glCreateProgram();
GL20.glAttachShader(shaderProgram, vertex);
GL20.glAttachShader(shaderProgram, fragment);
GL20.glLinkProgram(shaderProgram);
int vlength = GL20.GL_SHADER_SOURCE_LENGTH;
int iscompiled = GL20.glGetProgrami(fragment, GL20.GL_COMPILE_STATUS);
if(iscompiled == GL_FALSE)
{
     System.out.println(glGetString(GL_VERSION));
     System.out.println("not compiled");
     System.out.println(GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
     System.out.println(GL20.glGetShaderInfoLog(vertex));
     return;
}
int isLinked = GL20.glGetProgrami(shaderProgram, GL20.GL_LINK_STATUS);
if(isLinked == GL_FALSE)
{
    System.out.println("failed linking");
    return;
}

这是顶点着色器:

 #version 330 core
 layout (location = 0) in vec3 position; // The position variable has attribute position 0

 out vec4 vertexColor; // Specify a color output to the fragment shader

 void main()
 {
     gl_Position = vec4(position, 1.0); // See how we directly give a vec3 to vec4's constructor
     vertexColor = vec4(0.5f, 0.0f, 0.0f, 1.0f); // Set the output variable to a dark-red color
 }

这是片段着色器:

 #version 330 core
 in vec4 vertexColor; // The input variable from the vertex shader (same name and same type)

 out vec4 color;

 void main()
 {
     color = vertexColor;
 } 

两个着色器都无法编译。 Niether顶点或片段着色器。需要修复什么? 我使用的是opengl 3.3版的核心配置文件。 正在运行的操作系统是windows vista home premium 64 bit。

1 个答案:

答案 0 :(得分:2)

int iscompiled = GL20.glGetProgrami(fragment, GL20.GL_COMPILE_STATUS);

您无法查询程序的编译状态。这是每个着色器对象的属性,可以通过glGetShaderiv()查询。对GL_COMPILE_STATUS使用glGetProgramiv()只会导致GL_INVALID_ENUM错误。