I'm trying to provide access to a 3-dimensional array of scalar data to a fragment shader, from a Python program using PyOpenGL.
In the fragment shader, I declare the a 3d sampler uniform
uniform sampler3D vol;
and in the Python program I have the following code to set up a scalar 3d texture
vol = numpy.random.rand(3, 3, 3).astype(np.float32)
texture = glGenTextures(1)
glUniform1i(glGetUniformLocation(program, "vol"), 0)
glActiveTexture(GL_TEXTURE0 + 0)
glBindTexture(GL_TEXTURE_3D, texture)
glTexImage3D(GL_TEXTURE_3D, 0, GL_RED, 3, 3, 3, 0, GL_RED, GL_FLOAT, vol)
glEnable(GL_TEXTURE_3D)
However, no matter where from the sampler I take values, e.g.
color = texture(vol, vec3(0, 0, 0));
it appears that I always obtain black (0, 0, 0).
What am I doing wrong?
I know that the basic setup of my fragment shader works, i.e. if I write color = vec3(1, 0, 0)
I get red pixels.
I also know that there are no OpenGL errors, because I'm running the program with the option -glerror
processed by glutInit()
, which leads to OpenGL errors being translated into Python exceptions.