gpt4 book ai didi

java - 在使用 NVIDIA Geforce 9800 显卡的 Windows Vista 上,GLSL 着色器无法编译并且没有错误消息

转载 作者:行者123 更新时间:2023-12-02 03:12:35 24 4
gpt4 key购买 nike

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

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;
}

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

最佳答案

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

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

关于java - 在使用 NVIDIA Geforce 9800 显卡的 Windows Vista 上,GLSL 着色器无法编译并且没有错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40823776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com