Cara membuat robot sederhana di OpenGL
Berikut merupakan script lengkap membuat robot :
- #include <windows.h>
- #include <stdlib.h>
- #include <glut.h>
- void aa(void)
- {
- glClear( GL_COLOR_BUFFER_BIT);
- glBegin(GL_POLYGON);
- glColor3ub(0, 0, 255);
- glVertex2i(-50,200);
- glVertex2i(-50,100);
- glVertex2i(100,100);
- glVertex2i(100,200);
- glEnd();
- glBegin(GL_TRIANGLES);
- glColor3ub(255,0,0);
- glVertex2i(100,180);
- glVertex2i(100,250);
- glVertex2i(110,200);
- glEnd();
- glBegin(GL_TRIANGLES);
- glColor3ub(255,0,0);
- glVertex2i(-50,180);
- glVertex2i(-50,250);
- glVertex2i(-60,200);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(255,255,255);
- glVertex2i(-25,180);
- glVertex2i(75,180);
- glVertex2i(75,160);
- glVertex2i(-25,160);
- glEnd();
- glLineWidth(10);
- glBegin(GL_LINES);
- glColor3ub(255,0,0);
- glVertex2i(-15,170);
- glVertex2i(65,170);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(0, 255, 242);
- glVertex2i(0,100);
- glVertex2i(0,80);
- glVertex2i(50,80);
- glVertex2i(50,100);
- glEnd();
- glBegin(GL_TRIANGLES);
- glColor3ub(207, 207, 207);
- glVertex2i(80,70);
- glVertex2i(200,200);
- glVertex2i(190,130);
- glEnd();
- glBegin(GL_TRIANGLES);
- glVertex2i(80,70);
- glVertex2i(180,120);
- glVertex2i(170,80);
- glEnd();
- glBegin(GL_TRIANGLES);
- glVertex2i(80,70);
- glVertex2i(160,70);
- glVertex2i(150,30);
- glEnd();
- glBegin(GL_TRIANGLES);
- glVertex2i(80,70);
- glVertex2i(140,30);
- glVertex2i(130,0);
- glEnd();
- glBegin(GL_TRIANGLES);
- glColor3ub(207, 207, 207);
- glVertex2i(-40,70);
- glVertex2i(-160,200);
- glVertex2i(-150,130);
- glEnd();
- glBegin(GL_TRIANGLES);
- glVertex2i(-40,70);
- glVertex2i(-150,120);
- glVertex2i(-140,80);
- glEnd();
- glBegin(GL_TRIANGLES);
- glVertex2i(-40,70);
- glVertex2i(-130,70);
- glVertex2i(-120,30);
- glEnd();
- glBegin(GL_TRIANGLES);
- glVertex2i(-40,70);
- glVertex2i(-110,30);
- glVertex2i(-100,0);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(0,0,255);
- glVertex2i(-40,80);
- glVertex2i(-40,20);
- glVertex2i(90,20);
- glVertex2i(90,80);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(255,255,255);
- glVertex2i(30,70);
- glVertex2i(50,55);
- glVertex2i(30,25);
- glVertex2i(10,55);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(145, 0, 0);
- glVertex2i(-40,80);
- glVertex2i(-100,80);
- glVertex2i(-100,60);
- glVertex2i(-40,60);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(0,0,255);
- glVertex2i(-100,60);
- glVertex2i(-100,20);
- glVertex2i(-80,20);
- glVertex2i(-80,60);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex2i(-100,40);
- glVertex2i(-100,-10);
- glVertex2i(-120,20);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex2i(-80,40);
- glVertex2i(-80,-10);
- glVertex2i(-60,20);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(145, 0, 0);
- glVertex2i(90,80);
- glVertex2i(150,80);
- glVertex2i(150,60);
- glVertex2i(90,60);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(0,0,255);
- glVertex2i(150,60);
- glVertex2i(150,20);
- glVertex2i(130,20);
- glVertex2i(130,60);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex2i(130,40);
- glVertex2i(130,-10);
- glVertex2i(110,20);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex2i(150,40);
- glVertex2i(150,-10);
- glVertex2i(170,20);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(145, 0, 0);
- glVertex2i(-20,20);
- glVertex2i(20,20);
- glVertex2i(10,10);
- glVertex2i(-10,10);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(145, 0, 0);
- glVertex2i(70,20);
- glVertex2i(30,20);
- glVertex2i(40,10);
- glVertex2i(60,10);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(0, 255, 242);
- glVertex2i(-10,10);
- glVertex2i(10,10);
- glVertex2i(10,-20);
- glVertex2i(-10,-20);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex2i(40,10);
- glVertex2i(60,10);
- glVertex2i(60,-20);
- glVertex2i(40,-20);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3ub(145, 0, 0);
- glVertex2i(20,-20);
- glVertex2i(20,-40);
- glVertex2i(-40,-40);
- glVertex2i(-20,-20);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex2i(30,-20);
- glVertex2i(30,-40);
- glVertex2i(90,-40);
- glVertex2i(70,-20);
- glEnd();
- glFlush();
- }
- void main(int argc, char *argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGB);
- glutInitWindowPosition(100,100);
- glutInitWindowSize(720,720);
- glutCreateWindow("tugas praktikum 4");
- gluOrtho2D(-300.,300.,-300.,300.);
- glutDisplayFunc(aa);
- glutMainLoop();
- }
Komentar
Posting Komentar