Source code of Windows XP (NT5)
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.

301 lines
9.8 KiB

  1. #include <GL/glu.h>
  2. #include <GL/glx.h>
  3. #include <X11/Intrinsic.h>
  4. #include <Xm/Xm.h>
  5. #include <Xm/CascadeB.h>
  6. #include <Xm/Frame.h>
  7. #include <Xm/MainW.h>
  8. #include <Xm/PushB.h>
  9. #include <Xm/PushBG.h>
  10. #include <Xm/RowColumn.h>
  11. #include <Xm/ToggleB.h>
  12. #include <GLwMDrawA.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #ifdef WIN32
  16. #include "stonehen.h"
  17. #endif
  18. #include "atmosphe.h"
  19. #include "scene.h"
  20. #include "callback.h"
  21. static Display *display;
  22. XtAppContext app_context;
  23. Widget glw;
  24. const int max_args = 20;
  25. XVisualInfo *find_visual()
  26. {
  27. int attr[256], i, stencil, dbuffer, accum;
  28. XVisualInfo *vi;
  29. i = 0;
  30. attr[i++] = GLX_RGBA;
  31. attr[i++] = GLX_RED_SIZE; attr[i++] = 1;
  32. attr[i++] = GLX_GREEN_SIZE; attr[i++] = 1;
  33. attr[i++] = GLX_BLUE_SIZE; attr[i++] = 1;
  34. attr[i++] = GLX_DEPTH_SIZE; attr[i++] = 1;
  35. dbuffer = i;
  36. attr[i++] = GLX_DOUBLEBUFFER;
  37. stencil = i;
  38. attr[i++] = GLX_STENCIL_SIZE;
  39. attr[i++] = 1;
  40. accum = i;
  41. attr[i++] = GLX_ACCUM_RED_SIZE; attr[i++] = 1;
  42. attr[i++] = GLX_ACCUM_BLUE_SIZE; attr[i++] = 1;
  43. attr[i++] = GLX_ACCUM_GREEN_SIZE; attr[i++] = 1;
  44. attr[i++] = GLX_ACCUM_ALPHA_SIZE; attr[i++] = 1;
  45. attr[i++] = (int)None;
  46. vi = glXChooseVisual(display, DefaultScreen(display), attr);
  47. if (vi == NULL) {
  48. fprintf(stderr, "Unable to find visual with accumulation buffer.\n");
  49. fprintf(stderr, "(Fancy fog won't work).\n");
  50. attr[accum] = (int)None;
  51. vi = glXChooseVisual(display, DefaultScreen(display), attr);
  52. if (vi == NULL) {
  53. fprintf(stderr, "Unable to find visual with stencil buffer.\n");
  54. fprintf(stderr, "(Things won't look quite as good).\n");
  55. attr[stencil] = (int)None;
  56. vi = glXChooseVisual(display, DefaultScreen(display), attr);
  57. if (vi == NULL) {
  58. fprintf(stderr, "Unable to find double-buffered visual.\n");
  59. fprintf(stderr, "(Things will look even worse).\n");
  60. attr[dbuffer] = (int)None;
  61. vi = glXChooseVisual(display, DefaultScreen(display), attr);
  62. if (vi == NULL) fprintf(stderr, "Can't find visual at all.\n");
  63. }
  64. }
  65. }
  66. return vi;
  67. }
  68. Widget create_widgets(Widget parent)
  69. {
  70. Widget main_window;
  71. Widget menu_bar;
  72. Widget menu_pane;
  73. Widget button;
  74. Widget cascade;
  75. Widget frame;
  76. XVisualInfo *vi;
  77. Arg args[max_args];
  78. int argcount;
  79. #ifdef X11
  80. char buffer[128];
  81. #endif
  82. int i;
  83. main_window = XmCreateMainWindow(parent, "main1", NULL, 0);
  84. XtManageChild(main_window);
  85. menu_bar = XmCreateMenuBar(main_window, "menu_bar", NULL, 0);
  86. XtManageChild(menu_bar);
  87. menu_pane = XmCreatePulldownMenu(menu_bar, "menu_pane", NULL, 0);
  88. button = XmCreatePushButton(menu_pane, "Exit", NULL, 0);
  89. XtManageChild(button);
  90. XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)exitCB, NULL);
  91. XtSetArg(args[0], XmNsubMenuId, menu_pane);
  92. cascade = XmCreateCascadeButton(menu_bar, "File", args, 1);
  93. XtManageChild(cascade);
  94. menu_pane = XmCreatePulldownMenu(menu_bar, "menu_pane", NULL, 0);
  95. XtSetArg(args[0], XmNset, use_lighting);
  96. button = XmCreateToggleButton(menu_pane, "Lighting", args, 1);
  97. XtManageChild(button);
  98. XtAddCallback(button, XmNvalueChangedCallback,
  99. (XtCallbackProc)intToggleCB, &use_lighting);
  100. XtSetArg(args[0], XmNset, draw_shadows);
  101. button = XmCreateToggleButton(menu_pane, "Shadows", args, 1);
  102. XtManageChild(button);
  103. XtAddCallback(button, XmNvalueChangedCallback,
  104. (XtCallbackProc)intToggleCB, &draw_shadows);
  105. XtSetArg(args[0], XmNset, use_normal_fog);
  106. button = XmCreateToggleButton(menu_pane, "Fog", args, 1);
  107. XtManageChild(button);
  108. XtAddCallback(button, XmNvalueChangedCallback,
  109. (XtCallbackProc)intToggleCB, &use_normal_fog);
  110. #ifdef TEXTURE
  111. XtSetArg(args[0], XmNset, use_textures);
  112. button = XmCreateToggleButton(menu_pane, "Texture Map", args, 1);
  113. XtManageChild(button);
  114. XtAddCallback(button, XmNvalueChangedCallback,
  115. (XtCallbackProc)intToggleCB, &use_textures);
  116. #endif
  117. XtSetArg(args[0], XmNset, use_telescope);
  118. button = XmCreateToggleButton(menu_pane, "Telescope", args, 1);
  119. XtManageChild(button);
  120. XtAddCallback(button, XmNvalueChangedCallback,
  121. (XtCallbackProc)intToggleCB, &use_telescope);
  122. XtSetArg(args[0], XmNset, use_antialias);
  123. button = XmCreateToggleButton(menu_pane, "Antialias", args, 1);
  124. XtManageChild(button);
  125. XtAddCallback(button, XmNvalueChangedCallback,
  126. (XtCallbackProc)intToggleCB, &use_antialias);
  127. XtSetArg(args[0], XmNsubMenuId, menu_pane);
  128. cascade = XmCreateCascadeButton(menu_bar, "SPFX", args, 1);
  129. XtManageChild(cascade);
  130. argcount = 0;
  131. XtSetArg(args[argcount], XmNradioBehavior, True); argcount++;
  132. menu_pane = XmCreatePulldownMenu(menu_bar, "menu_pane", args, argcount);
  133. XtSetArg(args[0], XmNset, TRUE);
  134. for (i = 0; i < nweathers; i++) {
  135. if (i == def_weather_index) argcount = 1;
  136. else argcount = 0;
  137. button = XmCreateToggleButton(menu_pane, (char *)weathers[i].name,
  138. args, argcount);
  139. XtManageChild(button);
  140. XtAddCallback(button, XmNvalueChangedCallback,
  141. (XtCallbackProc)weatherCB,
  142. (XtPointer)(&weathers[i]));
  143. }
  144. XtSetArg(args[0], XmNsubMenuId, menu_pane);
  145. cascade = XmCreateCascadeButton(menu_bar, "Weather", args, 1);
  146. XtManageChild(cascade);
  147. argcount = 0;
  148. XtSetArg(args[argcount], XmNradioBehavior, True); argcount++;
  149. menu_pane = XmCreatePulldownMenu(menu_bar, "menu_pane", args, argcount);
  150. button = XmCreatePushButton(menu_pane, "Current Time", NULL, 0);
  151. XtManageChild(button);
  152. XtAddCallback(button, XmNactivateCallback,
  153. (XtCallbackProc)currentTimeCB, NULL);
  154. button = XmCreatePushButton(menu_pane, "10 a.m.", NULL, 0);
  155. XtManageChild(button);
  156. XtAddCallback(button, XmNactivateCallback,
  157. (XtCallbackProc)time10amCB, NULL);
  158. button = XmCreatePushButton(menu_pane, "Noon", NULL, 0);
  159. XtManageChild(button);
  160. XtAddCallback(button, XmNactivateCallback,
  161. (XtCallbackProc)time12pmCB, NULL);
  162. button = XmCreatePushButton(menu_pane, "4 p.m.", NULL, 0);
  163. XtManageChild(button);
  164. XtAddCallback(button, XmNactivateCallback,
  165. (XtCallbackProc)time4pmCB, NULL);
  166. XtSetArg(args[0], XmNset, 1); argcount = 1;
  167. button = XmCreateToggleButton(menu_pane, "Hold Time", args, 1);
  168. XtManageChild(button);
  169. XtAddCallback(button, XmNvalueChangedCallback,
  170. (XtCallbackProc)timeSpeedCB, (XtPointer)0);
  171. button = XmCreateToggleButton(menu_pane, "Scale = 1:1", NULL, 0);
  172. XtManageChild(button);
  173. XtAddCallback(button, XmNvalueChangedCallback,
  174. (XtCallbackProc)timeSpeedCB, (XtPointer)1);
  175. button = XmCreateToggleButton(menu_pane, "Scane = 1:10", NULL, 0);
  176. XtManageChild(button);
  177. XtAddCallback(button, XmNvalueChangedCallback,
  178. (XtCallbackProc)timeSpeedCB, (XtPointer)10);
  179. button = XmCreateToggleButton(menu_pane, "Scane = 1:100", NULL, 0);
  180. XtManageChild(button);
  181. XtAddCallback(button, XmNvalueChangedCallback,
  182. (XtCallbackProc)timeSpeedCB, (XtPointer)100);
  183. button = XmCreateToggleButton(menu_pane, "Scane = 1:500", NULL, 0);
  184. XtManageChild(button);
  185. XtAddCallback(button, XmNvalueChangedCallback,
  186. (XtCallbackProc)timeSpeedCB, (XtPointer)500);
  187. XtSetArg(args[0], XmNsubMenuId, menu_pane);
  188. cascade = XmCreateCascadeButton(menu_bar, "Time", args, 1);
  189. XtManageChild(cascade);
  190. menu_pane = XmCreatePulldownMenu(menu_bar, "menu_pane", NULL, 0);
  191. XtSetArg(args[0], XmNset, cb_demo_mode); argcount = 1;
  192. button = XmCreateToggleButton(menu_pane, "Demo Mode", args, 1);
  193. XtManageChild(button);
  194. XtAddCallback(button, XmNvalueChangedCallback,
  195. (XtCallbackProc)demo_modeCB, (XtPointer)0);
  196. button = XmCreatePushButton(menu_pane, "Reset viewer", NULL, 0);
  197. XtManageChild(button);
  198. XtAddCallback(button, XmNactivateCallback,
  199. (XtCallbackProc)resetViewerCB, NULL);
  200. XtSetArg(args[0], XmNsubMenuId, menu_pane);
  201. cascade = XmCreateCascadeButton(menu_bar, "Misc", args, 1);
  202. XtManageChild(cascade);
  203. argcount = 0;
  204. XtSetArg(args[argcount], XmNmarginWidth, 0); argcount++;
  205. XtSetArg(args[argcount], XmNmarginHeight, 0); argcount++;
  206. XtSetArg(args[argcount], XmNshadowThickness, 1); argcount++;
  207. XtSetArg(args[argcount], XmNshadowType, XmSHADOW_OUT); argcount++;
  208. frame = XmCreateFrame(main_window, "frame", args, argcount);
  209. XtManageChild(frame);
  210. argcount = 0;
  211. vi = find_visual();
  212. if (vi) {
  213. XtSetArg(args[argcount], GLwNvisualInfo, vi); argcount++;
  214. }
  215. else {
  216. XtSetArg(args[argcount], GLwNrgba, TRUE); argcount++;
  217. XtSetArg(args[argcount], GLwNdepthSize, 1); argcount++;
  218. XtSetArg(args[argcount], GLwNdoublebuffer, TRUE); argcount++;
  219. }
  220. XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++;
  221. XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++;
  222. XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++;
  223. XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++;
  224. glw = GLwCreateMDrawingArea(frame, "glwidget", args, argcount);
  225. XtManageChild(glw);
  226. XtAddCallback(glw, GLwNginitCallback, (XtCallbackProc)initCB, 0);
  227. XtAddCallback(glw, GLwNexposeCallback, (XtCallbackProc)exposeCB, 0);
  228. XtAddCallback(glw, GLwNresizeCallback, (XtCallbackProc)resizeCB, 0);
  229. XtAddCallback(glw, GLwNinputCallback, (XtCallbackProc)inputCB, 0);
  230. return main_window;
  231. }
  232. void _cdecl main(int argc, char **argv)
  233. {
  234. Widget app_shell;
  235. Arg args[max_args];
  236. int argcount;
  237. XtToolkitInitialize();
  238. app_context = XtCreateApplicationContext();
  239. display = XtOpenDisplay(app_context, NULL, argv[0],
  240. "XMdemos", NULL, 0, &argc, argv);
  241. if (!display) {
  242. XtWarning("Can't open display.");
  243. exit(0);
  244. }
  245. argcount = 0;
  246. XtSetArg(args[argcount], XmNmaxAspectX, 1); argcount++;
  247. XtSetArg(args[argcount], XmNmaxAspectY, 1); argcount++;
  248. XtSetArg(args[argcount], XmNminAspectX, 1); argcount++;
  249. XtSetArg(args[argcount], XmNminAspectY, 1); argcount++;
  250. app_shell =
  251. XtAppCreateShell(argv[0], "XMdemos", applicationShellWidgetClass,
  252. display, args, argcount);
  253. create_widgets(app_shell);
  254. XtRealizeWidget(app_shell);
  255. XtAppMainLoop(app_context);
  256. }