I was trying to texture a cube in PyOpenGL when I ran into an issue. PyOpenGL only supports 1.10, 1.20, 1.30, 1.00 ES, and 3.00 ES. I need at least version 1.40 because in 1.40 layout
was introduced and I need to use layout
to get the texture coordinates. I'm trying to texture each side of a cube differently using array textures. Here are some of my code snippets if they are required.
Loading the array texture:
def load_texture_array(path,width,height):
teximg = pygame.image.load(path)
texels = teximg.get_buffer().raw
texture = GLuint(0)
layerCount = 6
mipLevelCount = 1
glGenTextures(1, texture)
glBindTexture(GL_TEXTURE_2D_ARRAY, texture)
glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, layerCount)
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, width, height, layerCount, GL_RGBA, GL_UNSIGNED_BYTE, texels)
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
My vertex shader:
#version 130
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTexCoord;
out vec3 color;
out vec2 TexCoord;
void main() {
gl_Position = vec4(aPos, 1.0);
color = aColor;
TexCoord = aTexCoord;
}
my fragment shader:
#version 130
out vec4 FragColor;
in vec3 color;
in vec2 TexCoord;
uniform sampler2D texture;
void main()
{
FragColor = texture(texture, TexCoord);
}
If you need any more information, just ask in the comments and I will add it.