Clone of mesa.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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