From: ercolessi@uimrl3.mrl.uiuc.edu (furio ercolessi)
Subject: Re: winopen() with no graphics
Reply-To: ercolessi@uimrl3.mrl.uiuc.edu (furio ercolessi)
Organization: MRL - UIUC
Date: Tue, 29 Dec 1992 00:02:37 GMT
Keywords: getgdesc winopen

In article <BzzHC2.9AM@sidefx.uucp>, mark@sidefx.uucp (Mark Elendt) writes:
|>If you have no graphics console and you try to do a winopen(), the
|>call doesn't fail, it actually terminates your process or hangs.
|>Apparently, there is no getgdesc() call to determine whether it is
|>possible to do a winopen() safely.
|>
|>Of course this problem really crops up if an application is run from
|>a dumb terminal or run at night after everyone has logged out.
|>
|>Sometimes, the graphics are nice if the user is using an application
|>interactively, but not necessary if the application is run in batch
|>mode.  Occasionally, the user leaves options on for the interactive
|>graphics when doing batch runs and it would be nice if the program
|>didn't terminate on them.
|>
|>Any ideas?

I asked the same question some time ago, and Michael Portuesi
of SGI offered the answer below.   The solution is SGI-specific,
but unfortunately I need to run my program on both SGI and
RS/6000s, so I eventually gave up and just ask the user if
he/she is sitting in front of a GL device, and call winopen() only
if the answer was 'yes'.

---------------------------------------------------
From: portuesi@tweezers.esd.sgi.com (Michael Portuesi)
Newsgroups: comp.sys.sgi,comp.unix.aix
Subject: Re: How to ask GL whether the server is there
Date: 18 Jun 92 16:02:19 GMT
Organization: Silicon Graphics, Inc.  Mountain View, CA

I know of one solution, but it involves making some Xlib calls.
This is quoted from the current issue of "Pipeline", a publication
of our Customer Support Division.  I've changed the code ever
so slightly for correctness.

--------------

Determining if an X Server is GL-Capable

Since GL capability is not currently implemented as a standard
X extension, there is no standard way to determine if an X
server is GL-capable.  However, there is a "string" that an
application can query the server to determine if it is a Silicon
Graphics X server:

	int major_opcode, first_event, first_error;

	Bool SGIserver = XQueryExtension(display, "SGI-SUNDRY-NONSTANDARD",
					 &major_opcode,
					 &first_event,
					 &first_error);

	if (SGIserver) {
	    printf("The display is an SGI X server.\n");
	} else {
	    printf("The display is not an SGI X server.\n");
	}

The above code is known to work for IRIX 4.0.* releases.  Silicon
Graphics is planning to provide a standard way to query an X
server to determine if it has a GL extension.  The above code
may not work in future IRIX releases.

--------------

The programming example as printed in the pipeline leaves out
a few details to make it complete.  First, you will need to include
Xlib.h in your code.  You will need to make sure that Xlib.h is
included before gl.h.  Secondly, you will need to open a display
on the X server you're curious about before making the
XQueryExtension call.

Here's a self-contained program I wrote based on the above code
fragment, that shows everything you need to do.  Enjoy.

/*
 * sgix.c - determine if an X server is a Silicon graphics X server.
 *
 * to compile on an SGI system:
 *
 * cc sgix.c -o sgix -lX11
 *
 */

#include <X11/Xlib.h>
#include <stdio.h>

main(int argc, char* argv[])
{
    Display* display;
    int major_opcode, first_event, first_error;
    Bool SGIserver;

    if (argc > 1) {
    	display = XOpenDisplay(argv[1]);
    } else {
	display = XOpenDisplay(NULL);	/* use default DISPLAY env variable */
    }

    if (display == NULL) {
	printf("%s: can't open connection.\n", argv[0]);
	exit(1);
    }

    SGIserver = XQueryExtension(display, "SGI-SUNDRY-NONSTANDARD",
				&major_opcode,
				&first_event,
				&first_error);

    if (SGIserver) {
	printf("The display is an SGI X server.\n");
    } else {
	printf("The display is not an SGI X server.\n");
    }

    XCloseDisplay(display);
}



--
Furio Ercolessi
Materials Research Laboratory           |   Intl School for Advanced Studies
Univ. of Illinois at Urbana-Champaign   |   Trieste, Italy
furio@uiuc.edu                          |   furio@sissa.it