Kuda 2D Dengan Glut Dev C++


Coding

#include
#include
#define PI 3.1415926

void Display()
{
     glClear(GL_COLOR_BUFFER_BIT);
     /* Hidung */
     glBegin(GL_POLYGON);
     glColor3f(0.7,0.1,0);
     glVertex2f(155,175);
     glVertex2f(110,200);
     glVertex2f(125,225);
     glVertex2f(170,200);
     glVertex2f(155,175);
     glEnd();
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     glVertex2f(155,175);
     glVertex2f(110,200);
     glVertex2f(125,225);
     glVertex2f(170,200);
     glVertex2f(155,175);
     glEnd();
    
     /* Badan */
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     glVertex2f(125,225);
     glVertex2f(149,265);
     glVertex2f(150,285);
     glVertex2f(163,260);
     glVertex2f(178,250);
     glVertex2f(207,255);
     glVertex2f(188,242);
     glVertex2f(210,220);
     glVertex2f(350,220);
     glVertex2f(350,120);
     glVertex2f(330,120);
     glVertex2f(330,160);
     glVertex2f(225,160);
     glVertex2f(225,120);
     glVertex2f(205,120);
     glVertex2f(205,160);
     glVertex2f(180,160);
     glVertex2f(178,185);
     glVertex2f(170,200);
     glVertex2f(125,225);
     glEnd();
         
     /* Pundak */
     // Bagian 1
     glBegin(GL_POLYGON);
     glColor3f(1,0,0);
     glVertex2f(163,260);
     glVertex2f(170,275);
     glVertex2f(200,254);
     glVertex2f(178,250);
     glEnd();  
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     glVertex2f(163,260);
     glVertex2f(170,275);
     glVertex2f(200,254);
     glVertex2f(178,250);
     glVertex2f(163,260);
     glEnd();
     // Bagian 2
     glBegin(GL_POLYGON);
     glColor3f(1,0,0);
     glVertex2f(210,220);
     glVertex2f(340,220);
     glVertex2f(335,235);
     glVertex2f(220,235);
     glEnd();
     glBegin(GL_POLYGON);
     glColor3f(1,0,0);
     glVertex2f(203,252);
     glVertex2f(188,242);  
     glVertex2f(210,220);
     glVertex2f(220,235);
     glEnd();
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     glVertex2f(203,252);
     glVertex2f(220,235);
     glVertex2f(335,235);
     glVertex2f(340,220);
     glVertex2f(210,220);
     glVertex2f(188,242);
     glVertex2f(203,252);
     glEnd();
    
     /* Ekor */
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     glVertex2f(350,210);
     glVertex2f(350,200);
     glVertex2f(358,200);
     glVertex2f(358,160);
     glVertex2f(395,160);
     glVertex2f(375,170);
     glVertex2f(375,210);
     glVertex2f(350,210);
     glEnd();

     /* Kaki */
     // Bagian 1
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     glVertex2f(190,128);
     glVertex2f(190,160);
     glEnd();
     // Bagian 2
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     glVertex2f(315,128);
     glVertex2f(315,160);
     glEnd();
     // Alas Kaki Bagian 1
     glBegin(GL_POLYGON);
     glColor3f(0,0,0);
     glVertex2f(350,120);
     glVertex2f(350,110);
     glVertex2f(320,110);
     glVertex2f(330,120);
     glVertex2f(350,120);
     glEnd();
     glBegin(GL_POLYGON);
     glColor3f(0,0,0);
     glVertex2f(330,118);
     glVertex2f(305,118);
     glVertex2f(315,128);
     glVertex2f(330,128);
     glVertex2f(330,118);
     glEnd();
     // Alas Kaki Bagian 2   
     glBegin(GL_POLYGON);
     glColor3f(0,0,0);
     glVertex2f(205,118);
     glVertex2f(180,118);
     glVertex2f(190,128);
     glVertex2f(205,128);
     glVertex2f(205,118);
     glEnd();
     glBegin(GL_POLYGON);
     glColor3f(0,0,0);
     glVertex2f(225,120);
     glVertex2f(225,110);
     glVertex2f(195,110);
     glVertex2f(205,120);
     glVertex2f(225,120);
     glEnd();    
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     glVertex2f(330,160);
     glVertex2f(330,180);
     glEnd();
    
     /* Mata */
     GLint circle_points=100;
     GLint radius1=10;
     GLint radius2=10;
     GLint i;
     GLdouble theta;
     glBegin(GL_POLYGON);
     glColor3f(1,1,1);
     for(i=0;i     {
       theta = 2*PI*i/circle_points;
       glVertex2f(135+radius1*cos(theta),243+radius2*sin(theta));
       }   
     glEnd();
    
     GLint j;
     glBegin(GL_POLYGON);
     glColor3f(1,1,1);
     for(j=0;j     {
       theta = 2*PI*j/circle_points;
       glVertex2f(165+radius1*cos(theta),230+radius2*sin(theta));
       }  
     glEnd();
    
     GLint k;
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     for(k=0;k     {
       theta = 2*PI*k/circle_points;
       glVertex2f(135+radius1*cos(theta),243+radius2*sin(theta));
       }   
     glEnd();
         
     GLint l;
     glBegin(GL_LINE_STRIP);
     glColor3f(0,0,0);
     for(l=0;l     {
       theta = 2*PI*l/circle_points;
       glVertex2f(165+radius1*cos(theta),230+radius2*sin(theta));
       }  
     glEnd();
    
     glBegin(GL_POINTS);
     glColor3f(0,0,0);
     glVertex2f(136,240);
     glVertex2f(160,230);
     glEnd();
    
     glBegin(GL_LINES);
     glColor3f(0,0,0);
     glVertex2f(120,199);
     glVertex2f(128,213);
     glEnd();
     glBegin(GL_LINES);
     glColor3f(0,0,0);
     glVertex2f(150,200);
     glVertex2f(143,188);
     glEnd();
     glFlush();
}
void reshape(int w,int h)
{
     glViewport(0,0,(GLsizei)w,(GLsizei)h);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     gluOrtho2D(0,500,0,500);
     }
void init()
{
     glEnable (GL_LINE_SMOOTH);
     glEnable (GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     glHint(GL_LINE_SMOOTH_HINT | GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);
     glClearColor(1,1,1,1);
     glLineWidth(1);
     glPointSize(5);
}
int main(int args,char* argv[])
{
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(500,500);
    glutCreateWindow("Habibul Hakim [12111042]");
    init();
    glutDisplayFunc(Display);
    glutReshapeFunc(reshape);
    glutMainLoop();
}

Post a Comment

1. Jangan lupa tinggalkan Likenya ya
2. Berkomentarlah dengan baik dan sopan

[blogger]

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget