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.

scissor-viewport.c 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
  3. * Copyright (c) 2009 VMware, 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. #include <stdio.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <GL/glut.h>
  29. struct program
  30. {
  31. unsigned width;
  32. unsigned height;
  33. int i;
  34. };
  35. struct program prog;
  36. static void init(void)
  37. {
  38. fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  39. fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  40. fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  41. fflush(stderr);
  42. prog.i = 0;
  43. }
  44. static void reshape(int width, int height)
  45. {
  46. glViewport(0, 0, 100, 100);
  47. prog.width = width;
  48. prog.height = height;
  49. glMatrixMode(GL_PROJECTION);
  50. glLoadIdentity();
  51. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  52. glMatrixMode(GL_MODELVIEW);
  53. }
  54. static void key(unsigned char key, int x, int y)
  55. {
  56. switch (key) {
  57. case 27:
  58. exit(1);
  59. default:
  60. glutPostRedisplay();
  61. return;
  62. }
  63. }
  64. static void drawQuad(void)
  65. {
  66. glBegin(GL_QUADS);
  67. glVertex2d(-1.0, -1.0);
  68. glVertex2d( 1.0, -1.0);
  69. glVertex2d( 1.0, 1.0);
  70. glVertex2d(-1.0, 1.0);
  71. glEnd();
  72. }
  73. static void draw(void)
  74. {
  75. int i;
  76. glClearColor(0.0, 0.0, 1.0, 0.0);
  77. glClear(GL_COLOR_BUFFER_BIT);
  78. i = prog.i++;
  79. if (prog.i >= 3)
  80. prog.i = 0;
  81. glEnable(GL_SCISSOR_TEST);
  82. {
  83. glColor4d(1.0, 0.0, 0.0, 1.0);
  84. glScissor(i, i, 10 - 2*i, 10 - 2*i);
  85. drawQuad();
  86. }
  87. glDisable(GL_SCISSOR_TEST);
  88. /* glutSwapBuffers(); */
  89. glFlush();
  90. }
  91. int main(int argc, char **argv)
  92. {
  93. GLenum type;
  94. glutInit(&argc, argv);
  95. prog.width = 200;
  96. prog.height = 200;
  97. glutInitWindowPosition(100, 0);
  98. glutInitWindowSize(prog.width, prog.height);
  99. /* type = GLUT_RGB | GLUT_DOUBLE; */
  100. type = GLUT_RGB | GLUT_SINGLE;
  101. glutInitDisplayMode(type);
  102. if (glutCreateWindow(*argv) == GL_FALSE) {
  103. exit(1);
  104. }
  105. init();
  106. glutReshapeFunc(reshape);
  107. glutKeyboardFunc(key);
  108. glutDisplayFunc(draw);
  109. glutMainLoop();
  110. return 0;
  111. }