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.

line.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and
  5. * its documentation for any purpose is hereby granted without fee, provided
  6. * that (i) the above copyright notices and this permission notice appear in
  7. * all copies of the software and related documentation, and (ii) the name of
  8. * Silicon Graphics may not be used in any advertising or
  9. * publicity relating to the software without the specific, prior written
  10. * permission of Silicon Graphics.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
  13. * ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
  18. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <GL/glut.h>
  28. #define CI_OFFSET 16
  29. GLenum rgb, doubleBuffer, windType;
  30. GLenum mode1, mode2;
  31. GLint size;
  32. float pntA[3] = {
  33. -160.0, 0.0, 0.0
  34. };
  35. float pntB[3] = {
  36. -130.0, 0.0, 0.0
  37. };
  38. float pntC[3] = {
  39. -40.0, -50.0, 0.0
  40. };
  41. float pntD[3] = {
  42. 30.0, 60.0, 0.0
  43. };
  44. #include "tkmap.c"
  45. static void Init(void)
  46. {
  47. GLint i;
  48. glClearColor(0.0, 0.0, 0.0, 0.0);
  49. glLineStipple(1, 0xF0E0);
  50. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  51. if (!rgb) {
  52. for (i = 0; i < 16; i++) {
  53. glutSetColor(i+CI_OFFSET, i/15.0, i/15.0, 0.0);
  54. }
  55. }
  56. mode1 = GL_FALSE;
  57. mode2 = GL_FALSE;
  58. size = 1;
  59. }
  60. static void Reshape(int width, int height)
  61. {
  62. glViewport(0, 0, (GLint)width, (GLint)height);
  63. glMatrixMode(GL_PROJECTION);
  64. glLoadIdentity();
  65. gluOrtho2D(-175, 175, -175, 175);
  66. glMatrixMode(GL_MODELVIEW);
  67. }
  68. static void Key(unsigned char key, int x, int y)
  69. {
  70. switch (key) {
  71. case 27:
  72. exit(1);
  73. case '1':
  74. mode1 = !mode1;
  75. break;
  76. case '2':
  77. mode2 = !mode2;
  78. break;
  79. case 'W':
  80. size++;
  81. break;
  82. case 'w':
  83. size--;
  84. if (size < 1) {
  85. size = 1;
  86. }
  87. break;
  88. default:
  89. return;
  90. }
  91. glutPostRedisplay();
  92. }
  93. static void Draw(void)
  94. {
  95. GLint ci, i;
  96. glClear(GL_COLOR_BUFFER_BIT);
  97. glLineWidth(size);
  98. if (mode1) {
  99. glEnable(GL_LINE_STIPPLE);
  100. } else {
  101. glDisable(GL_LINE_STIPPLE);
  102. }
  103. if (mode2) {
  104. ci = CI_OFFSET;
  105. glEnable(GL_LINE_SMOOTH);
  106. glEnable(GL_BLEND);
  107. } else {
  108. ci = COLOR_YELLOW;
  109. glDisable(GL_LINE_SMOOTH);
  110. glDisable(GL_BLEND);
  111. }
  112. glPushMatrix();
  113. glShadeModel( GL_FLAT );
  114. for (i = 0; i < 360; i += 5) {
  115. glRotatef(5.0, 0,0,1);
  116. (rgb) ? glColor3f(1.0, 1.0, 0.0) : glIndexi(ci);
  117. glBegin(GL_LINE_STRIP);
  118. glVertex3fv(pntA);
  119. glVertex3fv(pntB);
  120. glEnd();
  121. glPointSize(1);
  122. SetColor(COLOR_GREEN);
  123. glBegin(GL_POINTS);
  124. glVertex3fv(pntA);
  125. glVertex3fv(pntB);
  126. glEnd();
  127. }
  128. glPopMatrix();
  129. glFlush();
  130. if (doubleBuffer) {
  131. glutSwapBuffers();
  132. }
  133. }
  134. static GLenum Args(int argc, char **argv)
  135. {
  136. GLint i;
  137. rgb = GL_TRUE;
  138. doubleBuffer = GL_TRUE;
  139. for (i = 1; i < argc; i++) {
  140. if (strcmp(argv[i], "-ci") == 0) {
  141. rgb = GL_FALSE;
  142. } else if (strcmp(argv[i], "-rgb") == 0) {
  143. rgb = GL_TRUE;
  144. } else if (strcmp(argv[i], "-sb") == 0) {
  145. doubleBuffer = GL_FALSE;
  146. } else if (strcmp(argv[i], "-db") == 0) {
  147. doubleBuffer = GL_TRUE;
  148. } else {
  149. printf("%s (Bad option).\n", argv[i]);
  150. return GL_FALSE;
  151. }
  152. }
  153. return GL_TRUE;
  154. }
  155. int main(int argc, char **argv)
  156. {
  157. glutInit(&argc, argv);
  158. if (Args(argc, argv) == GL_FALSE) {
  159. exit(1);
  160. }
  161. glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
  162. windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
  163. windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  164. glutInitDisplayMode(windType);
  165. if (glutCreateWindow("Line Test") == GL_FALSE) {
  166. exit(1);
  167. }
  168. InitMap();
  169. Init();
  170. glutReshapeFunc(Reshape);
  171. glutKeyboardFunc(Key);
  172. glutDisplayFunc(Draw);
  173. glutMainLoop();
  174. return 0;
  175. }