我有這段不斷重複的代碼。在我的for循環中,如何將索引更改爲字符串?
g_materialAmbientIndex[0] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[0].ambient");
g_materialDiffuseIndex[0] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[0].diffuse");
g_materialSpecularIndex[0] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[0].specular");
g_materialAmbientIndex[1] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[1].ambient");
g_materialDiffuseIndex[1] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[1].diffuse");
g_materialSpecularIndex[1] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[1].specular");
g_materialAmbientIndex[2] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[2].ambient");
g_materialDiffuseIndex[2] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[2].diffuse");
g_materialSpecularIndex[2] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[2].specular");
我想把它放到一個for循環,但我有問題的字符串參數。下面是我的功能。我不斷收到一個錯誤,指出:
從沒有合適的轉換FUNC 「的std :: basic_string的.....」 到 「常量GLchar *」 存在
for (int i = 0; i < MAX_MATERIALS; i++)
{
stringstream ss;
ss << i;
string str = ss.str();
g_materialAmbientIndex[i] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[" + str + "].ambient");
g_materialDiffuseIndex[i] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[" + str + "].diffuse");
g_materialSpecularIndex[i] = glGetUniformLocation(g_shaderProgramID, "uMaterialProperties[" + str + "].specular");
}