Please comment it cause i'm still learning :)
my 1st program computer graphic with primitive picture
simple house
==========================================================
#include <GL/glut.h>
int i;
typedef struct {
float x;
float y;
}object;
typedef struct{
float r;
float g;
float b;
}color;
void setcolor(color col)
{
glColor3f(col.r, col.g, col.b);
}
void draw(object obj[], color col[], int n)
{
glBegin(GL_POLYGON);
for(i=0;i<n;i++)
{
setcolor(col[i]);
glVertex2f(obj[i].x,obj[i].y);
}
glEnd();
}
void langit()
{
object objlangit[4]={{-100,-100},{100,-100},{100,100},{-100,100}};
color collangit[4]={{1,1,1},{1,1,1},{0,0.2,0.6},{0,0.2,0.5}};
draw(objlangit,collangit,4);
}
void tanah()
{
object objtanah[5]={{-100,-100},{100,-100},{100,-52},{50,-55},{-100,-60}};
color coltanah[5]={{0.6,1,0.2},{0.7,1,0.3},{1,1,1},{1,0.8,0.3},{1,0.5,0.1}};
draw(objtanah,coltanah,5);
}
void gunung1()
{
object objgunung[3]={{-100,-60},{200,-50},{80,15}};
color colgunung[3]={{0,0,1},{1,1,1},{0,0,1}};
draw(objgunung,colgunung,3);
}
void gunung2()
{
object objgunung[3]={{-500,-250},{500,-150},{-10,20}};
color colgunung[3]={{0,0,1},{1,1,1},{0,0,1}};
draw(objgunung,colgunung,3);
}
void pagar()
{
object objpgr1[4]={{-20,-72},{2,-72},{2,-70},{-20,-70}};
color colpgr1[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objpgr1,colpgr1,4);
object objpgr2[4]={{-20,-77},{2,-77},{2,-75},{-20,-75}};
color colpgr2[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objpgr2,colpgr2,4);
object objpgr3[4]={{-18,-80},{-16,-80},{-16,-68},{-18,-68}};
color colpgr3[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objpgr3,colpgr3,4);
object objpgr4[4]={{-14,-80},{-12,-80},{-12,-68},{-14,-68}};
color colpgr4[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objpgr4,colpgr4,4);
object objpgr5[4]={{-10,-80},{-8,-80},{-8,-68},{-10,-68}};
color colpgr5[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objpgr5,colpgr5,4);
object objpgr6[4]={{-6,-80},{-4,-80},{-4,-68},{-6,-68}};
color colpgr6[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objpgr6,colpgr6,4);
object objpgr7[4]={{-2,-80},{0,-80},{0,-68},{-2,-68}};
color colpgr7[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objpgr7,colpgr7,4);
}
void rumah()
{
object objtemb7[4]={{3,-77},{55,-77},{55,-60},{3,-60}};
color coltemb7[4]={{1,0.5,0.3},{1,0.5,0.3},{1,0.5,0.3},{1,0.5,0.3}};
draw(objtemb7,coltemb7,4);
object objtemb1[4]={{0,-80},{60,-80},{60,-77},{0,-77}};
color coltemb1[4]={{0.3,0.3,0.3},{0.3,0.3,0.3},{0.6,0.6,0.6},{0.6,0.6,0.6}};
draw(objtemb1,coltemb1,4);
object objtemb6[4]={{20,-77},{32,-77},{32,-20},{20,-20}};
color coltemb6[4]={{0.4,0.4,0.4},{0.4,0.4,0.4},{0.4,0.4,0.4},{0.4,0.4,0.4}};
draw(objtemb6,coltemb6,4);
object objtemb2[4]={{3,-77},{7,-77},{7,-65},{3,-65}};
color coltemb2[4]={{0.3,0.3,0.3},{0.3,0.3,0.3},{0.3,0.3,0.3},{0.3,0.3,0.3}};
draw(objtemb2,coltemb2,4);
object objtemb3[4]={{20,-77},{24,-77},{24,-65},{20,-65}};
color coltemb3[4]={{0.3,0.3,0.3},{0.3,0.3,0.3},{0.3,0.3,0.3},{0.3,0.3,0.3}};
draw(objtemb3,coltemb3,4);
object objtemb4[4]={{0,-65},{27,-65},{27,-61},{0,-61}};
color coltemb4[4]={{0.3,0.1,0.1},{0.3,0.1,0.1},{0.3,0.1,0.1},{0.3,0.1,0.1}};
draw(objtemb4,coltemb4,4);
object objtemb5[4]={{3,-61},{20,-61},{20,-40},{3,-40}};
color coltemb5[4]={{0.6,0.6,0.6},{0.6,0.6,0.6},{0.6,0.6,0.6},{0.6,0.6,0.6}};
draw(objtemb5,coltemb5,4);
object objtemb8[4]={{32,-60},{53,-60},{53,-40},{32,-30}};
color coltemb8[4]={{1,1,1},{1,1,1},{0.6,0.6,0.6},{0.6,0.6,0.6}};
draw(objtemb8,coltemb8,4);
object objtemb9[4]={{30,-60},{60,-60},{60,-58},{30,-58}};
color coltemb9[4]={{1,1,1},{1,1,1},{1,1,1},{1,1,1}};
draw(objtemb9,coltemb9,4);
object objtemb10[4]={{32,-30},{55,-43},{55,-41},{32,-28}};
color coltemb10[4]={{0.3,0.1,0.1},{0.3,0.1,0.1},{0.3,0.1,0.1},{0.3,0.1,0.1}};
draw(objtemb10,coltemb10,4);
object objtemb11[4]={{28,-40},{33,-40},{33,-38},{28,-38}};
color coltemb11[4]={{1,1,1},{1,1,1},{1,1,1},{1,1,1}};
draw(objtemb11,coltemb11,4);
object objtemb12[4]={{28,-43},{33,-43},{33,-45},{28,-45}};
color coltemb12[4]={{1,1,1},{1,1,1},{1,1,1},{1,1,1}};
draw(objtemb12,coltemb11,4);
object objtemb13[4]={{12,-59},{25,-59},{25,-43},{12,-43}};
color coltemb13[4]={{1,0.4,0.1},{1,0.4,0.1},{1,0.4,0.1},{1,0.4,0.1}};
draw(objtemb13,coltemb13,4);
object objtemb14[4]={{15,-56},{22,-56},{22,-46},{15,-46}};
color coltemb14[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objtemb14,coltemb14,4);
object objtemb15[4]={{38,-56},{41,-56},{41,-42},{38,-42}};
color coltemb15[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objtemb15,coltemb15,4);
object objtemb16[4]={{45,-56},{48,-56},{48,-42},{45,-42}};
color coltemb16[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objtemb16,coltemb16,4);
object objtemb17[4]={{42,-71},{45,-71},{45,-65},{42,-65}};
color coltemb17[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objtemb17,coltemb17,4);
object objtemb18[4]={{47,-71},{50,-71},{50,-65},{47,-65}};
color coltemb18[4]={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
draw(objtemb18,coltemb18,4);
object objtemb19[4]={{34,-77},{40,-77},{40,-65},{34,-65}};
color coltemb19[4]={{0.3,0.1,0.1},{0.3,0.1,0.1},{0.3,0.1,0.1},{0.3,0.1,0.1}};
draw(objtemb19,coltemb19,4);
}
void kartesius()
{
glColor3f(0,0,0);
for(float x=-100;x<=100;x+=10)
{
glBegin(GL_LINES);
glVertex2f(x,-100);
glVertex2f(x,100);
glEnd();
glBegin(GL_LINES);
glVertex2f(-100,x);
glVertex2f(100,x);
glEnd();
}
glColor3f(0,1,1);
glBegin(GL_LINES);
glVertex2f(100,0);
glVertex2f(-100,0);
glEnd();
glBegin(GL_LINES);
glVertex2f(0,-100);
glVertex2f(0,100);
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
langit();
gunung1();
gunung2();
tanah();
rumah();
pagar();
//kartesius();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(640,480);
glutCreateWindow("Muhammad Ridwan 7609040003 3D4Teknik Komputer");
glClearColor(0,0,0,0);
gluOrtho2D(-100.0,100.0,-100.0,100.0);
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
here the result :)
thanks..
No comments:
Post a Comment