[QUOTE=GClements;1281604]Yes, you need to convert from uint to int (or uvec to ivec) for texelFetch.
- Why 16-bit? Because my values range from 0 to 65535 no?
- GL_ALPHA is deprecated. Use, GL_RED or GL_RED_INTEGER (or a sized version) for a single-channel texture. Replaced by GL_RED
- GL_R16UI isn’t valid for the type parameter.
It should be:
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16UI, img.shape[0], img.shape[1], 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, img_data)
I do not know why but I manage to solve my issue using texture() instead of texture2D in my fragment shader. Besides, I thought they should yield the same result.
But I still get nothing on screen.
Here, you’re converting the data to np.uint16 but telling OpenGL that it’s GL_UNSIGNED_BYTE.[/QUOTE]
It is a copy/paste mistake, I wrote dtype=np.uint8 in my code.
Thus, I fill my two textures like that:
[LEFT]
glBindTexture(GL_TEXTURE_2D, tileObj.TBO)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
img_data = np.ascontiguousarray(tile.flatten(), dtype=np.uint16)
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16UI, tile.shape[0], tile.shape[1], 0, GL_RED_INTEGER,
GL_UNSIGNED_SHORT, img_data)
# fill transcod buffer with the colormap
colormap = misc.imread('shadow_tile.png')
glBindTexture(GL_TEXTURE_2D, self.colormapBuffer)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
img_data = np.ascontiguousarray(colormap.flatten(), dtype=np.uint8)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colormap.shape[0], colormap.shape[1], 0, GL_RGB,
GL_UNSIGNED_BYTE, img_data)
[/LEFT]
And I render using:
loc_pos = glGetAttribLocation(programID, "position")
glEnableVertexAttribArray(loc_pos)
glBindBuffer(GL_ARRAY_BUFFER, tile.VBO[0])
glVertexAttribPointer(loc_pos, 2, GL_DOUBLE, False, 0, ctypes.c_void_p(0))
loc_uv = glGetAttribLocation(programID, "texcoord")
glEnableVertexAttribArray(loc_uv)
glBindBuffer(GL_ARRAY_BUFFER, tile.VBO[1])
glVertexAttribPointer(loc_uv, 2, GL_DOUBLE, False, 0, ctypes.c_void_p(0))
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, tile.TBO)
glUniform1i(glGetUniformLocation(1, 'texSonar'), 0)
glActiveTexture(GL_TEXTURE1)
glBindTexture(GL_TEXTURE_2D, self.colormapBuffer)
glUniform1i(glGetUniformLocation(1, 'transcodMap'), 1)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tile.EBO)
glDrawElements(GL_TRIANGLES, tile.indices.size, GL_UNSIGNED_INT, ctypes.c_void_p(0))