我正在用Python和OpenGL构建一个视觉研究实验。我正在执行纹理的置换贴图。GLSL代码与版本330兼容,在我的机器上呈现得非常完美。但是当我在实验桌面上运行代码时,我什么也没有得到,没有记录的消息或错误,它只是呈现一个空白屏幕。在
我在两台机器上运行了以下内容:
print "OpenGL version:\t\t%s" % glGetString(GL_VERSION)
print "GLSL version:\t\t%s" % glGetString(GL_SHADING_LANGUAGE_VERSION)
print "Vendor:\t\t\t%s" % glGetString(GL_VENDOR)
print "Renderer:\t\t%s" % glGetString(GL_RENDERER)
从我的机器中,我得到以下输出:
^{pr2}$在实验桌面上,我得到了以下信息:
OpenGL version: 3.3.0
GLSL version: 3.30 NVIDIA via Cg compiler
Vendor: NVIDIA Corporation
Renderer: Quadro FX 3700/PCIe/SSE2
这是顶点和碎片着色器的节选,有什么我忽略了吗?在
顶点.shd:
#version 330 compatibility
layout (location = 0) in vec2 vertVertex;
layout (location = 1) in vec2 vertTexCoord;
layout (location = 2) in vec3 vertNormal;
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform sampler2D heightmap;
out vec4 fragVertex;
out vec2 fragTexCoord;
float convert_luminance(vec4 pixel) {
return (0.2126 * pixel.r) + (0.7152 + pixel.g) + (0.0722 * pixel.b);
}
vec4 displacement_mapping(void) {
// Get pixel values for TexCoord
vec4 pixel = texture2D(heightmap, vertTexCoord.st);
float grey_value = convert_luminance(pixel);
// Return displaced position coordinates
return vec4(vertNormal * grey_value, 0.0) + vec4(vertVertex, 0.0, 0.0);
}
void main(void) {
fragTexCoord = vertTexCoord.st;
fragVertex = displacement_mapping();
gl_Position = ProjectionMatrix * (ModelViewMatrix * fragVertex);
}
碎片.shd:
#version 330 compatibility
in vec2 fragTexCoord;
in vec4 fragVertex;
uniform sampler2D colormap;
void main(void) {
gl_FragColor = texture2D(colormap, fragTexCoord.st);
}
目前没有回答
相关问题 更多 >
编程相关推荐