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.

accum.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. GLenum doubleBuffer;
  29. GLint thing1, thing2;
  30. static void Init(void)
  31. {
  32. glClearColor(0.0, 0.0, 0.0, 0.0);
  33. glClearAccum(0.0, 0.0, 0.0, 0.0);
  34. thing1 = glGenLists(1);
  35. glNewList(thing1, GL_COMPILE);
  36. glColor3f(1.0, 0.0, 0.0);
  37. glRectf(-1.0, -1.0, 1.0, 0.0);
  38. glEndList();
  39. thing2 = glGenLists(1);
  40. glNewList(thing2, GL_COMPILE);
  41. glColor3f(0.0, 1.0, 0.0);
  42. glRectf(0.0, -1.0, 1.0, 1.0);
  43. glEndList();
  44. }
  45. static void Reshape(int width, int height)
  46. {
  47. glViewport(0, 0, (GLint)width, (GLint)height);
  48. glMatrixMode(GL_PROJECTION);
  49. glLoadIdentity();
  50. glMatrixMode(GL_MODELVIEW);
  51. glLoadIdentity();
  52. }
  53. static void Key(unsigned char key, int x, int y)
  54. {
  55. (void) x;
  56. (void) y;
  57. switch (key) {
  58. case 27:
  59. exit(1);
  60. case '1':
  61. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  62. break;
  63. case '2':
  64. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  65. break;
  66. default:
  67. return;
  68. }
  69. glutPostRedisplay();
  70. }
  71. static void Draw(void)
  72. {
  73. glPushMatrix();
  74. glScalef(0.8, 0.8, 1.0);
  75. glClear(GL_COLOR_BUFFER_BIT);
  76. glCallList(thing1);
  77. glAccum(GL_LOAD, 0.5);
  78. glClear(GL_COLOR_BUFFER_BIT);
  79. glCallList(thing2);
  80. glAccum(GL_ACCUM, 0.5);
  81. glAccum(GL_RETURN, 1.0);
  82. glPopMatrix();
  83. glFlush();
  84. if (doubleBuffer) {
  85. glutSwapBuffers();
  86. }
  87. }
  88. static GLenum Args(int argc, char **argv)
  89. {
  90. GLint i;
  91. doubleBuffer = GL_FALSE;
  92. for (i = 1; i < argc; i++) {
  93. if (strcmp(argv[i], "-sb") == 0) {
  94. doubleBuffer = GL_FALSE;
  95. } else if (strcmp(argv[i], "-db") == 0) {
  96. doubleBuffer = GL_TRUE;
  97. } else {
  98. printf("%s (Bad option).\n", argv[i]);
  99. return GL_FALSE;
  100. }
  101. }
  102. return GL_TRUE;
  103. }
  104. int main(int argc, char **argv)
  105. {
  106. GLenum type;
  107. glutInit(&argc, argv);
  108. if (Args(argc, argv) == GL_FALSE) {
  109. exit(1);
  110. }
  111. glutInitWindowPosition(0, 0);
  112. glutInitWindowSize( 300, 300);
  113. type = GLUT_RGB | GLUT_ACCUM;
  114. type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  115. glutInitDisplayMode(type);
  116. if (glutCreateWindow("Accum Test") == GL_FALSE) {
  117. exit(1);
  118. }
  119. Init();
  120. glutReshapeFunc(Reshape);
  121. glutKeyboardFunc(Key);
  122. glutDisplayFunc(Draw);
  123. glutMainLoop();
  124. return 0;
  125. }