i get an error when i doing in the following way:
Firstly I declare a class in file light.cpp as follows:
class light {
public:
light(const char* light_file, const int n);
~light();
void LoadLight(string light_file);
//private:
int light_num;
float **p;
float **a;
float **d;
float **s;
float *amb;
};
Then I use light class in main.cpp:
light *light_data;
...
...
other code
...
...
void lighting()
{
// The following lines contain errors
GLfloat light_specular[light_data->light_num][4]; //**error line: from here I receive error about light_data, saying that expression must have a constant** value
GLfloat light_diffuse[light_data->light_num][4]; //error line
GLfloat light_ambient[light_data->light_num][4]; //error line
GLfloat light_position[light_data->light_num][4];// error line
for(int i = 0; i < light_data->light_num; i++) {
int j;
for(j = 0; j < 3; j++) {
light_specular[i][j] = light_data->s[i][j];
light_diffuse[i][j] = light_data->d[i][j];
light_ambient[i][j] = light_data->a[i][j];
light_position[i][j] = light_data->p[i][j];
}
light_specular[i][j] = 1.0f;
light_diffuse[i][j] = 1.0f;
light_ambient[i][j] = 1.0f;
light_position[i][j] = 1.0f;
}
GLfloat ambient[3];
for(int i = 0; i < 3; i++) {
ambient[i] = light_data->amb[i];
}
In the above lighting() function, it says that light_data
must have constant value. I am so confusing about this error, could anyone help me?
I am new to c++, sorry for the messy code.