2014年4月11日 星期五

01160661 Week08 , Doreamon


#include <GL/glut.h>
//#include "glm.h"
//GLMmodle *modle;
float angle=0;
void eye()
{
 glPushMatrix();
  glTranslatef(-0.1, 0.4, 0.2);
  glColor3f(1, 1, 1);
  glutSolidSphere(0.1, 20, 20);
 
  glColor3f(0,0,0);
  glTranslatef(-0.02, 0.05 , 0.07);
  glutSolidSphere(0.03, 10, 10);
 glPopMatrix();
 glPushMatrix();
  glTranslatef(0.1, 0.4, 0.2);
  glColor3f(1, 1, 1);
  glutSolidSphere(0.1, 20, 20);
 
  glColor3f(0,0,0);
  glTranslatef(-0.02, 0.05 , 0.07);
  glutSolidSphere(0.03, 10, 10);
 glPopMatrix();
}
void head()
{
 glPushMatrix();
  glTranslatef(0, 0.3, 0);
  glColor3f(0, 0, 1);
  glutSolidSphere(0.3, 30, 30);
 
  glColor3f(1,1,1);
  glTranslatef(0, -0.05 , 0.1);
  glutSolidSphere(0.24, 30, 30);
 glPopMatrix();
}
void display()
{
 glEnable(GL_DEPTH_TEST);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
  glRotatef(angle, 0, 1 ,0);
  head();
  eye();
 glPopMatrix();
 glutSwapBuffers();
}
void timer(int t)
{
 glutTimerFunc(20,timer,1);
 angle++;
 glutPostRedisplay();
}
const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };//打光
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };//打光
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };//打光
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };//打光//-5.0f把光打到前面

int main()
{
 glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
 glutCreateWindow("week08");
 glutDisplayFunc(display);

    glEnable(GL_LIGHT0);//打光
    glEnable(GL_NORMALIZE);//打光
    glEnable(GL_COLOR_MATERIAL);//打光
    glEnable(GL_LIGHTING);//打光
 
    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);//打光
// model=glmReadOBJ("檔名");
// glmUnitize(model);
 glutTimerFunc(2000,timer,1);
 glutMainLoop();
}

沒有留言:

張貼留言