er

Berbagai Tutorial dan Info Menarik

Belajar, Berjuang, dan Bertaqwa

Saturday 31 January 2015

Rumah Sederhana 3D

Dengan menggunakan aplikasi Sweet Home 3d. saya membuat model replika rumah sendiri. dan hasilnya cukup bagus dengan menggunakan aplikasi tersebut yang menurut saya, sangat mudah digunakan khususnya bagi perancang bangunan rumah seperti arsitek. hehe



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 :

Primitve Object 3D OpenGL

#include <Windows.h>
#include <iostream>
#include <gl\GL.h>
#include <gl\GLU.h>
#include <gl\glut.h>
#include <math.h>
void renderScene(void){

 glClear(GL_COLOR_BUFFER_BIT);

 // Draw a white torus of outer radius 3, inner radius 0.5 with 15 stacks
 // and 30 slices.
 glColor3f(1.0, 1.0, 1.0);
 //glutWireTorus(0.5, 3, 15, 30);
 glutWireCube(1.3);

 // Draw a red x-axis, a green y-axis, and a blue z-axis. Each of the
 // axes are ten units long.
 glBegin(GL_LINES);
 glColor3f(1, 0, 0); glVertex3f(0, 0, 0); glVertex3f(10, 0, 0);
 glColor3f(0, 1, 0); glVertex3f(0, 0, 0); glVertex3f(0, 10, 0);
 glColor3f(0, 0, 1); glVertex3f(0, 0, 0); glVertex3f(0, 0, 10);
 glEnd();

 glFlush();
}
void kunci(unsigned char key, int x, int y) {
 switch (key)
 {
 case 27 :
 case 'q':
 exit(0);
 break;
 }
 glutPostRedisplay();
}
void init() {

 // Set the current clear color to black and the current drawing color to
 // white.
 glClearColor(0.0, 0.0, 0.0, 1.0);
 glColor3f(1.0, 1.0, 1.0);

 // Set the camera lens to have a 60 degree (vertical) field of view, an
 // aspect ratio of 4/3, and have everything closer than 1 unit to the
 // camera and greater than 40 units distant clipped away.
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(60.0, 4.0/3.0, 1, 40);

 // Position camera at (4, 6, 5) looking at (0, 0, 0) with the vector
 // <0, 1, 0> pointing upward.
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 gluLookAt(4, 6, 5, 0, 0, 0, 0, 1, 0);
}

int main(int argc, char *argv[])
{
 glutInit(&argc, argv);
 glutInitWindowSize(800,600);
 glutInitWindowPosition(100,100);
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 glutCreateWindow("Primitive Object");
 glutDisplayFunc(renderScene);
 glutKeyboardFunc(kunci);
 init();
 glutMainLoop();
 return 0;
}

Screenshot :