資源簡介
用opengl實現的一個帶有光照效果和材質效果的立方體模型
代碼片段和文件信息
#include??????
#include???????????
#include???????????
#include???????????
static?const?GLfloat?vertex_list[][3]?=?{
-0.5f?-0.5f?-0.5f
0.5f?-0.5f?-0.5f
0.5f?0.5f?-0.5f
-0.5f?0.5f?-0.5f
-0.5f?-0.5f?0.5f
0.5f?-0.5f?0.5f
0.5f?0.5f?0.5f
-0.5f?0.5f?0.5f
};
??GLfloat?colors[][3]?=?{
??{?1.0?0.0?0.0?}
??{?1.0?1.0?0.0?}
??{?0.0?1.0?0.0?}
??{?0.0?1.0?1.0?}
??{?1.0?0.0?1.0?}
??{?0.0?0.0?1.0?}
??};
??static?const?GLint?index_list[][4]?=?{
??0?1?2?3//bottem????
??0?3?7?4//left????
??2?3?7?6//front????
??1?2?6?5//right????
??0?1?5?4//back????
??4?5?6?7//top????
??};
??void?myDisplay(void){
??glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
??glEnable(GL_DEPTH_TEST);
??
??glEnable(GL_LIGHT0);?//使用第0號光照??
??glEnable(GL_LIGHTING);?//在后面的渲染中使用光照??
??GLfloat?sun_light_position[]?=?{?0.0f?0.0f?0.0f?1.0f?};
?????????//定義??的漫反射特性
?????????GLfloat?mat_diffuse[]={
??1.0?0.0?0.01.0
??????????1.0?1.0?0.01.0
??0.0?1.0?0.01.0
??0.0?1.0?1.01.0
??1.0?0.0?1.01.0
評論
共有 條評論