Ini merupakan hasil running dari program saya untuk tampil NRP dengan menggunakan OpenGL.
Scriptnya kira-kira berikut ini:
// 120.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "GL/glut.h"
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();
if(i%2==1){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0f,0.0f,0.0f);} // warna hitam
glBegin(GL_QUADS); //buat objek
glVertex2d(4,1);
glVertex2d(5,1);
glVertex2d(5,8);
glVertex2d(4,8);
glVertex2d(1,4);
glVertex2d(8,4);
glVertex2d(8,5);
glVertex2d(1,5);
glEnd();
glFlush();
}
void tampil1(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();
if(i%2==1){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0f,0.0f,0.0f);} // warna hitam
glBegin(GL_QUADS); //buat objek
glVertex2d(3,1);
glVertex2d(5,1);
glVertex2d(5,2);
glVertex2d(3,2);//
glVertex2d(4,2);
glVertex2d(5,2);
glVertex2d(5,8);
glVertex2d(4,8);//
glEnd();
glFlush();
}
void tampil2(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();
if(i%2==1){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0f,0.0f,0.0f);} // warna hitam
glBegin(GL_QUADS); //buat objek
glVertex2d(2,1);
glVertex2d(7,1);
glVertex2d(7,2);
glVertex2d(2,2);//
glVertex2d(2,2);
glVertex2d(3,2);
glVertex2d(3,7);
glVertex2d(2,7);//
glVertex2d(2,7);
glVertex2d(7,7);
glVertex2d(7,8);
glVertex2d(2,8);//
glVertex2d(6,8);
glVertex2d(7,8);
glVertex2d(7,2);
glVertex2d(6,2);
glEnd();
glFlush();
}
void tampil0(int i){
if(i%2==0){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0,1.0,0.0);} // warna hijau
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();
if(i%2==1){
glColor3f(1.0f,1.0f,1.0f); //warna putih
}else {glColor3f(0.0f,0.0f,0.0f);} // warna hitam
glBegin(GL_QUADS); //buat objek
glVertex2d(2,1);
glVertex2d(7,1);
glVertex2d(7,2);
glVertex2d(2,2);//
glVertex2d(6,2);
glVertex2d(7,2);
glVertex2d(7,4);
glVertex2d(6,4);//
glVertex2d(2,4);
glVertex2d(7,4);
glVertex2d(7,5);
glVertex2d(2,5);//
glVertex2d(2,5);
glVertex2d(3,5);
glVertex2d(3,7);
glVertex2d(2,7);//
glVertex2d(2,7);
glVertex2d(7,7);
glVertex2d(7,8);
glVertex2d(2,8);
glEnd();
glFlush();
}
void init (void)
{
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 10.0, 10.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void drawTiling(void) {
int x=0;
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
x++;
glViewport(i*45, j*45, 45, 45);
if(x%4==0){tampil1(x);}
else if(x%4==2){tampil2(x);}
else if(x%4==3){tampil0(x);}
else if(x%4==1){tampilsimbol(x);}
}
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (405, 405); //Ukuran window
glutCreateWindow ("TugasOpenGL 2D_09.04.111.00120");
glutDisplayFunc(drawTiling);
init ();
glutMainLoop();
return 0;
}
Minggu, 16 Oktober 2011
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar