OpenGL两个光源下的三维静物场景

设置两组Phong光源,绘制几个不同的三维模型,设置了透明度,加上键盘交互控制旋转

OpenGL两个光源下的三维静物场景_第1张图片

设置光源的代码:


void init(void) {
	GLfloat light_position1[] = { 5.0, 5.0, 5.0, 1.0 };
	GLfloat ambient1[] = { 0.2, 0.2, 0.2, 1.0 };
	GLfloat diffuse1[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat specular1[] = { 1.0, 1.0, 1.0, 1.0 };

	GLfloat light_position2[] = { -10.0, -10.0, -10.0, 0.0 };
	GLfloat ambient2[] = { 0.2, 0.2, 0.2, 1.0 };
	GLfloat diffuse2[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat specular2[] = { 1.0, 1.0, 1.0, 1.0 };

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel(GL_SMOOTH);

	glLightfv(GL_LIGHT0, GL_POSITION, light_position1);
	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
	glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);

	glLightfv(GL_LIGHT1, GL_POSITION, light_position2);
	glLightfv(GL_LIGHT1, GL_AMBIENT, ambient2);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2);
	glLightfv(GL_LIGHT1, GL_SPECULAR, specular2);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);
}

你可能感兴趣的:(c++)