MEMBUAT PAPAN CATUR DENGAN CODE BLOCK
#include <windows.h>
#include <iostream>
#include <stdlib.h> //Needed for "exit" function
#include <GL/glut.h>
void myinit()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glColor3f(0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 90.0, 0.0, 90.0);
glMatrixMode(GL_MODELVIEW);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
int k = 0;
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
if ((i+j)%2==0)
glColor3f(1.0, 0.6, 0.6);
else
glColor3f(1.0, 1.0, 1.0);
glRecti((i*10),(j*10),(i*10)+10,(j*10)+10);
glColor3f(1.0, 1.0, 0.0);
if (k % 4 == 0) {
glColor3f(0.0, 0.0, 0.0);
for(int l=0;l<7;l+=4)
{
for(int m=0;m<7;m+=4)
{
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glColor3f(0.0, 0.6, 1.0);
glVertex2f(1+l+i*10, 1+m+j*10);
glVertex2f(3+l+i*10, 5+m+j*10);
glVertex2f(5+l+i*10, 1+m+j*10);
glVertex2f(1+l+i*10, 3.5+m+j*10);
glVertex2f(5+l+i*10, 3.5+m+j*10);
glEnd();
}
}
}
if (k%4==1){
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+8,j*10+2);
glVertex2f(i*10+8,j*10+8);
glVertex2f(i*10+3,j*10+8);
glVertex2f(i*10+3,j*10+2);
glEnd();
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+7,j*10+3);
glVertex2f(i*10+7,j*10+7);
glVertex2f(i*10+4,j*10+7);
glVertex2f(i*10+4,j*10+3);
glEnd();
}
if (k%4==2){
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+7,j*10+1);
glVertex2f(i*10+7,j*10+8);
glVertex2f(i*10+2,j*10+8);
glVertex2f(i*10+2,j*10+1);
glEnd();
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+6,j*10+2);
glVertex2f(i*10+6,j*10+4);
glVertex2f(i*10+3,j*10+4);
glVertex2f(i*10+3,j*10+2);
glEnd();
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+6,j*10+5);
glVertex2f(i*10+6,j*10+7);
glVertex2f(i*10+3,j*10+7);
glVertex2f(i*10+3,j*10+5);
glEnd();
}
if (k%4==3){
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+7,j*10+2);
glVertex2f(i*10+7,j*10+8);
glVertex2f(i*10+6,j*10+8);
glVertex2f(i*10+6,j*10+5);
glVertex2f(i*10+3,j*10+5);
glVertex2f(i*10+3,j*10+8);
glVertex2f(i*10+2,j*10+8);
glVertex2f(i*10+2,j*10+4);
glVertex2f(i*10+6,j*10+4);
glVertex2f(i*10+6,j*10+2);
glEnd();
}
k++;
}
}
glFlush();
}
void key(unsigned char key, int mouseX, int mouseY)
{
if (key=='q' || key=='Q') exit(-1);
}
int main(int argc, char* argv[])
{
glutInitWindowSize(800,700);
glutInitWindowPosition(100,100);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("Papan Catur NRP ");
glutDisplayFunc(display);
glutKeyboardFunc(key);
myinit();
glutMainLoop();
return 0;
}
#include <iostream>
#include <stdlib.h> //Needed for "exit" function
#include <GL/glut.h>
void myinit()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glColor3f(0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 90.0, 0.0, 90.0);
glMatrixMode(GL_MODELVIEW);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
int k = 0;
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
if ((i+j)%2==0)
glColor3f(1.0, 0.6, 0.6);
else
glColor3f(1.0, 1.0, 1.0);
glRecti((i*10),(j*10),(i*10)+10,(j*10)+10);
glColor3f(1.0, 1.0, 0.0);
if (k % 4 == 0) {
glColor3f(0.0, 0.0, 0.0);
for(int l=0;l<7;l+=4)
{
for(int m=0;m<7;m+=4)
{
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glColor3f(0.0, 0.6, 1.0);
glVertex2f(1+l+i*10, 1+m+j*10);
glVertex2f(3+l+i*10, 5+m+j*10);
glVertex2f(5+l+i*10, 1+m+j*10);
glVertex2f(1+l+i*10, 3.5+m+j*10);
glVertex2f(5+l+i*10, 3.5+m+j*10);
glEnd();
}
}
}
if (k%4==1){
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+8,j*10+2);
glVertex2f(i*10+8,j*10+8);
glVertex2f(i*10+3,j*10+8);
glVertex2f(i*10+3,j*10+2);
glEnd();
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+7,j*10+3);
glVertex2f(i*10+7,j*10+7);
glVertex2f(i*10+4,j*10+7);
glVertex2f(i*10+4,j*10+3);
glEnd();
}
if (k%4==2){
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+7,j*10+1);
glVertex2f(i*10+7,j*10+8);
glVertex2f(i*10+2,j*10+8);
glVertex2f(i*10+2,j*10+1);
glEnd();
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+6,j*10+2);
glVertex2f(i*10+6,j*10+4);
glVertex2f(i*10+3,j*10+4);
glVertex2f(i*10+3,j*10+2);
glEnd();
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+6,j*10+5);
glVertex2f(i*10+6,j*10+7);
glVertex2f(i*10+3,j*10+7);
glVertex2f(i*10+3,j*10+5);
glEnd();
}
if (k%4==3){
glColor3f(1,0,0);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(i*10+7,j*10+2);
glVertex2f(i*10+7,j*10+8);
glVertex2f(i*10+6,j*10+8);
glVertex2f(i*10+6,j*10+5);
glVertex2f(i*10+3,j*10+5);
glVertex2f(i*10+3,j*10+8);
glVertex2f(i*10+2,j*10+8);
glVertex2f(i*10+2,j*10+4);
glVertex2f(i*10+6,j*10+4);
glVertex2f(i*10+6,j*10+2);
glEnd();
}
k++;
}
}
glFlush();
}
void key(unsigned char key, int mouseX, int mouseY)
{
if (key=='q' || key=='Q') exit(-1);
}
int main(int argc, char* argv[])
{
glutInitWindowSize(800,700);
glutInitWindowPosition(100,100);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("Papan Catur NRP ");
glutDisplayFunc(display);
glutKeyboardFunc(key);
myinit();
glutMainLoop();
return 0;
}
Komentar