tugas opengl dalam bahasa c
(Bentuk Primitive)
1) Garis(Horizontal, Serong Kiri, Vertical, Serong Kanan, dan Horizontal)
void garis1() {
glDisable(GL_LIGHTING);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINES);
/*
Documentation :
1) glColor3f adalah fungsi yang dipanggil untuk mewarnai elemen, parameternya adalah code RGB dari 0 hingga 255
1.1) Contoh fungsi -> void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
2) glVertex2f adalah fungsi untuk membuat vertex dengan dua coordinat dari grafik cartesian -> X,Y
2.1) Contoh fungsi -> void glVertex2f(X Coordinate, Y Coordinate)
3.0) glBegin adalah fungsi untuk mendefinisikan bentuk primitive pada open GL
*/
// Garis 0
i = 1;
glColor3f(255, 0, 0);
glVertex2f(-0.6,0.2);
glVertex2f(-1, 0.2);
// Garis 1
glColor3f(1 - .15*i, 1 - .15*i, 1 - .15*i);
glVertex2f(-0.2, 0);
glVertex2f(-0.6, 0.5);
// Garis 2
glColor3f(0, 255,0);
glVertex2f(0,0);
glVertex2f(0, 0.5);
// Garis 3
glColor3f(1 - .15*i, 1 - .15*i, 1 - .15*i);
glVertex2f(0.2,0);
glVertex2f(0.6, 0.5);
// Garis 4
glColor3f(0,0,255);
glVertex2f(0.6,0.2);
glVertex2f(1, 0.2);
//
glEnd();
glFlush();
2) LINGKARAN
a
d
void lingkaran1() {
/*
Documentation :
1) GL_MODELVIEW adalah menerapkan operasi matrix
1.1) Contoh fungsi -> void glColor4f( GLfloat
red, GLfloat green, GLfloat blue, GLfloat alpha);
2) glVertex2d adalah fungsi untuk membuat vertex dengan dua value
2.1) Contoh fungsi -> void glVertex2f(X Coordinate, Y Coordinate)
3.0) glBegin adalah fungsi untuk mendefinisikan bentuk primitive pada
open GL
*/
glDisable(GL_LIGHTING);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float x;
float y;
float radius;
x
= 0.0f;
y
= 0.0f;
radius = 0.2f;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(x,
y, 0.0f);
static const int circle_points = 100;
static const float angle = 2.0f * 3.1416f / circle_points;
glBegin(GL_POLYGON);
double angle1=0.0;
glVertex2d(radius * cos(0.0) , radius * sin(0.0));
int i;
for (i=0; i<circle_points; i++)
{
glVertex2d(radius * cos(angle1), radius *sin(angle1));
angle1 += angle;
}
glPopMatrix();
glEnd();
glFlush();
}
3)
SEGITIGA Sama Sisi(Satu
Warna) dan Sama Sisi(Gradasi)
void segitiga1(){
glDisable(GL_LIGHTING);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*
Documentation :
1) glColor3f adalah fungsi yang
dipanggil untuk mewarnai elemen, parameternya adalah code RGB dari 0 hingga 255
1.1) Contoh fungsi -> void
glColor4f( GLfloat red,
GLfloat green, GLfloat blue, GLfloat alpha);
2) glVertex2f adalah fungsi untuk
membuat vertex dengan dua coordinat dari grafik cartesian -> X,Y
2.1) Contoh fungsi -> void
glVertex2f(X Coordinate, Y Coordinate)
3) glBegin adalah fungsi untuk
mendefinisikan bentuk primitive pada open GL
3.1) glBegin(GL_TRIANGLES) adalah
fungsi untuk membentuk segitiga dari vertex2 yang ada(glVertex2f)
*/
glBegin(GL_TRIANGLES);
//Segitiga 1
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex2f(0.1f, -0.6f);
glVertex2f(0.7f, -0.6f);
glVertex2f(0.4f, -0.1f);
glColor3f(1.0f, 0.0f, 0.0f); // Red
// Segitiga 2
glVertex2f(0.3f, -0.4f);
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex2f(0.9f, -0.4f);
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex2f(0.6f, -0.9f);
glEnd();
glFlush();
}
4) POLYHEDRAL (KUBUS)
void polyhedral1(){
/*
Documentation :
1) glColor3f adalah fungsi yang dipanggil untuk mewarnai elemen,
parameternya adalah code RGB dari 0 hingga 255
1.1) Contoh fungsi -> void glColor4f( GLfloat
red, GLfloat green, GLfloat blue, GLfloat alpha);
2) glVertex2f adalah fungsi untuk membuat vertex dengan dua coordinat
dari grafik cartesian -> X,Y
2.1) Contoh fungsi -> void glVertex2f(X Coordinate, Y Coordinate)
3) glBegin adalah fungsi untuk mendefinisikan bentuk primitive pada open
GL
3.1) glutSolidCube adalah fungsi untuk membuat object kubus berupa
wireframe ataupun solid
4) glRotatef fungsi untuk merotasi matrix dengan menggunakan perkalian
matrix
*/
glEnable(GL_LIGHTING);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1, 150, 50);
glPushMatrix();
glRotatef(-45.0, 1.0, 0.0, 0.0);
glRotatef(45.0, 0.0, 0.0, 1.0);
glutSolidCube(1.0);
glPopMatrix();
glFlush();
}
No comments:
Post a Comment