Rabu, 11 Januari 2017

Cara membuat gambar Bintang Berwarna di Microsoft Visual C++


     Setelah sebelumnya saya memposting Sintak gambar TV di Microsoft Visual C++, kali ini saya akan memposting bagaimana Cara membuat gambar Bintang Berwarna di Microsoft Visual C++. Aplikasi yang saya gunakan adalah Microsoft Visual C++ 2010 Express tapi bisa juga digunakan untuk Microsoft Visual C++ 2008. Untuk melihat bagaimana screenshoot ataupun sintaksnya silahkan lihat dibawah ini:

#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>


typedef struct point2D_t
{
float x;
float y;
};

typedef struct color_t
{
float r;
float g;
float b;
};

void setColor(color_t col)
{
glColor3f(col.r, col.g, col.b);
}

void Bintang1(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){
glBegin(GL_POLYGON);
glColor3f(0,0,0);
 glVertex2i(x1,y1);
 glVertex2i(x2,y2);
 glVertex2i(x3,y3);
 glVertex2i(x4,y4);
 glVertex2i(x5,y5);
 glVertex2i(x6,y6);
 glVertex2i(x7,y7);
 glVertex2i(x8,y8);
glEnd();
}

void Kaki1(int x1, int y1,int x2, int y2,int x3, int y3){
glBegin(GL_POLYGON);
glColor3f(0,0,0);
 glVertex2i(x1,y1);
 glVertex2i(x2,y2);
 glVertex2i(x3,y3);
glEnd();
}

void Bintang2(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){
glBegin(GL_POLYGON);
glColor3f(0,0.8,1);
 glVertex2i(x1,y1);
 glVertex2i(x2,y2);
 glVertex2i(x3,y3);
 glVertex2i(x4,y4);
 glVertex2i(x5,y5);
 glVertex2i(x6,y6);
 glVertex2i(x7,y7);
 glVertex2i(x8,y8);
glEnd();
}
void Kaki2(int x1, int y1,int x2, int y2,int x3, int y3){
glBegin(GL_POLYGON);
glColor3f(0,0.8,1);
 glVertex2i(x1,y1);
 glVertex2i(x2,y2);
 glVertex2i(x3,y3);
glEnd();
}

void Bintang3(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){
glBegin(GL_POLYGON);
glColor3f(0,1,1);
 glVertex2i(x1,y1);
 glVertex2i(x2,y2);
 glVertex2i(x3,y3);
 glVertex2i(x4,y4);
 glVertex2i(x5,y5);
 glVertex2i(x6,y6);
 glVertex2i(x7,y7);
 glVertex2i(x8,y8);
glEnd();
}
void Kaki3(int x1, int y1,int x2, int y2,int x3, int y3){
glBegin(GL_POLYGON);
glColor3f(0,1,1);
 glVertex2i(x1,y1);
 glVertex2i(x2,y2);
 glVertex2i(x3,y3);
glEnd();
}

/*void Bintang4(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){
glBegin(GL_POLYGON);
glColor3f(0,0,1);
 glVertex2i(x1,y1);
 glVertex2i(x2,y2);
 glVertex2i(x3,y3);
 glVertex2i(x4,y4);
 glVertex2i(x5,y5);
 glVertex2i(x6,y6);
 glVertex2i(x7,y7);
 glVertex2i(x8,y8);
glEnd();
}
void Kaki4(int x1, int y1,int x2, int y2,int x3, int y3){
glBegin(GL_POLYGON);
glColor3f(0,0,1);
 glVertex2i(x1,y1);
 glVertex2i(x2,y2);
 glVertex2i(x3,y3);
glEnd();
}*/

void fillPolygon(point2D_t p[],color_t col, int n)
{
int i;
glBegin(GL_POLYGON);
setColor(col);
for (i=0;i<n;i++) glVertex2f(p[i].x, p[i].y);
glEnd();
}

void gradatePolygon(point2D_t p[],color_t col[], int n){
int i;
glBegin(GL_POLYGON);
for (i=0;i<n;i++){
setColor(col[i]);
glVertex2f(p[i].x, p[i].y);
}
glEnd();
}

void userdraw(void) {
 // Disini tempat untuk menggambar
 color_t gradasi1[4]={{0,0,0},{0,0,0},{1,1,1},{1,1,1}};
 color_t gradasi2[4]={{1,1,1},{1,1,1},{0,0,0},{0,0,0}};
 color_t gradasi3[4]={{0,1,1},{0,0,0},{0,1,1},{1,0,0}};
 point2D_t background1[4]={{0,240},{640,240},{640,480},{0,480}};
 gradatePolygon(background1, gradasi1, 4);
 point2D_t background2[4]={{0,0},{640,0},{640,240},{0,240}};
 gradatePolygon(background2, gradasi2, 4);

 Bintang1(300,70,460,0,410,150,580,250,370,250,300,380,230,250,30,250);
 Bintang2(300,85,440,20,395,155,540,240,360,240,300,360,240,240,65,240);
 Bintang3(300,100,420,40,380,160,500,230,350,230,300,340,250,230,100,230);
 //Bintang4(300,115,400,60,365,165,460,220,340,220,300,320,260,220,135,220);

 Kaki1(140,0,300,70,200,150);
 Kaki2(160,20,300,85,215,155);
 Kaki3(180,40,300,100,230,160);
 //Kaki4(200,60,300,115,245,165);

point2D_t segitiga4[4]={{235,155},{200,60},{300,115},{300,190}};
gradatePolygon(segitiga4,gradasi3,4);

point2D_t segitiga5[4]={{300,115},{400,60},{365,160},{300,190}};
gradatePolygon(segitiga5,gradasi3,4);

point2D_t segitiga6[4]={{365,160},{460,220},{340,220},{300,190}};
gradatePolygon(segitiga6,gradasi3,4);

point2D_t segitiga7[4]={{340,220},{300,320},{260,220},{300,190}};
gradatePolygon(segitiga7,gradasi3,4);

point2D_t segitiga8[4]={{260,220},{135,220},{235,155},{300,190}};
gradatePolygon(segitiga8,gradasi3,4);

glEnd();
}
void display(void) {
glClear( GL_COLOR_BUFFER_BIT);
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("Create By : Rochmad Dwi U"); //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;
}


Itulah sekilas sintak tentang Cara membuat gambar Bintang Berwarna di Microsoft Visual C++, semoga postingan tadi bermanfaat bagi anda. Untuk postingan lainnya dapat dilihat di TujuanTerbaik.

Silahkan tinggalkan komentar anda apabila perlu. Atas kunjungannya saya ucapkan terimakasih....

Share this

0 Comment to "Cara membuat gambar Bintang Berwarna di Microsoft Visual C++"

Posting Komentar