Setting textures of a uniform Sampler2D array with ofShader

I’ve tried to set a uniform Sampler2D array like this

// shader.frag

uniform sampler2D textures[3];

// ofApp.cpp

for (int i = 0; i < 3; i++) {
   shader.setUniformTexture("textures[0]", textures[i], i);

but it doesn’t work.

Is there a way to do this with ofShader or only possible with vanilla opengl?


After some digging on the forum I’ve found an old thread with a simillar question here

ofShader does not wrap this functionallity so one have to use vanilla opengl.

The thread has an example on how to use a GL_TEXTURE_2D_ARRAY (not quite the same as an array of uniform samplers but close enough):

1 Like