Ad 468 X 60

Selasa, 21 Oktober 2014

Widgets

Membuat Robot dengan OpenGl C++

CODING

#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
void mydisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
//bacground
glBegin(GL_POLYGON);
glColor3f(0,0,0);//make the color Dark Blue
glVertex2f(-1, 1);
glVertex2f(-1, -99);
glVertex2f(1, -99);
glVertex2f(1, 1);
glEnd();

//pinggang
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,255.0); //make the color Dark Blue
glVertex2f(-0.25, -0.2);
glVertex2f(-0.25, 0.1);
glVertex2f(0.25, 0.1);
glVertex2f(0.25, -0.2);
glEnd();
//pinggang warna
glBegin(GL_POLYGON);
glColor3f(1,0,0); //make the color Dark Blue
glVertex2f(-0.25, -0.2);
glVertex2f(-0.25, 0.1);
glVertex2f(-0.1, 0.1);
glVertex2f(-0.25, -0.2);
glEnd();
//pinggang warna
glBegin(GL_POLYGON);
glColor3f(1,0,0); //make the color Dark Blue
glVertex2f(0.25, -0.2);
glVertex2f(0.25, 0.1);
glVertex2f(0.1, 0.1);
glVertex2f(0.25, -0.2);
glEnd();
//pinggul kiri
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(-0.2, -0.35);
glVertex2f(-0.2, -0.2);
glVertex2f(-0.05, -0.2);
glVertex2f(-0.05, -0.35);
glEnd();
//bawah pinggul kiri
glBegin(GL_POLYGON);
glColor3f(255.0,0.0,0.0); //make the color Dark Blue
glVertex2f(-0.25, -0.85);
glVertex2f(-0.25, -0.35);
glVertex2f(-0.025, -0.35);
glVertex2f(-0.025, -0.85);
glEnd();
//bawah pinggul kiri (kotak)
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0); //make the color Dark Blue
glVertex2f(-0.2, -0.75);
glVertex2f(-0.2, -0.7);
glVertex2f(-0.05, -0.7);
glVertex2f(-0.05, -0.75);
glEnd();
//bawah pinggul kiri (kotak)
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0); //make the color Dark Blue
glVertex2f(-0.2, -0.65);
glVertex2f(-0.2, -0.6);
glVertex2f(-0.05, -0.6);
glVertex2f(-0.05, -0.65);
glEnd();
//bawah pinggul kiri (kotak)
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0); //make the color Dark Blue
glVertex2f(-0.2, -0.55);
glVertex2f(-0.2, -0.5);
glVertex2f(-0.05, -0.5);
glVertex2f(-0.05, -0.55);
glEnd();
//kaki
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(-0.3, -0.97);
glVertex2f(-0.2, -0.85);
glVertex2f(-0.05, -0.85);
glVertex2f(-0.05, -0.97);
glEnd();
//pinggul kanan
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(0.05, -0.35);
glVertex2f(0.05, -0.2);
glVertex2f(0.2, -0.2);
glVertex2f(0.2, -0.35);
glEnd();
//bawah pinggul kanan
glBegin(GL_POLYGON);
glColor3f(255.0,0.0,0.0); //make the color Dark Blue
glVertex2f(0.025, -0.85);
glVertex2f(0.025, -0.35);
glVertex2f(0.25, -0.35);
glVertex2f(0.25, -0.85);
glEnd();
//bawah pinggul kanan (kotak)
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0); //make the color Dark Blue
glVertex2f(0.05, -0.75);
glVertex2f(0.05, -0.7);
glVertex2f(0.2, -0.7);
glVertex2f(0.2, -0.75);
glEnd();
//bawah pinggul kanan (kotak)
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0); //make the color Dark Blue
glVertex2f(0.05, -0.65);
glVertex2f(0.05, -0.6);
glVertex2f(0.2, -0.6);
glVertex2f(0.2, -0.65);
glEnd();
//bawah pinggul kanan (kotak)
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0); //make the color Dark Blue
glVertex2f(0.05, -0.55);
glVertex2f(0.05, -0.5);
glVertex2f(0.2, -0.5);
glVertex2f(0.2, -0.55);
glEnd();
//kaki
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(0.05, -0.97);
glVertex2f(0.05, -0.85);
glVertex2f(0.2, -0.85);
glVertex2f(0.3, -0.97);
glEnd();
//perut
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(-0.2, 0.1);
glVertex2f(-0.2, 0.3);
glVertex2f(0.2, 0.3);
glVertex2f(0.2, 0.1);
glEnd();
//dada
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,255.0); //make the color Dark Blue
glVertex2f(-0.3, 0.3);
glVertex2f(-0.3, 0.5);
glVertex2f(0.3, 0.5);
glVertex2f(0.3, 0.3);
glEnd();
//dada leher
glBegin(GL_POLYGON);
glColor3f(1,0,0); //make the color Dark Blue
glVertex2f(-0.1, 0.4);
glVertex2f(-0.15, 0.5);
glVertex2f(0.15, 0.5);
glVertex2f(0.1, 0.4);
glEnd();
//dada leher hitam
glBegin(GL_POLYGON);
glColor3f(1,1,0); //make the color Dark Blue
glVertex2f(-0.1, 0.43);
glVertex2f(-0.15, 0.5);
glVertex2f(0.15, 0.5);
glVertex2f(0.1, 0.43);
glEnd();
//lengan kanan
glBegin(GL_POLYGON);
glColor3f(179.0,179.0,179.0); //make the color Dark Blue
glVertex2f(0.3, 0.3);
glVertex2f(0.3, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.45, 0.3);
glEnd();
//lengan kanan
glBegin(GL_POLYGON);
glColor3f(179.0,179.0,179.0); //make the color Dark Blue
glVertex2f(0.7, 0.1);
glVertex2f(0.7, 0.5);
glVertex2f(0.7, 0.5);
glVertex2f(0.7, 0.1);
glEnd();
//lengan kanan warna
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,255.0); //make the color Dark Blue
glVertex2f(0.31, 0.47);
glVertex2f(0.31, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.45, 0.47);
glEnd();
//lengan kiri
glBegin(GL_POLYGON);
glColor3f(179.0,179.0,179.0); //make the color Dark Blue
glVertex2f(-0.45, 0.3);
glVertex2f(-0.5, 0.5);
glVertex2f(-0.3, 0.5);
glVertex2f(-0.3, 0.3);
glEnd();
//lengan kiri warna
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,255.0); //make the color Dark Blue
glVertex2f(-0.45, 0.47);
glVertex2f(-0.5, 0.5);
glVertex2f(-0.31, 0.5);
glVertex2f(-0.31, 0.47);
glEnd();
//leher
glBegin(GL_POLYGON);
glColor3f(1,0,0); //make the color Dark Blue
glVertex2f(-0.1, 0.5);
glVertex2f(-0.08, 0.6);
glVertex2f(0.08, 0.6);
glVertex2f(0.1, 0.5);
glEnd();
//kepala
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(-0.1, 0.6);
glVertex2f(-0.1, 0.75);
glVertex2f(0.1, 0.75);
glVertex2f(0.1, 0.6);
glEnd();
//mata kiri
glBegin(GL_POLYGON);
glColor3f(0,0,0); //make the color Dark Blue
glVertex2f(-0.08, 0.69);
glVertex2f(-0.1, 0.72);
glVertex2f(-0.03, 0.72);
glVertex2f(-0.01, 0.69);
glEnd();
//mata kanan
glBegin(GL_POLYGON);
glColor3f(0,0,0); //make the color Dark Blue
glVertex2f(0.01, 0.69);
glVertex2f(0.03, 0.72);
glVertex2f(0.1, 0.72);
glVertex2f(0.08, 0.69);
glEnd();
//mulut
glBegin(GL_POLYGON);
glColor3f(0,0,0); //make the color Dark Blue
glVertex2f(-0.05, 0.62);
glVertex2f(-0.05, 0.65);
glVertex2f(0.05, 0.65);
glVertex2f(0.05, 0.62);
glEnd();
//kuping kanan
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,255.0); //make the color Dark Blue
glVertex2f(0.1, 0.65);
glVertex2f(0.1, 0.85);
glVertex2f(0.15, 0.75);
glVertex2f(0.12, 0.65);
glEnd();
//kuping kiri
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,255.0); //make the color Dark Blue
glVertex2f(-0.12, 0.65);
glVertex2f(-0.15, 0.75);
glVertex2f(-0.1, 0.85);
glVertex2f(-0.1, 0.65);
glEnd();
//tangan kiri
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(-0.42, 0.4);
glVertex2f(-0.42, 0.2);
glVertex2f(-0.3, 0.2);
glVertex2f(-0.3, 0.4);
glEnd();
//tangan kiri panjang
glBegin(GL_POLYGON);
glColor3f(255.0,0.0,0.0); //make the color Dark Blue
glVertex2f(-0.45, 0.2);
glVertex2f(-0.45, 0.0);
glVertex2f(-0.3, 0.0);
glVertex2f(-0.3, 0.2);
glEnd();
//genggam
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(-0.4, 0.0);
glVertex2f(-0.4, -0.1);
glVertex2f(-0.3, -0.1);
glVertex2f(-0.3, 0.0);
glEnd();
//tangan kanan
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(0.3, 0.4);
glVertex2f(0.3, 0.2);
glVertex2f(0.42, 0.2);
glVertex2f(0.42, 0.4);
glEnd();
//tangan kanan panjang
glBegin(GL_POLYGON);
glColor3f(255.0,0.0,0.0); //make the color Dark Blue
glVertex2f(0.3, 0.2);
glVertex2f(0.3, 0.0);
glVertex2f(0.45, 0.0);
glVertex2f(0.45, 0.2);
glEnd();
//genggam kanan
glBegin(GL_POLYGON);
glColor3f(1,1,1); //make the color Dark Blue
glVertex2f(0.3, 0.0);
glVertex2f(0.3, -0.1);
glVertex2f(0.4, -0.1);
glVertex2f(0.4, 0.0);
glEnd();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600,700);
glutInitWindowPosition(0,0);
glutCreateWindow("gundam");
glutDisplayFunc(mydisplay);
glutMainLoop();
}

Output :

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
Author: Mohammad
Mohammad is the founder of STC Network which offers Web Services and Online Business Solutions to clients around the globe. Read More →

1 komentar: