本文介绍了在C ++中OpenGL的定位并直射光之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是做了从videotutorialsrock.com教程照明在C ++中的OpenGL。我明白了环境光,但不明白的位置和光线直射光之间的差别,因为这个想法和双方的code看起来非常相似。这是我的code为定位的光:

I just did a tutorial from videotutorialsrock.com on lighting in C++ OpenGL. I understand ambient light, but don't understand the difference between positioned light and direct light, since the idea and the code of both looked very similar. Here's my code for positioned light:

//Add positioned light
GLfloat lightColor0[] = {.6, .6, .6, 1};
GLfloat lightPos0[] = {4, 0, 8, 1};
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);

和定向光:

//Add direct light
GLfloat lightColor1[] = {.5, .2, .2, 1};
GLfloat lightPos1[] = {-1, .5, .5, 0};
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);

有人能解释一下吗?

Could someone explain?

推荐答案

在定向,光线只能从一个方向来了,而一个点光源辐射光在从它的每一个方向。

In directional, the light is only coming from a single direction, while a point light radiates light out in every direction from it.

定向光可以用来模拟一个点光源的非常的很远,如太阳照耀着大地。

Directional light can be used to simulate a point light extremely far away, such as the sun shining on earth.

(图片信贷okino.com)

(image credit to okino.com)

这篇关于在C ++中OpenGL的定位并直射光之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 06:39