Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <iostream>
  7. #include <freeglut.h>
  8.  
  9. float startX = -180.0f;
  10. float startZ = -100.0f;
  11.  
  12. float qtyX = 36;
  13. float qtyZ = 20;
  14.  
  15. float red = 0.0f, green = 0.0f, blue = 0.0f;
  16.  
  17. void init(void)
  18. {
  19.     glClearColor(0.0, 0.0, 0.0, 0.0);
  20. }
  21.  
  22. void display(void)
  23. {
  24.     glClear(GL_COLOR_BUFFER_BIT);
  25.     //glColor3f(1.0, 1.0, 1.0);
  26.     glLoadIdentity();             /* clear the matrix */
  27.             /* viewing transformation  */
  28.    
  29.     gluLookAt(0.0, 30.0f , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0);
  30.  
  31.     for (int i = 0; i <= qtyX; i = i++)
  32.     {
  33.         red = 0.0f;
  34.  
  35.         for (int j = 0; j <= qtyZ; j++)
  36.         {
  37.             if ((i+j)%2 == 0)
  38.             {
  39.                 blue = 0.1f;
  40.                 red = 0.1f;
  41.                 green = 0.1f;
  42.             }
  43.             else red = green = blue = 0.0f;
  44.  
  45.             glColor3f(red, green, blue);
  46.             glBegin(GL_QUADS);
  47.             glVertex3f(startX + (i * 10) - 5.0f, 0.0f, startZ + (j * 10) - 5.0f);
  48.             glVertex3f(startX + (i * 10) + 5.0f, 0.0f, startZ + (j * 10) - 5.0f);
  49.             glVertex3f(startX + (i * 10) + 5.0f, 0.0f, startZ + (j * 10) + 5.0f);
  50.             glVertex3f(startX + (i * 10) - 5.0f, 0.0f, startZ + (j * 10) + 5.0f);
  51.             glEnd();
  52.         }
  53.     }
  54.  
  55.     //glutWireSphere(20.0f, 20.0f, 20.0f);
  56.  
  57.     glutSwapBuffers();
  58.     glFlush();
  59. }
  60.  
  61. void reshape(int w, int h)
  62. {
  63.     glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  64.     glMatrixMode(GL_PROJECTION);
  65.     glLoadIdentity();
  66.     glFrustum(-64.0, 64.0, -36.0, 36.0, 10, 10000.0);
  67.    
  68.     glMatrixMode(GL_MODELVIEW);
  69. }
  70.  
  71. int main(int argc, char** argv)
  72. {
  73.     glutInit(&argc, argv);
  74.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  75.     glutInitWindowSize(1280, 720);
  76.     glutInitWindowPosition(100, 100);
  77.     glutCreateWindow(argv[0]);
  78.     init();
  79.     glutDisplayFunc(display);
  80.     glutIdleFunc(display);
  81.     glutReshapeFunc(reshape);
  82.     glutMainLoop();
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement