I want to put some lighting into a project i created, but i get the following compiler error:
error C2440: 'initializing' : cannot convert from 'float' to 'GLfloat []'
What is the problem?
GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
GLfloat lightColor0[] = (0.5f, 0.5f, 0.5f, 1.0f);
GLfloat lightPos0[] = (4.0f, 0.0f, 8.0f, 1.0f);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightPos0);
GLfloat lightColor1[] = (0.5f, 0.2f, 0.2f, 1.0f);
GLfloat lightPos1[] = (-1.0f, 0.5f, 0.5f, 0.0f);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
glLightfv(GL_LIGHT1, GL_开发者_如何学运维DIFFUSE, lightPos1);
You have used wrong array initialization syntax. You may not use () to list array elements.
Syntax is { list_of_the_elements }
So change () to {}
GLfloat lightColor0[] = (0.5f, 0.5f, 0.5f, 1.0f);
to
GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f};
GLfloat lightColor0[] = (0.5f, 0.5f, 0.5f, 1.0f);
You need curly braces there {...}
not parentheses (...)
. The way you wrote it, the compiler sees a buch of floating point literals, with comma operators inbetween. The last expression of a comma series becomes the value of what's inside the parenthesis.
You must use { ... }
, not ( ... )
to initialize your array of floats.
Note that you are doing it right in the first line:
GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f};
But wrong in the lines below:
GLfloat lightColor0[] = (0.5f, 0.5f, 0.5f, 1.0f);
In the example shown you have parentheses around the data for lightColor0
and onwards. I think you meant curly braces as used for ambientColor
.
精彩评论