Membuat gambar bintang menggunakan Visual C++
Berikut adalah tampilan gambar bintang yang dibuat menggunakan program Visual C++.
Berikut kode programnya :
#include <GL/glut.h>
void GambarPolyline(int x1,int y1,int x2,int y2,int x3, int y3,int x4, int y4,int x5, int y5,int x6, int y6,int x7, int y7,int x8,int y8, int x9, int y9, int x10, int y10){
glPointSize(4);
glBegin(GL_LINE_LOOP);
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glVertex2i(x3,y3);
glVertex2i(x4,y4);
glVertex2i(x5,y5);
glVertex2i(x6,y6);
glVertex2i(x7,y7);
glVertex2i(x8,y8);
glVertex2i(x9,y9);
glVertex2i(x10,y10);
glEnd();
}
//draw area
void userdraw() {
static int tick=0;
//set warna (R,G,B)
glColor3f(1,0,0);
GambarPolyline(200,60,300,115,400,60,365,160,460,220,340,220,300,320,260,220,135,220,235,155);
glColor3f(1,1,0);
GambarPolyline(180,40,300,100,420,40,380,160,500,230,350,230,300,340,250,230,100,230,220,150);
glColor3f(0,1,0);
GambarPolyline(160,20,300,85,440,20,395,155,540,240,360,240,300,360,240,240,65,240,205,145);
glColor3f(0,0,1);
GambarPolyline(140,0,300,70,460,0,410,150,580,250,370,250,300,380,230,250,30,250,190,140);
}
void display(void){
//clear screen
glClear(GL_COLOR_BUFFER_BIT);
userdraw(); //jalanan userdraw()
glutSwapBuffers();
}
int main(int argc,char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowPosition(100,100); //posisi windownya di(100,100)
glutInitWindowSize(640,480); //set ukuran window jadi 640x480
glutCreateWindow("Bintang Colorfull"); //set judul app
glClearColor(0,0,0,0); //set warna backgroun(r,g,b,a)(range 0-1)
gluOrtho2D(0.,640.,0.,480.); //set area menggambar
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
0 komentar: