Advertisement
atm959

A

Jul 5th, 2019
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. void updateTilemap() {
  2.     float u, v, u2, v2;
  3.     for (int i = 0; i < (64 * 64); i++) {
  4.         u = (float)((tiles[i] % 16) * 16) / 256;
  5.         v = (float)((tiles[i] / 16) * 16) / 256;
  6.         u2 = (float)(((tiles[i] % 16) * 16) + 16) / 256;
  7.         v2 = (float)(((tiles[i] / 16) * 16) + 16) / 256;
  8.         if (switchBlockActivated) {
  9.             if (tiles[i] == 9) {
  10.                 u = (float)((10 % 16) * 16) / 256;
  11.                 v = (float)((10 / 16) * 16) / 256;
  12.                 u2 = (float)(((10 % 16) * 16) + 16) / 256;
  13.                 v2 = (float)(((10 / 16) * 16) + 16) / 256;
  14.             } else if (tiles[i] == 10) {
  15.                 u = (float)((9 % 16) * 16) / 256;
  16.                 v = (float)((9 / 16) * 16) / 256;
  17.                 u2 = (float)(((9 % 16) * 16) + 16) / 256;
  18.                 v2 = (float)(((9 / 16) * 16) + 16) / 256;
  19.             } else if (tiles[i] == 7) {
  20.                 u = (float)((8 % 16) * 16) / 256;
  21.                 v = (float)((8 / 16) * 16) / 256;
  22.                 u2 = (float)(((8 % 16) * 16) + 16) / 256;
  23.                 v2 = (float)(((8 / 16) * 16) + 16) / 256;
  24.             }
  25.         }
  26.  
  27.         bgVertices[i * 24] = (float)(i % 64);
  28.         bgVertices[(i * 24) + 1] = (float)((i / 64) + 1);
  29.         bgVertices[(i * 24) + 2] = u;
  30.         bgVertices[(i * 24) + 3] = v2;
  31.  
  32.         bgVertices[(i * 24) + 4] = (float)((i % 64) + 1);
  33.         bgVertices[(i * 24) + 5] = (float)(i / 64);
  34.         bgVertices[(i * 24) + 6] = u2;
  35.         bgVertices[(i * 24) + 7] = v;
  36.  
  37.         bgVertices[(i * 24) + 8] = (float)(i % 64);
  38.         bgVertices[(i * 24) + 9] = (float)(i / 64);
  39.         bgVertices[(i * 24) + 10] = u;
  40.         bgVertices[(i * 24) + 11] = v;
  41.  
  42.         bgVertices[(i * 24) + 12] = (float)(i % 64);
  43.         bgVertices[(i * 24) + 13] = (float)((i / 64) + 1);
  44.         bgVertices[(i * 24) + 14] = u;
  45.         bgVertices[(i * 24) + 15] = v2;
  46.  
  47.         bgVertices[(i * 24) + 16] = (float)((i % 64) + 1);
  48.         bgVertices[(i * 24) + 17] = (float)((i / 64) + 1);
  49.         bgVertices[(i * 24) + 18] = u2;
  50.         bgVertices[(i * 24) + 19] = v2;
  51.  
  52.         bgVertices[(i * 24) + 20] = (float)((i % 64) + 1);
  53.         bgVertices[(i * 24) + 21] = (float)(i / 64);
  54.         bgVertices[(i * 24) + 22] = u2;
  55.         bgVertices[(i * 24) + 23] = v;
  56.     }
  57.  
  58.     glBindVertexArray(bgVAO);
  59.  
  60.     glBindBuffer(GL_ARRAY_BUFFER, bgVBO);
  61.     glBufferData(GL_ARRAY_BUFFER, sizeof(bgVertices), bgVertices, GL_DYNAMIC_DRAW);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement