I recently discovered a strange error with my fragment shader:

#version 330 core

in vec4 v_color;
in vec2 v_texCoords[10];

out vec4 frag_color;

uniform int actual_textures;
uniform sampler2D u_texture[10];

void main() {
    vec4 final_color = texture2D(u_texture[0], v_texCoords[0]);
    for(int i = 1; i < actual_textures; i++){
        vec4 tex = texture2D(u_texture[i], v_texCoords[i]);
        final_color = tex * tex.a + final_color * (1 - tex.a);

    frag_color = v_color * final_color;

On my PC with a GTX 960 and OpenGL 4.5.1 there is no error at all. But on my laptop with an Intel HD 3000 and OpenGL 3.3, I get a compile error that the texture2D function is deprecated and that the sampler2D array size is too big because I only pass 3 textures at the moment and I want the array to be able to handle up to 10 textures. On any other computer I testedm the error didn't occur, but they all had nvidia or amd gpus. Why do I keep getting this error on my laptop?

  • \$\begingroup\$ Are you absolutely sure that the texture2D deprecation is a error, not a warning? I was using it for ages and users didn't complain. \$\endgroup\$ – HolyBlackCat Aug 15 '17 at 18:19

Don't use texture2D, it was replaced by texture after glsl version 130 and it supports every sampler type.

The array size is too big error isn't about unused space. It simply means that you can't have 10 active textures at once, so there's no reason to expect that much. Usually the limit is around 8. You should use array textures instead.

  • \$\begingroup\$ Unfortunately with LWJGL I can't use array textures with open gl 3.3 because several funtions are open gl 4.0+ \$\endgroup\$ – mrdlink Aug 16 '17 at 12:05
  • \$\begingroup\$ @mrdlink you can use array textures in GL 3.3, you just need to use the glTexImage... functions instead of glTexStorage.... \$\endgroup\$ – Bálint Aug 16 '17 at 12:24
  • \$\begingroup\$ Ok, so I changed it to glTexImage3D(). Now it looks like this: GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA8, width, height, 10, 0, GL11.GL_RGBA8, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)null); But the screen stays black now. \$\endgroup\$ – mrdlink Aug 16 '17 at 12:48
  • \$\begingroup\$ @mrdlink you need to use texImage3d to create the storge, then texSubImage3d to add the data to it \$\endgroup\$ – Bálint Aug 16 '17 at 12:57
  • \$\begingroup\$ @mrdlink I think. I never worked much with array textures before, so it's probably worth looking up the documentation of them. They existed before OpenGL 4 and people used them back then too, so you should be able to do the same \$\endgroup\$ – Bálint Aug 16 '17 at 13:09

Use texture instead of texture2D.

Secondly, the max number of active texture units varies with hardware. I've ran into this problem before, and found that the HD4000 integrated graphics processor only supports two active texture units, so I'd imagine the HD3000 will be similar.

A call to glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB,&value); will tell you the max bound textures you can have per pass for a target graphics device.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.