c++ - 如何初始化 GLfloat 数组?

标签 c++ c

我想在我创建的项目中添加一些光照,但出现以下编译器错误:

error C2440: 'initializing' : cannot convert from 'float' to 'GLfloat []' 

问题是什么?

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);

最佳答案

您使用了错误的数组初始化语法。您不能使用 () 来列出数组元素。
语法是 { list_of_the_elements }

所以将 () 改为 {}

GLfloat lightColor0[] = (0.5f, 0.5f, 0.5f, 1.0f);

GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f};

关于c++ - 如何初始化 GLfloat 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5389792/

相关文章:

c++ - Open Inventor 中的 SoRayPickAction?

c - 在 c 的命令行中使用标志读写文件

c - 声明和定义之间的数组/指针不匹配 - 那么会发生什么?

c - C 编译器的默认结构填充

c++ - select() 没有获取标准输入

c++ - 基于 GLEW 的程序无法编译

比较 If 和 Else 上的两个函数

c++ - int main(int argc,char* argv[]) 为什么argc给出2个参数?

c++ - 指向模板接口(interface)的唯一指针

c++ - cpp : delete folder open by others