Wednesday, 6 November 2013

Drawing 3D Object and Scenes | Computer Graphics Lab Manual | Anna University Chennai | Final Year IT Department



9:PROGRAM:

#include
#include
void drawCube(){
    glBegin(GL_QUADS);
    glColor3f(1,0,0);
    glVertex3f(1,1,1);
    glVertex3f(-1,1,1);
    glVertex3f(-1,-1,1);
    glVertex3f(1,-1,1);
    glColor3f(0,1,1);
    glVertex3f(1,1,-1);
    glVertex3f(-1,1,-1);
    glVertex3f(-1,-1,-1);
    glVertex3f(1,-1,-1);
    glColor3f(0,1,0);
    glVertex3f(1,1,1);
    glVertex3f(1,-1,1);
    glVertex3f(1,-1,-1);
    glVertex3f(1,1,-1);
    glColor3f(1,0,1);
    glVertex3f(-1,1,1);
    glVertex3f(-1,-1,1);
    glVertex3f(-1,-1,-1);
    glVertex3f(-1,1,-1);
    glColor3f(0,0,1);
    glVertex3f(1,1,1);
    glVertex3f(-1,1,1);
    glVertex3f(-1,1,-1);
    glVertex3f(1,1,-1);
    glColor3f(1,1,0);
    glVertex3f(1,-1,1);
    glVertex3f(-1,-1,1);
    glVertex3f(-1,-1,-1);
    glVertex3f(1,-1,-1);
    glEnd();
}
void idle(){
    glutPostRedisplay();}
float deg= 0.0;
void display(){
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0,0,-3);
    deg += 0.01;
    glRotatef(2*deg,0,0,1);
    glRotatef(deg,0,1,0);
    drawCube();
glutSwapBuffers();
}
void reshape(int width,int height){
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0,0,width,height);
    float fovy = 60;
    float aspect_ratio = float(width) / height;
    float near_clip = 0.01;
    float far_clip = 100;
   gluPerspective(fovy, aspect_ratio, near_clip, far_clip );
   glMatrixMode(GL_MODELVIEW);
}
void key(unsigned char key,int x,int y){
    if(key == 27)//esc
        exit(0);}
void init(){
    glutInitWindowSize(800,600);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Tutorial Basics");
   glutIdleFunc(idle);
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(key);
   glEnable(GL_DEPTH_TEST);
}
int main(int argc, char ** argv){
    glutInit(&argc, argv);
    init();
    glutMainLoop();
    return 0;

}                           

No comments:

Don't You Think this Awesome Post should be shared ??
| Drawing 3D Object and Scenes | Computer Graphics Lab Manual | Anna University Chennai | Final Year IT Department |
Back To Top Related Posts Plugin for WordPress, Blogger...