1

我正在用 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)

从我的机器上,我得到以下输出:

OpenGL version: 4.0.0 - Build 9.17.10.2867
GLSL version: 4.00 - Build 9.17.10.2867
Vendor: Intel
Renderer: Intel(R) HD Graphics 4000

从实验桌面,我得到以下信息:

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

0 回答 0