ZDIRY-TUFWT-EBONM-EYJ00-IDBLANTER.COM
ZDIRY-TUFWT-EBONM-EYJ00
BLANTERWISDOM105

Cara membuat Rumah 3D dengan OpenGL

Saturday, June 29, 2019
Nesiasite - Tutorial & Berita Teknologi - Halo teman-teman apa kabar kalian hari ini, kali ini saya akan berbagi codingan/ sourch code Rumah 3D dengan OpenGl, Silahkan di sedot di bawah ini gan dan jangan lupa tinggalka jejak di kolom komentar di bawah sebagai tanda terimakasih,.

Oke teman-teman silahkan langsung saja di sedot semoga dapat membantu kalian dalam mengerjakan tugas kalian,. BDW di dalam postingan ini saya tidak kasih penjelsanan ya. Jika teman-teman ingin mendapatkan penjelasan yang lebih jelas tentan codinagn di bawah ini silahkan hubungi saya melalu Kontak di link bawah blog ini.


https://www.pemulabro.id/

 
#include "stdlib.h"
#include "glut.h"

int w = 600, h = 600, z = -15;
int x1 = 0, y1 = 10, sudut = 0, z1 = 0;
int cx, cy;



void motion(int x, int y) {
cx = x - (w / 2);
cy = (h / 2) - y;
}



void init() {
GLfloat LightPosition[] = { 10.0f, 10.0f, 20.0f, 0.0f };
GLfloat LightAmbient[] = { 0.0f, 1.0f, 0.0f, 1.0f };
GLfloat LightDiffuse[] = { 0.7f, 0.7f, 0.7f, 1.0f };
GLfloat LightSpecular[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat Shine[] = { 80 };

glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glMaterialfv(GL_FRONT, GL_SPECULAR, LightAmbient);
glMaterialfv(GL_FRONT, GL_SPECULAR, LightSpecular);
glMaterialfv(GL_FRONT, GL_SHININESS, Shine);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
return;

}


void atap() {
glEnable(GL_COLOR_MATERIAL);
glColor3f(1, 0, 0);
//atap belakang
glPushMatrix();
glTranslatef(0, 2, -1.);
glRotatef(45, 1, 0, 0);
glScalef(3.6, 2.8, 0.2);
glutSolidCube(1);
glPopMatrix();
//atap depan
glPushMatrix();
glTranslatef(0, 2, 1.);
glRotatef(45, -1, 0, 0);
glScalef(3.6, 2.8, 0.2);
glutSolidCube(1);
glPopMatrix();

//langit-langit
glPushMatrix();
glTranslatef(0, 1, 0);
glRotatef(90, 1, 0, 0);
glScalef(3.6, 3.9, 0.2);
glutSolidCube(1);
glPopMatrix();

glBegin(GL_TRIANGLES);

glVertex3f(1.8, 1, 2);
glVertex3f(1.8, 1, -2);
glVertex3f(1.8, 3, 0);

glVertex3f(-1.8, 1, 2);
glVertex3f(-1.8, 1, -2);
glVertex3f(-1.8, 3, 0);

glDisable(GL_COLOR_MATERIAL);
glEnd();
}


void pagar() {
//pagar
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glTranslatef(3, -1, 1);
glColor3f(0.7, 0.3, 0);

glPushMatrix();
glTranslatef(-1, 0.2, 0);
glScalef(5.4, 0.2, 0.1);
glutSolidCube(1);
glPopMatrix();

glPushMatrix();
glTranslatef(-1, -0.2, 0);
glScalef(5.4, 0.2, 0.1);
glutSolidCube(1);
glPopMatrix();

glScalef(0.2, 1, 0.1);
glTranslatef(2, 0, 0);
glutSolidCube(1);
glTranslatef(2, 0, 0);
glutSolidCube(1);
glTranslatef(2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);
glTranslatef(-2, 0, 0);
glutSolidCube(1);

glDisable(GL_COLOR_MATERIAL);
glPopMatrix();

}

void omah() {
//tembok
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(0, 0, 0.5);
glScalef(2, 1, 1);
glutSolidCube(3);
glDisable(GL_COLOR_MATERIAL);
//pintu
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.5, 0.8, 0);
glTranslatef(-0.6, -0.6, 1.46);
glScalef(7, 18, 1);
glutSolidCube(0.1);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();

//jendela
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.5, 0.8, 0);
glTranslatef(0.5, 0.1, 1.46);
glScalef(3, 3, 1);
glutSolidCube(0.1);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();

glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.5, 0.8, 0);
glTranslatef(0.9, 0.1, 1.46);
glScalef(3, 3, 1);
glutSolidCube(0.1);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();

glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.5, 0.8, 0);
glTranslatef(0.9, -0.3, 1.46);
glScalef(3, 3, 1);
glutSolidCube(0.1);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();

glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.5, 0.8, 0);
glTranslatef(0.5, -0.3, 1.46);
glScalef(3, 3, 1);
glutSolidCube(0.1);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();


//pagar depan
glPushMatrix();
glTranslatef(-1, 0, 1.5);
glScalef(0.8, 1, 1);
pagar();
glPopMatrix();
//pagar belakang
glPushMatrix();
glTranslatef(-2, 0, -3.5);
pagar();
glPopMatrix();
//pagar kiri
glPushMatrix();
glRotatef(-90, 0, 1, 0);
glTranslatef(-2, 0, 1.5);
pagar();
glPopMatrix();
//pagar kanan
glPushMatrix();
glRotatef(-90, 0, 1, 0);
glTranslatef(-2, 0, -3.5);
pagar();
glPopMatrix();

atap();

//cerobong asap
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.7, 0.3, 0);
glTranslatef(0.8, 2.8, -1);
glScalef(0.5, 2, 1);
glutSolidCube(1);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();

//rumput
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(0, 1.0, 0);
glTranslatef(0, -1.4, 0);
glRotatef(90, 1, 0, 0);
glScalef(5.1, 4.95, 0.2);
glutSolidCube(1);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();

glPopMatrix();
}

void renderScene(void) {
GLfloat LightPosition[] = { 10.0f, 10.0f, 20.0f, 0.0f };
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 1, 1, 1);
LightPosition[0] = cx;
LightPosition[1] = cy;

glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);

glLoadIdentity();
glTranslatef(0, 0, z);
glRotatef(sudut, x1, y1, z1);

glPushMatrix();
glRotatef(30, 0, 1, 0);
omah();
glPopMatrix();

glutSwapBuffers();
}

void resize(int w1, int h1) {
glViewport(0, 0, w1, h1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float)w1 / (float)h1, 1.0, 300.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}



void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(w, h);
glutCreateWindow("Rumah");
glutDisplayFunc(renderScene);
glutReshapeFunc(resize);
//glutKeyboardFunc(myKeyboard);
//glutMouseFunc(mouse);
glutMotionFunc(motion);
// glutTimerFunc(1, timer, 0);
init();
glutMainLoop();
}
loading...
Baca Juga
Share This :

2 Comments

  1. Mantap min infonya,
    Di paragraf pertama min ada kesalahan penulisan "tinggalka" dan di paragraf kedua "codinagn" thanks min

    ReplyDelete
  2. sangat membantu sekali kaka hahahaha

    ReplyDelete
loading...
Notification
Donasi yang kamu berikan akan saya gunakan untuk mengembangkan blog ini menjadi lebih baik.

Donate
 BANK BRI : 777201000999534 a/n Juan Karly Matheus.
 Paypal       : paypal.me/juanmatheus37
  PULSA       : 0823-9958-5050 (Telkomsel)
Done