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.

clear-scissor.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * glClear + glScissor
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <GL/glut.h>
  8. GLenum doubleBuffer;
  9. GLint Width = 200, Height = 150;
  10. static void Init(void)
  11. {
  12. fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  13. fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  14. fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  15. }
  16. static void Reshape(int width, int height)
  17. {
  18. Width = width;
  19. Height = height;
  20. glViewport(0, 0, (GLint)width, (GLint)height);
  21. glMatrixMode(GL_PROJECTION);
  22. glLoadIdentity();
  23. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  24. glMatrixMode(GL_MODELVIEW);
  25. }
  26. static void Key(unsigned char key, int x, int y)
  27. {
  28. switch (key) {
  29. case 27:
  30. exit(1);
  31. default:
  32. return;
  33. }
  34. glutPostRedisplay();
  35. }
  36. static void Draw(void)
  37. {
  38. glEnable(GL_SCISSOR_TEST);
  39. glClearColor(1, 0, 0, 0);
  40. glScissor(0, 0, Width / 2, Height / 2);
  41. glClear(GL_COLOR_BUFFER_BIT);
  42. glClearColor(0, 1, 0, 0);
  43. glScissor(Width / 2, 0, Width - Width / 2, Height / 2);
  44. glClear(GL_COLOR_BUFFER_BIT);
  45. glClearColor(0, 0, 1, 0);
  46. glScissor(0, Height / 2, Width / 2, Height - Height / 2);
  47. glClear(GL_COLOR_BUFFER_BIT);
  48. glClearColor(1, 1, 1, 0);
  49. glScissor(Width / 2, Height / 2, Width - Width / 2, Height - Height / 2);
  50. glClear(GL_COLOR_BUFFER_BIT);
  51. glFlush();
  52. if (doubleBuffer) {
  53. glutSwapBuffers();
  54. }
  55. }
  56. static GLenum Args(int argc, char **argv)
  57. {
  58. GLint i;
  59. doubleBuffer = GL_FALSE;
  60. for (i = 1; i < argc; i++) {
  61. if (strcmp(argv[i], "-sb") == 0) {
  62. doubleBuffer = GL_FALSE;
  63. } else if (strcmp(argv[i], "-db") == 0) {
  64. doubleBuffer = GL_TRUE;
  65. } else {
  66. fprintf(stderr, "%s (Bad option).\n", argv[i]);
  67. return GL_FALSE;
  68. }
  69. }
  70. return GL_TRUE;
  71. }
  72. int main(int argc, char **argv)
  73. {
  74. GLenum type;
  75. glutInit(&argc, argv);
  76. if (Args(argc, argv) == GL_FALSE) {
  77. exit(1);
  78. }
  79. glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height );
  80. type = GLUT_RGB | GLUT_ALPHA;
  81. type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  82. glutInitDisplayMode(type);
  83. if (glutCreateWindow(argv[0]) == GL_FALSE) {
  84. exit(1);
  85. }
  86. Init();
  87. glutReshapeFunc(Reshape);
  88. glutKeyboardFunc(Key);
  89. glutDisplayFunc(Draw);
  90. glutMainLoop();
  91. return 0;
  92. }