Tugas
1. Buat
gambar segi empat berdasarkan percobaan program.
2. Buat
warna pelangi yang terdiri dari 7 warna pada gambar segi empat diatas.
Penyelesaian :
1 Membuat segi empat
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void display(void)
{
glClearColor (0.0,0.0,0.0,0.0);
glClear (GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5,-0.5);
glVertex2f(-0.5,0.5);
glVertex2f(0.5,0.5);
glVertex2f(0.5,-0.5);
glEnd ();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutCreateWindow("Membuat Segi Empat");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void display(void)
{
glClearColor (0.0,0.0,0.0,0.0);
glClear (GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0 ,0.0);
glVertex2f(-0.8,0.7);
glVertex2f(-0.8,0.8);
glVertex2f(0.8,0.8);
glVertex2f(0.8,0.7);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0, 0.5, 0.0);
glVertex2f(-0.8,0.6);
glVertex2f(-0.8,0.7);
glVertex2f(0.8,0.7);
glVertex2f(0.8,0.6);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(-0.8,0.5);
glVertex2f(-0.8,0.6);
glVertex2f(0.8,0.6);
glVertex2f(0.8,0.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(-0.8,0.4);
glVertex2f(-0.8,0.5);
glVertex2f(0.8,0.5);
glVertex2f(0.8,0.4);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 1.0);
glVertex2f(-0.8,0.3);
glVertex2f(-0.8,0.4);
glVertex2f(0.8,0.4);
glVertex2f(0.8,0.3);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 1.0);
glVertex2f(-0.8,0.2);
glVertex2f(-0.8,0.3);
glVertex2f(0.8,0.3);
glVertex2f(0.8,0.2);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.53, 0.12, 0.47);
glVertex2f(-0.8,0.1);
glVertex2f(-0.8,0.2);
glVertex2f(0.8,0.2);
glVertex2f(0.8,0.1);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutCreateWindow("Membuat Segi Empat Pelangi");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}






































