1 2/* 3 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. 4 * 5 * Permission to use, copy, modify, distribute, and sell this software and 6 * its documentation for any purpose is hereby granted without fee, provided 7 * that (i) the above copyright notices and this permission notice appear in 8 * all copies of the software and related documentation, and (ii) the name of 9 * Silicon Graphics may not be used in any advertising or 10 * publicity relating to the software without the specific, prior written 11 * permission of Silicon Graphics. 12 * 13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF 14 * ANY KIND, 15 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 16 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 17 * 18 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR 19 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 20 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 21 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 22 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 23 * OF THIS SOFTWARE. 24 */ 25 26#include <stdio.h> 27#include <string.h> 28#include <stdlib.h> 29#include "glut_wrap.h" 30 31 32#define PI 3.141592654 33 34#define BLACK 0 35#define GRAY 128 36#define WHITE 255 37#define BL 0x00 38#define WH 0xFF 39#define RD 0xA4,0x00,0x00,0xFF 40#define WT 0xFF,0xFF,0xFF,0xFF 41 42#define CHECKIMAGEWIDTH 8 43#define CHECKIMAGEHEIGHT 8 44#define BRICKIMAGEWIDTH 16 45#define BRICKIMAGEHEIGHT 16 46 47 48GLenum rgb, doubleBuffer; 49 50#include "tkmap.c" 51 52float black[3] = {0.0, 0.0, 0.0}; 53float white[3] = {1.0, 1.0, 1.0}; 54float gray[3] = {0.5, 0.5, 0.5}; 55float blue[3] = {0.0, 0.0, 1.0}; 56GLint colorIndexes[3] = {0, 200, 255}; 57 58GLenum polyMode; 59GLboolean dithering; 60GLboolean shade; 61GLboolean doStipple; 62GLboolean noDraw = 0; 63GLboolean LineSmooth = GL_FALSE; 64 65double plane[4] = {1.0, 0.0, -1.0, 0.0}; 66float xRotation = 30.0, yRotation = 30.0; 67float zTranslation = -15.0; 68 69GLint singleCylinder; 70GLint doubleCylinder; 71GLint elbow, logo; 72 73GLubyte checkImage[3*CHECKIMAGEWIDTH*CHECKIMAGEHEIGHT] = { 74 BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, 75 WH, WH, BL, BL, BL, WH, WH, WH, WH, WH, WH, BL, BL, BL, WH, WH, 76 WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, 77 BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, 78 WH, WH, BL, BL, BL, WH, WH, WH, WH, WH, WH, BL, BL, BL, WH, WH, 79 WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, 80 BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, 81 WH, WH, BL, BL, BL, WH, WH, WH, WH, WH, WH, BL, BL, BL, WH, WH, 82 WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, 83 BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, 84 WH, WH, BL, BL, BL, WH, WH, WH, WH, WH, WH, BL, BL, BL, WH, WH, 85 WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, 86}; 87GLubyte brickImage[4*BRICKIMAGEWIDTH*BRICKIMAGEHEIGHT] = { 88 RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, 89 RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, 90 RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, 91 RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, 92 WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, 93 RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, 94 RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, 95 RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, 96 RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, 97 WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, 98 RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, 99 RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, 100 RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, 101 RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, 102 WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, 103 RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD 104}; 105 106GLubyte *image = checkImage; 107GLint imageHeight = CHECKIMAGEHEIGHT; 108GLint imageWidth = CHECKIMAGEWIDTH; 109 110static float decal[] = { 111 GL_DECAL, 112}; 113static float modulate[] = { 114 GL_MODULATE, 115}; 116static float repeat[] = { 117 GL_REPEAT, 118}; 119static float nearest[] = { 120 GL_NEAREST, 121}; 122 123GLubyte stipple[4*32] = { 124 0x00, 0x00, 0x00, 0x00, 125 0x00, 0x00, 0x00, 0x00, 126 0x00, 0x00, 0x00, 0x00, 127 0x00, 0x00, 0x00, 0x00, 128 0x00, 0x00, 0x00, 0x00, 129 0x00, 0x00, 0x00, 0x00, 130 0x00, 0x00, 0x00, 0x00, 131 0x00, 0x00, 0x00, 0x00, 132 133 0x00, 0x0F, 0xF0, 0x00, 134 0x00, 0x0F, 0xF0, 0x00, 135 0x00, 0x0F, 0xF0, 0x00, 136 0x00, 0x0F, 0xF0, 0x00, 137 0x00, 0x0F, 0xF0, 0x00, 138 0x00, 0x0F, 0xF0, 0x00, 139 0x00, 0x0F, 0xF0, 0x00, 140 0x00, 0x0F, 0xF0, 0x00, 141 142 0x00, 0x0F, 0xF0, 0x00, 143 0x00, 0x0F, 0xF0, 0x00, 144 0x00, 0x0F, 0xF0, 0x00, 145 0x00, 0x0F, 0xF0, 0x00, 146 0x00, 0x0F, 0xF0, 0x00, 147 0x00, 0x0F, 0xF0, 0x00, 148 0x00, 0x0F, 0xF0, 0x00, 149 0x00, 0x0F, 0xF0, 0x00, 150 151 0x00, 0x00, 0x00, 0x00, 152 0x00, 0x00, 0x00, 0x00, 153 0x00, 0x00, 0x00, 0x00, 154 0x00, 0x00, 0x00, 0x00, 155 0x00, 0x00, 0x00, 0x00, 156 0x00, 0x00, 0x00, 0x00, 157 0x00, 0x00, 0x00, 0x00, 158 0x00, 0x00, 0x00, 0x00, 159}; 160 161float tscp[18][2] = { 162 { 163 0.0, 0.0 164 }, 165 { 166 1.0, 0.0 167 }, 168 { 169 0.0, 0.125 170 }, 171 { 172 1.0, 0.125 173 }, 174 { 175 0.0, 0.250 176 }, 177 { 178 1.0, 0.25 179 }, 180 { 181 0.0, 0.375 182 }, 183 { 184 1.0, 0.375 185 }, 186 { 187 0.0, 0.50 188 }, 189 { 190 1.0, 0.50 191 }, 192 { 193 0.0, 0.625 194 }, 195 { 196 1.0, 0.625 197 }, 198 { 199 0.0, 0.75 200 }, 201 { 202 1.0, 0.75 203 }, 204 { 205 0.0, 0.875 206 }, 207 { 208 1.0, 0.875 209 }, 210 { 211 0.0, 1.0 212 }, 213 { 214 1.0, 1.0 215 } 216}; 217float scp[18][3] = { 218 { 219 1.000000, 0.000000, 0.000000 220 }, 221 { 222 1.000000, 0.000000, 5.000000 223 }, 224 { 225 0.707107, 0.707107, 0.000000 226 }, 227 { 228 0.707107, 0.707107, 5.000000 229 }, 230 { 231 0.000000, 1.000000, 0.000000 232 }, 233 { 234 0.000000, 1.000000, 5.000000 235 }, 236 { 237 -0.707107, 0.707107, 0.000000 238 }, 239 { 240 -0.707107, 0.707107, 5.000000 241 }, 242 { 243 -1.000000, 0.000000, 0.000000 244 }, 245 { 246 -1.000000, 0.000000, 5.000000 247 }, 248 { 249 -0.707107, -0.707107, 0.000000 250 }, 251 { 252 -0.707107, -0.707107, 5.000000 253 }, 254 { 255 0.000000, -1.000000, 0.000000 256 }, 257 { 258 0.000000, -1.000000, 5.000000 259 }, 260 { 261 0.707107, -0.707107, 0.000000 262 }, 263 { 264 0.707107, -0.707107, 5.000000 265 }, 266 { 267 1.000000, 0.000000, 0.000000 268 }, 269 { 270 1.000000, 0.000000, 5.000000 271 } 272}; 273float dcp[18][3] = { 274 { 275 1.000000, 0.000000, 0.000000 276 }, 277 { 278 1.000000, 0.000000, 7.000000 279 }, 280 { 281 0.707107, 0.707107, 0.000000 282 }, 283 { 284 0.707107, 0.707107, 7.000000 285 }, 286 { 287 0.000000, 1.000000, 0.000000 288 }, 289 { 290 0.000000, 1.000000, 7.000000 291 }, 292 { 293 -0.707107, 0.707107, 0.000000 294 }, 295 { 296 -0.707107, 0.707107, 7.000000 297 }, 298 { 299 -1.000000, 0.000000, 0.000000 300 }, 301 { 302 -1.000000, 0.000000, 7.000000 303 }, 304 { 305 -0.707107, -0.707107, 0.000000 306 }, 307 { 308 -0.707107, -0.707107, 7.000000 309 }, 310 { 311 0.000000, -1.000000, 0.000000 312 }, 313 { 314 0.000000, -1.000000, 7.000000 315 }, 316 { 317 0.707107, -0.707107, 0.000000 318 }, 319 { 320 0.707107, -0.707107, 7.000000 321 }, 322 { 323 1.000000, 0.000000, 0.000000 324 }, 325 { 326 1.000000, 0.000000, 7.000000 327 } 328}; 329float ep[7][9][3] = { 330 { 331 { 332 1.000000, 0.000000, 0.000000 333 }, 334 { 335 0.707107, 0.707107, 0.000000 336 }, 337 { 338 0.000000, 1.000000, 0.000000 339 }, 340 { 341 -0.707107, 0.707107, 0.000000 342 }, 343 { 344 -1.000000, 0.000000, 0.000000 345 }, 346 { 347 -0.707107, -0.707107, 0.000000 348 }, 349 { 350 0.000000, -1.000000, 0.000000 351 }, 352 { 353 0.707107, -0.707107, 0.000000 354 }, 355 { 356 1.000000, 0.000000, 0.000000 357 } 358 }, 359 { 360 { 361 1.000000, 0.034074, 0.258819 362 }, 363 { 364 0.707107, 0.717087, 0.075806 365 }, 366 { 367 0.000000, 1.000000, 0.000000 368 }, 369 { 370 -0.707107, 0.717087, 0.075806 371 }, 372 { 373 -1.000000, 0.034074, 0.258819 374 }, 375 { 376 -0.707107, -0.648939, 0.441832 377 }, 378 { 379 0.000000, -0.931852, 0.517638 380 }, 381 { 382 0.707107, -0.648939, 0.441832 383 }, 384 { 385 1.000000, 0.034074, 0.258819 386 } 387 }, 388 { 389 { 390 1.000000, 0.133975, 0.500000 391 }, 392 { 393 0.707107, 0.746347, 0.146447 394 }, 395 { 396 0.000000, 1.000000, 0.000000 397 }, 398 { 399 -0.707107, 0.746347, 0.146447 400 }, 401 { 402 -1.000000, 0.133975, 0.500000 403 }, 404 { 405 -0.707107, -0.478398, 0.853553 406 }, 407 { 408 0.000000, -0.732051, 1.000000 409 }, 410 { 411 0.707107, -0.478398, 0.853553 412 }, 413 { 414 1.000000, 0.133975, 0.500000 415 } 416 }, 417 { 418 { 419 1.000000, 0.292893, 0.707107 420 }, 421 { 422 0.707107, 0.792893, 0.207107 423 }, 424 { 425 0.000000, 1.000000, 0.000000 426 }, 427 { 428 -0.707107, 0.792893, 0.207107 429 }, 430 { 431 -1.000000, 0.292893, 0.707107 432 }, 433 { 434 -0.707107, -0.207107, 1.207107 435 }, 436 { 437 0.000000, -0.414214, 1.414214 438 }, 439 { 440 0.707107, -0.207107, 1.207107 441 }, 442 { 443 1.000000, 0.292893, 0.707107 444 } 445 }, 446 { 447 { 448 1.000000, 0.500000, 0.866025 449 }, 450 { 451 0.707107, 0.853553, 0.253653 452 }, 453 { 454 0.000000, 1.000000, 0.000000 455 }, 456 { 457 -0.707107, 0.853553, 0.253653 458 }, 459 { 460 -1.000000, 0.500000, 0.866025 461 }, 462 { 463 -0.707107, 0.146447, 1.478398 464 }, 465 { 466 0.000000, 0.000000, 1.732051 467 }, 468 { 469 0.707107, 0.146447, 1.478398 470 }, 471 { 472 1.000000, 0.500000, 0.866025 473 } 474 }, 475 { 476 { 477 1.000000, 0.741181, 0.965926 478 }, 479 { 480 0.707107, 0.924194, 0.282913 481 }, 482 { 483 0.000000, 1.000000, 0.000000 484 }, 485 { 486 -0.707107, 0.924194, 0.282913 487 }, 488 { 489 -1.000000, 0.741181, 0.965926 490 }, 491 { 492 -0.707107, 0.558168, 1.648939 493 }, 494 { 495 0.000000, 0.482362, 1.931852 496 }, 497 { 498 0.707107, 0.558168, 1.648939 499 }, 500 { 501 1.000000, 0.741181, 0.965926 502 } 503 }, 504 { 505 { 506 1.000000, 1.000000, 1.000000 507 }, 508 { 509 0.707107, 1.000000, 0.292893 510 }, 511 { 512 0.000000, 1.000000, 0.000000 513 }, 514 { 515 -0.707107, 1.000000, 0.292893 516 }, 517 { 518 -1.000000, 1.000000, 1.000000 519 }, 520 { 521 -0.707107, 1.000000, 1.707107 522 }, 523 { 524 0.000000, 1.000000, 2.000000 525 }, 526 { 527 0.707107, 1.000000, 1.707107 528 }, 529 { 530 1.000000, 1.000000, 1.000000 531 } 532 } 533}; 534float en[7][9][3] = { 535 { 536 { 537 1.000000, 0.000000, 0.000000 538 }, 539 { 540 0.707107, 0.707107, 0.000000 541 }, 542 { 543 0.000000, 1.000000, 0.000000 544 }, 545 { 546 -0.707107, 0.707107, 0.000000 547 }, 548 { 549 -1.000000, 0.000000, 0.000000 550 }, 551 { 552 -0.707107, -0.707107, 0.000000 553 }, 554 { 555 0.000000, -1.000000, 0.000000 556 }, 557 { 558 0.707107, -0.707107, 0.000000 559 }, 560 { 561 1.000000, 0.000000, 0.000000 562 } 563 }, 564 { 565 { 566 1.000000, 0.000000, 0.000000 567 }, 568 { 569 0.707107, 0.683013, -0.183013 570 }, 571 { 572 0.000000, 0.965926, -0.258819 573 }, 574 { 575 -0.707107, 0.683013, -0.183013 576 }, 577 { 578 -1.000000, 0.000000, 0.000000 579 }, 580 { 581 -0.707107, -0.683013, 0.183013 582 }, 583 { 584 0.000000, -0.965926, 0.258819 585 }, 586 { 587 0.707107, -0.683013, 0.183013 588 }, 589 { 590 1.000000, 0.000000, 0.000000 591 } 592 }, 593 { 594 { 595 1.000000, 0.000000, 0.000000 596 }, 597 { 598 0.707107, 0.612372, -0.353553 599 }, 600 { 601 0.000000, 0.866025, -0.500000 602 }, 603 { 604 -0.707107, 0.612372, -0.353553 605 }, 606 { 607 -1.000000, 0.000000, 0.000000 608 }, 609 { 610 -0.707107, -0.612372, 0.353553 611 }, 612 { 613 0.000000, -0.866025, 0.500000 614 }, 615 { 616 0.707107, -0.612372, 0.353553 617 }, 618 { 619 1.000000, 0.000000, 0.000000 620 } 621 }, 622 { 623 { 624 1.000000, 0.000000, 0.000000 625 }, 626 { 627 /* These 3 lines added by BEP */ 628 0.707107, 0.500000, -0.500000 629 }, 630 { 631 0.000000, 0.707107, -0.707107 632 }, 633 { 634 -0.707107, 0.500000, -0.500000 635 }, 636 { 637 -1.000000, 0.000000, 0.000000 638 }, 639 { 640 -0.707107, -0.500000, 0.500000 641 }, 642 { 643 0.000000, -0.707107, 0.707107 644 }, 645 { 646 0.707107, -0.500000, 0.500000 647 }, 648 { 649 1.000000, 0.000000, 0.000000 650 } 651 }, 652 { 653 { 654 1.000000, 0.000000, 0.000000 655 }, 656 { 657 0.707107, 0.353553, -0.612372 658 }, 659 { 660 0.000000, 0.500000, -0.866025 661 }, 662 { 663 -0.707107, 0.353553, -0.612372 664 }, 665 { 666 -1.000000, 0.000000, 0.000000 667 }, 668 { 669 -0.707107, -0.353553, 0.612372 670 }, 671 { 672 0.000000, -0.500000, 0.866025 673 }, 674 { 675 0.707107, -0.353553, 0.612372 676 }, 677 { 678 1.000000, 0.000000, 0.000000 679 } 680 }, 681 { 682 { 683 1.000000, 0.000000, 0.000000 684 }, 685 { 686 0.707107, 0.183013, -0.683013 687 }, 688 { 689 0.000000, 0.258819, -0.965926 690 }, 691 { 692 -0.707107, 0.183013, -0.683013 693 }, 694 { 695 -1.000000, 0.000000, 0.000000 696 }, 697 { 698 -0.707107, -0.183013, 0.683013 699 }, 700 { 701 0.000000, -0.258819, 0.965926 702 }, 703 { 704 0.707107, -0.183013, 0.683013 705 }, 706 { 707 1.000000, 0.000000, 0.000000 708 } 709 }, 710 { 711 { 712 1.000000, 0.000000, 0.000000 713 }, 714 { 715 0.707107, 0.000000, -0.707107 716 }, 717 { 718 0.000000, 0.000000, -1.000000 719 }, 720 { 721 -0.707107, 0.000000, -0.707107 722 }, 723 { 724 -1.000000, 0.000000, 0.000000 725 }, 726 { 727 -0.707107, 0.000000, 0.707107 728 }, 729 { 730 0.000000, 0.000000, 1.000000 731 }, 732 { 733 0.707107, 0.000000, 0.707107 734 }, 735 { 736 1.000000, 0.000000, 0.000000 737 } 738 } 739}; 740float tep[7][9][2] = { 741 { 742 { 743 0, 0.0 744 }, 745 { 746 0.125, 0.0 747 }, 748 { 749 0.25, 0.0 750 }, 751 { 752 0.375, 0.0 753 }, 754 { 755 0.5, 0.0 756 }, 757 { 758 0.625, 0.0 759 }, 760 { 761 0.75, 0.0 762 }, 763 { 764 0.875, 0.0 765 }, 766 { 767 1.0, 0.0 768 } 769 }, 770 { 771 { 772 0, 0.16667 773 }, 774 { 775 0.125, 0.16667 776 }, 777 { 778 0.25, 0.16667 779 }, 780 { 781 0.375, 0.16667 782 }, 783 { 784 0.5, 0.16667 785 }, 786 { 787 0.625, 0.16667 788 }, 789 { 790 0.75, 0.16667 791 }, 792 { 793 0.875, 0.16667 794 }, 795 { 796 1.0, 0.16667 797 } 798 }, 799 { 800 { 801 0, 0.33333 802 }, 803 { 804 0.125, 0.33333 805 }, 806 { 807 0.25, 0.33333 808 }, 809 { 810 0.375, 0.33333 811 }, 812 { 813 0.5, 0.33333 814 }, 815 { 816 0.625, 0.33333 817 }, 818 { 819 0.75, 0.33333 820 }, 821 { 822 0.875, 0.33333 823 }, 824 { 825 1.0, 0.33333 826 } 827 }, 828 { 829 { 830 0, 0.5 831 }, 832 { 833 0.125, 0.5 834 }, 835 { 836 0.25, 0.5 837 }, 838 { 839 0.375, 0.5 840 }, 841 { 842 0.5, 0.5 843 }, 844 { 845 0.625, 0.5 846 }, 847 { 848 0.75, 0.5 849 }, 850 { 851 0.875, 0.5 852 }, 853 { 854 1.0, 0.5 855 } 856 }, 857 { 858 { 859 0, 0.6667 860 }, 861 { 862 0.125, 0.6667 863 }, 864 { 865 0.25, 0.6667 866 }, 867 { 868 0.375, 0.6667 869 }, 870 { 871 0.5, 0.6667 872 }, 873 { 874 0.625, 0.6667 875 }, 876 { 877 0.75, 0.6667 878 }, 879 { 880 0.875, 0.6667 881 }, 882 { 883 1.0, 0.6667 884 } 885 }, 886 { 887 { 888 0, 0.83333 889 }, 890 { 891 0.125, 0.83333 892 }, 893 { 894 0.25, 0.83333 895 }, 896 { 897 0.375, 0.83333 898 }, 899 { 900 0.5, 0.83333 901 }, 902 { 903 0.625, 0.83333 904 }, 905 { 906 0.75, 0.83333 907 }, 908 { 909 0.875, 0.83333 910 }, 911 { 912 1.0, 0.83333 913 } 914 }, 915 { 916 { 917 0, 1.0 918 }, 919 { 920 0.125, 1.0 921 }, 922 { 923 0.25, 1.0 924 }, 925 { 926 0.375, 1.0 927 }, 928 { 929 0.5, 1.0 930 }, 931 { 932 0.625, 1.0 933 }, 934 { 935 0.75, 1.0 936 }, 937 { 938 0.875, 1.0 939 }, 940 { 941 1.0, 1.0 942 } 943 } 944}; 945 946 947static void SetUpAntiAliasedGrayScale(void) 948{ 949 float color; 950 GLint i, j; 951 952 for (i = 0; i < 16; i++) { 953 color = (2 * i + 1) / 32.0; 954 for (j = 0; j < 16; j++) { 955 glutSetColor(i*16+j, color*j/15.0, color*j/15.0, color*j/15.0); 956 } 957 } 958} 959 960static void BendForward(void) 961{ 962 963 glTranslatef(0.0, 1.0, 0.0); 964 glRotatef(90.0, 1, 0, 0); 965 glTranslatef(0.0, -1.0, 0.0); 966} 967 968static void BendLeft(void) 969{ 970 971 glRotatef(-90.0, 0, 0, 1); 972 glTranslatef(0.0, 1.0, 0.0); 973 glRotatef(90.0, 1, 0, 0); 974 glTranslatef(0.0, -1.0, 0.0); 975} 976 977static void BendRight(void) 978{ 979 980 glRotatef(90.0, 0, 0, 1); 981 glTranslatef(0.0, 1.0, 0.0); 982 glRotatef(90.0, 1, 0, 0); 983 glTranslatef(0.0, -1.0, 0.0); 984} 985 986static void BuildSingleCylinder(void) 987{ 988 989 glNewList(singleCylinder, GL_COMPILE); 990 991 glBegin(GL_TRIANGLE_STRIP); 992 glNormal3fv(scp[0]); glTexCoord2fv(tscp[0]); glVertex3fv(scp[0]); 993 glNormal3fv(scp[0]); glTexCoord2fv(tscp[1]); glVertex3fv(scp[1]); 994 glNormal3fv(scp[2]); glTexCoord2fv(tscp[2]); glVertex3fv(scp[2]); 995 glNormal3fv(scp[2]); glTexCoord2fv(tscp[3]); glVertex3fv(scp[3]); 996 glNormal3fv(scp[4]); glTexCoord2fv(tscp[4]); glVertex3fv(scp[4]); 997 glNormal3fv(scp[4]); glTexCoord2fv(tscp[5]); glVertex3fv(scp[5]); 998 glNormal3fv(scp[6]); glTexCoord2fv(tscp[6]); glVertex3fv(scp[6]); 999 glNormal3fv(scp[6]); glTexCoord2fv(tscp[7]); glVertex3fv(scp[7]); 1000 glNormal3fv(scp[8]); glTexCoord2fv(tscp[8]); glVertex3fv(scp[8]); 1001 glNormal3fv(scp[8]); glTexCoord2fv(tscp[9]); glVertex3fv(scp[9]); 1002 glNormal3fv(scp[10]); glTexCoord2fv(tscp[10]); glVertex3fv(scp[10]); 1003 glNormal3fv(scp[10]); glTexCoord2fv(tscp[11]); glVertex3fv(scp[11]); 1004 glNormal3fv(scp[12]); glTexCoord2fv(tscp[12]); glVertex3fv(scp[12]); 1005 glNormal3fv(scp[12]); glTexCoord2fv(tscp[13]); glVertex3fv(scp[13]); 1006 glNormal3fv(scp[14]); glTexCoord2fv(tscp[14]); glVertex3fv(scp[14]); 1007 glNormal3fv(scp[14]); glTexCoord2fv(tscp[15]); glVertex3fv(scp[15]); 1008 glNormal3fv(scp[16]); glTexCoord2fv(tscp[16]); glVertex3fv(scp[16]); 1009 glNormal3fv(scp[16]); glTexCoord2fv(tscp[17]); glVertex3fv(scp[17]); 1010 glEnd(); 1011 1012 glEndList(); 1013} 1014 1015static void BuildDoubleCylinder(void) 1016{ 1017 1018 glNewList(doubleCylinder, GL_COMPILE); 1019 1020 glBegin(GL_TRIANGLE_STRIP); 1021 glNormal3fv(dcp[0]); glTexCoord2fv(tscp[0]); glVertex3fv(dcp[0]); 1022 glNormal3fv(dcp[0]); glTexCoord2fv(tscp[1]); glVertex3fv(dcp[1]); 1023 glNormal3fv(dcp[2]); glTexCoord2fv(tscp[2]); glVertex3fv(dcp[2]); 1024 glNormal3fv(dcp[2]); glTexCoord2fv(tscp[3]); glVertex3fv(dcp[3]); 1025 glNormal3fv(dcp[4]); glTexCoord2fv(tscp[4]); glVertex3fv(dcp[4]); 1026 glNormal3fv(dcp[4]); glTexCoord2fv(tscp[5]); glVertex3fv(dcp[5]); 1027 glNormal3fv(dcp[6]); glTexCoord2fv(tscp[6]); glVertex3fv(dcp[6]); 1028 glNormal3fv(dcp[6]); glTexCoord2fv(tscp[7]); glVertex3fv(dcp[7]); 1029 glNormal3fv(dcp[8]); glTexCoord2fv(tscp[8]); glVertex3fv(dcp[8]); 1030 glNormal3fv(dcp[8]); glTexCoord2fv(tscp[9]); glVertex3fv(dcp[9]); 1031 glNormal3fv(dcp[10]); glTexCoord2fv(tscp[10]); glVertex3fv(dcp[10]); 1032 glNormal3fv(dcp[10]); glTexCoord2fv(tscp[11]); glVertex3fv(dcp[11]); 1033 glNormal3fv(dcp[12]); glTexCoord2fv(tscp[12]); glVertex3fv(dcp[12]); 1034 glNormal3fv(dcp[12]); glTexCoord2fv(tscp[13]); glVertex3fv(dcp[13]); 1035 glNormal3fv(dcp[14]); glTexCoord2fv(tscp[14]); glVertex3fv(dcp[14]); 1036 glNormal3fv(dcp[14]); glTexCoord2fv(tscp[15]); glVertex3fv(dcp[15]); 1037 glNormal3fv(dcp[16]); glTexCoord2fv(tscp[16]); glVertex3fv(dcp[16]); 1038 glNormal3fv(dcp[16]); glTexCoord2fv(tscp[17]); glVertex3fv(dcp[17]); 1039 glEnd(); 1040 1041 glEndList(); 1042} 1043 1044static void BuildElbow(void) 1045{ 1046 1047 glNewList(elbow, GL_COMPILE); 1048 1049 glBegin(GL_TRIANGLE_STRIP); 1050 glNormal3fv(en[0][0]); glTexCoord2fv(tep[0][0]); glVertex3fv(ep[0][0]); 1051 glNormal3fv(en[1][0]); glTexCoord2fv(tep[1][0]); glVertex3fv(ep[1][0]); 1052 glNormal3fv(en[0][1]); glTexCoord2fv(tep[0][1]); glVertex3fv(ep[0][1]); 1053 glNormal3fv(en[1][1]); glTexCoord2fv(tep[1][1]); glVertex3fv(ep[1][1]); 1054 glNormal3fv(en[0][2]); glTexCoord2fv(tep[0][2]); glVertex3fv(ep[0][2]); 1055 glNormal3fv(en[1][2]); glTexCoord2fv(tep[1][2]); glVertex3fv(ep[1][2]); 1056 glNormal3fv(en[0][3]); glTexCoord2fv(tep[0][3]); glVertex3fv(ep[0][3]); 1057 glNormal3fv(en[1][3]); glTexCoord2fv(tep[1][3]); glVertex3fv(ep[1][3]); 1058 glNormal3fv(en[0][4]); glTexCoord2fv(tep[0][4]); glVertex3fv(ep[0][4]); 1059 glNormal3fv(en[1][4]); glTexCoord2fv(tep[1][4]); glVertex3fv(ep[1][4]); 1060 glNormal3fv(en[0][5]); glTexCoord2fv(tep[0][5]); glVertex3fv(ep[0][5]); 1061 glNormal3fv(en[1][5]); glTexCoord2fv(tep[1][5]); glVertex3fv(ep[1][5]); 1062 glNormal3fv(en[0][6]); glTexCoord2fv(tep[0][6]); glVertex3fv(ep[0][6]); 1063 glNormal3fv(en[1][6]); glTexCoord2fv(tep[1][6]); glVertex3fv(ep[1][6]); 1064 glNormal3fv(en[0][7]); glTexCoord2fv(tep[0][7]); glVertex3fv(ep[0][7]); 1065 glNormal3fv(en[1][7]); glTexCoord2fv(tep[1][7]); glVertex3fv(ep[1][7]); 1066 glNormal3fv(en[0][8]); glTexCoord2fv(tep[0][8]); glVertex3fv(ep[0][8]); 1067 glNormal3fv(en[1][8]); glTexCoord2fv(tep[1][8]); glVertex3fv(ep[1][8]); 1068 glEnd(); 1069 glBegin(GL_TRIANGLE_STRIP); 1070 glNormal3fv(en[1][0]); glTexCoord2fv(tep[1][0]); glVertex3fv(ep[1][0]); 1071 glNormal3fv(en[2][0]); glTexCoord2fv(tep[2][0]); glVertex3fv(ep[2][0]); 1072 glNormal3fv(en[1][1]); glTexCoord2fv(tep[1][1]); glVertex3fv(ep[1][1]); 1073 glNormal3fv(en[2][1]); glTexCoord2fv(tep[2][1]); glVertex3fv(ep[2][1]); 1074 glNormal3fv(en[1][2]); glTexCoord2fv(tep[1][2]); glVertex3fv(ep[1][2]); 1075 glNormal3fv(en[2][2]); glTexCoord2fv(tep[2][2]); glVertex3fv(ep[2][2]); 1076 glNormal3fv(en[1][3]); glTexCoord2fv(tep[1][3]); glVertex3fv(ep[1][3]); 1077 glNormal3fv(en[2][3]); glTexCoord2fv(tep[2][3]); glVertex3fv(ep[2][3]); 1078 glNormal3fv(en[1][4]); glTexCoord2fv(tep[1][4]); glVertex3fv(ep[1][4]); 1079 glNormal3fv(en[2][4]); glTexCoord2fv(tep[2][4]); glVertex3fv(ep[2][4]); 1080 glNormal3fv(en[1][5]); glTexCoord2fv(tep[1][5]); glVertex3fv(ep[1][5]); 1081 glNormal3fv(en[2][5]); glTexCoord2fv(tep[2][5]); glVertex3fv(ep[2][5]); 1082 glNormal3fv(en[1][6]); glTexCoord2fv(tep[1][6]); glVertex3fv(ep[1][6]); 1083 glNormal3fv(en[2][6]); glTexCoord2fv(tep[2][6]); glVertex3fv(ep[2][6]); 1084 glNormal3fv(en[1][7]); glTexCoord2fv(tep[1][7]); glVertex3fv(ep[1][7]); 1085 glNormal3fv(en[2][7]); glTexCoord2fv(tep[2][7]); glVertex3fv(ep[2][7]); 1086 glNormal3fv(en[1][8]); glTexCoord2fv(tep[1][8]); glVertex3fv(ep[1][8]); 1087 glNormal3fv(en[2][8]); glTexCoord2fv(tep[2][8]); glVertex3fv(ep[2][8]); 1088 glEnd(); 1089 glBegin(GL_TRIANGLE_STRIP); 1090 glNormal3fv(en[2][0]); glTexCoord2fv(tep[2][0]); glVertex3fv(ep[2][0]); 1091 glNormal3fv(en[3][0]); glTexCoord2fv(tep[3][0]); glVertex3fv(ep[3][0]); 1092 glNormal3fv(en[2][1]); glTexCoord2fv(tep[2][1]); glVertex3fv(ep[2][1]); 1093 glNormal3fv(en[3][1]); glTexCoord2fv(tep[3][1]); glVertex3fv(ep[3][1]); 1094 glNormal3fv(en[2][2]); glTexCoord2fv(tep[2][2]); glVertex3fv(ep[2][2]); 1095 glNormal3fv(en[3][2]); glTexCoord2fv(tep[3][2]); glVertex3fv(ep[3][2]); 1096 glNormal3fv(en[2][3]); glTexCoord2fv(tep[2][3]); glVertex3fv(ep[2][3]); 1097 glNormal3fv(en[3][3]); glTexCoord2fv(tep[3][3]); glVertex3fv(ep[3][3]); 1098 glNormal3fv(en[2][4]); glTexCoord2fv(tep[2][4]); glVertex3fv(ep[2][4]); 1099 glNormal3fv(en[3][4]); glTexCoord2fv(tep[3][4]); glVertex3fv(ep[3][4]); 1100 glNormal3fv(en[2][5]); glTexCoord2fv(tep[2][5]); glVertex3fv(ep[2][5]); 1101 glNormal3fv(en[3][5]); glTexCoord2fv(tep[3][5]); glVertex3fv(ep[3][5]); 1102 glNormal3fv(en[2][6]); glTexCoord2fv(tep[2][6]); glVertex3fv(ep[2][6]); 1103 glNormal3fv(en[3][6]); glTexCoord2fv(tep[3][6]); glVertex3fv(ep[3][6]); 1104 glNormal3fv(en[2][7]); glTexCoord2fv(tep[2][7]); glVertex3fv(ep[2][7]); 1105 glNormal3fv(en[3][7]); glTexCoord2fv(tep[3][7]); glVertex3fv(ep[3][7]); 1106 glNormal3fv(en[2][8]); glTexCoord2fv(tep[2][8]); glVertex3fv(ep[2][8]); 1107 glNormal3fv(en[3][8]); glTexCoord2fv(tep[3][8]); glVertex3fv(ep[3][8]); 1108 glEnd(); 1109 glBegin(GL_TRIANGLE_STRIP); 1110 glNormal3fv(en[3][0]); glTexCoord2fv(tep[3][0]); glVertex3fv(ep[3][0]); 1111 glNormal3fv(en[4][0]); glTexCoord2fv(tep[4][0]); glVertex3fv(ep[4][0]); 1112 glNormal3fv(en[3][1]); glTexCoord2fv(tep[3][1]); glVertex3fv(ep[3][1]); 1113 glNormal3fv(en[4][1]); glTexCoord2fv(tep[4][1]); glVertex3fv(ep[4][1]); 1114 glNormal3fv(en[3][2]); glTexCoord2fv(tep[3][2]); glVertex3fv(ep[3][2]); 1115 glNormal3fv(en[4][2]); glTexCoord2fv(tep[4][2]); glVertex3fv(ep[4][2]); 1116 glNormal3fv(en[3][3]); glTexCoord2fv(tep[3][3]); glVertex3fv(ep[3][3]); 1117 glNormal3fv(en[4][3]); glTexCoord2fv(tep[4][3]); glVertex3fv(ep[4][3]); 1118 glNormal3fv(en[3][4]); glTexCoord2fv(tep[3][4]); glVertex3fv(ep[3][4]); 1119 glNormal3fv(en[4][4]); glTexCoord2fv(tep[4][4]); glVertex3fv(ep[4][4]); 1120 glNormal3fv(en[3][5]); glTexCoord2fv(tep[3][5]); glVertex3fv(ep[3][5]); 1121 glNormal3fv(en[4][5]); glTexCoord2fv(tep[4][5]); glVertex3fv(ep[4][5]); 1122 glNormal3fv(en[3][6]); glTexCoord2fv(tep[3][6]); glVertex3fv(ep[3][6]); 1123 glNormal3fv(en[4][6]); glTexCoord2fv(tep[4][6]); glVertex3fv(ep[4][6]); 1124 glNormal3fv(en[3][7]); glTexCoord2fv(tep[3][7]); glVertex3fv(ep[3][7]); 1125 glNormal3fv(en[4][7]); glTexCoord2fv(tep[4][7]); glVertex3fv(ep[4][7]); 1126 glNormal3fv(en[3][8]); glTexCoord2fv(tep[3][8]); glVertex3fv(ep[3][8]); 1127 glNormal3fv(en[4][8]); glTexCoord2fv(tep[4][8]); glVertex3fv(ep[4][8]); 1128 glEnd(); 1129 glBegin(GL_TRIANGLE_STRIP); 1130 glNormal3fv(en[4][0]); glTexCoord2fv(tep[4][0]); glVertex3fv(ep[4][0]); 1131 glNormal3fv(en[5][0]); glTexCoord2fv(tep[5][0]); glVertex3fv(ep[5][0]); 1132 glNormal3fv(en[4][1]); glTexCoord2fv(tep[4][1]); glVertex3fv(ep[4][1]); 1133 glNormal3fv(en[5][1]); glTexCoord2fv(tep[5][1]); glVertex3fv(ep[5][1]); 1134 glNormal3fv(en[4][2]); glTexCoord2fv(tep[4][2]); glVertex3fv(ep[4][2]); 1135 glNormal3fv(en[5][2]); glTexCoord2fv(tep[5][2]); glVertex3fv(ep[5][2]); 1136 glNormal3fv(en[4][3]); glTexCoord2fv(tep[4][3]); glVertex3fv(ep[4][3]); 1137 glNormal3fv(en[5][3]); glTexCoord2fv(tep[5][3]); glVertex3fv(ep[5][3]); 1138 glNormal3fv(en[4][4]); glTexCoord2fv(tep[4][4]); glVertex3fv(ep[4][4]); 1139 glNormal3fv(en[5][4]); glTexCoord2fv(tep[5][4]); glVertex3fv(ep[5][4]); 1140 glNormal3fv(en[4][5]); glTexCoord2fv(tep[4][5]); glVertex3fv(ep[4][5]); 1141 glNormal3fv(en[5][5]); glTexCoord2fv(tep[5][5]); glVertex3fv(ep[5][5]); 1142 glNormal3fv(en[4][6]); glTexCoord2fv(tep[4][6]); glVertex3fv(ep[4][6]); 1143 glNormal3fv(en[5][6]); glTexCoord2fv(tep[5][6]); glVertex3fv(ep[5][6]); 1144 glNormal3fv(en[4][7]); glTexCoord2fv(tep[4][7]); glVertex3fv(ep[4][7]); 1145 glNormal3fv(en[5][7]); glTexCoord2fv(tep[5][7]); glVertex3fv(ep[5][7]); 1146 glNormal3fv(en[4][8]); glTexCoord2fv(tep[4][8]); glVertex3fv(ep[4][8]); 1147 glNormal3fv(en[5][8]); glTexCoord2fv(tep[5][8]); glVertex3fv(ep[5][8]); 1148 glEnd(); 1149 glBegin(GL_TRIANGLE_STRIP); 1150 glNormal3fv(en[5][0]); glTexCoord2fv(tep[5][0]); glVertex3fv(ep[5][0]); 1151 glNormal3fv(en[6][0]); glTexCoord2fv(tep[6][0]); glVertex3fv(ep[6][0]); 1152 glNormal3fv(en[5][1]); glTexCoord2fv(tep[5][1]); glVertex3fv(ep[5][1]); 1153 glNormal3fv(en[6][1]); glTexCoord2fv(tep[6][1]); glVertex3fv(ep[6][1]); 1154 glNormal3fv(en[5][2]); glTexCoord2fv(tep[5][2]); glVertex3fv(ep[5][2]); 1155 glNormal3fv(en[6][2]); glTexCoord2fv(tep[6][2]); glVertex3fv(ep[6][2]); 1156 glNormal3fv(en[5][3]); glTexCoord2fv(tep[5][3]); glVertex3fv(ep[5][3]); 1157 glNormal3fv(en[6][3]); glTexCoord2fv(tep[6][3]); glVertex3fv(ep[6][3]); 1158 glNormal3fv(en[5][4]); glTexCoord2fv(tep[5][4]); glVertex3fv(ep[5][4]); 1159 glNormal3fv(en[6][4]); glTexCoord2fv(tep[6][4]); glVertex3fv(ep[6][4]); 1160 glNormal3fv(en[5][5]); glTexCoord2fv(tep[5][5]); glVertex3fv(ep[5][5]); 1161 glNormal3fv(en[6][5]); glTexCoord2fv(tep[6][5]); glVertex3fv(ep[6][5]); 1162 glNormal3fv(en[5][6]); glTexCoord2fv(tep[5][6]); glVertex3fv(ep[5][6]); 1163 glNormal3fv(en[6][6]); glTexCoord2fv(tep[6][6]); glVertex3fv(ep[6][6]); 1164 glNormal3fv(en[5][7]); glTexCoord2fv(tep[5][7]); glVertex3fv(ep[5][7]); 1165 glNormal3fv(en[6][7]); glTexCoord2fv(tep[6][7]); glVertex3fv(ep[6][7]); 1166 glNormal3fv(en[5][8]); glTexCoord2fv(tep[5][8]); glVertex3fv(ep[5][8]); 1167 glNormal3fv(en[6][8]); glTexCoord2fv(tep[6][8]); glVertex3fv(ep[6][8]); 1168 glEnd(); 1169 1170 glEndList(); 1171} 1172 1173static void BuildLogo(void) 1174{ 1175 1176 glNewList(logo, GL_COMPILE); 1177 1178 glTranslatef(5.5, -3.5, 4.5); 1179 glTranslatef(0.0, 0.0, -7.0); 1180 glCallList(doubleCylinder); 1181 BendForward(); 1182 glCallList(elbow); 1183 glTranslatef(0.0, 0.0, -7.0); 1184 glCallList(doubleCylinder); 1185 BendForward(); 1186 glCallList(elbow); 1187 glTranslatef(0.0, 0.0, -5.0); 1188 glCallList(singleCylinder); 1189 BendRight(); 1190 glCallList(elbow); 1191 glTranslatef(0.0, 0.0, -7.0); 1192 glCallList(doubleCylinder); 1193 BendForward(); 1194 glCallList(elbow); 1195 glTranslatef(0.0, 0.0, -7.0); 1196 glCallList(doubleCylinder); 1197 BendForward(); 1198 glCallList(elbow); 1199 glTranslatef(0.0, 0.0, -5.0); 1200 glCallList(singleCylinder); 1201 BendLeft(); 1202 glCallList(elbow); 1203 glTranslatef(0.0, 0.0, -7.0); 1204 glCallList(doubleCylinder); 1205 BendForward(); 1206 glCallList(elbow); 1207 glTranslatef(0.0, 0.0, -7.0); 1208 glCallList(doubleCylinder); 1209 BendForward(); 1210 glCallList(elbow); 1211 glTranslatef(0.0, 0.0, -5.0); 1212 glCallList(singleCylinder); 1213 BendRight(); 1214 glCallList(elbow); 1215 glTranslatef(0.0, 0.0, -7.0); 1216 glCallList(doubleCylinder); 1217 BendForward(); 1218 glCallList(elbow); 1219 glTranslatef(0.0, 0.0, -7.0); 1220 glCallList(doubleCylinder); 1221 BendForward(); 1222 glCallList(elbow); 1223 glTranslatef(0.0, 0.0, -5.0); 1224 glCallList(singleCylinder); 1225 BendLeft(); 1226 glCallList(elbow); 1227 glTranslatef(0.0, 0.0, -7.0); 1228 glCallList(doubleCylinder); 1229 BendForward(); 1230 glCallList(elbow); 1231 glTranslatef(0.0, 0.0, -7.0); 1232 glCallList(doubleCylinder); 1233 BendForward(); 1234 glCallList(elbow); 1235 glTranslatef(0.0, 0.0, -5.0); 1236 glCallList(singleCylinder); 1237 BendRight(); 1238 glCallList(elbow); 1239 glTranslatef(0.0, 0.0, -7.0); 1240 glCallList(doubleCylinder); 1241 BendForward(); 1242 glCallList(elbow); 1243 glTranslatef(0.0, 0.0, -7.0); 1244 glCallList(doubleCylinder); 1245 BendForward(); 1246 glCallList(elbow); 1247 glTranslatef(0.0, 0.0, -5.0); 1248 glCallList(singleCylinder); 1249 BendLeft(); 1250 glCallList(elbow); 1251 1252 glEndList(); 1253} 1254 1255static void BuildLists(void) 1256{ 1257 1258 singleCylinder = glGenLists(1); 1259 doubleCylinder = glGenLists(1); 1260 elbow = glGenLists(1); 1261 logo = glGenLists(1); 1262 1263 BuildSingleCylinder(); 1264 BuildDoubleCylinder(); 1265 BuildElbow(); 1266 BuildLogo(); 1267} 1268 1269static void Init(void) 1270{ 1271 static float ambient[] = {0.1, 0.1, 0.1, 1.0}; 1272 static float diffuse[] = {0.5, 1.0, 1.0, 1.0}; 1273 static float position[] = {90.0, 90.0, 150.0, 0.0}; 1274 static float front_mat_shininess[] = {30.0}; 1275 static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0}; 1276 static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0}; 1277 static float back_mat_shininess[] = {50.0}; 1278 static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0}; 1279 static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; 1280 static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; 1281 static float lmodel_twoside[] = {GL_TRUE}; 1282 1283 glClearColor(0.0, 0.0, 0.0, 0.0); 1284 1285 glFrontFace(GL_CW); 1286 1287 glEnable(GL_DEPTH_TEST); 1288 1289 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 1290 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); 1291 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 1292 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); 1293 glLightfv(GL_LIGHT0, GL_POSITION, position); 1294 glEnable(GL_LIGHTING); 1295 glEnable(GL_LIGHT0); 1296 1297 glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess); 1298 glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular); 1299 glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse); 1300 glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess); 1301 glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular); 1302 glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse); 1303 1304 glEnable(GL_CLIP_PLANE0); 1305 1306 if (rgb) { 1307 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal); 1308 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); 1309 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); 1310 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nearest); 1311 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nearest); 1312 glTexImage2D(GL_TEXTURE_2D, 0, 3, CHECKIMAGEWIDTH, CHECKIMAGEHEIGHT, 0, 1313 GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)checkImage); 1314 glEnable(GL_TEXTURE_2D); 1315 1316 glCullFace(GL_BACK); 1317 glEnable(GL_CULL_FACE); 1318 } else { 1319 SetGreyRamp(); 1320 /* commented out by BrianP because it's the wrong way to handle a 4-bit visual! 1321 if (doubleBuffer) { 1322 colorIndexes[1] = 10; 1323 colorIndexes[2] = 15; 1324 } 1325 */ 1326 glMaterialiv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES, colorIndexes); 1327 } 1328 1329 BuildLists(); 1330 1331 dithering = GL_TRUE; 1332 shade = GL_TRUE; 1333 doStipple = GL_FALSE; 1334 polyMode = GL_BACK; 1335} 1336 1337static void Reshape(int width, int height) 1338{ 1339 glViewport(0, 0, (GLint)width, (GLint)height); 1340 1341 glMatrixMode(GL_PROJECTION); 1342 glLoadIdentity(); 1343 gluPerspective(90, 1.0, 1.0, 200.0); 1344 glMatrixMode(GL_MODELVIEW); 1345} 1346 1347static void Key2(int key, int x, int y) 1348{ 1349 (void) x; 1350 (void) y; 1351 switch (key) { 1352 case GLUT_KEY_LEFT: 1353 yRotation += 0.5; 1354 break; 1355 case GLUT_KEY_RIGHT: 1356 yRotation -= 0.5; 1357 break; 1358 case GLUT_KEY_UP: 1359 plane[3] += 2.0; 1360 break; 1361 case GLUT_KEY_DOWN: 1362 plane[3] -= 2.0; 1363 break; 1364 default: 1365 return; 1366 } 1367 1368 glutPostRedisplay(); 1369} 1370 1371static void Key(unsigned char key, int x, int y) 1372{ 1373 (void) x; 1374 (void) y; 1375 switch (key) { 1376 case 27: 1377 exit(1); 1378 1379 case 'Z': 1380 zTranslation -= 1.0; 1381 break; 1382 case 'z': 1383 zTranslation += 1.0; 1384 break; 1385 1386 case '1': 1387 glPolygonMode(polyMode, GL_POINT); 1388 break; 1389 case '2': 1390 glPolygonMode(polyMode, GL_LINE); 1391 break; 1392 case '3': 1393 glPolygonMode(polyMode, GL_FILL); 1394 break; 1395 case 'p': 1396 switch (polyMode) { 1397 case GL_BACK: 1398 polyMode = GL_FRONT; 1399 printf("PolygonMode GL_FRONT\n"); 1400 break; 1401 case GL_FRONT: 1402 polyMode = GL_FRONT_AND_BACK; 1403 printf("PolygonMode GL_FRONT_AND_BACK\n"); 1404 break; 1405 case GL_FRONT_AND_BACK: 1406 polyMode = GL_BACK; 1407 printf("PolygonMode GL_BACK\n"); 1408 break; 1409 default: 1410 break; 1411 } 1412 break; 1413 1414 case '4': 1415 glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); 1416 break; 1417 case '5': 1418 glEnable(GL_POLYGON_SMOOTH); 1419 if (rgb) { 1420 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 1421 glEnable(GL_BLEND); 1422 glDisable(GL_DEPTH_TEST); 1423 } else { 1424 SetUpAntiAliasedGrayScale(); 1425 } 1426 break; 1427 case '6': 1428 glDisable(GL_POLYGON_SMOOTH); 1429 if (rgb) { 1430 glBlendFunc(GL_ONE, GL_ZERO); 1431 glDisable(GL_BLEND); 1432 glEnable(GL_DEPTH_TEST); 1433 } else { 1434 SetGreyRamp(); 1435 } 1436 break; 1437 1438 case '8': 1439 dithering = !dithering; 1440 (dithering) ? glEnable(GL_DITHER) : glDisable(GL_DITHER); 1441 break; 1442 1443 case '9': 1444 doStipple = !doStipple; 1445 if (doStipple) { 1446 glPolygonStipple(stipple); 1447 glEnable(GL_POLYGON_STIPPLE); 1448 } else { 1449 glDisable(GL_POLYGON_STIPPLE); 1450 } 1451 break; 1452 1453 case '0': 1454 shade = !shade; 1455 (shade) ? glShadeModel(GL_SMOOTH) : glShadeModel(GL_FLAT); 1456 break; 1457 1458 case 'q': 1459 glDisable(GL_CULL_FACE); 1460 printf("disable culling\n"); 1461 break; 1462 case 'w': 1463 glEnable(GL_CULL_FACE); 1464 glCullFace(GL_FRONT); 1465 printf("enable front face culling\n"); 1466 break; 1467 case 'e': 1468 glEnable(GL_CULL_FACE); 1469 glCullFace(GL_BACK); 1470 printf("enable back face culling\n"); 1471 break; 1472 1473 case 'r': 1474 glFrontFace(GL_CW); 1475 break; 1476 case 't': 1477 glFrontFace(GL_CCW); 1478 break; 1479 case 'y': 1480 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 1481 glPixelStorei(GL_UNPACK_LSB_FIRST, 0); 1482 glPolygonStipple(stipple); 1483 break; 1484 case 'u': 1485 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 1486 glPixelStorei(GL_UNPACK_LSB_FIRST, 1); 1487 glPolygonStipple(stipple); 1488 break; 1489 1490 case 'a': 1491 glEnable(GL_TEXTURE_2D); 1492 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); 1493 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); 1494 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nearest); 1495 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nearest); 1496 glTexImage2D(GL_TEXTURE_2D, 0, 4, BRICKIMAGEWIDTH, 1497 BRICKIMAGEHEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 1498 (GLvoid *)brickImage); 1499 break; 1500 case 's': 1501 glEnable(GL_TEXTURE_2D); 1502 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); 1503 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); 1504 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nearest); 1505 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nearest); 1506 glTexImage2D(GL_TEXTURE_2D, 0, 3, CHECKIMAGEWIDTH, 1507 CHECKIMAGEHEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 1508 (GLvoid *)checkImage); 1509 break; 1510 case 'd': 1511 glDisable(GL_TEXTURE_2D); 1512 break; 1513 1514 case 'f': 1515 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal); 1516 break; 1517 case 'g': 1518 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, modulate); 1519 break; 1520 1521 case 'n': 1522 /* added by BrianP */ 1523 noDraw = !noDraw; 1524 if (noDraw) { 1525 glDrawBuffer( GL_NONE ); 1526 } 1527 else { 1528 if (doubleBuffer) { 1529 glDrawBuffer( GL_BACK ); 1530 } 1531 else { 1532 glDrawBuffer( GL_FRONT ); 1533 } 1534 } 1535 break; 1536 1537 case 'l': 1538 /* Line Smooth - added by BrianP */ 1539 LineSmooth = !LineSmooth; 1540 if (LineSmooth) { 1541 glEnable(GL_LINE_SMOOTH); 1542 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1543 glEnable(GL_BLEND); 1544 } 1545 else { 1546 glDisable(GL_LINE_SMOOTH); 1547 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1548 glDisable(GL_BLEND); 1549 } 1550 break; 1551 default: 1552 return; 1553 } 1554 1555 glutPostRedisplay(); 1556} 1557 1558static void Draw(void) 1559{ 1560 1561 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 1562 1563 glPushMatrix(); 1564 1565 glTranslatef(0, 0, zTranslation); 1566 glRotatef(30.0, 1, 0, 0); 1567 glRotatef(yRotation, 0, 1, 0); 1568 glClipPlane(GL_CLIP_PLANE0, plane); 1569 glCallList(logo); 1570 1571 glPopMatrix(); 1572 1573 glFlush(); 1574 1575 if (doubleBuffer) { 1576 glutSwapBuffers(); 1577 } 1578} 1579 1580static GLenum Args(int argc, char **argv) 1581{ 1582 GLint i; 1583 1584 rgb = GL_TRUE; 1585 doubleBuffer = GL_FALSE; 1586 1587 for (i = 1; i < argc; i++) { 1588 if (strcmp(argv[i], "-ci") == 0) { 1589 rgb = GL_FALSE; 1590 } else if (strcmp(argv[i], "-rgb") == 0) { 1591 rgb = GL_TRUE; 1592 } else if (strcmp(argv[i], "-sb") == 0) { 1593 doubleBuffer = GL_FALSE; 1594 } else if (strcmp(argv[i], "-db") == 0) { 1595 doubleBuffer = GL_TRUE; 1596 } else { 1597 printf("%s (Bad option).\n", argv[i]); 1598 return GL_FALSE; 1599 } 1600 } 1601 return GL_TRUE; 1602} 1603 1604int main(int argc, char **argv) 1605{ 1606 unsigned int type; 1607 1608 glutInit(&argc, argv); 1609 1610 if (Args(argc, argv) == GL_FALSE) { 1611 exit(1); 1612 } 1613 1614 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); 1615 1616 type = GLUT_DEPTH; 1617 type |= (rgb) ? GLUT_RGB : GLUT_INDEX; 1618 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; 1619 glutInitDisplayMode(type); 1620 1621 if (glutCreateWindow("Logo Test") == GL_FALSE) { 1622 exit(1); 1623 } 1624 1625 InitMap(); 1626 1627 Init(); 1628 1629 glutReshapeFunc(Reshape); 1630 glutKeyboardFunc(Key); 1631 glutSpecialFunc(Key2); 1632 glutDisplayFunc(Draw); 1633 glutMainLoop(); 1634 return 0; 1635} 1636