Menggambar Grafik Primitif dengan Glut

Sedikit berbagi dengan teman-teman yang mungkin masih mengalami kesulitan mengerjakan tugas Komputer Grafik

here’s the code..

#include<windows.h>

#include<gl\glut.h>

#define PI  3.1415926535898

GLint circle_points = 100;

void MyCircle(GLfloat centerx, GLfloat centery, GLfloat radius)

{

GLint i;

GLdouble theta;

glBegin(GL_POLYGON);

for (i=0; i<circle_points;i++)

{

theta = 2*PI*i/circle_points;

glVertex2f(centerx+ radius*cos(theta),

centery + radius*sin(theta));

}

glEnd();

}

void Display(void)

{

//gambar kepalanya dulu.. ^.^

glClear(GL_COLOR_BUFFER_BIT);

glColor2f(1.0,0.8,0.1);

MyCircle2f(80.,85.,10.);

//gambar matanya .. ^.^

glBegin(GL_POINTS);

glColor2f(1.0,0.0,0.0);

glVertex2f(77.,88.);

glVertex2f(83.,88.);

glEnd();

//gambar badannya .. ^.^

glColor3f(0.5,0.0,0.8);

glBegin(GL_POLYGON);

glVertex2f(75.,75.);

glVertex2f(85.,75.);

glVertex2f(100.,30.);

glVertex2f(60.,30.);

glEnd();

//gambar dua kakinya .. ^.^

glColor3f(1.0,0.8,0.1);

glRectf(70.,5.,75.,30.);

glRectf(85.,5.,90.,30.);

//gambar dua tangannya .. ^.^

glBegin(GL_LINES);

glVertex2f(74.,70.);

glVertex2f(50.,50.);

glEnd();

glBegin(GL_LINES);

glVertex2f(86.,70.);

glVertex2f(110.,50.);

glEnd();

glFlush();

}

void init(void)

{

glClearColor(1.0,0.0,0.0,0.1);

glViewport(0,0,320,240);

gluOrtho2D(0.0,160.0,0.0,120.0);

}

int main(int args,char* argv[])

{

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowSize(320,240);

glutCreateWindow(“Gambar Orang.. ^.^ “);

init();

glutDisplayFunc(Display);

glutMainLoop();

}

 

Kalau semuanya bener..gini penampakannya friend’s..

Advertisements
Menggambar Grafik Primitif dengan Glut

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s