Re: [gtk-list] Strange "delete_event" and "destroy_event"




There was a gtkGL widget announced in this list a few weeks ago.  See
the URL below:

http://www.sakuranet.or.jp/~aozasa/shige/doc/comp/gtk/gtkGL/files-en.html

I have had trouble using it - mainly because I don't understand it.
The code is split into gdkGL and gtkGL.  I am new to gtk so I may be
off here, but it seems to me we could just make a gtkGL widget that
took of (handled and allowed signals) for the realize, resize, expose,
mouse, and key events.  Please forgive my terminology if it's not
correct (I've used Motif for 5 years and may be using its
terminology).

I am willing to write one (especially since I would like to use it
:-) if it can be done more simply then having both a gdk and gtk
portion.  Could I just create a drawing area widget and include the
setup for Mesa or GL in it?

Below is code I have (modified from a Mesa demo) to create a Mesa
window.  Could I just create a MesaGL widget and include this code in
the new widget call (with some slight modification - e.g., no need to
call XOpenDisplay, XCreateWindow, etc, just the stuff to create the
Mesa visual and context)?

Thanks,
Dave
dreed@capital.edu

void createWindow(int xPos, int yPos, int width, int height, char *name,
                  int colorFlag = 1)
{
  int scr;
  Colormap cmap;
  int attr_flags;
  XVisualInfo *visinfo;
  XSetWindowAttributes attr;
  XTextProperty tp;
  XSizeHints sh;
  XEvent e;
  XMesaContext context;
  XMesaVisual visual;
  XMesaBuffer buffer;
 
  windowWidth = width;
  windowHeight = height;
 
  dpy = XOpenDisplay(NULL);
  if (!dpy) {
    fprintf(stderr, "Couldn't open default display!\n");
    exit(1);
  }
  
  scr = DefaultScreen(dpy);
  root = RootWindow(dpy, scr);
  
  // alloc visinfo struct 
  visinfo = (XVisualInfo *) malloc( sizeof(XVisualInfo) );
  
  // Get a visual and colormap 
  if (colorFlag) {
    // Open TrueColor window   
    if (!XMatchVisualInfo(dpy, scr, 24, TrueColor, visinfo)) {
      printf("Couldn't get 24-bit TrueColor visual!\n");
      exit(1);
    }
   cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
  }
  else {
    // Open color index window - not implemented see Mesa demo: xdemo.c
  }
 
  // set window attributes 
  attr.colormap = cmap;
  attr.event_mask = ExposureMask | StructureNotifyMask;
  attr.border_pixel = BlackPixel( dpy, scr );
  attr.background_pixel = BlackPixel( dpy, scr );
  attr_flags = CWColormap | CWEventMask | CWBorderPixel | CWBackPixel;
  
  // Create the window 
  win = XCreateWindow(dpy, root, xPos, yPos, width, height, 0,
                      visinfo->depth, InputOutput,
                      visinfo->visual,
                      attr_flags, &attr);
  
  if (!win) {
    fprintf(stderr, "Couldn't open window!\n");
    exit(1);
  }
  
  XStringListToTextProperty(&name, 1, &tp);
  sh.flags = USPosition | USSize;
  XSetWMProperties(dpy, win, &tp, &tp, 0, 0, &sh, 0, 0);
  XMapWindow(dpy, win);
 
  // wait for window to be created???
  while (1) {
    XNextEvent( dpy, &e );
    if (e.type == MapNotify && e.xmap.window == win) {
      break;
    }
  }
  
  
  // Now do the special Mesa/Xlib stuff!
  
  visual = XMesaCreateVisual( dpy, visinfo,
                              (GLboolean) colorFlag,
                              GL_FALSE,  // alpha_flag 
                              GL_FALSE,  // db_flag 
                              GL_FALSE,  // ximage_flag 
                              0,         // depth size 
                              0,         // stencil size 
                              0,         // accum_size 
                              0          // level 
                              );
  if (!visual) {
    fprintf(stderr, "Couldn't create Mesa/X visual!\n");
    exit(1);
  }
  
  // Create a Mesa rendering context 
  context = XMesaCreateContext(visual, NULL);
 
  if (!context) {
    fprintf(stderr, "Couldn't create Mesa/X context!\n");
    exit(1);
  }
  
  buffer = XMesaCreateWindowBuffer( visual, win );
  if (!buffer) {
    fprintf(stderr, "Couldn't create Mesa/X buffer!\n");
    exit(1);
  }
  
  XMesaMakeCurrent( context, buffer );
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]