Fanning Software Consulting

First Graphics Window Blank

QUESTION: I have run into the following problem on UNIX machines, including IDL 7 on Mac and IDL 8 on an UBuntu LINUX machine. It seems to be a long standing problem that is giving me grief.

Here is the situation. If the following program is run at the very start of a new IDL session, the window will draw a white plot on a white background. Look carefully, because the graphics output is very hard to see!

Subsequently in the IDL session, the program will run fine and I will see a black plot on a white background, exactly as I expect to see it. Here is the simple program:

   PRO MakeWidget
   tlb = widget_base()
   draw = widget_draw(tlb, xsize=400, ysize=400, retain=1)
   widget_control, tlb, /realize
   widget_control, draw, get_value=wid
   wset, wid
   end

   PRO FirstWindowBlank
   device, decomposed=1
   !p.background=16777215L
   !p.color=0L
   print, 'Before MakeWidget: ', !p.color, !p.background
   makewidget
   plot, findgen(11)
   print, 'After MakeWidget:  ', !p.color, !p.background
   END

Here is the output on the two machines I mentioned.

   IDL> .compile firstwindowblank
   IDL> FirstWindowBlank
   Before MakeWidget:            0    16777215
   After MakeWidget:      16777215    16777215

Any ideas on what is going on?

ANSWER: Yes, this is a long standing problem on all UNIX machines, including Macs. The problem seems to be in the way IDL initializes color tables in an X Windows environment. Until IDL actually interrogates the X Window Manager for the particular X visual it is using, it doesn't know anything about what X visuals are available. This interrogation takes place after the first graphics window is created. Upon interrogation, IDL overwrites some (not all!) system variables with the default values for the discovered visual class. In this case, the !P.Color variable is overwritten to be white, while the !P.Background variable is not overwritten, so it stays white. The result, obviously, is difficult to interpret!

The trick is to get IDL to initialize the X Windows environment before you set the colors or do anything else to the graphics window. The easiest way to do this is to simply open and close a graphics window in your IDL start-up file. All UNIX users should do this. It can even be a pixmap window, so nothing appears on your display.

   window, xsize=10, ysize=10, /pixmap
   wdelete, !d.window

The other alternative is to not set default program drawing colors until after the window appears on the display.

   PRO FirstWindowBlank
   device, decomposed=1
   makewidget
   !p.background=16777215L
   !p.color=0L
   plot, findgen(11)
   END

Version of IDL used to prepare this article: IDL 8.1.

Last Updated: 5 May 2011