From: dweber@ncsa.uiuc.edu (Daniel Weber)
Newsgroups: comp.sys.sgi
Subject: Hardware/Colormap differences?
Date: 19 Aug 92 20:34:40 GMT
Article-I.D.: news.Bt8zts.EFz
Reply-To: dweber@ncsa.uiuc.edu
Organization: National Center for Supercomputing Applications
Originator: dweber@nvs.ncsa.uiuc.edu


I have some questions about the behavior of gl colormaps on different
hardware platforms.  (Yes, another question from me about colormaps.)

Attached to this question is a program "cmap.c" that can be compiled using:

	cc cmap.c -o cmap -lXirisw -lXm_s -lXt_s -lgl_s -lX11_s -lPW -lc_s

And here is the machine setups I have to run it on:
		IRIX 4.0.5
		1 IRIS Indigo Entry Sys. w/ 8 bits Color
		1 VGX with an R4000 upgrade

When I run this on the VGX, unless the mouse is in the window, the first N
(128?) polygons are weird colors.  Once the mouse is moved into the window,
the polygons are correctly colored, but now the rest of the screen's colors
are freaky.

When I run this program on our Indigo, the colormap is loaded correctly and
the gl window gets filled with grayscale polygons, as it should *WITHOUT*
the rest of the screen changing!  (I should say that the first time it is run,
the whole screen looks like the VGX version until the mouse is moved outside 
the program's window, but retains the normal screen colors when the mouse is 
moved back in.  Subsequent invocations don't even affect the root window 
colors at all.)

Why does the Indigo behave as I truly want this program to behave?  That is,
I *want* to be able to change the gl colormap *without* the rest of the 
screen flaking out.  I've tried various things to change the VGX version's
behavior, but to no avail.  How is it that the Indigo is capable of doing
this, yet the "better" VGX is not?  It once looked like "multimap" would
solve the problem, but that apparently doesn't work with the new widgets?

                                    -d weber
                                    dweber@ncsa.uiuc.edu

ps.  I can't "just set the upper N colormap values" leaving the others alone
as usually suggested when dealing with X colormaps.  Forcing the range is 
unfortunately out of the question.



/*
 * When running, click the mouse in the window to get the gray rectangles.
 */
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <gl/glws.h>
#include <X11/Xirisw/GlxMDraw.h>
#include <gl.h>
#include <device.h>


/* Draws bars on input (mouse click in window).  */
void drawBarsCB(Widget widget, caddr_t ignored, caddr_t unused)
{
	float				i = 0.0;
	static float	rect[4][2] = {{0.0,0.0},{1.0,0.0},{1.0,256.0},{0.0,256.0}};
	GL_Object		rectangle;

   rectangle = genobj();
	makeobj(rectangle);
		bgnpolygon();
			v2f(rect[0]); v2f(rect[1]); v2f(rect[2]); v2f(rect[3]); v2f(rect[0]);
		endpolygon();
	closeobj();

	ortho2(0.0, 256.0, 0.0, 256.0);
	for (i = 0.0; i < 256.0; i+=1.0) {
		color(i);
		callobj(rectangle);
		translate(1.0, 0.0, 0.0);
	}

} /* drawBarsCB */
 

void exposeCB(Widget widget, Widget appShell, caddr_t unused)
{
	int			c, ac = 0;
	Arg			args[3];
	XColor		colors[256];
	Colormap		colormap;
	XVisualInfo	*visual;
	Window		windows[2];
	Display		*display = XtDisplay(widget);

	windows[0] = XtWindow(widget);
	windows[1] = XtWindow(appShell);
	GLXwinset(display, windows[0]);
	XSetWMColormapWindows(XtDisplay(appShell), XtWindow(appShell), windows, 2);

   XtSetArg(args[ac], XtNvisual, &visual); ac++;
   XtGetValues(widget, args, ac);
	colormap = XCreateColormap(display, windows[0], visual->visual, AllocAll);

	for (c = 0; c < 256; c++) {
		colors[c].pixel = c;
		colors[c].red=colors[c].green=colors[c].blue=(unsigned short)(c << 8);
		colors[c].flags = DoRed | DoGreen | DoBlue;
   }

	ac = 0;
	XtSetArg(args[ac], XtNcolormap, colormap); ac++;
	XtSetValues(widget, args, ac);
	XStoreColors(display, colormap, colors, 256);

} /* exposeCB */


void createGLWidget(Widget appShell)
{
	Widget		glWidget;
   GLXconfig	glxConfig[] = { {0, 0, 0} };
   Arg			args[10];
   int			ac = 0;

   XtSetArg(args[ac], GlxNglxConfig, glxConfig); ac++;
	XtSetArg(args[ac], XtNwidth, 512); ac++;
	XtSetArg(args[ac], XtNheight, 512); ac++;
   glWidget = GlxCreateMDraw(appShell, "CMapTest", args, ac);
   XtAddCallback(glWidget, GlxNexposeCallback, exposeCB, appShell);
   XtAddCallback(glWidget, GlxNexposeCallback, drawBarsCB, NULL);
   XtManageChild(glWidget);

} /* createGLWidget */


main(int argc, char *argv[])
{
	Widget			appShell;				/* The top level application sh	*/
	XtAppContext	appContext;				/* The application context	*/

   appShell = XtInitialize(argv[0], "Testcmap", NULL, 0, &argc, argv);
   appContext = XtWidgetToApplicationContext(appShell);

   createGLWidget(appShell);
   XtRealizeWidget(appShell);
	XtMainLoop();
}
Newsgroups: comp.sys.sgi