I have an array of GLuint with fixed size:
GLuint textures[10];
Now I need to set a size of array dynamically. I wrote something like this:
*.h:
GLuint *textures;
*.m:
textures = malloc(N * sizeof(GLuint));
where N – needed size.
Then it used like this:
glGenTextures(N, &textures[0]);
// load texture from image
-(GLuint)getTexture:(int)index{
return textures[index];
}
I used the answer from here, but program fell in runtime. How to fix this?
Program is written on Objective-C and uses OpenGL ES.
I figured out this issue.
This code is valid but seems like not working. This problem is described here, but it’s not so clear.
The solution that works for me is to create separate class with GLuint property:
Then we can create NSMutableArray of Textures:
In *.m file we should fill our array:
If you use other array(s) with textures you have to shift GLuint indexes, e.g.:
where M – size of earlier used array of GLuint’s.
Then getTexture will be rewritten as following:
I am not excited with this approach but it’s a single one I make work.