Berikut adalah program untuk membuat sebuah rumah sederhana dengan menggunakan Dev C++. Langsung saja ikuti langkah-langkahnya.
Langkah 1 :
Buat 1 Project untuk
menyimpan file yang ingin kita buat kemudian buka lembar kerja baru (Ctrl
+ N)
Langkah 2 :
Pada Menu Project, pilih Project Option (Alt +
P), pilih tab Parameters. Pada kolom Linker, copy kan linker di bawah ini dan
klik Ok.
-lopengl32
-lfreeglut
-lglu32
Langkah 3 :
Simpan, compile, dan run file berikut
:
#include <iostream>
#include <windows.h>
#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;
};
void myInit(void)
{
glClearColor (0.0,0,0.0,0);
glColor3f(1.0f,1.0f,0.0f);
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)
{
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);
glVertex2i(peak.x + width / 2, peak.y - height);
glEnd();
glBegin(GL_LINE_STRIP);
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);
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);
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=300;
p.y=300;
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();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(800,600);
glutInitWindowPosition(100,150);
glutCreateWindow("HOUSE");
glutDisplayFunc(Display);
myInit();
glutMainLoop();
}
Jadilah gambar rumah sederhana seperti diatas.
Tidak ada komentar:
Posting Komentar