home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / sviluppo / mesa-glut / test / glut / test27.c < prev    next >
C/C++ Source or Header  |  1998-10-23  |  2KB  |  106 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1997. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. /* This tests creation of a subwindow that gets "popped" to
  9.    check if it also (erroneously) gets moved.  GLUT 3.5 had
  10.    this bug (fixed in GLUT 3.6). */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <GL/glut.h>
  16.  
  17. int parent, child;
  18. int parentDrawn = 0, childDrawn = 0;
  19.  
  20. /* ARGSUSED */
  21. void
  22. failTest(int value)
  23. {
  24.   printf("FAIL: test27\n");
  25.   exit(1);
  26. }
  27.  
  28. /* ARGSUSED */
  29. void
  30. passTest(int value)
  31. {
  32.   printf("PASS: test27\n");
  33.   exit(0);
  34. }
  35.  
  36. void
  37. installFinish(void)
  38. {
  39.   if (childDrawn && parentDrawn) {
  40.     glutTimerFunc(1000, passTest, 0);
  41.   }
  42. }
  43.  
  44. void
  45. output(GLfloat x, GLfloat y, char *string)
  46. {
  47.   int len, i;
  48.  
  49.   glRasterPos2f(x, y);
  50.   len = (int) strlen(string);
  51.   for (i = 0; i < len; i++) {
  52.     glutBitmapCharacter(GLUT_BITMAP_9_BY_15, string[i]);
  53.   }
  54. }
  55.  
  56. void
  57. displayParent(void)
  58. {
  59.   glClear(GL_COLOR_BUFFER_BIT);
  60.   glFlush();
  61.   parentDrawn++;
  62.   installFinish();
  63. }
  64.  
  65. void
  66. displayChild(void)
  67. {
  68.   glClear(GL_COLOR_BUFFER_BIT);
  69.   output(-0.4, 0.5, "this");
  70.   output(-0.8, 0.1, "subwindow");
  71.   output(-0.8, -0.3, "should be");
  72.   output(-0.7, -0.7, "centered");
  73.   glFlush();
  74.   childDrawn++;
  75.   installFinish();
  76. }
  77.  
  78. int
  79. main(int argc, char **argv)
  80. {
  81.   int possible;
  82.  
  83.   glutInit(&argc, argv);
  84.   glutInitWindowSize(300, 300);
  85.   glutInitWindowPosition(5, 5);
  86.   glutInitDisplayMode(GLUT_RGB);
  87.   parent = glutCreateWindow("test27");
  88.   glClearColor(1.0, 0.0, 0.0, 0.0);
  89.   glutDisplayFunc(displayParent);
  90.   possible = glutGet(GLUT_DISPLAY_MODE_POSSIBLE);
  91.   if (possible != 1) {
  92.     printf("FAIL: glutGet returned display mode not possible: %d\n", possible);
  93.     exit(1);
  94.   }
  95.   child = glutCreateSubWindow(parent, 100, 100, 100, 100);
  96.   glClearColor(0.0, 1.0, 0.0, 0.0);
  97.   glColor3f(0.0, 0.0, 0.0);
  98.   glutDisplayFunc(displayChild);
  99.   glutPopWindow();
  100.  
  101.   glutTimerFunc(10000, failTest, 0);
  102.  
  103.   glutMainLoop();
  104.   return 0;             /* ANSI C requires main to return int. */
  105. }
  106.