Menggambar Kotak 3 Dimensi dengan 3 warna Berbeda. Komputer Grafik

 Source code

//menampilkan bentuk 3D-kubus

#include<windows.h>

#include<math.h>

#include<gl\glut.h>

void Display()

{

 glClear(GL_COLOR_BUFFER_BIT);

 glBegin(GL_POLYGON);

 glColor3f(1.0, 0.1, 0.0); //orange

 glVertex3f(0,0,0);

 glVertex3f(0.5,-0.3,0);

 glVertex3f(0.5,0.6,0);

 glVertex3f(0,0.8,0);

 glEnd();

 glBegin(GL_POLYGON);

 glColor3f(1,1,1); //pink

 glVertex3f(0.5,-0.3,0);

 glVertex3f(0.5,0.6,0);

 glVertex3f(1.3,0.8,-1);

 glVertex3f(1.3,-0.4,-1);

 glEnd();

 glBegin(GL_POLYGON);

 glColor3f (1.0, 1.0, 0.0); //hitam

 glVertex3f(1.3,0.8,-1);

 glVertex3f(0.5,0.6,0);

 glVertex3f(0,0.8,0);

 glVertex3f(0.5,0.9,0);

 glEnd();

 glFlush();

}

void reshape(int w, int h)

{

 glViewport(0,0,(GLsizei)w,(GLsizei)h);

 glMatrixMode(GL_PROJECTION);

 glFrustum(-0.5*(GLfloat)w/h,0.5*(GLfloat)w/h,-0.5,0.5,1,20);

 gluLookAt(0.5,0.5,2.5,0,0,-200,0,1,0);

}

void init(void)

{

 glClearColor(0,1,1,1);

}

int main(int args, char*argv[])

{

 glutInit( & args, argv );

 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

 glutInitWindowSize(400,400);

 glutCreateWindow("Tugas P10");

 init();

 glutDisplayFunc(Display);

 glutReshapeFunc(reshape);

 glutMainLoop();

}


hasil run



1 Comments

Previous Post Next Post