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.4KB

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