Sebagai ganti ditiadakan nya pratikum grafkom. maka kita diberi tugas pengganti dan ini tugas pertamanya yaitu menyusun segitiga , berikut codingya ;
/**********************************************************************/
/******************************************/
/* Sierpinski Gasket (manual) */
/******************************************/
#include <windows.h>
#include <gl\gl.h>
#include <gl\glut.h>
void init(void);
void display(void);
void keyboard(unsigned char, int, int);
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(50, 50);
glutCreateWindow("gasket Sierpinski (manual)");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard); /* set keyboard handler */
glutMainLoop();
return 0;
}
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15.0, 15.0, -15.0, 15.0, -15.0, 15.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0, 0.0); // segitiga baris 1
glVertex3f(0.0, 15.0, 0.0);
glVertex3f(-3.0, 9.0, 0.0);
glVertex3f(3.0, 9.0, 0.0);
glColor3f(0.0, 0.0, 0.0); // segitiga baris 2
glVertex3f(-3.0, 9.0, 0.0);
glVertex3f(-6.0, 3.0, 0.0);
glVertex3f( 0.0, 3.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glVertex3f( 3.0, 9.0, 0.0);
glVertex3f( 6.0, 3.0, 0.0);
glVertex3f( 0.0, 3.0, 0.0);
glColor3f(0.0, 0.0, 0.0); // segitiga baris 3
glVertex3f(-6.0, 3.0, 0.0);
glVertex3f(-9.0, -3.0, 0.0);
glVertex3f( -3.0,-3.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glVertex3f( 6.0, 3.0, 0.0);
glVertex3f( 9.0, -3.0, 0.0);
glVertex3f( 3.0, -3.0, 0.0);
glColor3f(0.0, 0.0, 0.0); // segitiga baris 4
glVertex3f(-9.0, -3.0, 0.0);
glVertex3f(-12.0, -9.0, 0.0);
glVertex3f( -6.0,-9.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glVertex3f( 9.0, -3.0, 0.0);
glVertex3f( 12.0, -9.0, 0.0);
glVertex3f( 6.0, -9.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glVertex3f(-3.0, -3.0, 0.0);
glVertex3f(-6.0, -9.0, 0.0);
glVertex3f( 0.0,-9.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glVertex3f( 3.0, -3.0, 0.0);
glVertex3f( 6.0, -9.0, 0.0);
glVertex3f( 0.0, -9.0, 0.0);
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
/* this is the keyboard event handler
the x and y parameters are the mouse
coordintes when the key was struck */
switch (key)
{
case 'u':
case 'U':
glRotatef(3.0, 1.0, 0.0, 0.0); /* rotate up */
break;
case 'd':
case 'D':
glRotatef(-3.0, 1.0, 0.0, 0.0); /* rotate down */
break;
case 'l':
case 'L':
glRotatef(3.0, 0.0, 1.0, 0.0); /* rotate left */
break;
case 'r':
case 'R':
glRotatef(-3.0, 0.0, 1.0, 0.0); /* rotate right */
}
display(); /* repaint the window */
}
/**********************************************************************/
dan setelah dijalankan hasilnya seperti ini
Jika Pusing dengan coding diatas berikut sourcode yang udah jadi Klik Download
Tidak ada komentar:
Posting Komentar