Advertisement
Shishu

chase board

Mar 1st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GL/glut.h>
  2.  
  3. void shapes(void) {
  4.     float y1 = 0.0;
  5.     float y2 = 0.0;
  6.     float y3 = 0.1;
  7.     float y4 = 0.1;
  8.     for (int j = 0; j < 8; j++) {
  9.         float x1 = 0.0;
  10.         float x2 = 0.1;
  11.         float x3 = 0.1;
  12.         float x4 = 0.0;
  13.         for (int i = 0; i < 8; i++) {
  14.             glBegin(GL_QUADS);
  15.             if ((j % 2) != 0) {
  16.                 if ((i % 2) != 0) {
  17.                     glColor3f(1.0, 1.0, 1.0);
  18.                 }
  19.                 else {
  20.                     glColor3f(0.2, 0.2, 0.2);
  21.                 }
  22.             }
  23.             if ((j % 2) == 0) {
  24.                 if ((i % 2) != 0) {
  25.                     glColor3f(0.2, 0.2, 0.2);
  26.                 }
  27.                 else {
  28.                     glColor3f(1.0, 1.0, 1.0);
  29.                 }
  30.             }
  31.             glVertex3f(x1, y1, 0.0);
  32.             glVertex3f(x2, y2, 0.0);
  33.             glVertex3f(x3, y3, 0.0);
  34.             glVertex3f(x4, y4, 0.0);
  35.             glEnd();
  36.             x1 += 0.1;
  37.             x2 += 0.1;
  38.             x3 += 0.1;
  39.             x4 += 0.1;
  40.         }
  41.         y1 += 0.1;
  42.         y2 += 0.1;
  43.         y3 += 0.1;
  44.         y4 += 0.1;
  45.     }
  46. }
  47.  
  48. void display(void) {
  49.     // clearing the window with black color, 1st 3 parameter are for R,G,B. last one for opacity
  50.     glClearColor(0.0, 0.0, 0.0, 1.0);
  51.     glClear(GL_COLOR_BUFFER_BIT);
  52.     glLoadIdentity();
  53.  
  54.     //viewing transformation
  55.     //glulookat() positions the camera towards the object
  56.     //camera position, camera target, up vector
  57.     gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  58.     shapes();
  59.     glFlush();
  60. }
  61.  
  62. void reshape(int w, int h) {
  63.     // 1st 2 parameters for lower left corner of the viewport rectangle. the default is 0,0
  64.     // the next coordinates are width and height of the viewport
  65.     //Set the viewport to be the entire window
  66.     glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  67.  
  68.     // setting the camera
  69.     glMatrixMode(GL_PROJECTION);
  70.     glLoadIdentity();
  71.  
  72.     //perspective transform
  73.     //gluPerspective (30, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
  74.     gluPerspective(30, 1, 1.0, 100.0);
  75.     glMatrixMode(GL_MODELVIEW); //switch back the the model editing mode.
  76.  
  77. }
  78.  
  79. int main(int argc, char **argv) {
  80.     glutInit(&argc, argv);
  81.     // single buffering.. (double buffering for animation)
  82.     glutInitDisplayMode(GLUT_SINGLE);
  83.     // full screen is 1000,1000
  84.     // this 0,0 or 1000,1000 are world coordinates
  85.     glutInitWindowSize(700, 700);
  86.     glutInitWindowPosition(100, 100);
  87.     glutCreateWindow("A basic OpenGL Window");
  88.     // registering callback functions
  89.     glutDisplayFunc(display);
  90.     glutReshapeFunc(reshape);
  91.  
  92.     glutMainLoop();
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement