1.Prosedur membuat segiempat
void kotak(int x1, int y1, int x2, int y2, int r, int g, int b )
{
glColor3f(r,g,b);
glBegin(GL_LINES);
for (int i=y1; i<=y2; i++)
{
glVertex2i(x1,i);
glVertex2i(x2,i);
}
glEnd();
}
2.Prosedur membuatgaris lengkung
void lengkungan(int x, int y, int jari,int awal, int akhir, int r, int g, int b )
{
glPointSize(3);
int x1,y1;
float rad = 3.14/180;
glColor3f(r,g,b);
glBegin(GL_POINTS);
for (int a=awal; a<=akhir; a++)
{
x1=jari*cos(a*rad);
y1=jari*sin(a*rad);
glVertex2f(x+x1,y+y1);
}
glEnd();
}
3.Prosedur membuat tembereng
void tembereng(int x, int y, int jari,int mula, int akhir, int r, int g, int b )
{
glPointSize(3);
int x1,y1;
float rad = 3.14/180;
glColor3f(r,g,b);
glBegin(GL_LINES);
for (int a=mula; a<=akhir; a++)
{
x1=jari*cos(a*rad);
y1=jari*sin(a*rad);
glVertex2i(x,y);
glVertex2i(x+x1,y+y1);
}
glEnd();
}
4.Membuat gambar mobil dari prosedur no 1-3
#include
#include
void lengkungan(int x, int y, int jari,int awal, int akhir, int r, int g, int b )
{
glPointSize(3);
int x1,y1;
float rad = 3.14/180;
glColor3f(r,g,b);
glBegin(GL_POINTS);
for (int a=awal; a<=akhir; a++)
{
x1=jari*cos(a*rad);
y1=jari*sin(a*rad);
glVertex2f(x+x1,y+y1);
}
glEnd();
}
void lingk_penuh(int x, int y, int jari, int r, int g, int b )
{
int x1,y1;
float rad = 3.14/180;
glColor3f(r,g,b);
glBegin(GL_POINTS);
for (int v=0; v<=jari; v++)
{
for (int a=0; a<=360; a++)
{
x1=v*cos(a*rad);
y1=v*sin(a*rad);
glVertex2f(x+x1,y+y1);
}
}
glEnd();
}
void kotak(int x1, int y1, int x2, int y2, int r, int g, int b )
{
glColor3f(r,g,b);
glBegin(GL_LINES);
for (int i=y1; i<=y2; i++)
{
glVertex2i(x1,i);
glVertex2i(x2,i);
}
glEnd();
}
void userdraw()
{
lengkungan(260,220,59,90,180,1,0,0);//lengkung kaca
kotak(260,220,340,280,1,0,0);//jendela kotak
kotak(200,150,490,220,0,0,0);//badan mobil
lengkungan(199,199,10,90,270,1,0,0);//lamp dpn
lengkungan(490,160,9,275,436,1,0,0);//lamp blakang
lengkungan(270,150,34,2,178,1,0,0);// lengkungan ban dpn
lingk_penuh(270,150,28,0,0,0);//ban depan
lengkungan(420,150,34,2,178,1,0,0);//lengkung ban belakang
lingk_penuh(420,150,28,0,0,0);//ban belakang
lingk_penuh(270,150,1,1,1,1);//tengah ban blk
lingk_penuh(420,150,1,1,1,1);//tengah ban blk
}
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(400,200);
glutInitWindowSize(640,480);
glutCreateWindow("Mobil");
glClearColor(1,1,1,0.0);
gluOrtho2D(0,640,0,480);
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Tidak ada komentar:
Posting Komentar