Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.1 KiB

  1. #define STB_DEFINE
  2. #include "stb.h"
  3. #define STB_PG_IMPLEMENTATION
  4. #include "stb_pg.h"
  5. #define STB_IMAGE_IMPLEMENTATION
  6. #include "stb_image.h"
  7. #define STB_IMAGE_WRITE_IMPLEMENTATION
  8. #include "stb_image_write.h"
  9. static float *hf;
  10. static int hf_width = 10001;
  11. static int hf_height = 10001;
  12. static float get_height(float x, float y)
  13. {
  14. float h00,h01,h10,h11,h0,h1;
  15. int ix,iy;
  16. if (x < 0) x = 0;
  17. if (x > hf_width-1) x = (float) hf_width-1;
  18. if (y < 0) y = 0;
  19. if (y > hf_height-1) y = (float) hf_height-1;
  20. ix = (int) x; x -= ix;
  21. iy = (int) y; y -= iy;
  22. h00 = hf[(iy+0)*hf_height+(ix+0)];
  23. h10 = hf[(iy+0)*hf_height+(ix+1)];
  24. h01 = hf[(iy+1)*hf_height+(ix+0)];
  25. h11 = hf[(iy+1)*hf_height+(ix+1)];
  26. h0 = stb_lerp(y, h00, h01);
  27. h1 = stb_lerp(y, h10, h11);
  28. return stb_lerp(x, h0, h1);
  29. }
  30. void stbpg_tick(float dt)
  31. {
  32. int i=0,j=0;
  33. int step = 1;
  34. glUseProgram(0);
  35. glClearColor(0.6f,0.7f,1.0f,1.0f);
  36. glClearDepth(1.0f);
  37. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  38. glDepthFunc(GL_LESS);
  39. glEnable(GL_DEPTH_TEST);
  40. #if 1
  41. glEnable(GL_CULL_FACE);
  42. glMatrixMode(GL_PROJECTION);
  43. glLoadIdentity();
  44. gluPerspective(60.0, 1920/1080.0f, 0.02f, 8000.0f);
  45. //glOrtho(-8,8,-6,6, -100, 100);
  46. glMatrixMode(GL_MODELVIEW);
  47. glLoadIdentity();
  48. glRotatef(-90, 1,0,0); // z-up
  49. {
  50. float x,y;
  51. stbpg_get_mouselook(&x,&y);
  52. glRotatef(-y, 1,0,0);
  53. glRotatef(-x, 0,0,1);
  54. }
  55. {
  56. static float cam_x = 1000;
  57. static float cam_y = 1000;
  58. static float cam_z = 700;
  59. float x=0,y=0;
  60. stbpg_get_keymove(&x,&y);
  61. cam_x += x*dt*5.0f;
  62. cam_y += y*dt*5.0f;
  63. glTranslatef(-cam_x, -cam_y, -cam_z);
  64. if (cam_x >= 0 && cam_x < hf_width && cam_y >= 0 && cam_y < hf_height)
  65. cam_z = get_height(cam_x, cam_y) + 1.65f; // average eye height in meters
  66. }
  67. for (j=501; j+1 < 1500+0*hf_height; j += step) {
  68. glBegin(GL_QUAD_STRIP);
  69. for (i=501; i < 1500+0*hf_width; i += step) {
  70. static int flip=0;
  71. if (flip)
  72. glColor3f(0.5,0.5,0.5);
  73. else
  74. glColor3f(0.4f,0.4f,0.4f);
  75. flip = !flip;
  76. glVertex3f((float) i, (float) j+step,hf[(j+step)*hf_width+i]);
  77. glVertex3f((float) i, (float) j ,hf[ j *hf_width+i]);
  78. }
  79. glEnd();
  80. }
  81. glBegin(GL_LINES);
  82. glColor3f(1,0,0); glVertex3f(10,0,0); glVertex3f(0,0,0);
  83. glColor3f(0,1,0); glVertex3f(0,10,0); glVertex3f(0,0,0);
  84. glColor3f(0,0,1); glVertex3f(0,0,10); glVertex3f(0,0,0);
  85. glEnd();
  86. #endif
  87. }
  88. void stbpg_main(int argc, char **argv)
  89. {
  90. int i,j;
  91. #if 0
  92. int w,h,c;
  93. unsigned short *data = stbi_load_16("c:/x/ned_1m/test2.png", &w, &h, &c, 1);
  94. stb_filewrite("c:/x/ned_1m/x73_y428_10012_10012.bin", data, w*h*2);
  95. #else
  96. unsigned short *data = stb_file("c:/x/ned_1m/x73_y428_10012_10012.bin", NULL);
  97. int w=10012, h = 10012;
  98. #endif
  99. hf = malloc(hf_width * hf_height * 4);
  100. for (j=0; j < hf_height; ++j)
  101. for (i=0; i < hf_width; ++i)
  102. hf[j*hf_width+i] = data[j*w+i] / 32.0f;
  103. stbpg_gl_compat_version(1,1);
  104. stbpg_windowed("terrain_edit", 1920, 1080);
  105. stbpg_run();
  106. return;
  107. }