home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Development Libraries / SGI IRIX 6.2 Development Libraries.iso / dist / gl_dev.idb / usr / share / src / OpenGL / tools / glsplay / show.c.z / show.c
Encoding:
C/C++ Source or Header  |  1996-03-15  |  5.3 KB  |  211 lines

  1. /*------------------------------*\
  2. |* include
  3. \*------------------------------*/
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <Xm/Xm.h>
  7. #include <Xm/Protocols.h>
  8. #include <Xm/MwmUtil.h>
  9. #include <Xm/DialogS.h>
  10. #include <Xm/PanedW.h>
  11. #include <Xm/Form.h>
  12. #include <Xm/Frame.h>
  13. #include <Xm/PushB.h>
  14. #include <GL/gl.h>
  15. #include <GL/glx.h>
  16. #include <GL/gls.h>
  17. #include <GL/GLwMDrawA.h>
  18. #include "glsplay.h"
  19.  
  20. /*------------------------------*\
  21. |* local
  22. \*------------------------------*/
  23. static Widget wParent, wWindow;
  24. static Widget wFormControl, wFormAction;
  25. static Widget wFrame, wPicture;
  26. static Widget wDone;
  27. static char fileName[256];
  28. static int attribs[] = {GLX_RGBA, 0};
  29. static Display *display;
  30. static int screen;
  31. static XVisualInfo *vi;
  32. static GLXContext glx;
  33.  
  34. /*------------------------------*\
  35. |* Viewport2
  36. \*------------------------------*/
  37. static void Viewport2(GLint x, GLint y, GLsizei width, GLsizei height)
  38. {
  39.     Dimension w, h;
  40.  
  41.     XtVaGetValues(wFormControl, XmNwidth, &w, XmNheight, &h, NULL);
  42.     glViewport(x, y, (GLint)w, (GLint)h);
  43. }
  44.  
  45. /*------------------------------*\
  46. |* Draw2
  47. \*------------------------------*/
  48. static void Draw2(Widget w, XtPointer client, XtPointer info)
  49. {
  50.     GLuint gls;
  51.  
  52.     glXMakeCurrent(display, XtWindow(wPicture), glx);
  53.     gls = glsGenContext();
  54.     glsContext(gls);
  55.     glsCommandFunc(GLS_OP_glViewport, (GLSfunc)Viewport2);
  56.     glsCallStream(fileName);
  57.     glFlush();
  58.     glsDeleteContext(gls);
  59. }
  60.  
  61. /*------------------------------*\
  62. |* Viewport1
  63. \*------------------------------*/
  64. static void Viewport1(GLint x, GLint y, GLsizei width, GLsizei height)
  65. {
  66.  
  67.     glViewport(x, y, 300, 300);
  68. }
  69.  
  70. /*------------------------------*\
  71. |* Draw1
  72. \*------------------------------*/
  73. static void Draw1(Widget w, XtPointer client, XtPointer info)
  74. {
  75.     GLuint gls;
  76.  
  77.     glXMakeCurrent(display, XtWindow(wPicture), glx);
  78.     gls = glsGenContext();
  79.     glsContext(gls);
  80.     glsCommandFunc(GLS_OP_glViewport, (GLSfunc)Viewport1);
  81.     glsCallStream(fileName);
  82.     glFlush();
  83.     glsDeleteContext(gls);
  84.     XtRemoveAllCallbacks(wPicture, XmNexposeCallback);
  85.     XtAddCallback(wPicture, XmNexposeCallback, (XtCallbackProc)Draw2, NULL);
  86. }
  87.  
  88. /*------------------------------*\
  89. |* Done
  90. \*------------------------------*/
  91. static void Done(Widget w, XtPointer client, XtPointer info)
  92. {
  93.  
  94.     glXDestroyContext(display, glx);
  95.     XtDestroyWidget((Widget)client);
  96.     exit(1);
  97. }
  98.  
  99. /*------------------------------*\
  100. |* MinSize
  101. \*------------------------------*/
  102. static void MinSize(Widget w, XtPointer client, XtPointer info)
  103. {
  104.     XConfigureEvent *ptr = (XConfigureEvent *)info;
  105.     Dimension x;
  106.  
  107.     if (ptr->type == ConfigureNotify) {
  108.     XtVaGetValues((Widget)client, XmNheight, &x, NULL);
  109.     XtVaSetValues((Widget)client, XmNpaneMaximum, x, XmNpaneMinimum, x,
  110.               NULL);
  111.     XtRemoveEventHandler(w, StructureNotifyMask, False,
  112.                  (XtEventHandler)MinSize, (caddr_t)client);
  113.     }
  114. }
  115.  
  116. /*------------------------------*\
  117. |* Die
  118. \*------------------------------*/
  119. static void Die(Widget w, XtPointer client, XtPointer info)
  120. {
  121.  
  122.     exit(1);
  123. }
  124.  
  125. /*------------------------------*\
  126. |* ShowWindowInit
  127. \*------------------------------*/
  128. void ShowWindowInit(char *name)
  129. {
  130.     Atom atom;
  131.  
  132.     strcpy(fileName, name);
  133.  
  134.     display = XtDisplay(GLSwidget);
  135.     screen = DefaultScreen(display);
  136.     if ((vi = glXChooseVisual(display, screen, attribs)) == NULL)  {
  137.     return;
  138.     }
  139.     if ((glx = glXCreateContext(display, vi, 0, GL_TRUE)) == NULL) {
  140.     return;
  141.     }
  142.  
  143.     wParent = XtVaCreatePopupShell(
  144.     "shell", xmDialogShellWidgetClass, GLSwidget,
  145.     XmNtitle, "Show Panel",
  146.     NULL
  147.     );
  148.     wWindow = XtVaCreateWidget(
  149.     "window", xmPanedWindowWidgetClass, wParent,
  150.     XmNsashWidth, 1,
  151.     XmNsashHeight, 1,
  152.     XmNseparatorOn, False,
  153.     NULL
  154.     );
  155.  
  156.     wFormControl = XtVaCreateManagedWidget(
  157.     "form", xmFormWidgetClass, wWindow,
  158.     XmNwidth, 300,
  159.     XmNheight, 300,
  160.     NULL
  161.     );
  162.     wFrame = XtVaCreateManagedWidget(
  163.         "frame", xmFrameWidgetClass, wFormControl,
  164.     XmNtopAttachment, XmATTACH_FORM,
  165.     XmNbottomAttachment, XmATTACH_FORM,
  166.     XmNleftAttachment, XmATTACH_FORM,
  167.     XmNrightAttachment, XmATTACH_FORM,
  168.     NULL
  169.     );
  170.     wPicture = XtVaCreateManagedWidget(
  171.     "picture", glwMDrawingAreaWidgetClass, wFrame,
  172.     GLwNvisualInfo, vi,
  173.     NULL
  174.     );
  175.  
  176.     wFormAction = XtVaCreateManagedWidget(
  177.     "form", xmFormWidgetClass, wWindow,
  178.         XmNfractionBase, 3,
  179.     NULL
  180.     );
  181.     wDone = XtVaCreateManagedWidget(
  182.         " Done ", xmPushButtonWidgetClass, wFormAction,
  183.         XmNtopAttachment, XmATTACH_FORM,
  184.         XmNtopOffset, 3,
  185.         XmNbottomAttachment, XmATTACH_FORM,
  186.         XmNbottomOffset, 3,
  187.         XmNleftAttachment, XmATTACH_POSITION,
  188.         XmNleftPosition, 1,
  189.         XmNrightAttachment, XmATTACH_POSITION,
  190.         XmNrightPosition, 2,
  191.         NULL
  192.     );
  193.  
  194.     XtAddEventHandler(wParent, StructureNotifyMask, False,
  195.                       (XtEventHandler)MinSize, (caddr_t)wFormAction);
  196.  
  197.     atom = XmInternAtom(XtDisplay(wParent), "WM_DELETE_WINDOW", False);
  198.     XmAddWMProtocolCallback(wParent, atom, Die, NULL);
  199.     atom = XmInternAtom(XtDisplay(wParent), "_WM_QUIT_APP", False);
  200.     XmAddWMProtocolCallback(wParent, atom, Die, NULL);
  201.  
  202.     XtAddCallback(wPicture, XmNexposeCallback, (XtCallbackProc)Draw1, NULL);
  203.     XtAddCallback(wDone, XmNactivateCallback, (XtCallbackProc)Done, wParent);
  204.  
  205.     XtManageChild(wWindow);
  206. }
  207.  
  208. /*------------------------------*\
  209. |* bottom
  210. \*------------------------------*/
  211.