我有以下与 GLSL #130 完美配合的着色器代码,但我想将其转换为适用于版本 #330 的代码(因为不知何故,#130 版本在我的带有 Geforce 210 的 Ubuntu 机器上不起作用; 着色器什么都不做)。经过几次失败的尝试(我不断收到未描述的链接错误),我决定寻求一些帮助。下面的代码使用统一变量 Brightness 和 Contrast 动态更改纹理的对比度和亮度。我已经使用 PyOpenGL 在 Python 中实现了它:
def createShader():
"""
Compile a shader that adjusts contrast and brightness of active texture
Returns
OpenGL.shader - reference to shader
dict - reference to variables that can be passed to the shader
"""
fragmentShader = shaders.compileShader("""#version 130
uniform sampler2D Texture;
uniform float Brightness;
uniform float Contrast;
uniform vec4 AverageLuminance;
void main(void)
{
vec4 texColour = texture2D(Texture, gl_TexCoord[0].st);
gl_FragColor = mix(texColour * Brightness,
mix(AverageLuminance, texColour, Contrast), 0.5);
}
""", GL_FRAGMENT_SHADER)
shader = shaders.compileProgram(fragmentShader)
uniform_locations = {
'Brightness': glGetUniformLocation( shader, 'Brightness' ),
'Contrast': glGetUniformLocation( shader, 'Contrast' ),
'AverageLuminance': glGetUniformLocation( shader, 'AverageLuminance' ),
'Texture': glGetUniformLocation( shader, 'Texture' )
}
return shader, uniform_locations
我查看了需要为新的 GLSL 版本进行的更改,并尝试将片段着色器代码更改为以下内容,但随后只会出现非描述性链接错误:
fragmentShader = shaders.compileShader("""#version 330
uniform sampler2D Texture;
uniform float Brightness;
uniform float Contrast;
uniform vec4 AverageLuminance;
in vec2 TexCoord;
out vec4 FragColor;
void main(void)
{
vec4 texColour = texture2D(Texture, TexCoord);
FragColor = mix(texColour * Brightness,
mix(AverageLuminance, texColour, Contrast), 0.5);
}
""", GL_FRAGMENT_SHADER)
有没有人可以帮助我进行这种转换?