#include #include #include #include #include #include #include #include #include Display *display; XtAppContext appcontext; Widget toplevelshell; static void close_cb(Widget,void *,void *); Widget main_handle,gl_handle; Widget main_message, main_command, main_draw_area; void create_main_window(Widget); void create_gl_window(void); void gl_pointer_cb(Widget w,void *client_data,void *call_data); void gl_key_cb(Widget w,void *client_data,void *call_data); int main(int argc,char *argv[]) { Atom close_window; XtToolkitInitialize(); appcontext=XtCreateApplicationContext(); display=XtOpenDisplay(appcontext,NULL,argv[0],"XGLTest",NULL,0,&argc,argv); if (!display) { fprintf(stderr,"Error: Cannot open display [%s]!\n",XDisplayName((char *)NULL)); exit(1); } toplevelshell=XtVaAppCreateShell(argv[0],"XGLTest",applicationShellWidgetClass,display,NULL); create_main_window(toplevelshell); create_gl_window(); XtRealizeWidget(toplevelshell); XtMapWidget(toplevelshell); XtVaSetValues(toplevelshell, XmNdeleteResponse, XmDO_NOTHING, NULL); close_window=XmInternAtom(display,"WM_DELETE_WINDOW",FALSE); XmAddWMProtocolCallback(toplevelshell,close_window,close_cb,NULL); XtAppMainLoop(appcontext); } /* end of main() */ static void close_cb(Widget w,void *client_data,void *call_data) { exit(0); } /* end of close_cb() */ void create_main_window(Widget parent) { Widget main_form; main_form=XtVaCreateManagedWidget("form", xmFormWidgetClass, parent, NULL); main_command=XtVaCreateManagedWidget("main_command", xmTextFieldWidgetClass, main_form, NULL); main_draw_area=XtVaCreateManagedWidget("main_draw_area", xmFormWidgetClass, main_form, NULL); XtVaSetValues(main_command, XmNtopAttachment,XmATTACH_NONE, XmNbottomAttachment,XmATTACH_FORM, XmNleftAttachment,XmATTACH_FORM, XmNrightAttachment,XmATTACH_FORM, NULL); XtVaSetValues(main_draw_area, XmNtopAttachment,XmATTACH_FORM, XmNbottomAttachment,XmATTACH_WIDGET, XmNbottomWidget,main_command, XmNleftAttachment,XmATTACH_FORM, XmNrightAttachment,XmATTACH_FORM, NULL); } /* end of create_main_window() */ static int gl_prefs[]={ GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 8, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_STENCIL_SIZE, 1, None }; void create_gl_window(void) { XVisualInfo *vi; vi=glXChooseVisual(display,DefaultScreen(display),gl_prefs); gl_handle=XtVaCreateManagedWidget("gldraw", glwMDrawingAreaWidgetClass, main_draw_area, GLwNvisualInfo, vi, XmNwidth, 800, XmNheight, 600, NULL); XtAddEventHandler(gl_handle, ButtonPressMask|ButtonReleaseMask|PointerMotionMask|PointerMotionHintMask, FALSE,(XtEventHandler)gl_pointer_cb,NULL); XtAddEventHandler(gl_handle,KeyPressMask,FALSE,(XtEventHandler)gl_key_cb,NULL); XtVaSetValues(gl_handle, XmNtraversalOn, TRUE, NULL); XmProcessTraversal(gl_handle,XmTRAVERSE_CURRENT); } /* end of create_gl_window() */ void gl_pointer_cb(Widget w,void *client_data,void *call_data) { printf ("gl_pointer_cb\n" ); XmProcessTraversal(w,XmTRAVERSE_CURRENT); } /* end of gl_pointer_cb() */ void gl_key_cb(Widget w,void *client_data,void *call_data) { printf ("gl_key_cb\n" ); } /* end of gl_key_cb() */