er

Saturday 31 January 2015

Rumah 3D OpenGL

#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<GL/glut.h>

void renderScene(void){
 glPointSize(2);
 glClear(GL_COLOR_BUFFER_BIT);

 // rgb(108, 51, 18)
 glColor3f (108.0/255.0, 51.0/255., 18.0/255.);
 glBegin(GL_TRIANGLES);
 glVertex2f (-0.9, 0.0);
 glVertex2f (-0.5, 0.5);
 glVertex2f (-0.25, 0.0);
 glEnd();

 // rgb(200, 195, 145)
 glColor3f (200.0/255.0, 195.0/255., 145.0/255.);
 glBegin(GL_POLYGON);
 glVertex2f (-0.9, -0.4);
 glVertex2f (-0.9, 0.0);
 glVertex2f (-0.25, 0.0);
 glVertex2f (-0.25, -0.4);
 glEnd();

 // rgb(220, 215, 160)
 glColor3f (220.0/255.0, 215.0/255., 160.0/255.);
 glBegin(GL_POLYGON);
 glVertex2f (-0.25, 0.0);
 glVertex2f (-0.25, -0.4);
 glVertex2f (0.8, -0.1);
 glVertex2f (0.8, 0.25);
 glEnd();
// ATAP
 //rgb(134, 64, 22)
 glColor3f (134.0/255.0, 64.0/255., 22.0/255.);
 glBegin(GL_POLYGON);
 glVertex2f (-0.5, 0.5);
 glVertex2f (-0.25, 0.0);
 glVertex2f (0.8, 0.25);
 glVertex2f (0.35, 0.65);
 glEnd();

 // rgb(142, 85, 44)
 glColor3f (142.0/255.0, 85.0/255., 44.0/255.);
 glBegin(GL_POLYGON);
 glVertex2f (0.07, 0.0);
 glVertex2f (0.25, 0.05);
 glVertex2f (0.25, -0.25);
 glVertex2f (0.07, -0.3);
 glEnd();

 glFlush();
}
void kunci(unsigned char key, int x, int y) {
 switch (key)
 {
 case 27 :
     case 'q':
 exit(0);
 break;
 }
 glutPostRedisplay();
}
int main(int argc, char *argv[])
{
 glutInit(&argc, argv);
 glutInitWindowSize(640,480);
 glutInitWindowPosition(100,100);
 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
 glutCreateWindow("Primitive Object");
 glutDisplayFunc(renderScene);
 glutKeyboardFunc(kunci);
 glutMainLoop();
 return 0;
}


Screenshot :

Comments
2 Comments

2 comments:

buset itu script dimana gan?
haha gamudeng saya.

itu pakai aplikasi codeblock :D
mari sama2 blajar hehe

Post a Comment

Berkomentarlah dengan kata-kata yang sopan, tidak spam, dan bijak ^.^
Terima Kasih telah berkunjung