1

只是想知道是否有人可以帮助我使用以下代码:

// Get uniform locations.
GLint m_nUniforms = 0;
glUniformMatrix4fv(uniforms, 1, 0, _modelViewProjectionMatrix.m);


glGetProgramiv(_program, GL_ACTIVE_UNIFORMS, &m_nUniforms);
for(unsigned i = 0; i < m_nUniforms; i++)
{
    char *uniformName = NULL;
    GLint size;
    GLenum type;

    glGetActiveUniform(_program, i, max_length + 1, NULL, &size, &type, uniformName);
    uniforms[uniformName] = glGetUniformLocation(_program, uniformName);
}

我想为 for 循环的每次迭代分配带有“char* uiformName”类型下标的制服。我收到错误“数组下标不是整数”。

如何使用 char 作为数组下标?

谢谢

4

1 回答 1

3

那么你想要的是一个字典,其中键和值都是字符串:

NSMutableDictionary *uniforms = [[NSMutableDictionary alloc] init];

for (blah)
{
    glGetActiveUniform(_program, i, max_length + 1, NULL, &size, &type, uniformName);
    char *uniform = glGetUniformLocation(_program, uniformName);
    [uniforms addObject:[NSString stringWithUTF8String:uniform]
                 forKey:[NSString stringWithUTF8String:uniformName]];
}
于 2013-03-04T13:34:46.190 回答