Advertisement
rana1704

chess board

Dec 1st, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #include <GLFW/glfw3.h>
  6. #include <gl/GL.h>
  7.  
  8.  
  9. void render_loop()
  10. {
  11. glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
  12. glClear(GL_COLOR_BUFFER_BIT);
  13.  
  14. float x1 = 10.0f, y1 = 15.0f;
  15. float x2 = 80.0f, y2 = 95.f;
  16. int i, j;
  17.  
  18. for (i = 1; i <= 8; i++) {
  19. for (j = 1; j <= 8; j++) {
  20. if ((j+i) % 2 == 0)
  21. glColor3f(0.0, 0.0, 0.0);
  22. else
  23. glColor3f(1.0, 1.0, 1.0);
  24.  
  25. glBegin(GL_POLYGON);
  26. glVertex2f(x1, y1);
  27. glVertex2f(x2, y1);
  28. glVertex2f(x2, y2);
  29. glVertex2f(x1, y2);
  30. glEnd();
  31.  
  32. x1 += 70.0f;
  33. x2 += 70.0f;
  34. }
  35. x1 = 10.0f;
  36. x2 = 80.0f;
  37. y1 += 80.0f;
  38. y2 += 80.0f;
  39. }
  40. }
  41.  
  42. /* program entry */
  43. int main(int argc, char *argv[])
  44. {
  45. GLFWwindow* window;
  46.  
  47. if (!glfwInit())
  48. {
  49. fprintf(stderr, "Failed to initialize GLFW\n");
  50. exit(EXIT_FAILURE);
  51. }
  52.  
  53. glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  54. window = glfwCreateWindow(660, 610, "LearnOpenGL", NULL, NULL);
  55. if (!window)
  56. {
  57. fprintf(stderr, "Failed to open GLFW window\n");
  58. glfwTerminate();
  59. exit(EXIT_FAILURE);
  60. }
  61.  
  62.  
  63. glfwMakeContextCurrent(window);
  64. glfwSwapInterval(1);
  65.  
  66. // set up view
  67. glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
  68. glClear(GL_COLOR_BUFFER_BIT);
  69. glViewport(0, 0, 800, 600);
  70. glMatrixMode(GL_PROJECTION);
  71. glLoadIdentity();
  72.  
  73. // see https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml
  74. glOrtho(0.0, 700.0, 0.0, 650.0, 0.0, 1.0); // this creates a canvas you can do 2D drawing on
  75.  
  76.  
  77. // Main loop
  78. while (!glfwWindowShouldClose(window))
  79. {
  80. // Draw gears
  81. render_loop();
  82. // Swap buffers
  83. glfwSwapBuffers(window);
  84. glfwPollEvents();
  85. }
  86.  
  87. // Terminate GLFW
  88. glfwTerminate();
  89.  
  90. // Exit program
  91. exit(EXIT_SUCCESS);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement