2010-07-22 4 views
3

내 세계에서 차를 그려보고 싶습니다. 하지만 내 차가 회전 할 때 조명에 문제가 있습니다. 차가 회전 할 때 빛의 위치가 바뀌는 것처럼 보입니다. 하지만 glut 함수로 간단한 큐브를 그릴 때 제대로 작동합니다.조명 문제가있는 openGL 회전

보이드는 MyDisplay() {

glLoadIdentity() 
glDisable(GL_LIGHT0); 
glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE) ; 
glColor3f(1.0,1.0,1.0); 
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
p2[0]=50.0; 
p2[1]=3.0; 
p2[2]=0.0; 
glLightfv(GL_LIGHT0,GL_POSITION,p2); 
glEnable(GL_LIGHT0); 
gluLookAt(50.0,3.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0); 
glPushMatrix(); 
glRotatef(tet,0.0,1.0,0.0); 
glutSolidCube(20); 
glPopMatrix(); 
tet+=3.141592653/4; 
glutSwapBuffers(); 
}

때 glutSolidCube (20); 내 그림 코드로 변경, 나쁜 방식으로 작동 내 코드 : 그리기

무효() {

glEnableClientState(GL_VERTEX_ARRAY); 
GLfloat CubeVertex[]={ -20.0,0.0,10.0,//\/\/\/\/\/\\\///\/\/\/\/\/\/\/\/\/\/\/\/\/\/ 
       -20.0,0.0,-10.0, 
       -20.0,3.0,-10.0, 
       -20.0,3.0,10.0, ///BIG CUBE 
      20.0,0.0,10.0, 
      20.0,0.0,-10.0, 
      20.0,3.0,-10.0, 
      20.0,3.0,10.0,////////\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ 
      -10.0,3.0,10.0, 
      -10.0,3.0,-10.0, 
      -10.0,5.0,-10.0, 
      -10.0,5.0,10.0,  //SMALL CUBE 
      10.0,3.0,10.0, 
      10.0,3.0,-10.0, 
      10.0,5.0,-10.0, 
      10.0,5.0,10.0,//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\// 
      -100.0,-2.4,100.0, 
      -100.0,-2.4,-100.0,  //FLOOR 
      100.0,-2.4,100.0, 
      100.0,-2.4,-100.0 
      };//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\// 
GLubyte big_back[]={0,3,2,1}; 
GLubyte big_front[]={4,5,6,7}; 
GLubyte big_left[]={4,0,3,7}; 
GLubyte big_right[]={1,2,6,5}; 
GLubyte big_up[]={2,3,7,6}; 
GLubyte big_down[]={0,1,5,4}; 
GLubyte small_back[]={9,10,11,8}; 
GLubyte small_front[]={12,13,14,15}; 
GLubyte small_left[]={8,11,15,12}; 
GLubyte small_right[]={9,10,14,13}; 
GLubyte small_up[]={10,11,15,14}; 
GLubyte floor[]={16,17,19,18}; 
GLsizei count[]={4,4,4,4,4,4,4,4,4,4,4,4}; 
GLvoid* indices[12]={big_back,big_front,big_left,big_right,big_up,big_down,small_back,small_front,small_left,small_right,small_up,floor}; 
glVertexPointer(3,GL_FLOAT,0,CubeVertex); 
for(int i=0;i<12;i++){//////////////////glMultiDrawElement//////////////// 
if(count[i]>0) 
    glDrawElements(GL_QUADS,count[i],GL_UNSIGNED_BYTE,indices[i]); 
}//////////////////////////////glMultiDrawElements////////////////////// 

}

감사합니다.

+0

내 코드는 glutSolidCube (20)에서 올바르게 작동하지만 glDrawElements .why에 문제가 있다고 했습니까? 감사. – pooya

답변