Advertisement
Rejuan706

Cheese Board

May 29th, 2023
1,640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GL/gl.h>
  2. #include <GL/glu.h>
  3. #include <GL/glut.h>
  4. #include <cmath>
  5.  
  6. #define white 1
  7. #define black 0
  8.  
  9. void reshape(int w, int h)
  10. {
  11.     glClearColor(0.0, 0.5, 0.0, 0.0f);
  12.     glViewport(0, 0 ,w, h);
  13.     glMatrixMode(GL_PROJECTION);
  14.     glLoadIdentity();
  15.     float h2w= (float)h / (float) w;
  16.     float w2h= (float)w / (float) h;
  17.  
  18.     if(w<=h)
  19.     {
  20.         gluOrtho2D(0.0, 80.0, 0.0, 80.0*h2w);
  21.     }
  22.     else
  23.     {
  24.         gluOrtho2D(0.0*w2h, 80.0, 0.0, 80.0);
  25.     }
  26.     glMatrixMode(GL_MODELVIEW);
  27. }
  28.  
  29. //void init()
  30. //{
  31. //    glClearColor(0.0, 0.5, 0.0, 0.0f);
  32. //    glMatrixMode(GL_PROJECTION);
  33. //    glLoadIdentity();
  34. //    gluOrtho2D(0.0, 80.0, 0.0, 80.0 );
  35. //    glMatrixMode(GL_MODELVIEW);
  36. //}
  37.  
  38. void drawboard()
  39. {
  40.     bool state = white;
  41.     for (int i = 0; i<=80; i+=10)
  42.     {
  43.         for (int j = 0; j<=80; j+=10)
  44.         {
  45.             if (state==white)
  46.             {
  47.             glColor3ub(255,255,255);
  48.             state = black;
  49.             }
  50.             else
  51.             {
  52.             glColor3ub(0,0,0);
  53.             state = white;
  54.             }
  55.             glRecti(i,j, i+10,j+10);
  56.         }
  57.     }
  58. }
  59.  
  60.  
  61. void display()
  62. {
  63.     glClear(GL_COLOR_BUFFER_BIT);
  64.     glLoadIdentity();
  65.  
  66.     drawboard();
  67.  
  68.     glFlush();
  69.  
  70. }
  71.  
  72. int main(int argc, char** argv)
  73. {
  74.     glutInit(&argc, argv);
  75.     glutInitDisplayMode(GLUT_RGB);
  76.  
  77.     glutInitWindowPosition(300,200);
  78.     glutInitWindowSize(500,500);
  79.  
  80.     glutCreateWindow("Cheese Board");
  81.     glutDisplayFunc(display);
  82.     glutReshapeFunc(reshape);
  83. //    init();
  84.     glutMainLoop();
  85.  
  86.     return 0;
  87.  
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement