So I have been wracking my brain for a solid 3 days now trying to get texture units working for me. I have gone over my code dozens of times comparing it to other sources as well as trying every iteration I can imagine of using texture units. Specifically, my problem is that I have two textures, a wood texture and a face texture, that I’m assigning to two texture units and mixing in my fragment shader. The problem is that only one of these textures is rendering and the mixing is not happening. And if I swap the order in which I’m defining the textures (i.e. face texture before wood texture), then only the wood texture will display. The second texture defined trumps even though it’s a different texture unit. Here is a github repo for my OpenGL learning project with the main file and vertex and fragment shaders I’m using.
If anyone has any insight into my issue I would greatly appreciate the info! Thanks.
texture1 = GLuint(0)
With PyOpenGL, you need to use
texture1 = glGenTextures(1)
texture1, texture2 = glGenTextures(2)
If you absolutely need the C-style interface, the underlying ctypes wrapper can be obtained from OpenGL.raw:
from OpenGL.GL import arrays
from OpenGL.raw.GL.VERSION.GL_1_1 import glGenTextures
tex = arrays.GLuintArray.zeros(2)
texture1, texture2 = tex
In general, if a function takes an “output” array as a parameter, the PyOpenGL wrapper will omit that parameter, allocating the array itself and using it as the function’s return value.
Also, unless you explicitly set OpenGL.SIZE_1_ARRAY_UNPACK=False, glGenTextures(1) returns a single integer, while glGenTextures(n) for n>1 returns an array. If you set OpenGL.SIZE_1_ARRAY_UNPACK=False, it always returns an array.
Huzzah! Finally! Thanks for the information. I haven’t found any documentation about this case in the PyOpenGL docs since it mostly just redirects you to other various OpenGL tutorials which while helpful don’t fully explain the Python implementation. Thanks again.