Project Grafkom 1

12 Jan

Assalamualaikum,, wah wah,, sudah lama ga update blog nihh…

berhubung kemarin saya ngajar grafika komputer dan memberikan project untuk anak-anak murid saya, maka saya post kan hasil karya anak2,, walaupun hanya sebagianšŸ˜€.. semoga bisa jadi referensi..

 

menggunakan fungsi gabungan dan menghasilkan output 3D dengan memanfaatkan rotasi

#include <gl\glut.h>
GLfloat xRotated, yRotated, zRotated;
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glPushMatrix();
glLoadIdentity();
glTranslatef(0.0,0.0,-2.0);
//glRotatef(xRotated, 0.0,1.0,0.0);
//glRotatef(yRotated, 0.0,0.0,0.0);
glRotatef(zRotated, 0.0,1.0,0.0);

glScalef(1.0,1.0,1.0);

glPushMatrix();
glBegin (GL_POLYGON);
glColor3f (0.3f, 0.3f, 0.3f); // bagian frame
glVertex3f (-1, 1, 0.00);
glVertex3f (-1, -1, 0.00);
glVertex3f (1, -1, 0.00);
glVertex3f (1, 1, 0.00);
glEnd();
glBegin (GL_POLYGON);
glColor3f (0.4f, 0.4f, 0.4f); // bagian atap
glVertex3f (-0.95, 0.95, 0.00);
glVertex3f (-0.95, -0.95, 0.00);
glVertex3f (0.95, -0.95, 0.00);
glVertex3f (0.95, 0.95, 0.00);
glEnd();

glPopMatrix();

glPopMatrix();

glPushMatrix();
glLoadIdentity();
glTranslatef(0.0,-0.0,-2.0);
//glRotatef(xRotated, 0.0,1.0,0.0);
//glRotatef(yRotated, 0.0,0.0,0.0);
//glRotatef(zRotated, 1.0,0.0,0.0);

//glRotated (180.0, 0.0, 0.0, 1.0);
glScalef(1.0,1.0,1.0);

glPushMatrix();
//glBegin (GL_POLYGON);
glColor3f (1.0f, 1.0f, 1.0f); // bagian atap
glVertex3f (-0.72, 0.6, 0.00);
glVertex3f (-0.72, -0.6, 0.00);
glVertex3f (0.72, -0.6, 0.00);
glVertex3f (0.72, 0.6, 0.00);
glEnd();
glPopMatrix();

glPushMatrix();

glLineWidth(2.0f);
glBegin(GL_LINES);
glColor3f (0.4f, 0.4f, 0.4f);//untuk warna garis
glVertex3f(0.12, 0.44, 0.0);
glVertex3f(0.12, 0.34, 0.0);

glVertex3f(0.13, 0.34, 0.0);
glVertex3f(0.13, -0.60, 0.0);

glVertex3f(0.13, 0.346, 0.0);
glVertex3f(0.60, 0.24, 0.0);

glVertex3f(0.60, 0.24, 0.0);
glVertex3f(0.60, -0.60, 0.0);

glVertex3f(0.50, 0.26, 0.0);
glVertex3f(0.50, 0.30, 0.0);

glVertex3f(0.50, 0.30, 0.0);
glVertex3f(0.12, 0.44, 0.0);

glVertex3f(0.13, 0.34, 0.0);
glVertex3f(-0.08, 0.24, 0.0);

glVertex3f(-0.08, 0.24, 0.0);
glVertex3f(-0.08, -0.60, 0.0);

glVertex3f(-0.038, 0.27, 0.0);
glVertex3f(-0.038, 0.362, 0.0);

glVertex3f(-0.038, 0.362, 0.0);
glVertex3f(0.12, 0.44, 0.0);

glVertex3f(-0.08, 0.12, 0.0);
glVertex3f(-0.182, 0.216, 0.0);

glVertex3f(-0.182, 0.216, 0.0);
glVertex3f(-0.32, 0.092, 0.0);

glVertex3f(-0.182, 0.216, 0.0);
glVertex3f(-0.32, 0.092, 0.0);

glVertex3f(-0.32, 0.08, 0.0);
glVertex3f(-0.32, 0.02, 0.0);

glVertex3f(-0.34, -0.046, 0.0);
glVertex3f(-0.32, 0.02, 0.0);

glVertex3f(-0.038, 0.30, 0.0);
glVertex3f(0.12, 0.38, 0.0);

//glVertex3f(0.12, 0.38, 0.0);
//glVertex3f(0.46, 0.27, 0.0);

glVertex3f(-0.22, 0.106, 0.0);
glVertex3f(-0.22, -0.60, 0.0);

glVertex3f(-0.22, 0.106, 0.0);
glVertex3f(-0.26, 0.106, 0.0);

glVertex3f(-0.26, 0.106, 0.0);
glVertex3f(-0.32, 0.08, 0.0);

glVertex3f(-0.22, 0.106, 0.0);
glVertex3f(-0.20, 0.18, 0.0);

glVertex3f(-0.26, 0.106, 0.0);
glVertex3f(-0.226, 0.16, 0.0);

glVertex3f(-0.26, 0.08, 0.0);
glVertex3f(-0.26, -0.03, 0.0);

glVertex3f(-0.22, 0.106, 0.0);
glVertex3f(-0.08, 0.10, 0.0);

glVertex3f(-0.28, -0.166, 0.0);
glVertex3f(-0.28, -0.60, 0.0);

glVertex3f(-0.28, -0.166, 0.0);
glVertex3f(-0.34, -0.16, 0.0);

glVertex3f(-0.34, -0.16, 0.0);
glVertex3f(-0.36, -0.164, 0.0);

glVertex3f(-0.36, -0.164, 0.0);
glVertex3f(-0.36, -0.60, 0.0);

glVertex3f(-0.34, -0.046, 0.0);
glVertex3f(-0.34, -0.15, 0.0);

glVertex3f(-0.34, -0.16, 0.0);
glVertex3f(-0.34, -0.60, 0.0);

glVertex3f(-0.34, -0.076, 0.0);
glVertex3f(-0.34, -0.15, 0.0);

glVertex3f(-0.34, -0.076, 0.0);
glVertex3f(-0.412, -0.076, 0.0);

glVertex3f(-0.412, -0.076, 0.0);
glVertex3f(-0.412, 0.054, 0.0);

glVertex3f(-0.412, 0.054, 0.0);
glVertex3f(-0.666, 0.06, 0.0);

glVertex3f(-0.666, 0.06, 0.0);
glVertex3f(-0.674, 0.04, 0.0);

glVertex3f(-0.666, 0.06, 0.0);
glVertex3f(-0.666, -0.43, 0.0);

glVertex3f(-0.674, 0.04, 0.0);
glVertex3f(-0.674, -0.18, 0.0);

glVertex3f(0.90, -0.60, 0.0);
glVertex3f(-0.90, -0.60, 0.0);

glVertex3f(-0.674, -0.25, 0.0);
glVertex3f(-0.674, -0.38, 0.0);

glVertex3f(-0.674, -0.14, 0.0);
glVertex3f(-0.70, -0.14, 0.0);

glVertex3f(-0.70, -0.14, 0.0);
glVertex3f(-0.70, -0.354, 0.0);

glVertex3f(-0.70, -0.354, 0.0);
glVertex3f(-0.714, -0.354, 0.0);

glVertex3f(-0.674, -0.38, 0.0);
glVertex3f(-0.694, -0.38, 0.0);

glVertex3f(-0.694, -0.38, 0.0);
glVertex3f(-0.714, -0.354, 0.0);

glVertex3f(-0.674, -0.38, 0.0);
glVertex3f(-0.70, -0.354, 0.0);

glVertex3f(-0.714, -0.38, 0.0);
glVertex3f(-0.714, -0.42, 0.0);

glVertex3f(-0.60, -0.076, 0.0);
glVertex3f(-0.60, -0.532, 0.0);

glVertex3f(-0.412, -0.076, 0.0);
glVertex3f(-0.60, -0.076, 0.0);

glVertex3f(-0.60, -0.076, 0.0);
glVertex3f(-0.636, -0.10, 0.0);

glVertex3f(-0.636, -0.10, 0.0);
glVertex3f(-0.636, -0.48, 0.0);

glVertex3f(-0.60, -0.532, 0.0);
glVertex3f(-0.36, -0.50, 0.0);

glVertex3f(-0.60, -0.532, 0.0);
glVertex3f(-0.636, -0.48, 0.0);

glVertex3f(-0.36, -0.536, 0.0);
glVertex3f(-0.594, -0.566, 0.0);

glVertex3f(-0.594, -0.532, 0.0);
glVertex3f(-0.594, -0.56, 0.0);

glVertex3f(-0.594, -0.56, 0.0);
glVertex3f(-0.632, -0.496, 0.0);

glVertex3f(-0.632, -0.496, 0.0);
glVertex3f(-0.632, -0.480, 0.0);

glVertex3f(-0.36, -0.56, 0.0);
glVertex3f(-0.62, -0.60, 0.0);

glVertex3f(-0.692, -0.60, 0.0);
glVertex3f(-0.78, -0.40, 0.0);

glVertex3f(-0.624, -0.566, 0.0);
glVertex3f(-0.714, -0.42, 0.0);

glVertex3f(-0.694, -0.38, 0.0);
glVertex3f(-0.694, -0.45, 0.0);

glVertex3f(-0.76, -0.33, 0.0);
glVertex3f(-0.85, -0.342, 0.0);

glVertex3f(-0.76, -0.33, 0.0);
glVertex3f(-0.76, -0.45, 0.0);

glVertex3f(-0.84, -0.342, 0.0);
glVertex3f(-0.84, -0.357, 0.0);

glVertex3f(-0.82, -0.342, 0.0);
glVertex3f(-0.82, -0.356, 0.0);

glVertex3f(-0.80, -0.338, 0.0);
glVertex3f(-0.80, -0.355, 0.0);

glEnd();
glPopMatrix();

glPopMatrix();

glPushMatrix();
glLoadIdentity();
glTranslatef(-0.8,0.8,-4.0);
glRotatef(xRotated, 1.0,0.0,0.0);
glRotatef(yRotated, 0.0,1.0,0.0);
glRotatef(zRotated, 0.0,0.0,0.0);
glScalef(1.0,1.0,1.0);
glColor3f (0.0f, 0.4f, 0.0f);//untuk warna garis
glutWireSphere( 0.3, 10, 15);
//glutWireTetrahedron();
//glutWireOctahedron();
//glutSolidTeapot (0.3);
//glutWireCube (1.0);
glPopMatrix();

glPushMatrix();
glLoadIdentity();
glTranslatef(1.4,1.4,-8.0);
glRotatef(xRotated, 1.0,0.0,0.0);
glRotatef(yRotated, 0.0,1.0,0.0);
glRotatef(zRotated, 0.0,0.0,1.0);
glScalef(0.5,1.0,1.0);
glColor3f (0.8f, 0.0f, 0.0f);//untuk warna garis

//glutWireSphere( 0.3, 10, 15);
glutWireIcosahedron();
//glutWireOctahedron();
//glutSolidTeapot (0.3);
//glutWireCube (1.0);
glPopMatrix();

glPopMatrix();

glPushMatrix();
glLoadIdentity();
glTranslatef(-0.0,0.0,-4.0);
glRotatef(xRotated, 0.0,0.0,0.0);
glRotatef(yRotated, 0.0,0.0,0.0);
glRotatef(zRotated, 0.0,0.0,0.0);
glScalef(1.0,1.0,1.0);
glLineWidth(3.0f);
glBegin(GL_LINES);
//puspa
glColor3f (0.0f, 0.0f, 1.0f);//untuk warna garis

glVertex3f(0.05, 0.1, 0.0);
glVertex3f(-0.05, 0.1, 0.0);
glVertex3f(-0.05, 0.1, 0.0);
glVertex3f(-0.05, 0.0, 0.0);
glVertex3f(-0.05, 0.0, 0.0);
glVertex3f(0.05, 0.0, 0.0);
glVertex3f(0.05, 0.0, 0.0);
glVertex3f(0.05, -0.1, 0.0);
glVertex3f(0.05, -0.1, 0.0);
glVertex3f(-0.05, -0.1, 0.0);

glVertex3f(-0.1, 0.1, 0.0);
glVertex3f(-0.1, -0.1, 0.0);
glVertex3f(-0.1, -0.1, 0.0);
glVertex3f(-0.2, -0.1, 0.0);
glVertex3f(-0.2, -0.1, 0.0);
glVertex3f(-0.2, 0.1, 0.0);

glVertex3f(-0.25, 0.1, 0.0);
glVertex3f(-0.25, 0.0, 0.0);
glVertex3f(-0.25, 0.0, 0.0);
glVertex3f(-0.35, 0.0, 0.0);
glVertex3f(-0.35, 0.0, 0.0);
glVertex3f(-0.35, 0.1, 0.0);
glVertex3f(-0.35, 0.1, 0.0);
glVertex3f(-0.25, 0.1, 0.0);
glVertex3f(-0.35, 0.0, 0.0);
glVertex3f(-0.35, -0.1, 0.0);

glVertex3f(0.2, 0.1, 0.0);
glVertex3f(0.2, 0.0, 0.0);
glVertex3f(0.2, 0.0, 0.0);
glVertex3f(0.1, 0.0, 0.0);
glVertex3f(0.1, 0.0, 0.0);
glVertex3f(0.1, 0.1, 0.0);
glVertex3f(0.1, 0.1, 0.0);
glVertex3f(0.2, 0.1, 0.0);
glVertex3f(0.1, 0.0, 0.0);
glVertex3f(0.1, -0.1, 0.0);

glVertex3f(0.25, -0.1, 0.0);
glVertex3f(0.3, 0.1, 0.0);
glVertex3f(0.3, 0.1, 0.0);
glVertex3f(0.35, -0.1, 0.0);
glVertex3f(0.275, 0.0, 0.0);
glVertex3f(0.325, 0.0, 0.0);

glVertex3f(-0.4, 0.15, 0.0);
glVertex3f(-0.4, -0.15, 0.0);
glVertex3f(-0.4, -0.15, 0.0);
glVertex3f(0.4, -0.15, 0.0);
glVertex3f(0.4, -0.15, 0.0);
glVertex3f(0.4, 0.15, 0.0);
glVertex3f(0.4, 0.15, 0.0);
glVertex3f(-0.4, 0.15, 0.0);
glEnd();
glPopMatrix(); glPopMatrix();

glPushMatrix();
glLoadIdentity();
glTranslatef(1.3,0.0,-4.0);
glRotatef(xRotated, 1.0,0.0,0.0);
glRotatef(yRotated, 0.0,0.0,0.0);
glRotatef(zRotated, 0.0,0.0,0.0);
glScalef(1.0,1.0,1.0);
glColor3f (0.0f, 0.0f, 1.0f);//untuk warna garis

glLineWidth(3.0f);
glBegin(GL_LINES);
//romi
glVertex3f(0.1, 0.5, 0.0);
glVertex3f(0.2, 0.5, 0.0);
glVertex3f(0.2, 0.5, 0.0);
glVertex3f(0.2, 0.4, 0.0);
glVertex3f(0.2, 0.4, 0.0);
glVertex3f(0.1, 0.4, 0.0);
glVertex3f(0.1, 0.4, 0.0);
glVertex3f(0.1, 0.5, 0.0);
glVertex3f(0.1, 0.4, 0.0);
glVertex3f(0.1, 0.3, 0.0);
glVertex3f(0.1, 0.4, 0.0);
glVertex3f(0.2, 0.3, 0.0);

glVertex3f(0.25, 0.5, 0.0);
glVertex3f(0.35, 0.5, 0.0);
glVertex3f(0.35, 0.5, 0.0);
glVertex3f(0.35, 0.3, 0.0);
glVertex3f(0.35, 0.3, 0.0);
glVertex3f(0.25, 0.3, 0.0);
glVertex3f(0.25, 0.3, 0.0);
glVertex3f(0.25, 0.5, 0.0);

glVertex3f(0.4, 0.3, 0.0);
glVertex3f(0.4, 0.5, 0.0);
glVertex3f(0.4, 0.5, 0.0);
glVertex3f(0.45, 0.4, 0.0);
glVertex3f(0.45, 0.4, 0.0);
glVertex3f(0.5, 0.5, 0.0);
glVertex3f(0.5, 0.5, 0.0);
glVertex3f(0.5, 0.3, 0.0);

glVertex3f(0.55, 0.5, 0.0);
glVertex3f(0.55, 0.3, 0.0);

glVertex3f(0.05, 0.55, 0.0);
glVertex3f(0.05, 0.25, 0.0);
glVertex3f(0.05, 0.25, 0.0);
glVertex3f(0.6, 0.25, 0.0);
glVertex3f(0.6, 0.25, 0.0);
glVertex3f(0.6, 0.55, 0.0);
glVertex3f(0.6, 0.55, 0.0);
glVertex3f(0.05, 0.55, 0.0);

glEnd();
glPopMatrix(); glPopMatrix();

glPushMatrix();
glLoadIdentity();
glTranslatef(-1.3,0.0,-4.0);
glRotatef(xRotated, 1.0,0.0,0.0);
glRotatef(yRotated, 0.0,0.0,0.0);
glRotatef(zRotated, 0.0,0.0,0.0);
glScalef(1.0,1.0,1.0);
glColor3f (0.0f, 0.0f, 1.0f);//untuk warna garis
glPushMatrix();
glLineWidth(3.0f);
glBegin(GL_LINES);
glColor3f (0.0f, 0.0f, 1.0f);//untuk warna garis
//eko

glVertex3f(-0.1, 0.5, 0.0);
glVertex3f(-0.1, 0.3, 0.0);
glVertex3f(-0.1, 0.3, 0.0);
glVertex3f(-0.2, 0.3, 0.0);
glVertex3f(-0.2, 0.3, 0.0);
glVertex3f(-0.2, 0.5, 0.0);
glVertex3f(-0.2, 0.5, 0.0);
glVertex3f(-0.1, 0.5, 0.0);

glVertex3f(-0.25, 0.5, 0.0);
glVertex3f(-0.35, 0.4, 0.0);
glVertex3f(-0.35, 0.4, 0.0);
glVertex3f(-0.25, 0.3, 0.0);
glVertex3f(-0.35, 0.5, 0.0);
glVertex3f(-0.35, 0.3, 0.0);

glVertex3f(-0.4, 0.5, 0.0);
glVertex3f(-0.5, 0.5, 0.0);
glVertex3f(-0.5, 0.5, 0.0);
glVertex3f(-0.5, 0.4, 0.0);
glVertex3f(-0.5, 0.4, 0.0);
glVertex3f(-0.5, 0.3, 0.0);
glVertex3f(-0.5, 0.3, 0.0);
glVertex3f(-0.4, 0.3, 0.0);
glVertex3f(-0.5, 0.4, 0.0);
glVertex3f(-0.4, 0.4, 0.0);

glVertex3f(-0.05, 0.55, 0.0);
glVertex3f(-0.05, 0.25, 0.0);
glVertex3f(-0.05, 0.25, 0.0);
glVertex3f(-0.55, 0.25, 0.0);
glVertex3f(-0.55, 0.25, 0.0);
glVertex3f(-0.55, 0.55, 0.0);
glVertex3f(-0.55, 0.55, 0.0);
glVertex3f(-0.05, 0.55, 0.0);

glEnd();
glPopMatrix();
glPopMatrix();

glPushMatrix();
glLineWidth(3.0f);
glBegin(GL_LINES);
//eko
glVertex3f(-0.1, 0.5, 0.0);
glVertex3f(-0.1, 0.3, 0.0);
glVertex3f(-0.1, 0.3, 0.0);
glVertex3f(-0.2, 0.3, 0.0);
glVertex3f(-0.2, 0.3, 0.0);
glVertex3f(-0.2, 0.5, 0.0);
glVertex3f(-0.2, 0.5, 0.0);
glVertex3f(-0.1, 0.5, 0.0);

glVertex3f(-0.25, 0.5, 0.0);
glVertex3f(-0.35, 0.4, 0.0);
glVertex3f(-0.35, 0.4, 0.0);
glVertex3f(-0.25, 0.3, 0.0);
glVertex3f(-0.35, 0.5, 0.0);
glVertex3f(-0.35, 0.3, 0.0);

glVertex3f(-0.4, 0.5, 0.0);
glVertex3f(-0.5, 0.5, 0.0);
glVertex3f(-0.5, 0.5, 0.0);
glVertex3f(-0.5, 0.4, 0.0);
glVertex3f(-0.5, 0.4, 0.0);
glVertex3f(-0.5, 0.3, 0.0);
glVertex3f(-0.5, 0.3, 0.0);
glVertex3f(-0.4, 0.3, 0.0);
glVertex3f(-0.5, 0.4, 0.0);
glVertex3f(-0.4, 0.4, 0.0);

glVertex3f(-0.05, 0.55, 0.0);
glVertex3f(-0.05, 0.25, 0.0);
glVertex3f(-0.05, 0.25, 0.0);
glVertex3f(-0.55, 0.25, 0.0);
glVertex3f(-0.55, 0.25, 0.0);
glVertex3f(-0.55, 0.55, 0.0);
glVertex3f(-0.55, 0.55, 0.0);
glVertex3f(-0.05, 0.55, 0.0);

glEnd();
glPopMatrix();

glFlush();
glutSwapBuffers();
}

void Reshape(int x, int y)
{
if (y==0||x==0) return;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y);
}
void Idle(void)
{
xRotated += 0.1;
yRotated += 0.2;
zRotated += 0.3;
Display();
}

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(1024,768);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow(“PERSENTASI GRAFKOM”);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
xRotated = yRotated = zRotated = 1.0;
glClearColor(0.8,0.8,0.8,0.0);
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutIdleFunc(Idle);
glutMainLoop();
return 0;
}

ini outputnya:

nama kelompok :

eko, puspa dan romi..

semoga bermanfaat ^^

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: