OpenGL中光源的三種移動區別

來源:互聯網
上載者:User

1.光源不動:需要在設定完視圖模型變換之後。然後再設定光源的位置並且開啟。

虛擬碼如下:

glmatrixmode(gl_projection);

glloadidentity();

xxxxxxxxxx;

glmatrixmode(gl_modelview);

glloadidentity();

glfloat light_position []={1.0,1.0,1.0,1.0};//

glightfv(gl_light0,gl_position,light_position);//這兩句代碼在最i後才出現

2.獨立移動光源:

(1),在如方法1中最後再設定光源的移動。(2)在模型矩陣變化過程中,同時來考慮光源的移動。技巧就是巧妙運用glpushmatrix()和glpopmatrix();

虛擬碼如下:

glfloat light_position []={1.0,1.0,1.0,1.0};

glupushmatrix();

glulookat();

glupshmatrix();

glrotated();

gllightfv(gl_light0,gl_position,light_position);//注意gllightfv ()函數出現得位置
glupopmatrix();

然後在進行其他模型的操作。

glflush();

3.光源和觀察點一起移動:

方法就是在進行視圖變換之前設定光源位置

,接著進行視圖變換,就會以相同的方式同時影響光源和觀察點。記住光源是以視覺座標的形式儲存的。

虛擬碼:

glfloat light_position []={1.0,1.0,1.0,1.0};

glightfv(gl_light0,gl_position,light_position);//注意這兩行代碼出現在視圖設定之前。此時攝像機和視點的相對位置就固定了。

glviewport();

glmatrixmode(gl_projection);

glloadidenty();


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.