Advertisement
Guest User

Raycast Problem Forum

a guest
Feb 16th, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 44.06 KB | None | 0 0
  1. /*--HEADERS--*/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <GL/glut.h>
  5. #include <math.h>
  6.  
  7. /*--DEFINITIONS--*/
  8. #define PI 3.141592653589793238
  9. #define DR 0.0174533 //this is one degree in radians
  10.  
  11. struct BUTTON_KEYS
  12. {
  13.     int w, a, s, d; //tracks button states as 0 (off) or 1 (on);
  14. };
  15.  
  16. int Contains(int list[], int size, int number)
  17. {
  18.     if(size == -1)
  19.     {
  20.         //Why divide the sizeof the list to the sizeof the first element? Sizeof returns the size in bytes. This means that
  21.         // we can divide the number of bytes in the first element by the size of the whole array to get the array size
  22.         size = sizeof(list) / sizeof(list[0]);
  23.     }
  24.  
  25.     int i; //Delcaring variables in forloops only works in C99 version of C i guess.
  26.     for(i = 0; i <= size; i++)
  27.     {
  28.         if(list[i] == number)
  29.         {
  30.             return 1;
  31.         }
  32.     }
  33.    
  34.     return 0;
  35. }
  36.  
  37. int textures[] = //an array numbers. each texture is 1024 bits as they are 32 x 32 textures
  38. {
  39.     //brown brick texture - 1
  40.     3, 3, 3, 3, 3, 3, 3, 4,   4, 3, 3, 3, 3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 4,   4, 3, 3, 3, 3, 3, 3, 3,
  41.     1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 3, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 3, 1, 1, 1, 1, 1,
  42.     1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,
  43.     1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,
  44.     1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,
  45.     1, 1, 1, 1, 1, 2, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 2, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,
  46.     2, 2, 2, 2, 2, 2, 2, 4,   4, 3, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 4,   4, 3, 2, 2, 2, 2, 2, 2,
  47.     4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,
  48.    
  49.     4, 3, 3, 3, 3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 4,   4, 3, 3, 3, 3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 4,
  50.     4, 3, 3, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 3, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,
  51.     4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,
  52.     4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,
  53.     4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,
  54.     4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 2, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 2, 2, 4,
  55.     4, 3, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 4,   4, 3, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 4,
  56.     4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,
  57.    
  58.     3, 3, 3, 3, 3, 3, 3, 4,   4, 3, 3, 3, 3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 4,   4, 3, 3, 3, 3, 3, 3, 3,
  59.     1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 3, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 3, 1, 1, 1, 1, 1,
  60.     1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,
  61.     1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,
  62.     1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,
  63.     1, 1, 1, 1, 1, 2, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 2, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,
  64.     2, 2, 2, 2, 2, 2, 2, 4,   4, 3, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 4,   4, 3, 2, 2, 2, 2, 2, 2,
  65.     4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,
  66.    
  67.     4, 3, 3, 3, 3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 4,   4, 3, 3, 3, 3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 3,
  68.     4, 3, 3, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 3, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,
  69.     4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,
  70.     4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,
  71.     4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 2, 4,
  72.     4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 2, 2, 4,   4, 3, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 2, 2, 4,
  73.     4, 3, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 4,   4, 3, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 4,
  74.     4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,
  75.    
  76.     //Wood Door 1 - 2
  77.     5, 5, 5, 5, 5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,
  78.     5, 5, 5, 5, 5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,
  79.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 6, 6, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  80.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 6, 6, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  81.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 6, 6, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  82.     5, 5, 6, 6, 5, 5, 5, 5,   5, 5, 5, 5, 5, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  83.     5, 5, 6, 6, 7, 8, 8, 8,   8, 8, 8, 8, 7, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  84.     5, 5, 6, 6, 7, 8, 8, 8,   8, 8, 8, 9, 7, 6, 6, 5,   5, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 5, 5,
  85.    
  86.     5, 5, 6, 6, 7, 8, 8, 8,   8, 8, 9, 9, 7, 6, 6, 5,   5, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 5, 5,
  87.     5, 5, 6, 6, 7, 8, 8, 8,   8, 9, 9, 9, 7, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  88.     5, 5, 6, 6, 7, 8, 8, 8,   9, 9, 9, 9, 7, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  89.     5, 5, 6, 6, 7, 8, 8, 9,   9, 9, 9, 9, 7, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  90.     5, 5, 6, 6, 7, 7, 7, 7,   7, 7, 7, 7, 7, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  91.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 6, 6, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  92.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 6, 6, 6, 6, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  93.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 6, 6, 6, 6, 5,   5, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 5, 5,
  94.    
  95.     5, 5, 6, 6, 6, 6, 6, 6,   6, 0, 0, 0, 0, 0, 0, 5,   5, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 5, 5,
  96.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  97.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  98.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  99.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  100.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  101.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 6, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 0,   0, 2, 2, 2, 2, 2, 5, 5,
  102.     5, 5, 6, 6, 6, 6, 6, 6,   6, 6, 0, 0, 0, 0, 0, 5,   5, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 5, 5,
  103.    
  104.     5, 5, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 5,   5, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 5, 5,
  105.     5, 5, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  106.     5, 5, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  107.     5, 5, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  108.     5, 5, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  109.     5, 5, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  110.     5, 5, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 5,   5, 2, 2, 2, 2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 5, 5,
  111.     5, 5, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 5,   5, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 5, 5,
  112.    
  113.     //Checkerboard - 3
  114.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  115.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  116.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  117.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  118.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  119.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  120.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  121.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  122.    
  123.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  124.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  125.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  126.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  127.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  128.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  129.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  130.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  131.    
  132.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  133.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  134.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  135.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  136.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  137.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  138.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  139.     0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,
  140.    
  141.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  142.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  143.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  144.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  145.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  146.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  147.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  148.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  149.    
  150.     //striped down - 4
  151.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  152.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  153.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  154.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  155.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  156.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  157.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  158.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  159.    
  160.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  161.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  162.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  163.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  164.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  165.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  166.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  167.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  168.    
  169.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  170.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  171.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  172.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  173.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  174.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  175.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  176.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  177.    
  178.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  179.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  180.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  181.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  182.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  183.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  184.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  185.     1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,   1, 1, 1, 1, 1, 1, 1, 1,   0, 0, 0, 0, 0, 0, 0, 0,
  186. };
  187.  
  188. struct BUTTON_KEYS Keys;
  189.  
  190. struct F_TUPLE
  191. {
  192.     float x;
  193.     float y;
  194.     float z;
  195. };
  196.  
  197. float Convert255to1(float number)
  198. {
  199.     number = number / 255.0000;
  200.     return number;
  201. }
  202.  
  203. /*--MAP--*/
  204. int map_size_x = 8, map_size_y = 8, tile_size = 64.0000; //defines the map as being 8 tiles horizontally and vertically, with each tile being 64 units
  205.  
  206. //What tile codes are considered doors.
  207. int DoorTiles[] = {3, 2};
  208.  
  209. /*---
  210. -----
  211. Wall Map Codes
  212.  
  213. 1 - Brown Brick Texture 1 - WALL
  214. 2. Wood Door Texture 1 - DOOR
  215. -----
  216. ---*/
  217.  
  218. int wall_map[] =
  219. {
  220.     1, 1, 1, 1, 1, 1, 1, 1,
  221.     1, 0, 0, 0, 0, 0, 0, 1,
  222.     1, 0, 0, 0, 0, 0, 0, 1,
  223.     1, 0, 0, 0, 0, 0, 0, 1,
  224.     1, 0, 0, 0, 0, 0, 0, 1,
  225.     1, 0, 0, 0, 0, 0, 0, 1,
  226.     1, 0, 0, 0, 0, 0, 0, 1,
  227.     1, 1, 1, 1, 1, 1, 1, 1,
  228. };
  229.  
  230. /*---
  231. -----
  232. Floor Map Codes - Same as wall map, -1! So brick is 0, wood door is 1, etc.
  233. -----
  234. ---*/
  235.  
  236. int floor_map[] =
  237. {
  238.     0, 0, 0, 0, 0, 0, 0, 0,
  239.     0, 0, 0, 0, 0, 0, 0, 0,
  240.     0, 0, 0, 0, 0, 0, 0, 0,
  241.     0, 0, 0, 0, 0, 0, 0, 0,
  242.     0, 0, 0, 0, 0, 0, 0, 0,
  243.     0, 0, 0, 0, 0, 0, 0, 0,
  244.     0, 0, 0, 0, 0, 0, 0, 0,
  245.     0, 0, 0, 0, 0, 0, 0, 0,
  246.  
  247. };
  248.  
  249. int cieling_map[] =
  250. {
  251.     0, 0, 0, 0, 0, 0, 0, 0,
  252.     0, 0, 0, 0, 0, 0, 0, 0,
  253.     0, 0, 0, 0, 0, 0, 0, 0,
  254.     0, 0, 0, 0, 0, 0, 0, 0,
  255.     0, 0, 0, 0, 0, 0, 0, 0,
  256.     0, 0, 0, 0, 0, 0, 0, 0,
  257.     0, 0, 0, 0, 0, 0, 0, 0,
  258.     0, 0, 0, 0, 0, 0, 0, 0,
  259.  
  260. };
  261.  
  262.  
  263. void DrawMap2D()
  264. {
  265.     int x, y; //for loop iterators for each tile, x and y, on t he mpa
  266.     int x_offset, y_offset;
  267.    
  268.     for(y = 0; y < map_size_y; y++) //for loop continues for each tile on the y axis
  269.     {
  270.         for(x = 0; x < map_size_x; x++) //for loops goes through each x axis tile in each y column
  271.         {
  272.             if(wall_map[y * map_size_x + x] > 0) //a genius way of iterating through a 1 dimensional array as a 2 dimensional matrix. Hard to explain.
  273.             {
  274.                 glColor3f(0.9686, 0.7373, 0.6784); //if there's a wall, set the GL color to white
  275.             }
  276.             else
  277.             {
  278.                 glColor3f(0.3725, 0.3647, 0.4941); //if there's not a wall, set the GL color to black
  279.             }
  280.             /*
  281.             To draw a 64 unit block, multiply the current x and y coords for that tile by the tile size, 64.
  282.             This means that tile one will be drawn from units 0, 0; to units 64, 64;
  283.             Tile two will be drawn from units 64, 64 to units 128, 128; etc. forming the grid.
  284.             */
  285.            
  286.             x_offset = x * tile_size; y_offset = y * tile_size; //multiplies x and y by tile size to get the offset required
  287.             glBegin(GL_QUADS); //begins GL in quadrilateral mode
  288.             glVertex2i(x_offset+1,           y_offset+1          ); //draws point one at the offset (so for tile zero it will be (0, 0))
  289.             glVertex2i(x_offset+1,           y_offset + tile_size-1); //draws point two at the offset plus tile size for y (so for tile zero it will be (0, 64))
  290.             glVertex2i(x_offset-1 + tile_size, y_offset + tile_size-1); //draws point three at the offset plus tile size for both x and y (so for tile zero it will be (64, 64))
  291.             glVertex2i(x_offset-1 + tile_size, y_offset+1            ); //draws point four at the offset plus tile size for x (so for tile zero it will be (64, 0))
  292.             glEnd();
  293.             /*
  294.                 This creates a quadrilateral with points    (0,  0)----------(0,  64)   for tile zero
  295.                                                             |                       |
  296.                                                             |                       |
  297.                                                             |                       |
  298.                                                             (64, 0)----------(64, 64)
  299.                                                            
  300.                 This creates a quadrilateral with points    (64,  64)----------(64,  128)   for tile one
  301.                                                             |                           |
  302.                                                             |                           |
  303.                                                             |                           |
  304.                                                             (128, 64)----------(128, 128)
  305.                                                            
  306.                                                             and so on;
  307.                                                            
  308.                 These quads will be drawn regardless of if they are walls or not. If they are not walls, they will be
  309.                 drawn as black instead of white, but they are still drawn;
  310.                
  311.                 The plus and minus one throughout is just to draw a border around the blocks for visibility
  312.             */
  313.         }
  314.     }
  315. }
  316.  
  317. /*--PLAYER--*/
  318.  
  319. float player_x, player_y; //player position
  320. float player_delta_x, player_delta_y; //stores the amount of movement in the horizontal/vertical direction the player should move
  321. float player_angle;
  322.  
  323. void DrawPlayer2D()
  324. {
  325.     glColor3f(0.1765, 0.2588, 0.3216); //sets the current gl color
  326.     glPointSize(8); //sets the point size to 8
  327.     glBegin(GL_POINTS); //starts GL in point drawing mode
  328.     glVertex2i(player_x, player_y); //uses the vertex integer draw function to draw a point at player's position
  329.     glEnd(); //ends the current GL process
  330.    
  331.     glLineWidth(3);
  332.     glBegin(GL_LINES);
  333.    
  334.     //draw a line from the players position to the players delta position, i.e. where they are facing
  335.     glVertex2i(player_x, player_y);
  336.     glVertex2i(player_x + player_delta_x * 5, player_y + player_delta_y * 5);
  337.     glEnd();
  338. }
  339.  
  340. /*---RAYS---*/
  341.  
  342. float Dist(float ax, float ay, float bx, float by, float ang)
  343. {
  344.     float horizontal_dist = bx - ax;
  345.     float vertical_dist = by - ay;
  346.     float horizontal_dist_sqr = horizontal_dist * horizontal_dist;
  347.     float vertical_dist_sqr = vertical_dist * vertical_dist;
  348.     float final_dist = sqrt(horizontal_dist_sqr + vertical_dist_sqr);
  349.     return final_dist;
  350. }
  351.  
  352. void DrawRays2D()
  353. {
  354.     int r, mx, my, mp, depth_of_field; //DoF == number of tiles to cast over, if more than DoF then just end the ray
  355.     float ray_x, ray_y, ray_angle, x_offset, y_offset;
  356.     float final_distance; //holds either horizontal or vertical distance, whicherver is shorter
  357.    
  358.     float horizontal_distance = 100000;
  359.     float horizontal_x = player_x;
  360.     float horizontal_y = player_y;
  361.    
  362.     ray_angle = player_angle - (DR * 30);
  363.     if(ray_angle < 0)
  364.     {
  365.         ray_angle += 2*PI;
  366.     }
  367.     if(ray_angle > 2*PI)
  368.     {
  369.         ray_angle -= 2*PI;
  370.     }
  371.    
  372.     for(r = 0; r < 240; r++)
  373.     {
  374.        
  375.         int vmt = 0, hmt = 0; //vertical and horizontal map texture code
  376.         // Check Horizontal Lines
  377.        
  378.         depth_of_field = 0;
  379.         float aTan = -1 / tan(ray_angle);
  380.        
  381.         if(ray_angle > PI) //if the ray's angle is greater than Pi aka 180 degs, the player is looking up;
  382.         {
  383.             ray_y = ((((int)player_y) / tile_size) * tile_size) - 0.0001; //rounds the ray's y value to the nearest tile. Because each tile is 64 units, dividing and then multiplying by 64 rounds to the nearest multiple of 64, ensuring that the max y distance per depth_of_field iteration is a multiple of 64
  384.             //the -0.0001 is for accuracy. Floating point numbers are inherently a bit inaccurate, meaning sometimes the rays will overshoot their collision and keep firing forward to the next wall.
  385.             //Subtracting 0.0001 ensures that all rays undershoot by just a small amount, not enough to be perceptible but enough to prevent overshooting.
  386.             //Overshooting causes the ray to go to the next wall, which is 64 blocks away. Undershooting by 0.0001 is better than overshooting by 64.
  387.            
  388.             /*---
  389.             -----
  390.            
  391.             Tangent (Tan) is opposite over adjacent. We know the opposite line (the vertical one) is player_y - ray_y.
  392.             The Inverse Tangent (aTan) is adjacent over opposite. By multiplying opposite by aTan, we are multiplying
  393.             opp * adj/opp, the opps cancel out and give us adj. We then add the player's x position to adj to figure out
  394.             where on the map the ray's x vector is.
  395.            
  396.             -----
  397.             ---*/
  398.            
  399.             ray_x = (player_y - ray_y) * aTan + player_x;
  400.            
  401.             /*---
  402.             -----
  403.            
  404.             the offsets calculate the next hit position. y is the same, just up by 64 (GL renders with 0, 0 being top left,
  405.             and moving down increases y position). x is the negative of the y_offset (because x is rendered normally,
  406.             left to right. If we shoot a ray and don't hit, we increment the ray's y value by subtracting 64, then use
  407.             the aTan trick to find the proper x offset.
  408.            
  409.             -----
  410.             ---*/
  411.             y_offset = -64;
  412.             x_offset = -y_offset * aTan;
  413.         }
  414.        
  415.         if(ray_angle < PI) //if the ray's angle is less than Pi aka 180 degs, the player is looking down;
  416.         {
  417.             ray_y = ((((int)player_y) / tile_size) * tile_size) + tile_size;
  418.             //rounds the ray's y value to the nearest tile. Because each tile is 64 units, dividing and then multiplying
  419.             //by 64 rounds to the nearest multiple of 64, ensuring that the max y distance per depth_of_field iteration is a multiple
  420.             //of 64. By adding the tile_size (64), we ensure that the ray stops at the top of the tile rather than the bottom
  421.                                                                            
  422.             ray_x = (player_y - ray_y) * aTan + player_x;
  423.            
  424.             y_offset = 64;
  425.             x_offset = -y_offset * aTan;
  426.         }
  427.        
  428.         if(ray_angle == 0 || ray_angle == PI) //player is looking straight left or right, the ray will never intersect
  429.         {
  430.             ray_x = player_x;
  431.             ray_y = player_y;
  432.             depth_of_field = 16; //Setting depth_of_field to 8 means that we don't need to continue casting rays
  433.         }
  434.        
  435.         while(depth_of_field < 16) //if depth_of_field is less than 8, keep casting until it hits something or iterates 8 times
  436.         {
  437.             mx = (int)(ray_x) / tile_size; //the ray's x value divided by 64, effectively giving the tile position's x value
  438.             my = (int)(ray_y) / tile_size; //the ray's y value divided by 64, effectively giving the tile position's y value
  439.             mp = my * map_size_x + mx; //The ray's final point on the map
  440.            
  441.             if(mp > 0 && mp < map_size_x * map_size_y && wall_map[mp] > 0) //if the ray's final point on the map is less than the size of the map (AKA not out of bounds) and is a 1, then the ray hit a wall. Set depth_of_field to 8 so that the while loop stops. The search is over.
  442.             {
  443.                 hmt = wall_map[mp]-1;
  444.                 horizontal_x = ray_x;
  445.                 horizontal_y = ray_y;
  446.                 horizontal_distance = Dist(player_x, player_y, horizontal_x, horizontal_y, ray_angle);
  447.                
  448.                 depth_of_field = 16;
  449.             }
  450.             else
  451.             {
  452.                 ray_x += x_offset;
  453.                 ray_y += y_offset;
  454.                 depth_of_field += 1;
  455.             }
  456.         }
  457.        
  458.         // Check Vertical Lines
  459.         depth_of_field = 0;
  460.         float nTan = -tan(ray_angle);
  461.        
  462.         float vertical_distance = 100000;
  463.         float vertical_x = player_x;
  464.         float vertical_y = player_y;
  465.        
  466.         if(ray_angle > (PI/2) && ray_angle < ((3*PI)/2)) //if the ray's angle is greater than PI/2 aka 90 degs, and less than 3PI/2 aka 270 degs, the player is looking left;
  467.         {
  468.             ray_x = ((((int)player_x) / tile_size) * tile_size) - 0.0001;
  469.             ray_y = (player_x - ray_x) * nTan + player_y;
  470.             x_offset = -64;
  471.             y_offset = -x_offset * nTan;
  472.         }
  473.        
  474.         if(ray_angle < (PI/2) || ray_angle > ((3*PI)/2)) //if the ray's angle is less than PI/2 aka 90 or greater than 3PI/2 aka 270 degs, the player is looking right;
  475.         {
  476.             ray_x = ((((int)player_x) / tile_size) * tile_size) + tile_size;                                                               
  477.             ray_y = (player_x - ray_x) * nTan + player_y;
  478.             x_offset = 64;
  479.             y_offset = -x_offset * nTan;
  480.         }
  481.        
  482.         if(ray_angle == 0 || ray_angle == PI) //player is looking straight up or down, the ray will never intersect
  483.         {  
  484.             ray_x = player_x;
  485.             ray_y = player_y;
  486.            
  487.             depth_of_field = 16;
  488.         }
  489.        
  490.         while(depth_of_field < 16)
  491.         {
  492.             mx = (int)(ray_x) / tile_size;
  493.             my = (int)(ray_y) / tile_size;
  494.             mp = my * map_size_x + mx;
  495.            
  496.             if(mp > 0 && mp < map_size_x * map_size_y && wall_map[mp] > 0)
  497.             {
  498.                 vmt = wall_map[mp]-1;
  499.                 vertical_x = ray_x;
  500.                 vertical_y = ray_y;
  501.                 vertical_distance = Dist(player_x, player_y, vertical_x, vertical_y, ray_angle);
  502.                
  503.                 depth_of_field = 16;
  504.             }
  505.             else
  506.             {
  507.                 ray_x += x_offset;
  508.                 ray_y += y_offset;
  509.                 depth_of_field += 1;
  510.             }
  511.         }
  512.        
  513.        
  514.         float shade = 1; //value to shade our textures with
  515.        
  516.         if(horizontal_distance < vertical_distance)
  517.         {
  518.             ray_x = horizontal_x;
  519.             ray_y = horizontal_y;
  520.             final_distance = horizontal_distance;
  521.         }
  522.        
  523.         if(horizontal_distance > vertical_distance)
  524.         {
  525.             hmt = vmt;
  526.             ray_x = vertical_x;
  527.             ray_y = vertical_y;
  528.             final_distance = vertical_distance;
  529.         }
  530.        
  531.         //printf("Horizontal X: %f\nHorizontal Y: %f\nHorizontal Dist: %f\n\nVertical X: %f\nVertical Y: %f\nVertical Dist: %f\n\nRay X: %f\n Ray Y: %f\nRayDist: &f\n\n", horizontal_x, horizontal_y, horizontal_distance, vertical_x, vertical_y, vertical_distance, ray_x, ray_y, (float)Dist(player_x, player_y, ray_x, ray_y, ray_angle));
  532.        
  533.         glColor3f (0.6706, 0.5098, 0.6000);
  534.         glLineWidth(3);
  535.         glBegin(GL_LINES);
  536.         glVertex2i(player_x, player_y);
  537.         glVertex2i(ray_x, ray_y);
  538.         glEnd();
  539.        
  540.         /*------------*\
  541.         ----------------
  542.         DRAWING 3D WALLS!
  543.         ----------------
  544.         \*------------*/
  545.        
  546.         float angle_offset = player_angle - ray_angle; //finds the distance between the player_angle (forward) and each ray
  547.         if(angle_offset < 0)
  548.         {
  549.             angle_offset += 2*PI;
  550.         }
  551.         if(angle_offset > 2*PI)
  552.         {
  553.             angle_offset -= 2*PI;
  554.         }
  555.        
  556.         final_distance = final_distance * cos(angle_offset); //finds the correct ratio needed for level walls
  557.        
  558.         float screen_height = 320; float screen_width = 530;
  559.         int line_height = (tile_size * screen_height) / final_distance; //By dividing by final distance, further away things will have a higher final distance and thus will divide more, creating a smaller object
  560.        
  561.         float texture_y_step = 32.0 / (float)line_height; //because there are 32 bits in each y texture, we divide the line_height by 32 to map over the textures to different line heights
  562.         float texture_y_offset = 0;
  563.        
  564.         //Notes: we need to do the texture_y_step calc before clamping the line_height between 0 and 320. This is to ensure that textures are drawn to the full line, even if that line is later clipped out of frame
  565.        
  566.         if(line_height > screen_height)
  567.         {
  568.             texture_y_offset = (line_height - screen_height) / 2.0;
  569.             line_height = screen_height; //ensures that we are not drawing lines offscreen;
  570.         }
  571.        
  572.         float line_offset = (screen_height/2) - (line_height/2); //lowers the y value of each line so that it is centered on screen
  573.        
  574.         /*---
  575.         -----
  576.         Draws a line every 8 pixels (vertex x value is r iteration times 8) with a width of 8. It is then shifted
  577.         530 pixels to the right so that it is not overlapping with the 2D scene;
  578.        
  579.         All raycast 3D games have a fisheye warping effect. This is because lines further away from the center ray must
  580.         travel further than the center line, making their final_distance larger and thus the line smaller. To fix this, we
  581.         can calculate the distance between the center ray and each off-angle ray, then use trigonometry to find the correct
  582.         ratio to make all walls level;
  583.         -----
  584.         ---*/
  585.        
  586.         int y;
  587.         float texture_y = texture_y_offset * texture_y_step + (hmt * 32);
  588.         float texture_x;
  589.        
  590.         if(horizontal_distance < vertical_distance)
  591.         {
  592.             texture_x = 31 - (int)(ray_x / 2.0) % 32; //by doing mod 32 on the ray_x, we can effectively loop the ray x value between 0 and 31. This means that as the ray moves right, the texture_x value goes from 0 to 1 to 2 etc. across the textures[]
  593.        
  594.             if(ray_angle > PI) //if the player is looking south, then flip the texture. Count from 31 to 0 not 0 to 31. This is to ensure consistent texture as textures appear flipped depending on orientation
  595.             {
  596.                 texture_x = 31 - texture_x;
  597.             }
  598.         }
  599.         else if(horizontal_distance > vertical_distance)
  600.         {
  601.             texture_x = (int)(ray_y / 2.0) % 32; //by doing mod 32 on the ray_x, we can effectively loop the ray x value between 0 and 31. This means that as the ray moves right, the texture_x value goes from 0 to 1 to 2 etc. across the textures[]
  602.        
  603.             if(ray_angle > PI/2 && ray_angle < 3*PI/2) //if the player is looking left (more that 90, less that 270 degs), then flip the texture. Count from 31 to 0 not 0 to 31. This is to ensure consistent texture as textures appear flipped depending on orientation
  604.             {
  605.                 texture_x = 31 - texture_x;
  606.             }
  607.         }
  608.  
  609.         //shade = shade * 512 / final_distance / 2; //calculates distance shading
  610.        
  611.         if(shade < 0.4)
  612.         {
  613.             shade = 0.4;
  614.         }
  615.         else if(shade > 1)
  616.         {
  617.             shade = 1;
  618.         }
  619.        
  620.         /*---
  621.         -----
  622.         DRAWING WALLS
  623.         -----
  624.         ---*/
  625.            
  626.         for(y = 0; y < line_height; y++) //draws each pixel of each line in order to draw pixels
  627.         {
  628.             float c = textures[(int)(texture_y) * 32 + (int)(texture_x)]; //finds the texture code
  629.            
  630.             //COLOR BASED ON TEXTURE CODE
  631.             struct F_TUPLE color;
  632.            
  633.             if(c == 0) //black
  634.             {
  635.                 color.x = Convert255to1(0.0);
  636.                 color.y = Convert255to1(0.0);
  637.                 color.z = Convert255to1(0.0);
  638.             }
  639.             else if(c == 1) //brick_color
  640.             {
  641.                 color.x = 59.0 / 255.0;
  642.                 color.y = 19.0 / 255.0;
  643.                 color.z = 10.0 / 255.0;
  644.             }
  645.             else if(c == 2) //brick_shaded
  646.             {
  647.                 color.x = 41.0 / 255.0;
  648.                 color.y = 7.0 / 255.0;
  649.                 color.z = 4.0 / 255.0;
  650.             }
  651.             else if(c == 3) //brick_highlight
  652.             {
  653.                 color.x = 65.0 / 255.0;
  654.                 color.y = 28.0 / 255.0;
  655.                 color.z = 9.0 / 255.0;
  656.             }
  657.             else if(c == 4) //brick_mortar
  658.             {
  659.                 color.x = 27.0 / 255.0;
  660.                 color.y = 4.0 / 255.0;
  661.                 color.z = 12.0 / 255.0;
  662.             }
  663.             else if(c == 5) //wood_wall_1_outline
  664.             {
  665.                 color.x = 42.0 / 255.0;
  666.                 color.y = 24.0 / 255.0;
  667.                 color.z = 17.0 / 255.0;
  668.             }
  669.             else if(c == 6) //wood_wall_1_main
  670.             {
  671.                 color.x = 60.0 / 255.0;
  672.                 color.y = 36.0 / 255.0;
  673.                 color.z = 28.0 / 255.0;
  674.             }
  675.             else if(c == 7) //wood_wall_1_highlight
  676.             {
  677.                 color.x = 65.0 / 255.0;
  678.                 color.y = 41.0 / 255.0;
  679.                 color.z = 33.0 / 255.0;
  680.             }
  681.             else if(c == 8) //wood_wall_1_glass
  682.             {
  683.                 color.x = 33.0 / 255.0;
  684.                 color.y = 67.0 / 255.0;
  685.                 color.z = 81.0 / 255.0;
  686.             }
  687.             else if(c == 9) //wood_wall_1_glasslight
  688.             {
  689.                 color.x = 41.0 / 255.0;
  690.                 color.y = 76.0 / 255.0;
  691.                 color.z = 86.0 / 255.0;
  692.             }
  693.             else if(c == 10) //wood_wall_1_handle
  694.             {
  695.                 color.x = 75.0 / 255.0;
  696.                 color.y = 68.0 / 255.0;
  697.                 color.z = 66.0 / 255.0;
  698.             }
  699.            
  700.             glColor3f(color.x * shade, color.y * shade, color.z * shade);
  701.             glPointSize(2);
  702.             glBegin(GL_POINTS);
  703.             glVertex2i(r*2+530, y + line_offset); //draws a point at the line_offset then adds the y iterant so that each pixel of the line is drawn individually
  704.             glEnd();
  705.             texture_y += texture_y_step; //increases to the next texture y value each pixel, reading data from textures[];
  706.         }
  707.        
  708.         /*---
  709.         -----
  710.         DRAWING FLOORS
  711.         -----
  712.         ---*/
  713.        
  714.         //y starts at the middle of the screen due to the line offset, then goes down the size of the line to reach the
  715.         //bottom part of the line, AKA the start of the floor. Then,
  716.         for(y = line_offset + line_height; y < screen_height; y++) //start drawing at the bottom of the line (line_offset) and go draw down from there (positive y = down)
  717.         {
  718.             float dy = y - (screen_height/2.0); //we get the floor line start point by going
  719.             float deg = ray_angle;
  720.             float ra_fix = player_angle - ray_angle;
  721.        
  722.             if(ra_fix < 0)
  723.             {
  724.                 ra_fix += 2*PI;
  725.             }
  726.             if(ra_fix > 2*PI)
  727.             {
  728.                 ra_fix -= 2*PI;
  729.             }
  730.            
  731.             ra_fix = cos(ra_fix);
  732.            
  733.             texture_x = player_x/2 + cos(deg)*158*32/dy/ra_fix;
  734.             texture_y = player_y/2 + sin(deg)*158*32/dy/ra_fix;
  735.            
  736.             int mp = floor_map[(int)(texture_y/32.0) * map_size_x + (int)(texture_x/32.0)]*32*32;
  737.              
  738.             float c = textures[((int)(texture_y)&31)* 32 + ((int)(texture_x)&31)+mp];
  739.            
  740.                         //COLOR BASED ON TEXTURE CODE
  741.             struct F_TUPLE color;
  742.            
  743.             if(c == 0) //black
  744.             {
  745.                 color.x = Convert255to1(0.0);
  746.                 color.y = Convert255to1(0.0);
  747.                 color.z = Convert255to1(0.0);
  748.             }
  749.             else if(c == 1) //brick_color
  750.             {
  751.                 color.x = 59.0 / 255.0;
  752.                 color.y = 19.0 / 255.0;
  753.                 color.z = 10.0 / 255.0;
  754.             }
  755.             else if(c == 2) //brick_shaded
  756.             {
  757.                 color.x = 41.0 / 255.0;
  758.                 color.y = 7.0 / 255.0;
  759.                 color.z = 4.0 / 255.0;
  760.             }
  761.             else if(c == 3) //brick_highlight
  762.             {
  763.                 color.x = 65.0 / 255.0;
  764.                 color.y = 28.0 / 255.0;
  765.                 color.z = 9.0 / 255.0;
  766.             }
  767.             else if(c == 4) //brick_mortar
  768.             {
  769.                 color.x = 27.0 / 255.0;
  770.                 color.y = 4.0 / 255.0;
  771.                 color.z = 12.0 / 255.0;
  772.             }
  773.             else if(c == 5) //wood_wall_1_outline
  774.             {
  775.                 color.x = 42.0 / 255.0;
  776.                 color.y = 24.0 / 255.0;
  777.                 color.z = 17.0 / 255.0;
  778.             }
  779.             else if(c == 6) //wood_wall_1_main
  780.             {
  781.                 color.x = 60.0 / 255.0;
  782.                 color.y = 36.0 / 255.0;
  783.                 color.z = 28.0 / 255.0;
  784.             }
  785.             else if(c == 7) //wood_wall_1_highlight
  786.             {
  787.                 color.x = 65.0 / 255.0;
  788.                 color.y = 41.0 / 255.0;
  789.                 color.z = 33.0 / 255.0;
  790.             }
  791.             else if(c == 8) //wood_wall_1_glass
  792.             {
  793.                 color.x = 33.0 / 255.0;
  794.                 color.y = 67.0 / 255.0;
  795.                 color.z = 81.0 / 255.0;
  796.             }
  797.             else if(c == 9) //wood_wall_1_glasslight
  798.             {
  799.                 color.x = 41.0 / 255.0;
  800.                 color.y = 76.0 / 255.0;
  801.                 color.z = 86.0 / 255.0;
  802.             }
  803.             else if(c == 10) //wood_wall_1_handle
  804.             {
  805.                 color.x = 75.0 / 255.0;
  806.                 color.y = 68.0 / 255.0;
  807.                 color.z = 66.0 / 255.0;
  808.             }
  809.            
  810.             glColor3f(color.x * shade, color.y * shade, color.z * shade);
  811.             glPointSize(2);
  812.             glBegin(GL_POINTS);
  813.             glVertex2i(r*2+530, y); //no line_offset because its used in the for loop
  814.             glEnd();
  815.            
  816.             /*---
  817.             -----
  818.             DRAWING CIELING
  819.             -----
  820.             ---*/
  821.            
  822.             mp = cieling_map[(int)(texture_y/32.0) * map_size_x + (int)(texture_x/32.0)]*32*32;
  823.              
  824.             c = textures[((int)(texture_y)&31)* 32 + ((int)(texture_x)&31)+mp];
  825.            
  826.                         //COLOR BASED ON TEXTURE CODE
  827.            
  828.             if(c == 0) //black
  829.             {
  830.                 color.x = Convert255to1(0.0);
  831.                 color.y = Convert255to1(0.0);
  832.                 color.z = Convert255to1(0.0);
  833.             }
  834.             else if(c == 1) //brick_color
  835.             {
  836.                 color.x = 59.0 / 255.0;
  837.                 color.y = 19.0 / 255.0;
  838.                 color.z = 10.0 / 255.0;
  839.             }
  840.             else if(c == 2) //brick_shaded
  841.             {
  842.                 color.x = 41.0 / 255.0;
  843.                 color.y = 7.0 / 255.0;
  844.                 color.z = 4.0 / 255.0;
  845.             }
  846.             else if(c == 3) //brick_highlight
  847.             {
  848.                 color.x = 65.0 / 255.0;
  849.                 color.y = 28.0 / 255.0;
  850.                 color.z = 9.0 / 255.0;
  851.             }
  852.             else if(c == 4) //brick_mortar
  853.             {
  854.                 color.x = 27.0 / 255.0;
  855.                 color.y = 4.0 / 255.0;
  856.                 color.z = 12.0 / 255.0;
  857.             }
  858.             else if(c == 5) //wood_wall_1_outline
  859.             {
  860.                 color.x = 42.0 / 255.0;
  861.                 color.y = 24.0 / 255.0;
  862.                 color.z = 17.0 / 255.0;
  863.             }
  864.             else if(c == 6) //wood_wall_1_main
  865.             {
  866.                 color.x = 60.0 / 255.0;
  867.                 color.y = 36.0 / 255.0;
  868.                 color.z = 28.0 / 255.0;
  869.             }
  870.             else if(c == 7) //wood_wall_1_highlight
  871.             {
  872.                 color.x = 65.0 / 255.0;
  873.                 color.y = 41.0 / 255.0;
  874.                 color.z = 33.0 / 255.0;
  875.             }
  876.             else if(c == 8) //wood_wall_1_glass
  877.             {
  878.                 color.x = 33.0 / 255.0;
  879.                 color.y = 67.0 / 255.0;
  880.                 color.z = 81.0 / 255.0;
  881.             }
  882.             else if(c == 9) //wood_wall_1_glasslight
  883.             {
  884.                 color.x = 41.0 / 255.0;
  885.                 color.y = 76.0 / 255.0;
  886.                 color.z = 86.0 / 255.0;
  887.             }
  888.             else if(c == 10) //wood_wall_1_handle
  889.             {
  890.                 color.x = 75.0 / 255.0;
  891.                 color.y = 68.0 / 255.0;
  892.                 color.z = 66.0 / 255.0;
  893.             }
  894.            
  895.             glColor3f(color.x * shade, color.y * shade, color.z * shade);
  896.             glPointSize(2);
  897.             glBegin(GL_POINTS);
  898.             glVertex2i(r*2+530, screen_height-y); //no line_offset because its used in the for loop
  899.             glEnd();
  900.         }
  901.        
  902.        
  903.         ray_angle += DR / 4;
  904.         if(ray_angle < 0)
  905.         {
  906.             ray_angle += 2*PI;
  907.         }
  908.         if(ray_angle > 2*PI)
  909.         {
  910.             ray_angle -= 2*PI;
  911.         }
  912.     }
  913. }
  914.  
  915. float frame1, frame2, fps;
  916.  
  917. void Display()
  918. {
  919.     int angle = -(int)(player_angle*57.2957795);
  920.    
  921.     if(angle < 0)
  922.     {
  923.         angle += 360;
  924.     }
  925.    
  926.     printf("%d\n", angle);
  927.     //fps
  928.     frame2 = glutGet(GLUT_ELAPSED_TIME);
  929.     fps = (frame2 - frame1);
  930.     frame1 = glutGet(GLUT_ELAPSED_TIME);
  931.    
  932.     MovePlayer();
  933.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clears the color and depth buffer before drawing
  934.    
  935.     DrawMap2D(); //map must be drawn before player is drawn to ensure that player is drawn afterwards and appears on top
  936.     DrawPlayer2D();
  937.     DrawRays2D();
  938.    
  939.     glutSwapBuffers(); //swaps the buffers. One buffer draws, the other buffer displays. The draw buffer draws without showing the user, preventing artifacting and other weird junk
  940. }
  941.  
  942. void MovePlayer() //detects keystrokes, if active, moves player
  943. {
  944.     /*
  945.     ---------
  946.     If A or D are pressed, rotates the character by a small amount. We are moving by radians, not degrees, so 1 degree movement is 0.02 rads. 0.1 rads is 5.7 degrees
  947.    
  948.     Rotation works like this: You get the player's angle, then use cosine to determine x movement and sine to determine
  949.     y movement. These functions divide the amount of x and y movement by the hypotenuse of the right triangle made by
  950.     the angle of the player forwards. This is to normalize the value between 0 and 1. So if the player is facing all the
  951.     way to the right and moves forward, the player would move in the x direction by 1 and in the y direction by 0. If the
  952.     player is facing 45 degrees, then they would move 0.5 units up and 0.5 units right. This ensures proper movement
  953.     direction. These numbers (delta_x and delta_y) are then multiplied by 5, which is the 'speed' of the character;
  954.    
  955.     If W or D are pressed, the delta_y and delta_x variables that we calculated are then applied, moving the character
  956.     in the motion we want;
  957.     ---------
  958.     */
  959.    
  960.     int x_offset = 0; //amount to the left or right of the player for checking collisions
  961.     int y_offset = 0; //amount up or down from the player for checking collisions
  962.    
  963.     if(player_delta_x < 0) //if the players delta_x is less than zero, the player is moving left. Change the offset check to the left
  964.     {
  965.         x_offset = -20;
  966.     }
  967.     else //if player is moving right, change offset to the right
  968.     {
  969.         x_offset = 20;
  970.     }
  971.    
  972.     if(player_delta_y < 0) //if the players delta_y is less than zero, the player is moving down. Change the offset check to down
  973.     {
  974.         y_offset = -20;
  975.     }
  976.     else //if player is moving up, change offset to up
  977.     {
  978.         y_offset = 20;
  979.     }
  980.    
  981.     int player_grid_pos_x = player_x / 64.0; //finds player x pos in the tile_grid by dividing by tile size
  982.     int grid_pos_x_plus_offset = (player_x + x_offset) / tile_size; //adds the offset
  983.     int grid_pos_x_minus_offset = (player_x - x_offset) / tile_size; //subtracts the offset
  984.    
  985.     int player_grid_pos_y = player_y / 64.0; //finds player x pos in the tile_grid by dividing by tile size
  986.     int grid_pos_y_plus_offset = (player_y + y_offset) / tile_size; //adds the offset
  987.     int grid_pos_y_minus_offset = (player_y - y_offset) / tile_size; //subtracts the offset
  988.    
  989.     if(Keys.w == 1)
  990.     {
  991.         if(wall_map[player_grid_pos_y * map_size_x + grid_pos_x_plus_offset]==0) // y * width + x pattern, same as before if the tile in front of player is a zero, move player
  992.         {
  993.             player_x += player_delta_x * 0.2 * fps;
  994.         }
  995.        
  996.         if(wall_map[grid_pos_y_plus_offset * map_size_x + player_grid_pos_x]==0)
  997.         {
  998.             player_y += player_delta_y * 0.2 * fps;
  999.         }
  1000.     }
  1001.    
  1002.     if(Keys.a == 1)
  1003.     {
  1004.         player_angle -= 0.0035 * fps;
  1005.        
  1006.         if(player_angle < 0)
  1007.         {
  1008.             player_angle += 2*PI; //If player angle is negative, add 2*PI to ensure it is always between 0 and 360 degs
  1009.         }
  1010.        
  1011.         player_delta_x = cos(player_angle) * 0.2 * fps; //like Time.deltaTime, by multiplying the value by the elapsed time, we get frame-independent movement
  1012.         player_delta_y = sin(player_angle) * 0.2 * fps;
  1013.     }
  1014.    
  1015.     if(Keys.s == 1)
  1016.     {
  1017.         if(wall_map[player_grid_pos_y * map_size_x + grid_pos_x_minus_offset]==0) // exactly like w key, but using the reverse offset
  1018.         {
  1019.             player_x -= player_delta_x * 0.2 * fps;
  1020.         }
  1021.        
  1022.         if(wall_map[grid_pos_y_minus_offset * map_size_x + player_grid_pos_x]==0)
  1023.         {
  1024.             player_y -= player_delta_y * 0.2 * fps;
  1025.         }
  1026.     }
  1027.    
  1028.     if(Keys.d == 1)
  1029.     {
  1030.         player_angle += 0.0035 * fps;
  1031.        
  1032.         if(player_angle > (2*PI))
  1033.         {
  1034.             player_angle -= 2*PI; //If player angle is above 360 degrees, subtract 2*PI to ensure it is always between 0 and 360 degs
  1035.         }
  1036.        
  1037.         player_delta_x = cos(player_angle) * 0.2 * fps;
  1038.         player_delta_y = sin(player_angle) * 0.2 * fps;
  1039.     }
  1040.    
  1041.     glutPostRedisplay(); //tells GL that the screen needs to be redrawn because the player moved
  1042. }
  1043.  
  1044. void ButtonsDown(unsigned char key, int x, int y)
  1045. {
  1046.     if(key == 'w')
  1047.     {
  1048.         Keys.w = 1;
  1049.     }
  1050.     if(key == 'a')
  1051.     {
  1052.         Keys.a = 1;
  1053.     }
  1054.     if(key == 's')
  1055.     {
  1056.         Keys.s = 1;
  1057.     }
  1058.     if(key == 'd')
  1059.     {
  1060.         Keys.d = 1;
  1061.     }
  1062.     if(key == 'e')
  1063.     {
  1064.         //xo and yo are the offsets to check if a door is present. If it is, open the door
  1065.         int x_offset = 0;
  1066.         if(player_delta_x < 0)
  1067.         {
  1068.             x_offset = -25;
  1069.         }
  1070.         else
  1071.         {
  1072.             x_offset = 25;
  1073.         }
  1074.        
  1075.         int y_offset = 0;
  1076.         if(player_delta_y < 0)
  1077.         {
  1078.             y_offset = -25;
  1079.         }
  1080.         else
  1081.         {
  1082.             y_offset = 25;
  1083.         }
  1084.        
  1085.         //We only add the offset, not add and subtract like we did for collisions. This is because collisions need to check
  1086.         //All sides. We can only open doors in front of us.
  1087.         int player_grid_pos_x = player_x / tile_size; //finds player x pos in the tile_grid by dividing by tile size
  1088.         int grid_pos_x_plus_offset = (player_x + x_offset) / tile_size; //adds the offset
  1089.    
  1090.         int player_grid_pos_y = player_y / tile_size; //finds player x pos in the tile_grid by dividing by tile size
  1091.         int grid_pos_y_plus_offset = (player_y + y_offset) / tile_size; //adds the offset
  1092.        
  1093.         //if the player's grid position is a door code, then change it to an empty space
  1094.         if(Contains(DoorTiles, -1, wall_map[grid_pos_y_plus_offset * map_size_x + grid_pos_x_plus_offset])==1) // y * width + x pattern, same as before if the tile in front of player is a zero, move player
  1095.         {
  1096.             wall_map[grid_pos_y_plus_offset * map_size_x + grid_pos_x_plus_offset] = 0;
  1097.         }
  1098.     }
  1099.     //glutPostRedisplay();
  1100. }
  1101.  
  1102. void ButtonsUp(unsigned char key, int x, int y)
  1103. {
  1104.     if(key == 'w')
  1105.     {
  1106.         Keys.w = 0;
  1107.     }
  1108.     if(key == 'a')
  1109.     {
  1110.         Keys.a = 0;
  1111.     }
  1112.     if(key == 's')
  1113.     {
  1114.         Keys.s = 0;
  1115.     }
  1116.     if(key == 'd')
  1117.     {
  1118.         Keys.d = 0;
  1119.     }
  1120.     //glutPostRedisplay();
  1121. }
  1122.  
  1123. int SCREEN_WIDTH = 1024;
  1124. int SCREEN_HEIGHT = 510;
  1125.  
  1126. void ResizeScreen(int w, int h)
  1127. {
  1128.     glutReshapeWindow(SCREEN_WIDTH, SCREEN_HEIGHT);
  1129. }
  1130.  
  1131. void Init()
  1132. {
  1133.     glClearColor(0.3725, 0.3647, 0.4941, 0);
  1134.     gluOrtho2D(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
  1135.     player_x = 84; player_y = 84; //sets the player's position
  1136.     player_delta_x = cos(player_angle) * 0.5; player_delta_y = sin(player_angle) * 0.5; //sets the delta_x and y to show the line when the program starts
  1137. }
  1138.  
  1139. int main(int argc, char* argv[]) //dont worry about the parameters
  1140. {
  1141.     glutInit(&argc, argv); //dont worry about the parameters
  1142.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); //sets display mode to double buffer (uses buffer swap) and RGBA
  1143.     glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  1144.     glutInitWindowPosition(1920/4, 1080/4);
  1145.     glutCreateWindow("My Game");
  1146.     Init();
  1147.     glutReshapeFunc(ResizeScreen);
  1148.     glutDisplayFunc(Display); //the function that displays aka clears, draws, and swaps buffers
  1149.     glutKeyboardFunc(ButtonsDown); //this function is called whenever a key is pressed. It calls ButtonsDown with the pressed key as a parameter
  1150.     glutKeyboardUpFunc(ButtonsUp); //this function is called whenever a key is pressed. It calls ButtonsUp with the pressed key as a parameter
  1151.     glutMainLoop();
  1152.     return 0;
  1153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement