Re: XForms: interface between xforms and gl/mesa

Yan Zhuang (yzhuang@CS.berkeley.edu)
Thu, 02 Oct 1997 15:39:22 -0700

To subscribers of the xforms list from Yan Zhuang <yzhuang@CS.berkeley.edu> :

Thanks a lot for you help. I finally decided to completely bypass glcanvas.
I just displayed everything using a regular OpenGL window and use xform to
control the state. The problem with glcanvas on my HP is that the color does
not look right. It is either not smooth, or sometimes it suddenly turns dark.
The lighting is kind of weired, too. I guess xform does not really handle
colormap properly. I will try your prototype and see how it works. Thanks a
lot again.

-yan

> To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :
>
> > Does anyone out there use xforms for the interface, while
> > using opengl/mesa for display/rendering? ...
>
> Yes. Works fine for me. I use the GL Canvas and a somewhat modified
> version of the gl.c file supplied with the XForms distribution. I
> have especially modified the glx_init routine to use a the default
> Colormap whenever possible and to choose the Visual in a somewhat
> different manner.
>
> I enclose my version of the routine here:
>
> /*
> * Default GL canvas configuration. The user can modify this default
> * using fl_set_glcanvas_defaults(const int *config) or
> * fl_set_glcanvas_attributes(FL_OBJECT *, const int *config)
> *
> */
>
> static int glconfig[MAXATTRIB] =
> {
> GLX_RGBA, GLX_DEPTH_SIZE, 1,
> GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8,
> GLX_DOUBLEBUFFER,
> None
> };
>
> static int lists[][MAXATTRIB] = { /* Try these if we lose */
> {
> GLX_RGBA,
> GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8,
> GLX_DOUBLEBUFFER,
> None
> },
> {
> GLX_RGBA,
> GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8,
> None
> },
> {
> GLX_RGBA,
> GLX_DOUBLEBUFFER,
> None
> },
> {
> GLX_RGBA,
> None
> },
> };
>
> #define N(x) ( sizeof( x ) / sizeof( x[0] ) )
>
> [...]
>
> /* Initialize the OpenGL stuff before window creation */
> static int
> glx_init(FL_OBJECT * ob)
> {
> XVisualInfo *vi;
> GLXContext context;
> int screen_number;
> Visual *default_visual;
> int list;
>
> /* query for openGL capabilities */
> if (!glXQueryExtension(fl_display, 0, 0))
> abend( "GLCanvas: OpenGL not supported" );
>
> if ( !( vi = glXChooseVisual(fl_display,
> fl_screen, GLPROP(ob)->glconfig) ) )
> for ( list = 0; list < N( lists ); list++ )
> if ( vi = glXChooseVisual(fl_display,
> fl_screen, lists[list] ) ) {
>
> memcpy( GLPROP(ob)->glconfig,
> lists[list],
> MAXATTRIB * sizeof( int ) );
> break;
>
> }
>
> if ( !vi )
> abend( "GLCanvas: Can't get a visual for love nor money!" );
> /* change canvas defaults */
> fl_set_canvas_visual(ob, vi->visual);
> fl_set_canvas_depth(ob, vi->depth);
>
> screen_number = DefaultScreen( fl_get_display() );
> default_visual = DefaultVisual( fl_get_display(), screen_number );
> if ( default_visual->class != vi->visual->class )
> fl_set_canvas_colormap(ob, fl_create_colormap(vi, 1));
> else
> fl_set_canvas_colormap( ob,
> DefaultColormap( fl_get_display(),
> screen_number ) );
>
> context = glXCreateContext(fl_display, vi, None, GLPROP(ob)->direct);
>
> if (!context)
> abend( "Can't create GLX context!" );
>
> /* under some conditions, the parent of the gl canvas might go away,
> leaving the old context and vi hanging. */
> glx_cleanup(ob);
>
> GLPROP(ob)->context = context;
> GLPROP(ob)->xvinfo = vi;
> return 0;
> }
>
> You may want to set different perferences for suboptimal Visual
> fallback.
>
> You'll have to change a few things to integrate this into your
> application, especially references to my private abend() routine
> (guess which large mainframe vendor's systems I spent several years
> programming :-) ). abend() simply prints a message and terminates the
> program.
>
> spl
>
> _________________________________________________
> To unsubscribe, send the message "unsubscribe" to
> xforms-request@bob.usuf2.usuhs.mil or see
> http://bob.usuf2.usuhs.mil/mailserv/xforms.html
> Xforms Home Page: http://bragg.phys.uwm.edu/xforms
> List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/