OpenGL画3D圆柱形线段时的光照问题
我在环境下用OpenGL画线圈图,是用4边形逼近圆柱形线段,但光照总调节不好,图形没有立体感,哪位大侠帮忙调一下?正视图 旋转一定角度后的截图
光照设置代码:static float light_ambient[] = {1,1,1,1.0};//{0.5,1,1,1.0};
static float light_diffuse[] = {1.0,1.0,1.0,1.0};//{1,0.5,1,1.0};
static float light_specular[] = {0.6,0.6,0.6,1.0};//{1,0.5,1,1.0};
static float light_position[] = {0.0,10.0,60.0,1.0};//{90.0,90.0,150.0,1.0};{150.0,90.0,150.0,1.0}
static float dirvector[]={0.0,0.0,1.0};
static float light_ambient1[] = {1.0,1.0,1.0,1.0};//{0.6,0.6,0.6,1.0};
static float light_diffuse1[] = {1.0,1.0,1.0,1.0};//{0.6,0.6,0.6,1.0};
static float light_position1[] = {0.0,20.0,20.0,1.0};//w值为1时是定向光源,为0时是无穷远处
static float back_mat_shininess[] = {60.0};// {60.0};
static float back_mat_specular[] = {1.0,1.0,1.0,1.0};//{0.5,0.5,0.2,1.0};
static float back_mat_diffuse[] = {1.0,1.0,1.0,1.0};//{1.0,0.9,0.2,1.0};
static float Imodel_ambient[] = {1.0,1.0,1.0,1.0};//{0.6,0.3,1.0,1.0}
static float Imodel_twoside[] = {GL_TRUE};
glClearColor(0.0,0.0,0.0,0.0);// 清屏
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
/*设置光照*/
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);//定义光源环境光
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);//定义光源漫反射光
glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);//定义光源镜面反射光
glLightfv(GL_LIGHT0,GL_POSITION,light_position);//定义光源位置
glLightfv(GL_LIGHT1,GL_AMBIENT,light_ambient1);//定义光源环境光
glLightfv(GL_LIGHT1,GL_DIFFUSE,light_diffuse1);//定义光源漫射光
glLightfv(GL_LIGHT1,GL_POSITION,light_position1);
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,dirvector);//定义光源环境光
glLightf (GL_LIGHT1,GL_SPOT_CUTOFF,80);//定义光源漫反射光
glLightf (GL_LIGHT1,GL_SPOT_EXPONENT,0.5);//定义光源镜面反射光
/*设置材质*/
glMaterialfv(GL_BACK,GL_DIFFUSE,back_mat_diffuse);
glMaterialfv(GL_BACK,GL_SPECULAR,back_mat_specular);
glMaterialfv(GL_BACK,GL_SHININESS,back_mat_shininess);
/*设置光照模型参数*/
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Imodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,Imodel_twoside);
//glLightModelf (GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
/*激活关照*/
glEnable(GL_LIGHTING);//启动光照模型
glEnable(GL_LIGHT0);//使光源GL_LIGHT0有效
glEnable(GL_LIGHT1);
glShadeModel(GL_SMOOTH); //启用阴影平滑
////////////////////////////////////////////////////////////////////
glMatrixMode(GL_PROJECTION);// 选择投影矩阵
glLoadIdentity();// 重置投影矩阵
if(w<=h)
glOrtho(-7.0,7.0,-7.0*(GLfloat)h/(GLfloat)w,7.0*(GLfloat)h/(GLfloat)w,-700,700.0);//正视投影
else
glOrtho(-7.0*(GLfloat)h/(GLfloat)w, 7.0*(GLfloat)h/(GLfloat)w,-7.0,7.0,-700.0,700.0);
//glColor3f(0.3f,1.0f,0.5f);
glMatrixMode(GL_MODELVIEW); // 选择模型观察矩阵
glLoadIdentity();// 重置模型观察矩阵