Code:
#include <stdio.h>#include <stdarg.h>
#include <math.h>
#include <glut.h>
void initGL()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0); // Red
glVertex2f(.1, .3);
glVertex2f(.1, .8);
glVertex2f(-.1, .8);
glVertex2f(-.1, .3);
glVertex2f(.3, .8);
glVertex2f(.1, .8);
glVertex2f(.1, .7);
glVertex2f(.3, .7);
glVertex2f(-.1, .7);
glVertex2f(-.3, .7);
glVertex2f(-.3, .6);
glVertex2f(-.1, .6);
glColor3f(0.0, 1.0, 0.0); //Green
glVertex2f(.1, -.3);
glVertex2f(.1, -.8);
glVertex2f(-.1, -.8);
glVertex2f(-.1, -.3);
glVertex2f(.3, -.6);
glVertex2f(.1, -.6);
glVertex2f(.1, -.7);
glVertex2f(.3, -.7);
glVertex2f(-.1, -.7);
glVertex2f(-.3, -.7);
glVertex2f(-.3, -.8);
glVertex2f(-.1, -.8);
glColor3f(0.0, 0.0, 1.0); //Blue
glVertex2f(.3, .1);
glVertex2f(.8, .1);
glVertex2f(.8, -.1);
glVertex2f(.3, -.1);
glVertex2f(.7, -.1);
glVertex2f(.7, -.3);
glVertex2f(.8, -.3);
glVertex2f(.8, -.1);
glVertex2f(.7, .1);
glVertex2f(.7, .3);
glVertex2f(.6, .3);
glVertex2f(.6, .1);
glColor3f(1.0, 0.0, 1.0); //Pherozi
glVertex2f(-.3, .1);
glVertex2f(-.8, .1);
glVertex2f(-.8, -.1);
glVertex2f(-.3, -.1);
glVertex2f(-.7, -.1);
glVertex2f(-.7, -.3);
glVertex2f(-.6, -.3);
glVertex2f(-.6, -.1);
glVertex2f(-.7, .1);
glVertex2f(-.7, .3);
glVertex2f(-.8, .3);
glVertex2f(-.8, .1);
glEnd();
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(.3, -.9);
glVertex2f(.3, .9);
glVertex2f(.1, -.9);
glVertex2f(.1, .9);
glVertex2f(-.1, -.9);
glVertex2f(-.1, .9);
glVertex2f(-.3, -.9);
glVertex2f(-.3, .9);
glVertex2f(.9, -.3);
glVertex2f(-.9, -.3);
glVertex2f(.9, -.1);
glVertex2f(-.9, -.1);
glVertex2f(.9, .1);
glVertex2f(-.9, .1);
glVertex2f(.9, .3);
glVertex2f(-.9, .3);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(.3, .4);
glVertex2f(-.3, .4);
glVertex2f(.3, .5);
glVertex2f(-.3, .5);
glVertex2f(.3, .6);
glVertex2f(-.3, .6);
glVertex2f(.3, .7);
glVertex2f(-.3, .7);
glVertex2f(.3, .8);
glVertex2f(-.3, .8);
glVertex2f(.3, .9);
glVertex2f(-.3, .9);
glVertex2f(.3, -.4);
glVertex2f(-.3, -.4);
glVertex2f(.3, -.5);
glVertex2f(-.3, -.5);
glVertex2f(.3, -.6);
glVertex2f(-.3, -.6);
glVertex2f(.3, -.7);
glVertex2f(-.3, -.7);
glVertex2f(.3, -.8);
glVertex2f(-.3, -.8);
glVertex2f(.3, -.9);
glVertex2f(-.3, -.9);
glVertex2f(.3, .3);
glVertex2f(.3, -.3);
glVertex2f(.4, .3);
glVertex2f(.4, -.3);
glVertex2f(.5, .3);
glVertex2f(.5, -.3);
glVertex2f(.6, .3);
glVertex2f(.6, -.3);
glVertex2f(.7, .3);
glVertex2f(.7, -.3);
glVertex2f(.8, .3);
glVertex2f(.8, -.3);
glVertex2f(.9, .3);
glVertex2f(.9, -.3);
glVertex2f(-.3, .3);
glVertex2f(-.3, -.3);
glVertex2f(-.4, .3);
glVertex2f(-.4, -.3);
glVertex2f(-.5, .3);
glVertex2f(-.5, -.3);
glVertex2f(-.6, .3);
glVertex2f(-.6, -.3);
glVertex2f(-.7, .3);
glVertex2f(-.7, -.3);
glVertex2f(-.8, .3);
glVertex2f(-.8, -.3);
glVertex2f(-.9, .3);
glVertex2f(-.9, -.3);
glEnd();
glBegin(GL_POLYGON); //in center White Squar
glColor3f(1.0, 1.0, 1.0);
glVertex2f(.3, .3);
glVertex2f(-.3, .3);
glVertex2f(-.3, -.3);
glVertex2f(.3, -.3);
glEnd();
glBegin(GL_POLYGON); //Corner Red Squar
glColor3f(1.0, 0.0, 0.0);
glVertex2f(.4, .4);
glVertex2f(.4, .9);
glVertex2f(.9, .9);
glVertex2f(.9, .4);
glEnd();
glBegin(GL_POLYGON); //Corner Pherozi Squar
glColor3f(1.0, 0.0, 1.0);
glVertex2f(-.4, .4);
glVertex2f(-.4, .9);
glVertex2f(-.9, .9);
glVertex2f(-.9, .4);
glEnd();
glBegin(GL_POLYGON); //Corner Blue Squar
glColor3f(0.0, 0.0, 1.0);
glVertex2f(.4,-.4);
glVertex2f(.4, -.9);
glVertex2f(.9, -.9);
glVertex2f(.9, -.4);
glEnd();
glBegin(GL_POLYGON); //Corner Green Squar
glColor3f(0.0, 1.0, 0.0);
glVertex2f(-.4, -.4);
glVertex2f(-.4, -.9);
glVertex2f(-.9, -.9);
glVertex2f(-.9, -.4);
glEnd();
float cx = 0, cy = 0, r = 0.3, theta = 0;
int step = 500;
glBegin(GL_POLYGON); //Center Big Circle
for (int i = 0; i < step; i++)
{
theta = 2.0f * 3.1415926f * float(i) / float(step);
float x = cx + r * cosf(theta);
float y = cy + r * sinf(theta);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(x,y);
}
glEnd();
glBegin(GL_POLYGON); //Center Small Circle
for (int i = 0; i < step; i++)
{
theta = 2.0f * 3.1415926f * float(i) / float(step);
float x = cx + .2 * cosf(theta);
float y = cy + .2 * sinf(theta);
glColor3f(0.0, 0.0, 0.0);
glVertex2f(x, y);
}
glEnd();
glBegin(GL_POLYGON); //corner Red Squar Circle
for (int i = 0; i < step; i++)
{
theta = 2.0f * 3.1415926f * float(i) / float(step);
float x = .65 + .15 * cosf(theta);
float y = .65 + .15 * sinf(theta);
glColor3f(0.0, 0.0, 0.0);
glVertex2f(x, y);
}
glEnd();
glBegin(GL_POLYGON); //corner Blue Squar Circle
for (int i = 0; i < step; i++)
{
theta = 2.0f * 3.1415926f * float(i) / float(step);
float x = .65 + .15 * cosf(theta);
float y = -.65 + .15 * sinf(theta);
glColor3f(0.0, 0.0, 0.0);
glVertex2f(x, y);
}
glEnd();
glBegin(GL_POLYGON); //corner Pherozi Squar Circle
for (int i = 0; i < step; i++)
{
theta = 2.0f * 3.1415926f * float(i) / float(step);
float x = -.65 + .15 * cosf(theta);
float y = .65 + .15 * sinf(theta);
glColor3f(0.0, 0.0, 0.0);
glVertex2f(x, y);
}
glEnd();
glBegin(GL_POLYGON); //corner Green Squar Circle
for (int i = 0; i < step; i++)
{
theta = 2.0f * 3.1415926f * float(i) / float(step);
float x = -.65 + .15 * cosf(theta);
float y = -.65 + .15 * sinf(theta);
glColor3f(0.0, 0.0, 0.0);
glVertex2f(x, y);
}
glEnd();
glFlush();
}
/* Handler for window re-size event. Called back when the window first appears and
whenever the window is re-sized with its new width and height */
void reshape(GLsizei width, GLsizei height) { // GLsizei for non-negative integer
// Compute aspect ratio of the new window
if (height == 0)
height = 1; // To prevent divide by 0
GLfloat aspect = (GLfloat)width / (GLfloat)height;
// Set the viewport to cover the new window
glViewport(0, 0, width, height);
// Set the aspect ratio of the clipping area to match the viewport
glMatrixMode(GL_PROJECTION); // To operate on the Projection matrix
glLoadIdentity(); // Reset the projection matrix
if (width >= height)
{
// aspect >= 1, set the height from -1 to 1, with larger width
gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
}
else
{
// aspect < 1, set the width to -1 to 1, with larger height
gluOrtho2D(-1.0, 1.0, -1.0 / aspect, 1.0 / aspect);
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitWindowSize(840, 680); // Set the window's initial width & height - non-square
glutInitWindowPosition(0, 0); // Position the window's initial top-left corner
glutCreateWindow("CG_Project LUDO Game Board"); // Create window with the given title
glutDisplayFunc(display); // Register callback handler for window re-paint event
glutReshapeFunc(reshape); // Register callback handler for window re-size event
initGL(); // Our own OpenGL initialization
glutMainLoop(); // Enter the infinite event-processing loop
return 0;
}

No comments:
Post a Comment