Senin, 09 Oktober 2017

Cara Membuat Rumah dari Dev C++

Assalamualaikum, yey pembahasan kali ini seru gengs , apa kalian tau  ??? kalau membuat rumah itu tidak hanya dari semen,pasir,kayu,dll. tapi juga bisa dari aplikasi yang satu ini walaupun sederhana tetapi cukup rumit gengs hehehe ,yuks simak codingnya di bawah ini  ⤋⤋⤋⤋⤋ 


Coding :

#include <iostream>
#include <windows.h>           //use as needed for your system
#include <gl/GL.h>
#include <gl/glut.h>
#include <stdlib.h>
#include <stdio.h>
int screenWidth=640;
int screenHeight=480;
struct Point
{
            int x;
            int y;
};
struct GLintPoint
{
            GLint x,y;
};

/*struct GLintPointArray
{
            const int MAX_NUM = 10000;
            int num;
            GLintPoint pt[MAX_NUM];
};*/

void myInit(void)
{
            glClearColor(0.0,0,0.0,0); //for background
            glColor3f(1.0f,0.0f,1.0f); //for point color
            glPointSize(4.0);
            glLineWidth(4.0);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
           
}

void paraHouse(struct Point peak,GLint width,GLint height)          // to make a house
{
            glBegin(GL_LINE_LOOP);
           
                        glVertex2i(peak.x - width / 2, peak.y - height);
                        glVertex2i(peak.x - width / 2, peak.y - 4 * height/9);
                        glVertex2i(peak.x - width / 3, peak.y - 2 *height/9);
                        glVertex2i(peak.x + width / 3, peak.y - 2* height /9);
                        glVertex2i(peak.x + width / 2, peak.y - 4* height /9);
                        glVertex2i(peak.x + width / 2, peak.y - height);
            glEnd();
           
            glBegin(GL_LINE_STRIP); // Atap
                        glVertex2i(peak.x - width / 6, peak.y - 2* height /9);
                        glVertex2i(peak.x, peak.y);
                        glVertex2i(peak.x + width / 6, peak.y - 2* height/9);
            glEnd();
           
            glBegin(GL_LINE_STRIP); // Pintu
                        glVertex2i(peak.x - width / 3, peak.y - height);
                        glVertex2i(peak.x - width / 3, peak.y - 5 * height / 9);
                        glVertex2i(peak.x - 5 * width/60, peak.y - 5 * height /9);
                        glVertex2i(peak.x - 5 * width/60, peak.y - height);
            glEnd();
            glBegin(GL_LINE_LOOP); //Jendela
                        glVertex2i(peak.x + width/12, peak.y - 7 * height / 9);
                        glVertex2i(peak.x + width/12, peak.y - 5 * height / 9);
                        glVertex2i(peak.x + width /4, peak.y - 5 * height / 9);
                        glVertex2i(peak.x + width /4, peak.y - 7 * height / 9);
                       
            glEnd();
}

void Display(void)
{
            struct Point p;
            p.x=400;
            p.y=400;
            glClear(GL_COLOR_BUFFER_BIT);
            glBegin(GL_POINT);
            paraHouse(p,100,200);
            glBegin(GL_LINE_LOOP);
                        glVertex2i(10,10);
                        glVertex2i(10,60);
                        glVertex2i(20,80);
                        glVertex2i(60,80);
                        glVertex2i(70,60);
                        glVertex2i(70,10);
            glEnd();
            glBegin(GL_LINE_STRIP);
                        glVertex2i(20,10);      
                        glVertex2i(20,50);      
                        glVertex2i(35,50);      
                        glVertex2i(35,10);      
            glEnd();
            glBegin(GL_LINE_STRIP);
                        glVertex2i(30,80);
                        glVertex2i(40,100);
                        glVertex2i(50,80);
            glEnd();
            glBegin(GL_LINE_LOOP);
                        glVertex2i(45,30);
                        glVertex2i(45,50);
                        glVertex2i(55,50);
                        glVertex2i(55,30);
            glEnd();
            glFlush();
                       
}         
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)
{
            glutInit(&argc,argv);
            glutInitDisplayMode(GLUT_SINGLE);
            glutInitWindowSize(800,600);
            glutInitWindowPosition(100,150);
            glutCreateWindow("HOUSE");        
            glutDisplayFunc(Display);
            myInit();
            glutMainLoop();

}

maka hasil output dari coding di atas akan menjadi seperti di bawah ini : 

Bagaimana nih mba bro & mas bro apakah berhasil  ? mudah kan ,semoga tidak typo ya ☺☺☺ semangat terus ,dan semoga bermanfaat ya ... mampir terus ya di blog saya ☺☺, akan ada cara cara pembuatan dari Dev C++ dengan glut. byee wassalamua'laikum ☺☺☺ 

Tidak ada komentar:

Posting Komentar