Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*-----------------------------
  2. * stex3d.c GL example of the mesa 3d-texture extention to simulate procedural
  3. * texturing, it uses a perlin noise and turbulence functions.
  4. *
  5. * Author: Daniel Barrero
  6. * barrero@irit.fr
  7. * dbarrero@pegasus.uniandes.edu.co
  8. *
  9. * Converted to GLUT by brianp on 1/1/98
  10. * Massive clean-up on 2002/10/23 by brianp
  11. *
  12. *
  13. * cc stex3d.c -o stex3d -lglut -lMesaGLU -lMesaGL -lX11 -lXext -lm
  14. *
  15. *---------------------------- */
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <math.h>
  20. #include <GL/gl.h>
  21. #include <GL/glut.h>
  22. #ifndef M_PI
  23. #define M_PI 3.14159265358979323846
  24. #endif
  25. #define NOISE_TEXTURE 1
  26. #define GRADIENT_TEXTURE 2
  27. #define TORUS 1
  28. #define SPHERE 2
  29. static int tex_width=64, tex_height=64, tex_depth=64;
  30. static float angx=0, angy=0, angz=0;
  31. static int texgen = 2, animate = 1, smooth = 1, wireframe = 0;
  32. static int CurTexture = NOISE_TEXTURE, CurObject = TORUS;
  33. static void
  34. BuildTorus(void)
  35. {
  36. GLint i, j;
  37. float theta1, phi1, theta2, phi2, rings, sides;
  38. float v0[03], v1[3], v2[3], v3[3];
  39. float t0[03], t1[3], t2[3], t3[3];
  40. float n0[3], n1[3], n2[3], n3[3];
  41. float innerRadius = 0.25;
  42. float outerRadius = 0.5;
  43. float scalFac;
  44. rings = 16;
  45. sides = 12;
  46. scalFac = 1 / (outerRadius * 2);
  47. glNewList(TORUS, GL_COMPILE);
  48. for (i = 0; i < rings; i++) {
  49. theta1 = (float) i *2.0 * M_PI / rings;
  50. theta2 = (float) (i + 1) * 2.0 * M_PI / rings;
  51. for (j = 0; j < sides; j++) {
  52. phi1 = (float) j *2.0 * M_PI / sides;
  53. phi2 = (float) (j + 1) * 2.0 * M_PI / sides;
  54. v0[0] = cos(theta1) * (outerRadius + innerRadius * cos(phi1));
  55. v0[1] = -sin(theta1) * (outerRadius + innerRadius * cos(phi1));
  56. v0[2] = innerRadius * sin(phi1);
  57. v1[0] = cos(theta2) * (outerRadius + innerRadius * cos(phi1));
  58. v1[1] = -sin(theta2) * (outerRadius + innerRadius * cos(phi1));
  59. v1[2] = innerRadius * sin(phi1);
  60. v2[0] = cos(theta2) * (outerRadius + innerRadius * cos(phi2));
  61. v2[1] = -sin(theta2) * (outerRadius + innerRadius * cos(phi2));
  62. v2[2] = innerRadius * sin(phi2);
  63. v3[0] = cos(theta1) * (outerRadius + innerRadius * cos(phi2));
  64. v3[1] = -sin(theta1) * (outerRadius + innerRadius * cos(phi2));
  65. v3[2] = innerRadius * sin(phi2);
  66. n0[0] = cos(theta1) * (cos(phi1));
  67. n0[1] = -sin(theta1) * (cos(phi1));
  68. n0[2] = sin(phi1);
  69. n1[0] = cos(theta2) * (cos(phi1));
  70. n1[1] = -sin(theta2) * (cos(phi1));
  71. n1[2] = sin(phi1);
  72. n2[0] = cos(theta2) * (cos(phi2));
  73. n2[1] = -sin(theta2) * (cos(phi2));
  74. n2[2] = sin(phi2);
  75. n3[0] = cos(theta1) * (cos(phi2));
  76. n3[1] = -sin(theta1) * (cos(phi2));
  77. n3[2] = sin(phi2);
  78. t0[0] = v0[0] * scalFac + 0.5;
  79. t0[1] = v0[1] * scalFac + 0.5;
  80. t0[2] = v0[2] * scalFac + 0.5;
  81. t1[0] = v1[0] * scalFac + 0.5;
  82. t1[1] = v1[1] * scalFac + 0.5;
  83. t1[2] = v1[2] * scalFac + 0.5;
  84. t2[0] = v2[0] * scalFac + 0.5;
  85. t2[1] = v2[1] * scalFac + 0.5;
  86. t2[2] = v2[2] * scalFac + 0.5;
  87. t3[0] = v3[0] * scalFac + 0.5;
  88. t3[1] = v3[1] * scalFac + 0.5;
  89. t3[2] = v3[2] * scalFac + 0.5;
  90. glBegin(GL_POLYGON);
  91. glNormal3fv(n3);
  92. glTexCoord3fv(t3);
  93. glVertex3fv(v3);
  94. glNormal3fv(n2);
  95. glTexCoord3fv(t2);
  96. glVertex3fv(v2);
  97. glNormal3fv(n1);
  98. glTexCoord3fv(t1);
  99. glVertex3fv(v1);
  100. glNormal3fv(n0);
  101. glTexCoord3fv(t0);
  102. glVertex3fv(v0);
  103. glEnd();
  104. }
  105. }
  106. glEndList();
  107. }
  108. /*--------------------------------------------------------------------
  109. noise function over R3 - implemented by a pseudorandom tricubic spline
  110. EXCERPTED FROM SIGGRAPH 92, COURSE 23
  111. PROCEDURAL MODELING
  112. Ken Perlin
  113. New York University
  114. ----------------------------------------------------------------------*/
  115. #define DOT(a,b) (a[0] * b[0] + a[1] * b[1] + a[2] * b[2])
  116. #define B 128
  117. static int p[B + B + 2];
  118. static float g[B + B + 2][3];
  119. #define setup(i,b0,b1,r0,r1) \
  120. t = vec[i] + 10000.; \
  121. b0 = ((int)t) & (B-1); \
  122. b1 = (b0+1) & (B-1); \
  123. r0 = t - (int)t; \
  124. r1 = r0 - 1.;
  125. static float
  126. noise3(float vec[3])
  127. {
  128. int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
  129. float rx0, rx1, ry0, ry1, rz0, rz1, *q, sx, sy, sz, a, b, c, d, t, u, v;
  130. register int i, j;
  131. setup(0, bx0, bx1, rx0, rx1);
  132. setup(1, by0, by1, ry0, ry1);
  133. setup(2, bz0, bz1, rz0, rz1);
  134. i = p[bx0];
  135. j = p[bx1];
  136. b00 = p[i + by0];
  137. b10 = p[j + by0];
  138. b01 = p[i + by1];
  139. b11 = p[j + by1];
  140. #define at(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
  141. #define surve(t) ( t * t * (3. - 2. * t) )
  142. #define lerp(t, a, b) ( a + t * (b - a) )
  143. sx = surve(rx0);
  144. sy = surve(ry0);
  145. sz = surve(rz0);
  146. q = g[b00 + bz0];
  147. u = at(rx0, ry0, rz0);
  148. q = g[b10 + bz0];
  149. v = at(rx1, ry0, rz0);
  150. a = lerp(sx, u, v);
  151. q = g[b01 + bz0];
  152. u = at(rx0, ry1, rz0);
  153. q = g[b11 + bz0];
  154. v = at(rx1, ry1, rz0);
  155. b = lerp(sx, u, v);
  156. c = lerp(sy, a, b); /* interpolate in y at lo x */
  157. q = g[b00 + bz1];
  158. u = at(rx0, ry0, rz1);
  159. q = g[b10 + bz1];
  160. v = at(rx1, ry0, rz1);
  161. a = lerp(sx, u, v);
  162. q = g[b01 + bz1];
  163. u = at(rx0, ry1, rz1);
  164. q = g[b11 + bz1];
  165. v = at(rx1, ry1, rz1);
  166. b = lerp(sx, u, v);
  167. d = lerp(sy, a, b); /* interpolate in y at hi x */
  168. return 1.5 * lerp(sz, c, d); /* interpolate in z */
  169. }
  170. static void
  171. initNoise(void)
  172. {
  173. /*long random(); */
  174. int i, j, k;
  175. float v[3], s;
  176. /* Create an array of random gradient vectors uniformly on the unit sphere */
  177. /*srandom(1); */
  178. srand(1);
  179. for (i = 0; i < B; i++) {
  180. do { /* Choose uniformly in a cube */
  181. for (j = 0; j < 3; j++)
  182. v[j] = (float) ((rand() % (B + B)) - B) / B;
  183. s = DOT(v, v);
  184. } while (s > 1.0); /* If not in sphere try again */
  185. s = sqrt(s);
  186. for (j = 0; j < 3; j++) /* Else normalize */
  187. g[i][j] = v[j] / s;
  188. }
  189. /* Create a pseudorandom permutation of [1..B] */
  190. for (i = 0; i < B; i++)
  191. p[i] = i;
  192. for (i = B; i > 0; i -= 2) {
  193. k = p[i];
  194. p[i] = p[j = rand() % B];
  195. p[j] = k;
  196. }
  197. /* Extend g and p arrays to allow for faster indexing */
  198. for (i = 0; i < B + 2; i++) {
  199. p[B + i] = p[i];
  200. for (j = 0; j < 3; j++)
  201. g[B + i][j] = g[i][j];
  202. }
  203. }
  204. static float
  205. turbulence(float point[3], float lofreq, float hifreq)
  206. {
  207. float freq, t, p[3];
  208. p[0] = point[0] + 123.456;
  209. p[1] = point[1];
  210. p[2] = point[2];
  211. t = 0;
  212. for (freq = lofreq; freq < hifreq; freq *= 2.) {
  213. t += fabs(noise3(p)) / freq;
  214. p[0] *= 2.;
  215. p[1] *= 2.;
  216. p[2] *= 2.;
  217. }
  218. return t - 0.3; /* readjust to make mean value = 0.0 */
  219. }
  220. static void
  221. create3Dtexture(void)
  222. {
  223. unsigned char *voxels = NULL;
  224. int i, j, k;
  225. unsigned char *vp;
  226. float vec[3];
  227. int tmp;
  228. printf("creating 3d textures...\n");
  229. voxels =
  230. (unsigned char *)
  231. malloc((size_t) (4 * tex_width * tex_height * tex_depth));
  232. vp = voxels;
  233. for (i = 0; i < tex_width; i++) {
  234. vec[0] = i;
  235. for (j = 0; j < tex_height; j++) {
  236. vec[1] = j;
  237. for (k = 0; k < tex_depth; k++) {
  238. vec[2] = k;
  239. tmp = (sin(k * i * j + turbulence(vec, 0.01, 1)) + 1) * 127.5;
  240. *vp++ = 0;
  241. *vp++ = 0;
  242. *vp++ = tmp;
  243. *vp++ = tmp + 128;
  244. }
  245. }
  246. }
  247. printf("setting up 3d texture...\n");
  248. glBindTexture(GL_TEXTURE_3D, NOISE_TEXTURE);
  249. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  250. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  251. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  252. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  253. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
  254. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  255. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  256. glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA,
  257. tex_width, tex_height, tex_depth,
  258. 0, GL_RGBA, GL_UNSIGNED_BYTE, voxels);
  259. free(voxels);
  260. printf("finished setting up 3d texture image.\n");
  261. }
  262. static void
  263. printHelp(void)
  264. {
  265. printf("\nUsage: stex3d <cmd line options>\n");
  266. printf(" cmd line options:\n");
  267. printf(" -wxxx Width of the texture (Default=64)\n");
  268. printf(" -hxxx Height of the texture (Default=64)\n");
  269. printf(" -dxxx Depth of the texture (Default=64)\n");
  270. printf(" Keyboard Options:\n");
  271. printf(" up/down rotate around X\n");
  272. printf(" left/right rotate around Y\n");
  273. printf(" z/Z rotate around Z\n");
  274. printf(" a toggle animation\n");
  275. printf(" s toggle smooth shading\n");
  276. printf(" t toggle texgen mode\n");
  277. printf(" o toggle object: torus/sphere\n");
  278. printf(" i toggle texture image: noise/gradient\n");
  279. }
  280. static GLenum
  281. parseCmdLine(int argc, char **argv)
  282. {
  283. GLint i;
  284. for (i = 1; i < argc; i++) {
  285. if (strcmp(argv[i], "-help") == 0) {
  286. printHelp();
  287. return GL_FALSE;
  288. }
  289. else if (strstr(argv[i], "-w") != NULL) {
  290. tex_width = atoi((argv[i]) + 2);
  291. }
  292. else if (strstr(argv[i], "-h") != NULL) {
  293. tex_height = atoi((argv[i]) + 2);
  294. }
  295. else if (strstr(argv[i], "-d") != NULL) {
  296. tex_depth = atoi((argv[i]) + 2);
  297. }
  298. else {
  299. printf("%s (Bad option).\n", argv[i]);
  300. printHelp();
  301. return GL_FALSE;
  302. }
  303. }
  304. if (tex_width == 0 || tex_height == 0 || tex_depth == 0) {
  305. printf("%s (Bad option).\n", "size parameters can't be 0");
  306. printHelp();
  307. return GL_FALSE;
  308. }
  309. return GL_TRUE;
  310. }
  311. static void
  312. drawScene(void)
  313. {
  314. static const GLfloat sPlane[4] = { 0.5, 0, 0, -.5 };
  315. static const GLfloat tPlane[4] = { 0, 0.5, 0, -.5 };
  316. static const GLfloat rPlane[4] = { 0, 0, 0.5, -.5 };
  317. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  318. glPushMatrix();
  319. if (texgen == 2) {
  320. glTexGenfv(GL_S, GL_EYE_PLANE, sPlane);
  321. glTexGenfv(GL_T, GL_EYE_PLANE, tPlane);
  322. glTexGenfv(GL_R, GL_EYE_PLANE, rPlane);
  323. }
  324. glRotatef(angx, 1.0, 0.0, 0.0);
  325. glRotatef(angy, 0.0, 1.0, 0.0);
  326. glRotatef(angz, 0.0, 0.0, 1.0);
  327. if (texgen == 1) {
  328. glTexGenfv(GL_S, GL_EYE_PLANE, sPlane);
  329. glTexGenfv(GL_T, GL_EYE_PLANE, tPlane);
  330. glTexGenfv(GL_R, GL_EYE_PLANE, rPlane);
  331. }
  332. if (texgen) {
  333. glEnable(GL_TEXTURE_GEN_S);
  334. glEnable(GL_TEXTURE_GEN_T);
  335. glEnable(GL_TEXTURE_GEN_R);
  336. }
  337. else {
  338. glDisable(GL_TEXTURE_GEN_S);
  339. glDisable(GL_TEXTURE_GEN_T);
  340. glDisable(GL_TEXTURE_GEN_R);
  341. }
  342. glCallList(CurObject);
  343. glPopMatrix();
  344. glutSwapBuffers();
  345. }
  346. static void
  347. resize(int w, int h)
  348. {
  349. float ar = (float) w / (float) h;
  350. float ax = 0.6 * ar;
  351. float ay = 0.6;
  352. glViewport(0, 0, (GLint) w, (GLint) h);
  353. glMatrixMode(GL_PROJECTION);
  354. glLoadIdentity();
  355. glFrustum(-ax, ax, -ay, ay, 2, 20);
  356. /*glOrtho(-2, 2, -2, 2, -10, 10);*/
  357. glMatrixMode(GL_MODELVIEW);
  358. glLoadIdentity();
  359. glTranslatef(0, 0, -4);
  360. }
  361. static void
  362. Idle(void)
  363. {
  364. float t = glutGet(GLUT_ELAPSED_TIME);
  365. angx = 0.01 * t;
  366. angy = 0.03 * t;
  367. angz += 0;
  368. glutPostRedisplay();
  369. }
  370. static void
  371. SpecialKey(int k, int x, int y)
  372. {
  373. switch (k) {
  374. case GLUT_KEY_UP:
  375. angx += 5.0;
  376. break;
  377. case GLUT_KEY_DOWN:
  378. angx -= 5.0;
  379. break;
  380. case GLUT_KEY_LEFT:
  381. angy += 5.0;
  382. break;
  383. case GLUT_KEY_RIGHT:
  384. angy -= 5.0;
  385. break;
  386. default:
  387. return;
  388. }
  389. glutPostRedisplay();
  390. }
  391. static void
  392. KeyHandler(unsigned char key, int x, int y)
  393. {
  394. static const char *mode[] = {
  395. "glTexCoord3f (no texgen)",
  396. "texgen fixed to object coords",
  397. "texgen fixed to eye coords"
  398. };
  399. (void) x;
  400. (void) y;
  401. switch (key) {
  402. case 27:
  403. case 'q':
  404. case 'Q': /* quit game. */
  405. exit(0);
  406. break;
  407. case 'z':
  408. angz += 10;
  409. break;
  410. case 'Z':
  411. angz -= 10;
  412. break;
  413. case 's':
  414. smooth = !smooth;
  415. if (smooth)
  416. glShadeModel(GL_SMOOTH);
  417. else
  418. glShadeModel(GL_FLAT);
  419. break;
  420. case 't':
  421. texgen++;
  422. if (texgen > 2)
  423. texgen = 0;
  424. printf("Texgen: %s\n", mode[texgen]);
  425. break;
  426. case 'o':
  427. if (CurObject == TORUS)
  428. CurObject = SPHERE;
  429. else
  430. CurObject = TORUS;
  431. break;
  432. case 'i':
  433. if (CurTexture == NOISE_TEXTURE)
  434. CurTexture = GRADIENT_TEXTURE;
  435. else
  436. CurTexture = NOISE_TEXTURE;
  437. glBindTexture(GL_TEXTURE_3D, CurTexture);
  438. break;
  439. case 'a':
  440. animate = !animate;
  441. if (animate)
  442. glutIdleFunc(Idle);
  443. else
  444. glutIdleFunc(NULL);
  445. break;
  446. case 'w':
  447. wireframe = !wireframe;
  448. if (wireframe)
  449. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  450. else
  451. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  452. break;
  453. default:
  454. break;
  455. }
  456. glutPostRedisplay();
  457. }
  458. static void
  459. create3Dgradient(void)
  460. {
  461. unsigned char *v;
  462. int i, j, k;
  463. unsigned char *voxels = NULL;
  464. voxels = (unsigned char *) malloc(4 * tex_width * tex_height * tex_depth);
  465. v = voxels;
  466. for (i = 0; i < tex_depth; i++) {
  467. for (j = 0; j < tex_height; j++) {
  468. for (k = 0; k < tex_width; k++) {
  469. GLint r = (255 * i) / (tex_depth - 1);
  470. GLint g = (255 * j) / (tex_height - 1);
  471. GLint b = (255 * k) / (tex_width - 1);
  472. *v++ = r;
  473. *v++ = g;
  474. *v++ = b;
  475. *v++ = 255;
  476. }
  477. }
  478. }
  479. glBindTexture(GL_TEXTURE_3D, GRADIENT_TEXTURE);
  480. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  481. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  482. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  483. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  484. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
  485. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  486. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  487. glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA,
  488. tex_width, tex_height, tex_depth,
  489. 0, GL_RGBA, GL_UNSIGNED_BYTE, voxels);
  490. free(voxels);
  491. }
  492. static void
  493. init(void)
  494. {
  495. static const GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  496. static const GLfloat mat_shininess[] = { 25.0 };
  497. static const GLfloat gray[] = { 0.6, 0.6, 0.6, 0.0 };
  498. static const GLfloat white[] = { 1.0, 1.0, 1.0, 0.0 };
  499. static const GLfloat light_position[] = { 0.0, 1.0, 1.0, 0.0 };
  500. int max;
  501. /* see if we have OpenGL 1.2 or later, for 3D texturing */
  502. {
  503. const char *version = (const char *) glGetString(GL_VERSION);
  504. if (strncmp(version, "1.0", 3) == 0 || strncmp(version, "1.1", 3) == 0) {
  505. printf("Sorry, OpenGL 1.2 or later is required\n");
  506. exit(1);
  507. }
  508. }
  509. printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
  510. glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &max);
  511. printf("GL_MAX_3D_TEXTURE_SIZE: %d\n", max);
  512. printf("Current 3D texture size: %d x %d x %d\n",
  513. tex_width, tex_height, tex_depth);
  514. /* init light */
  515. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  516. glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  517. glLightfv(GL_LIGHT1, GL_POSITION, light_position);
  518. glLightfv(GL_LIGHT1, GL_AMBIENT, gray);
  519. glLightfv(GL_LIGHT1, GL_DIFFUSE, white);
  520. glLightfv(GL_LIGHT1, GL_SPECULAR, white);
  521. glColorMaterial(GL_FRONT, GL_DIFFUSE);
  522. glEnable(GL_COLOR_MATERIAL);
  523. glEnable(GL_LIGHTING);
  524. glEnable(GL_LIGHT1);
  525. glClearColor(.5, .5, .5, 0);
  526. {
  527. GLUquadricObj *q;
  528. q = gluNewQuadric();
  529. gluQuadricTexture( q, GL_TRUE );
  530. glNewList(SPHERE, GL_COMPILE);
  531. gluSphere( q, 0.95, 30, 15 );
  532. glEndList();
  533. gluDeleteQuadric(q);
  534. }
  535. BuildTorus();
  536. create3Dgradient();
  537. initNoise();
  538. create3Dtexture();
  539. glEnable(GL_TEXTURE_3D);
  540. /*
  541. glBlendFunc(GL_SRC_COLOR, GL_SRC_ALPHA);
  542. glEnable(GL_BLEND);
  543. */
  544. glEnable(GL_DEPTH_TEST);
  545. glColor3f(0.6, 0.7, 0.8);
  546. }
  547. int
  548. main(int argc, char **argv)
  549. {
  550. glutInit(&argc, argv);
  551. if (parseCmdLine(argc, argv) == GL_FALSE) {
  552. exit(0);
  553. }
  554. glutInitWindowPosition(0, 0);
  555. glutInitWindowSize(400, 400);
  556. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  557. if (glutCreateWindow("stex3d") <= 0) {
  558. exit(0);
  559. }
  560. init();
  561. printHelp();
  562. glutReshapeFunc(resize);
  563. glutKeyboardFunc(KeyHandler);
  564. glutSpecialFunc(SpecialKey);
  565. glutDisplayFunc(drawScene);
  566. if (animate)
  567. glutIdleFunc(Idle);
  568. glutMainLoop();
  569. return 0;
  570. }