我想在我的環境中使用C++在opengl中創建路燈。我需要爲此創建聚光燈,我已經編寫了下面的代碼,但它不能用作聚光燈。我做錯了什麼,或者你有什麼解決方案來解決我的問題?在opengl中創建路燈
GLfloat ambientLight[] = {0.7f, 0.2f, 0.2f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
GLfloat directedLight[] = {0.7f, 0.7f, 0.7f, 1.0f};
GLfloat directedLightPos[] = {-10.0f, 15.0f, 20.0f, 0.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, directedLight);
glLightfv(GL_LIGHT0, GL_POSITION, directedLightPos);
謝謝。
+1。另外:對於聚光燈,位置上的最後一個元素不需要爲零,並且GL_SPOT_CUTOFF需要小於90(對於light0,默認爲180)。 – 2011-12-26 16:56:55
感謝您的回答。我編輯我的代碼如下,但環境仍然很暗。我錯過了什麼? glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); GLfloat spotLightColour [] = {1.0,0.0,1.0}; GLfloat spotlightDirection [] = {0.0,-1.0,0.0}; GLfloat directedLightPos [] = {100.0f,100.0f,100.0f,10.0f}; glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,45); glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,spotlightDirection); glLightfv(GL_LIGHT0,GL_POSITION,directedLightPos); glLightfv(GL_LIGHT0,GL_SPECULAR,spotLightColour); glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,120); – goncag 2011-12-27 17:23:42