Clone of mesa.
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.

terrain.c 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * This program is under the GNU GPL.
  3. * Use at your own risk.
  4. *
  5. * written by David Bucciarelli (tech.hmw@plus.it)
  6. * Humanware s.r.l.
  7. *
  8. * based on a Mikael SkiZoWalker's (MoDEL) / France (Skizo@Hol.Fr) demo
  9. */
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <time.h>
  15. #ifdef WIN32
  16. #include <windows.h>
  17. #endif
  18. #include <GL/glut.h>
  19. #ifdef XMESA
  20. #include "GL/xmesa.h"
  21. static int fullscreen = 1;
  22. #endif
  23. #ifndef M_PI
  24. #define M_PI 3.14159265
  25. #endif
  26. #define heightMnt 450
  27. #define lenghtXmnt 62
  28. #define lenghtYmnt 62
  29. #define stepXmnt 96.0
  30. #define stepYmnt 96.0
  31. #define WIDTH 640
  32. #define HEIGHT 480
  33. static GLint T0 = 0;
  34. static GLint Frames = 0;
  35. #define TSCALE 4
  36. #define FOV 85
  37. static GLfloat terrain[256 * 256];
  38. static GLfloat terraincolor[256 * 256][3];
  39. static int win = 0;
  40. static int fog = 1;
  41. static int bfcull = 1;
  42. static int usetex = 1;
  43. static int poutline = 0;
  44. static int help = 1;
  45. static int joyavailable = 0;
  46. static int joyactive = 0;
  47. static float ModZMnt;
  48. static long GlobalMnt = 0;
  49. static int scrwidth = WIDTH;
  50. static int scrheight = HEIGHT;
  51. #define OBSSTARTX 992.0
  52. #define OBSSTARTY 103.0
  53. static float obs[3] = { OBSSTARTX, heightMnt * 1.3, OBSSTARTY };
  54. static float dir[3], v1[2], v2[2];
  55. static float v = 900.0;
  56. static float alpha = 75.0;
  57. static float beta = 90.0;
  58. static void
  59. calcposobs(void)
  60. {
  61. float alpha1, alpha2;
  62. static double t0 = -1.;
  63. double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
  64. if (t0 < 0.0)
  65. t0 = t;
  66. dt = t - t0;
  67. t0 = t;
  68. dir[0] = sin(alpha * M_PI / 180.0);
  69. dir[2] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0);
  70. dir[1] = cos(beta * M_PI / 180.0);
  71. if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5)
  72. dir[0] = 0;
  73. if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5)
  74. dir[1] = 0;
  75. if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5)
  76. dir[2] = 0;
  77. alpha1 = alpha + FOV / 2.0;
  78. v1[0] = sin(alpha1 * M_PI / 180.0);
  79. v1[1] = cos(alpha1 * M_PI / 180.0);
  80. alpha2 = alpha - FOV / 2.0;
  81. v2[0] = sin(alpha2 * M_PI / 180.0);
  82. v2[1] = cos(alpha2 * M_PI / 180.0);
  83. obs[0] += v * dir[0] * dt;
  84. obs[1] += v * dir[1] * dt;
  85. obs[2] += v * dir[2] * dt;
  86. if (obs[1] < 0.0)
  87. obs[1] = 0.0;
  88. }
  89. static void
  90. reshape(int width, int height)
  91. {
  92. scrwidth = width;
  93. scrheight = height;
  94. glViewport(0, 0, (GLint) width, (GLint) height);
  95. glMatrixMode(GL_PROJECTION);
  96. glLoadIdentity();
  97. gluPerspective(50.0, ((GLfloat) width / (GLfloat) height),
  98. lenghtXmnt * stepYmnt * 0.01, lenghtXmnt * stepYmnt * 0.7);
  99. glMatrixMode(GL_MODELVIEW);
  100. glLoadIdentity();
  101. }
  102. static int
  103. clipstrip(float y, float *start, float *end)
  104. {
  105. float x1, x2, t1, t2, tmp;
  106. if (v1[1] == 0.0) {
  107. t1 = 0.0;
  108. x1 = -HUGE_VAL;
  109. }
  110. else {
  111. t1 = y / v1[1];
  112. x1 = t1 * v1[0];
  113. }
  114. if (v2[1] == 0.0) {
  115. t2 = 0.0;
  116. x2 = HUGE_VAL;
  117. }
  118. else {
  119. t2 = y / v2[1];
  120. x2 = t2 * v2[0];
  121. }
  122. if (((x1 < -(lenghtXmnt * stepXmnt) / 2) && (t2 <= 0.0)) ||
  123. ((t1 <= 0.0) && (x2 > (lenghtXmnt * stepXmnt) / 2)) ||
  124. ((t1 < 0.0) && (t2 < 0.0)))
  125. return 0;
  126. if ((t1 == 0.0) && (t2 == 0.0)) {
  127. if ((v1[0] < 0.0) && (v1[1] > 0.0) && (v2[0] < 0.0) && (v2[1] < 0.0)) {
  128. *start = -(lenghtXmnt * stepXmnt) / 2;
  129. *end = stepXmnt;
  130. return 1;
  131. }
  132. else {
  133. if ((v1[0] > 0.0) && (v1[1] < 0.0) && (v2[0] > 0.0) && (v2[1] > 0.0)) {
  134. *start = -stepXmnt;
  135. *end = (lenghtXmnt * stepXmnt) / 2;
  136. return 1;
  137. }
  138. else
  139. return 0;
  140. }
  141. }
  142. else {
  143. if (t2 < 0.0) {
  144. if (x1 < 0.0)
  145. x2 = -(lenghtXmnt * stepXmnt) / 2;
  146. else
  147. x2 = (lenghtXmnt * stepXmnt) / 2;
  148. }
  149. if (t1 < 0.0) {
  150. if (x2 < 0.0)
  151. x1 = -(lenghtXmnt * stepXmnt) / 2;
  152. else
  153. x1 = (lenghtXmnt * stepXmnt) / 2;
  154. }
  155. }
  156. if (x1 > x2) {
  157. tmp = x1;
  158. x1 = x2;
  159. x2 = tmp;
  160. }
  161. x1 -= stepXmnt;
  162. if (x1 < -(lenghtXmnt * stepXmnt) / 2)
  163. x1 = -(lenghtXmnt * stepXmnt) / 2;
  164. x2 += stepXmnt;
  165. if (x2 > (lenghtXmnt * stepXmnt) / 2)
  166. x2 = (lenghtXmnt * stepXmnt) / 2;
  167. *start = ((int) (x1 / stepXmnt)) * stepXmnt;
  168. *end = ((int) (x2 / stepXmnt)) * stepXmnt;
  169. return 1;
  170. }
  171. static void
  172. printstring(void *font, char *string)
  173. {
  174. int len, i;
  175. len = (int) strlen(string);
  176. for (i = 0; i < len; i++)
  177. glutBitmapCharacter(font, string[i]);
  178. }
  179. static void
  180. printhelp(void)
  181. {
  182. glEnable(GL_BLEND);
  183. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  184. glColor4f(0.0, 0.0, 0.0, 0.5);
  185. glRecti(40, 40, 600, 440);
  186. glDisable(GL_BLEND);
  187. glColor3f(1.0, 0.0, 0.0);
  188. glRasterPos2i(300, 420);
  189. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Help");
  190. glRasterPos2i(60, 390);
  191. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Toggle Help");
  192. glRasterPos2i(60, 360);
  193. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Toggle Textures");
  194. glRasterPos2i(60, 330);
  195. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Toggle Fog");
  196. glRasterPos2i(60, 300);
  197. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "p - Wire frame");
  198. glRasterPos2i(60, 270);
  199. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "b - Toggle Back face culling");
  200. glRasterPos2i(60, 240);
  201. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Arrow Keys - Rotate");
  202. glRasterPos2i(60, 210);
  203. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "a - Increase velocity");
  204. glRasterPos2i(60, 180);
  205. printstring(GLUT_BITMAP_TIMES_ROMAN_24, "z - Decrease velocity");
  206. glRasterPos2i(60, 150);
  207. if (joyavailable)
  208. printstring(GLUT_BITMAP_TIMES_ROMAN_24,
  209. "j - Toggle jostick control (Joystick control available)");
  210. else
  211. printstring(GLUT_BITMAP_TIMES_ROMAN_24,
  212. "(No Joystick control available)");
  213. }
  214. static void
  215. drawterrain(void)
  216. {
  217. int h, i, idx, ox, oy;
  218. float j, k, start, end;
  219. ox = (int) (obs[0] / stepXmnt);
  220. oy = (int) (obs[2] / stepYmnt);
  221. GlobalMnt = ((ox * TSCALE) & 255) + ((oy * TSCALE) & 255) * 256;
  222. glPushMatrix();
  223. glTranslatef((float) ox * stepXmnt, 0, (float) oy * stepYmnt);
  224. for (h = 0, k = -(lenghtYmnt * stepYmnt) / 2; h < lenghtYmnt;
  225. k += stepYmnt, h++) {
  226. if (!clipstrip(k, &start, &end))
  227. continue;
  228. glBegin(GL_TRIANGLE_STRIP); /* I hope that the optimizer will be able to improve this code */
  229. for (i = (int) (lenghtXmnt / 2 + start / stepXmnt), j = start; j <= end;
  230. j += stepXmnt, i++) {
  231. idx = (i * TSCALE + h * 256 * TSCALE + GlobalMnt) & 65535;
  232. glColor3fv(terraincolor[idx]);
  233. glTexCoord2f((ox + i) / 8.0, (oy + h) / 8.0);
  234. glVertex3f(j, terrain[idx], k);
  235. idx =
  236. (i * TSCALE + h * 256 * TSCALE + 256 * TSCALE +
  237. GlobalMnt) & 65535;
  238. glColor3fv(terraincolor[idx]);
  239. glTexCoord2f((ox + i) / 8.0, (oy + h + 1) / 8.0);
  240. glVertex3f(j, terrain[idx], k + stepYmnt);
  241. }
  242. glEnd();
  243. }
  244. glDisable(GL_CULL_FACE);
  245. glDisable(GL_TEXTURE_2D);
  246. glEnable(GL_BLEND);
  247. glBegin(GL_QUADS);
  248. glColor4f(0.1, 0.7, 1.0, 0.4);
  249. glVertex3f(-(lenghtXmnt * stepXmnt) / 2.0, heightMnt * 0.6,
  250. -(lenghtYmnt * stepYmnt) / 2.0);
  251. glVertex3f(-(lenghtXmnt * stepXmnt) / 2.0, heightMnt * 0.6,
  252. (lenghtYmnt * stepYmnt) / 2.0);
  253. glVertex3f((lenghtXmnt * stepXmnt) / 2.0, heightMnt * 0.6,
  254. (lenghtYmnt * stepYmnt) / 2.0);
  255. glVertex3f((lenghtXmnt * stepXmnt) / 2.0, heightMnt * 0.6,
  256. -(lenghtYmnt * stepYmnt) / 2.0);
  257. glEnd();
  258. glDisable(GL_BLEND);
  259. if (bfcull)
  260. glEnable(GL_CULL_FACE);
  261. glEnable(GL_TEXTURE_2D);
  262. glPopMatrix();
  263. }
  264. static void
  265. dojoy(void)
  266. {
  267. #ifdef WIN32
  268. static UINT max[2] = { 0, 0 };
  269. static UINT min[2] = { 0xffffffff, 0xffffffff }, center[2];
  270. MMRESULT res;
  271. JOYINFO joy;
  272. res = joyGetPos(JOYSTICKID1, &joy);
  273. if (res == JOYERR_NOERROR) {
  274. joyavailable = 1;
  275. if (max[0] < joy.wXpos)
  276. max[0] = joy.wXpos;
  277. if (min[0] > joy.wXpos)
  278. min[0] = joy.wXpos;
  279. center[0] = (max[0] + min[0]) / 2;
  280. if (max[1] < joy.wYpos)
  281. max[1] = joy.wYpos;
  282. if (min[1] > joy.wYpos)
  283. min[1] = joy.wYpos;
  284. center[1] = (max[1] + min[1]) / 2;
  285. if (joyactive) {
  286. if (fabs(center[0] - (float) joy.wXpos) > 0.1 * (max[0] - min[0]))
  287. alpha +=
  288. 2.5 * (center[0] - (float) joy.wXpos) / (max[0] - min[0]);
  289. if (fabs(center[1] - (float) joy.wYpos) > 0.1 * (max[1] - min[1]))
  290. beta += 2.5 * (center[1] - (float) joy.wYpos) / (max[1] - min[1]);
  291. if (joy.wButtons & JOY_BUTTON1)
  292. v += 0.5;
  293. if (joy.wButtons & JOY_BUTTON2)
  294. v -= 0.5;
  295. }
  296. }
  297. else
  298. joyavailable = 0;
  299. #endif
  300. }
  301. static void
  302. drawscene(void)
  303. {
  304. static char frbuf[80] = "";
  305. dojoy();
  306. glShadeModel(GL_SMOOTH);
  307. glEnable(GL_DEPTH_TEST);
  308. if (usetex)
  309. glEnable(GL_TEXTURE_2D);
  310. else
  311. glDisable(GL_TEXTURE_2D);
  312. if (fog)
  313. glEnable(GL_FOG);
  314. else
  315. glDisable(GL_FOG);
  316. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  317. glPushMatrix();
  318. calcposobs();
  319. gluLookAt(obs[0], obs[1], obs[2],
  320. obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2],
  321. 0.0, 1.0, 0.0);
  322. drawterrain();
  323. glPopMatrix();
  324. glDisable(GL_TEXTURE_2D);
  325. glDisable(GL_DEPTH_TEST);
  326. glDisable(GL_FOG);
  327. glShadeModel(GL_FLAT);
  328. glMatrixMode(GL_PROJECTION);
  329. glLoadIdentity();
  330. glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
  331. glMatrixMode(GL_MODELVIEW);
  332. glLoadIdentity();
  333. glColor3f(1.0, 0.0, 0.0);
  334. glRasterPos2i(10, 10);
  335. printstring(GLUT_BITMAP_HELVETICA_18, frbuf);
  336. glRasterPos2i(350, 470);
  337. printstring(GLUT_BITMAP_HELVETICA_10,
  338. "Terrain V1.2 Written by David Bucciarelli (tech.hmw@plus.it)");
  339. glRasterPos2i(434, 457);
  340. printstring(GLUT_BITMAP_HELVETICA_10,
  341. "Based on a Mickael's demo (Skizo@Hol.Fr)");
  342. if (help)
  343. printhelp();
  344. reshape(scrwidth, scrheight);
  345. glutSwapBuffers();
  346. Frames++;
  347. {
  348. GLint t = glutGet(GLUT_ELAPSED_TIME);
  349. if (t - T0 >= 2000) {
  350. GLfloat seconds = (t - T0) / 1000.0;
  351. GLfloat fps = Frames / seconds;
  352. sprintf(frbuf, "Frame rate: %f", fps);
  353. T0 = t;
  354. Frames = 0;
  355. }
  356. }
  357. }
  358. static void
  359. key(unsigned char k, int x, int y)
  360. {
  361. switch (k) {
  362. case 27:
  363. exit(0);
  364. break;
  365. case 'a':
  366. v += 50.;
  367. break;
  368. case 'z':
  369. v -= 50.;
  370. break;
  371. case 'p':
  372. if (poutline) {
  373. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  374. poutline = 0;
  375. }
  376. else {
  377. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  378. poutline = 1;
  379. }
  380. break;
  381. case 'j':
  382. joyactive = (!joyactive);
  383. break;
  384. case 'h':
  385. help = (!help);
  386. break;
  387. case 'f':
  388. fog = (!fog);
  389. break;
  390. case 't':
  391. usetex = (!usetex);
  392. break;
  393. case 'b':
  394. if (bfcull) {
  395. glDisable(GL_CULL_FACE);
  396. bfcull = 0;
  397. }
  398. else {
  399. glEnable(GL_CULL_FACE);
  400. bfcull = 1;
  401. }
  402. break;
  403. #ifdef XMESA
  404. case ' ':
  405. XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW);
  406. fullscreen = (!fullscreen);
  407. break;
  408. #endif
  409. }
  410. }
  411. static void
  412. special(int k, int x, int y)
  413. {
  414. switch (k) {
  415. case GLUT_KEY_LEFT:
  416. alpha += 2.0;
  417. break;
  418. case GLUT_KEY_RIGHT:
  419. alpha -= 2.0;
  420. break;
  421. case GLUT_KEY_DOWN:
  422. beta -= 2.0;
  423. break;
  424. case GLUT_KEY_UP:
  425. beta += 2.0;
  426. break;
  427. }
  428. }
  429. static void
  430. calccolor(GLfloat height, GLfloat c[3])
  431. {
  432. GLfloat color[4][3] = {
  433. {1.0, 1.0, 1.0},
  434. {0.0, 0.8, 0.0},
  435. {1.0, 1.0, 0.3},
  436. {0.0, 0.0, 0.8}
  437. };
  438. GLfloat fact;
  439. height = height * (1.0 / 255.0);
  440. if (height >= 0.9) {
  441. c[0] = color[0][0];
  442. c[1] = color[0][1];
  443. c[2] = color[0][2];
  444. return;
  445. }
  446. if ((height < 0.9) && (height >= 0.7)) {
  447. fact = (height - 0.7) * 5.0;
  448. c[0] = fact * color[0][0] + (1.0 - fact) * color[1][0];
  449. c[1] = fact * color[0][1] + (1.0 - fact) * color[1][1];
  450. c[2] = fact * color[0][2] + (1.0 - fact) * color[1][2];
  451. return;
  452. }
  453. if ((height < 0.7) && (height >= 0.6)) {
  454. fact = (height - 0.6) * 10.0;
  455. c[0] = fact * color[1][0] + (1.0 - fact) * color[2][0];
  456. c[1] = fact * color[1][1] + (1.0 - fact) * color[2][1];
  457. c[2] = fact * color[1][2] + (1.0 - fact) * color[2][2];
  458. return;
  459. }
  460. if ((height < 0.6) && (height >= 0.5)) {
  461. fact = (height - 0.5) * 10.0;
  462. c[0] = fact * color[2][0] + (1.0 - fact) * color[3][0];
  463. c[1] = fact * color[2][1] + (1.0 - fact) * color[3][1];
  464. c[2] = fact * color[2][2] + (1.0 - fact) * color[3][2];
  465. return;
  466. }
  467. c[0] = color[3][0];
  468. c[1] = color[3][1];
  469. c[2] = color[3][2];
  470. }
  471. static void
  472. loadpic(void)
  473. {
  474. GLubyte bufferter[256 * 256], terrainpic[256 * 256];
  475. FILE *FilePic;
  476. int i, tmp;
  477. GLenum gluerr;
  478. if ((FilePic = fopen("terrain.dat", "r")) == NULL) {
  479. fprintf(stderr, "Error loading terrain.dat\n");
  480. exit(-1);
  481. }
  482. fread(bufferter, 256 * 256, 1, FilePic);
  483. fclose(FilePic);
  484. for (i = 0; i < (256 * 256); i++) {
  485. terrain[i] = (bufferter[i] * (heightMnt / 255.0f));
  486. calccolor((GLfloat) bufferter[i], terraincolor[i]);
  487. tmp = (((int) bufferter[i]) + 96);
  488. terrainpic[i] = (tmp > 255) ? 255 : tmp;
  489. }
  490. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  491. if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 1, 256, 256, GL_LUMINANCE,
  492. GL_UNSIGNED_BYTE,
  493. (GLvoid *) (&terrainpic[0])))) {
  494. fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr));
  495. exit(-1);
  496. }
  497. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  498. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  499. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  500. GL_LINEAR_MIPMAP_LINEAR);
  501. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  502. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  503. glEnable(GL_TEXTURE_2D);
  504. }
  505. static void
  506. init(void)
  507. {
  508. float fogcolor[4] = { 0.6, 0.7, 0.7, 1.0 };
  509. glClearColor(fogcolor[0], fogcolor[1], fogcolor[2], fogcolor[3]);
  510. glClearDepth(1.0);
  511. glDepthFunc(GL_LEQUAL);
  512. glShadeModel(GL_SMOOTH);
  513. glEnable(GL_DEPTH_TEST);
  514. glEnable(GL_CULL_FACE);
  515. glDisable(GL_BLEND);
  516. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  517. glEnable(GL_FOG);
  518. glFogi(GL_FOG_MODE, GL_EXP2);
  519. glFogfv(GL_FOG_COLOR, fogcolor);
  520. glFogf(GL_FOG_DENSITY, 0.0007);
  521. #ifdef FX
  522. glHint(GL_FOG_HINT, GL_NICEST);
  523. #endif
  524. reshape(scrwidth, scrheight);
  525. }
  526. int
  527. main(int ac, char **av)
  528. {
  529. glutInitWindowPosition(0, 0);
  530. glutInitWindowSize(WIDTH, HEIGHT);
  531. glutInit(&ac, av);
  532. glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
  533. if (!(win = glutCreateWindow("Terrain"))) {
  534. fprintf(stderr, "Error, couldn't open window\n");
  535. return -1;
  536. }
  537. ModZMnt = 0.0f;
  538. loadpic();
  539. init();
  540. #ifndef FX
  541. glDisable(GL_TEXTURE_2D);
  542. usetex = 0;
  543. #endif
  544. glutReshapeFunc(reshape);
  545. glutDisplayFunc(drawscene);
  546. glutKeyboardFunc(key);
  547. glutSpecialFunc(special);
  548. glutIdleFunc(drawscene);
  549. glutMainLoop();
  550. return 0;
  551. }