ne contoh yang berhasil saya buat ::
ne programnya ::
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include
#include
void tampilsimbol(int i)
{
if(i%2==0){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0f,0.0f,0.0f);} // warna hitam
glBegin(GL_QUADS);//buat persegi warna putih/hitam
glVertex2d(0,0);
glVertex2d(0,10);
glVertex2d(10,10);
glVertex2d(10,0);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f); //warna merah
glBegin(GL_LINE_STRIP); //buat garis segiempat
glVertex2d(0,0);
glVertex2d(0,10);
glVertex2d(10,10);
glVertex2d(10,0);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_QUADS); //buat objek
glVertex2d(1,3);
glVertex2d(9,3);
glVertex2d(9,4);
glVertex2d(1,4);//atas
glVertex2d(3,1);
glVertex2d(4,1);
glVertex2d(4,9);
glVertex2d(3,9);//kiri
glVertex2d(1,6);
glVertex2d(1,7);
glVertex2d(9,7);
glVertex2d(9,6);//bawah
glVertex2d(6,1);
glVertex2d(7,1);
glVertex2d(7,9);
glVertex2d(6,9);//kanan
glEnd();
glFlush();
}
void tampil0(int i){
if(i%2==0){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0f,0.0f,0.0f);} // warna hitam
glBegin(GL_QUADS);//buat persegi warna putih/hitam
glVertex2d(0,0);
glVertex2d(0,10);
glVertex2d(10,10);
glVertex2d(10,0);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f); //warna merah
glBegin(GL_LINE_STRIP); //buat garis segiempat
glVertex2d(0,0);
glVertex2d(0,10);
glVertex2d(10,10);
glVertex2d(10,0);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_QUADS); //buat objek
glVertex2d(2,1);
glVertex2d(7,1);
glVertex2d(7,2);
glVertex2d(2,2);// garis atas
glVertex2d(2,2);
glVertex2d(3,2);
glVertex2d(3,7);
glVertex2d(2,7);// gasris kiri
glVertex2d(2,7);
glVertex2d(7,7);
glVertex2d(7,8);
glVertex2d(2,8);// garis bawah
glVertex2d(6,8);
glVertex2d(7,8);
glVertex2d(7,2);
glVertex2d(6,2);// garis kanan
glEnd();
glFlush();
}
void tampil_7(int i){
if(i%2==0){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0f,0.0f,0.0f);} // warna hitam
glBegin(GL_QUADS);//buat persegi warna putih/hitam
glVertex2d(0,0);
glVertex2d(0,10);
glVertex2d(10,10);
glVertex2d(10,0);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f); //warna merah
glBegin(GL_LINE_STRIP); //buat garis segiempat
glVertex2d(0,0);
glVertex2d(0,10);
glVertex2d(10,10);
glVertex2d(10,0);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_QUADS); //buat objek
glVertex2d(2,1);
glVertex2d(7,1);
glVertex2d(7,2);
glVertex2d(2,2);// tampil atas
glVertex2d(7,8);
glVertex2d(6,8);
glVertex2d(6,2);
glVertex2d(7,2);// tampil kanan
glEnd();
glFlush();
}
void tampil_5(int i){
if(i%2==0){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0f,0.0f,0.0f);} // warna hitam
glBegin(GL_QUADS);//buat persegi warna putih/hitam
glVertex2d(0,0);
glVertex2d(0,10);
glVertex2d(10,10);
glVertex2d(10,0);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f); //warna merah
glBegin(GL_LINE_STRIP); //buat garis segiempat
glVertex2d(0,0);
glVertex2d(0,10);
glVertex2d(10,10);
glVertex2d(10,0);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_QUADS); //buat objek
glVertex2d(2,1);
glVertex2d(7,1);
glVertex2d(7,2);
glVertex2d(2,2);//garis atas
glVertex2d(2,2);
glVertex2d(3,2);
glVertex2d(3,5);
glVertex2d(2,5);//garis kiri 1/2
glVertex2d(2,7);
glVertex2d(2,8);
glVertex2d(7,8);
glVertex2d(7,7);//garis bawah
glVertex2d(7,7);
glVertex2d(6,7);
glVertex2d(6,4);
glVertex2d(7,4);//garis kanan 1/2
glVertex2d(7,4);
glVertex2d(7,5);
glVertex2d(2,5);
glVertex2d(2,4);//garis tengah
glEnd();
glFlush();
}
void init (void)
{
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 10.0, 10.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void tampilkan(void) {
int x=0;
for(int i=0;i<=8;i++){
for(int j=8;j>=0;j--){
x++;
glViewport(i*80, j*80, 80, 80);
if(x%4==1){tampilsimbol(x);}
else if(x%4==2){tampil0(x);}
else if(x%4==3){tampil8(x);}
else if(x%4==0){tampil9(x);}
}
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (720, 720); //Ukuran window
glutCreateWindow ("tugas2_OPENGL2D_09_75");
glutDisplayFunc(tampilkan);
init ();
glutMainLoop();
return 0;
}