dibawah ini code program untuk rumah 2D, semoga bermanfaat.
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<glut.h>
typedef struct{
float x,y;
}point2D_t;
void userdraw(void);
void drawDot(point2D_t p)
{
glBegin(GL_POINTS);
glVertex2f(p.x,p.y);
glEnd();
}
void drawLine(float x1, float y1, float x2, float y2){
glBegin(GL_LINES);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glEnd();
}
void drawLine(point2D_t p1, point2D_t p2){
drawLine(p1.x,p1.y,p2.x,p2.y);
}
void drawPolyline(point2D_t pnt[], int n){
int i;
glBegin(GL_LINE_STRIP);
for(i=0;i<n;i++){
glVertex2f(pnt[i].x,pnt[i].y);
}
glEnd();
}
void drawFillPolygon(point2D_t pnt[], int n){
int i;
glBegin(GL_POLYGON);
for(i=0;i<n;i++){
glVertex2f(pnt[i].x,pnt[i].y);
}
glEnd();
}
void setColor(float red,float green,float blue)
{
glColor3f(red,green,blue);
}
void userdraw(void){
point2D_t rumah[5]={{40.,40},{110.,40},{110.,90},{75.,120},{40.,90}};
setColor(1.,1.,0.);
drawFillPolygon(rumah,5);
point2D_t pintu[4]={{42.,42},{42.,70},{55.,70},{55.,42}};
setColor(1.,0.,1.);
drawFillPolygon(pintu,4);
point2D_t jendela[4]={{60.,60},{60.,70},{70.,70},{70.,60}};
setColor(1.,0.,0.);
drawFillPolygon(jendela,4);
point2D_t jendelax[4]={{75.,60},{75.,70},{85.,70},{85.,60}};
setColor(0.,1.,0.);
drawFillPolygon(jendelax,4);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
userdraw();
glFlush();
}
void main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,150);
glutInitWindowSize(640,480);
glutCreateWindow("Titik");
glClearColor(0.1,0.,1.0,0.0);
gluOrtho2D(0.,640.,0.0,480.0);
glutDisplayFunc(display);
glutMainLoop();
}
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<glut.h>
typedef struct{
float x,y;
}point2D_t;
void userdraw(void);
void drawDot(point2D_t p)
{
glBegin(GL_POINTS);
glVertex2f(p.x,p.y);
glEnd();
}
void drawLine(float x1, float y1, float x2, float y2){
glBegin(GL_LINES);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glEnd();
}
void drawLine(point2D_t p1, point2D_t p2){
drawLine(p1.x,p1.y,p2.x,p2.y);
}
void drawPolyline(point2D_t pnt[], int n){
int i;
glBegin(GL_LINE_STRIP);
for(i=0;i<n;i++){
glVertex2f(pnt[i].x,pnt[i].y);
}
glEnd();
}
void drawFillPolygon(point2D_t pnt[], int n){
int i;
glBegin(GL_POLYGON);
for(i=0;i<n;i++){
glVertex2f(pnt[i].x,pnt[i].y);
}
glEnd();
}
void setColor(float red,float green,float blue)
{
glColor3f(red,green,blue);
}
void userdraw(void){
point2D_t rumah[5]={{40.,40},{110.,40},{110.,90},{75.,120},{40.,90}};
setColor(1.,1.,0.);
drawFillPolygon(rumah,5);
point2D_t pintu[4]={{42.,42},{42.,70},{55.,70},{55.,42}};
setColor(1.,0.,1.);
drawFillPolygon(pintu,4);
point2D_t jendela[4]={{60.,60},{60.,70},{70.,70},{70.,60}};
setColor(1.,0.,0.);
drawFillPolygon(jendela,4);
point2D_t jendelax[4]={{75.,60},{75.,70},{85.,70},{85.,60}};
setColor(0.,1.,0.);
drawFillPolygon(jendelax,4);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
userdraw();
glFlush();
}
void main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,150);
glutInitWindowSize(640,480);
glutCreateWindow("Titik");
glClearColor(0.1,0.,1.0,0.0);
gluOrtho2D(0.,640.,0.0,480.0);
glutDisplayFunc(display);
glutMainLoop();
}
mantap bro, saya juga lagi belajar nih ijin untuk berbagi
BalasHapusheriadyblog.blogspot.com