Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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_RED COLOR_RED
  29. #define CI_ANTI_ALIAS_GREEN 16
  30. #define CI_ANTI_ALIAS_YELLOW 32
  31. #define CI_ANTI_ALIAS_RED 48
  32. GLenum rgb, doubleBuffer, windType;
  33. GLint windW, windH;
  34. #include "tkmap.c"
  35. GLenum mode;
  36. GLint size;
  37. float point[3] = {
  38. 1.0, 1.0, 0.0
  39. };
  40. static void Init(void)
  41. {
  42. GLint i;
  43. glClearColor(0.0, 0.0, 0.0, 0.0);
  44. glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
  45. if (!rgb) {
  46. for (i = 0; i < 16; i++) {
  47. glutSetColor(i+CI_ANTI_ALIAS_RED, i/15.0, 0.0, 0.0);
  48. glutSetColor(i+CI_ANTI_ALIAS_YELLOW, i/15.0, i/15.0, 0.0);
  49. glutSetColor(i+CI_ANTI_ALIAS_GREEN, 0.0, i/15.0, 0.0);
  50. }
  51. }
  52. mode = GL_FALSE;
  53. size = 1;
  54. }
  55. static void Reshape(int width, int height)
  56. {
  57. windW = (GLint)width;
  58. windH = (GLint)height;
  59. glViewport(0, 0, width, height);
  60. glMatrixMode(GL_PROJECTION);
  61. glLoadIdentity();
  62. gluOrtho2D(-windW/2, windW/2, -windH/2, windH/2);
  63. glMatrixMode(GL_MODELVIEW);
  64. }
  65. static void Key2(int key, int x, int y)
  66. {
  67. switch (key) {
  68. case GLUT_KEY_LEFT:
  69. point[0] -= 0.25;
  70. break;
  71. case GLUT_KEY_RIGHT:
  72. point[0] += 0.25;
  73. break;
  74. case GLUT_KEY_UP:
  75. point[1] += 0.25;
  76. break;
  77. case GLUT_KEY_DOWN:
  78. point[1] -= 0.25;
  79. break;
  80. default:
  81. return;
  82. }
  83. glutPostRedisplay();
  84. }
  85. static void Key(unsigned char key, int x, int y)
  86. {
  87. switch (key) {
  88. case 27:
  89. exit(1);
  90. case '1':
  91. mode = !mode;
  92. break;
  93. case 'W':
  94. size++;
  95. break;
  96. case 'w':
  97. size--;
  98. if (size < 1) {
  99. size = 1;
  100. }
  101. break;
  102. default:
  103. return;
  104. }
  105. glutPostRedisplay();
  106. }
  107. static void Draw(void)
  108. {
  109. glClear(GL_COLOR_BUFFER_BIT);
  110. SetColor(COLOR_YELLOW);
  111. glBegin(GL_LINE_STRIP);
  112. glVertex2f(-windW/2, 0);
  113. glVertex2f(windW/2, 0);
  114. glEnd();
  115. glBegin(GL_LINE_STRIP);
  116. glVertex2f(0, -windH/2);
  117. glVertex2f(0, windH/2);
  118. glEnd();
  119. if (mode) {
  120. glEnable(GL_BLEND);
  121. glEnable(GL_POINT_SMOOTH);
  122. } else {
  123. glDisable(GL_BLEND);
  124. glDisable(GL_POINT_SMOOTH);
  125. }
  126. glPointSize(size);
  127. if (mode) {
  128. (rgb) ? glColor3f(1.0, 0.0, 0.0) : glIndexf(CI_ANTI_ALIAS_RED);
  129. } else {
  130. (rgb) ? glColor3f(1.0, 0.0, 0.0) : glIndexf(CI_RED);
  131. }
  132. glBegin(GL_POINTS);
  133. glVertex3fv(point);
  134. glEnd();
  135. glDisable(GL_POINT_SMOOTH);
  136. glDisable(GL_BLEND);
  137. glPointSize(1);
  138. SetColor(COLOR_GREEN);
  139. glBegin(GL_POINTS);
  140. glVertex3fv(point);
  141. glEnd();
  142. glFlush();
  143. if (doubleBuffer) {
  144. glutSwapBuffers();
  145. }
  146. }
  147. static GLenum Args(int argc, char **argv)
  148. {
  149. GLint i;
  150. rgb = GL_TRUE;
  151. doubleBuffer = GL_FALSE;
  152. for (i = 1; i < argc; i++) {
  153. if (strcmp(argv[i], "-ci") == 0) {
  154. rgb = GL_FALSE;
  155. } else if (strcmp(argv[i], "-rgb") == 0) {
  156. rgb = GL_TRUE;
  157. } else if (strcmp(argv[i], "-sb") == 0) {
  158. doubleBuffer = GL_FALSE;
  159. } else if (strcmp(argv[i], "-db") == 0) {
  160. doubleBuffer = GL_TRUE;
  161. } else {
  162. printf("%s (Bad option).\n", argv[i]);
  163. return GL_FALSE;
  164. }
  165. }
  166. return GL_TRUE;
  167. }
  168. int main(int argc, char **argv)
  169. {
  170. glutInit(&argc, argv);
  171. if (Args(argc, argv) == GL_FALSE) {
  172. exit(1);
  173. }
  174. windW = 300;
  175. windH = 300;
  176. glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH);
  177. windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
  178. windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  179. glutInitDisplayMode(windType);
  180. if (glutCreateWindow("Point Test") == GL_FALSE) {
  181. exit(1);
  182. }
  183. InitMap();
  184. Init();
  185. glutReshapeFunc(Reshape);
  186. glutKeyboardFunc(Key);
  187. glutSpecialFunc(Key2);
  188. glutDisplayFunc(Draw);
  189. glutMainLoop();
  190. return 0;
  191. }