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 14KB

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