Mesa User's Guide
Subjects:
X supports 6 different visual types or classes (N=depth):
The most common visual type on low-end displays is 8-bit PseudoColor. In this case each byte in the frame buffer is an index into a 256-entry colormap which can be loaded with colors you choose.
A common visual type on high-end displays is 24-bit TrueColor. In this case each triplet of bytes in the frame buffer directly maps to an RGB color on the screen. 256 shades of red, 256 shades of green and 256 shades of blue allow 16,777,216 differeent colors. Some people say you can display "16 million colors at once" but that's false because nobody has a display with that many pixels!
Here are some other common visuals:
Another way to determine the default (root) visual is to use xwininfo. When you run xwininfo your pointer will turn into a cross-hair. Point over the root window and press a mouse button. Among the information printed will be the visual class and depth. Note that you can apply this program to any X window.
startx -- -bpp16
or
startx -- -bpp32
to start the X server with deeper visuals.
Ask your sysadmin or consult your system's X documentation to learn more.If your display supports more than one visual you should also be able to configure the default (root) visual to be which ever you want. Again, read your documentation.
When creating top-level windows it's much better to use XGetVisualInfo or XMatchVisualInfo to explicitly choose the visual and XCreateWindow to create the window. Alternatively, if you want to use the default visual, your code should verify that the default visual is suitable for your application's needs and deal with it appropriately.
Finally, If you create a window with a visual you've explicitly chosen you must also be sure to provide a colormap which matches the visual. Otherwise you'll get a BAD MATCH X protocol error.
An X colormap is really an abstraction over the hardware. While your X screen may only have one real colormap, X gives programmers the illusion of having an unlimited number of colormaps. If the hardware colormap(s) become over commited you'll probably see the "technicolor" effect or colormap "flashing" when you move the input focus from one window to another. That's caused by the window manager installing the virtual X colormap into the hardware colormap for the current window. Careful programming can reduce or eliminate this problem as we'll see.
X colormaps come into two varieties: private and shared. When you call XCreateColormap you indicate AllocAll for private or AllocNone for shared.
When you create a private colormap you get a whole colormap to yourself in which you can setup any mapping of pixels to colors you want using XStoreColor(s). You should avoid using private colormaps when possible because they inhibit color sharing. Remember, it's not sharing colors with other clients which leads to the dreaded colormap flashing.
When you create a shared colormap you must allocate colors from it using XAllocColor. You specify a color by red, green, and blue values and XAllocColor returns a pixel value for you to use when drawing things. If X can't allocate the color you need, XAllocColor will fail. Your best recourse is to then search the colormap for the closest match and use that color. X will try to combine shared colormaps into one hardware colormap to reduce flashing.
Programming tips:
Mesa's X driver is more flexible, allowing you to use any X visual type in RGB mode and either GrayScale, StaticGray, PseudoColor or StaticColor in color- index mode. Unfortunately, this flexibility sometimes causes problems.
It's very important to understand that most of the visual and colormap problems people have with Mesa are not caused by the core Mesa library but rather the higher level toolkits such as aux, tk and GLUT. However, the toolkits cannot be blamed too much because they were designed to work with OpenGL but not Mesa's unique features.
Remember that if Mesa's glXChooseVisual were modified to behave exactly like OpenGL's we would actually be losing functionality which a lot of people (everyone without a TrueColor display) depend on.
Note that the MESA_PRIVATE_CMAP variable is recognized by the aux and tk toolkits and not the Mesa core library. Colormap management is an issue at a level above the core of Mesa.
Experiment with the MESA_BACK_BUFFER environment variable if using double buffered mode. Possible values are "P" for pixmap and "X" for XImage. When displaying on the local host and using an XImage for the back buffer, the X shared memory extension is used to accelerate the glXSwapBuffers() function. Using an X image is usually faster except when rendering scenes which don't use any raster operations (such as depth-test, stenciling, dithering, etc) since the Xlib point, line and polygon functions can be used.
Experiment with different visuals with the MESA_RGB_VISUAL environment variable. Some are visuals faster than others.
Try to maximize the number of vertices between glBegin/glEnd.
Group state changes such as glEn/Disable, glShadeModel, etc together before glBegin/glEnd to minimize the number internal state change computations.
Disable smooth shading when not needed. Smooth shading is usually only needed for drawing lit polygons.
Disable dithering when not needed.
Disable depth testing and any other raster operations you don't need.
glDrawPixels works quickest with GL_UNSIGNED_BYTE, GL_RGB - format image data.
Use GLfloat-valued functions such as glVertex
Use backface culling to reduce the rasterization bottleneck.
Using a smaller window will speed up polygon rasterization, glClear,
and glXSwapBuffers.
Avoid using glColorMaterial.
Use directional lights rather than positional lights. i.e. W component of position = 0.0.
Avoid using GL_LIGHT_MODEL_LOCAL_VIEWER.
Avoid using spot lights.
Use low-numbered, consecutive lights such as GL_LIGHT0, GL_LIGHT1,
GL_LIGHT2 rather than GL_LIGHT2, GL_LIGHT5, GL_LIGHT7 for example.
Avoid using GL_NORMALIZE.
Use viewports which are completely inside the window boundaries.
When you compile your Mesa/OpenGL application just add
If your system doesn't have real OpenGL libraries it
may also be a good idea to make a few symbolic links so that "off the shelf"
OpenGL applications compile painlessly:
Then you can specify
If you have an OpenGL application and want to display it on a server which
lacks the GLX extension, Mesa can help you. You have two alternatives:
If you're not familiar with shared libraries you should read your
system's documentation. Man pages on ld, rld, ld.so or
Here are the steps to using a Mesa shared library in place of OpenGL:
Now when you execute the OpenGL application the runtime linker should
select the Mesa shared library instead of the OpenGL shared library.
Why did I say "almost any X server"? Because it might be the case that
the OpenGL application won't accept any of the visual types offered by
your display. For example, if the OpenGL app asks for an RGBA visual
and Mesa returns a PseudoColor visual the application may not accept it
because a TrueColor or DirectColor visual was expected. You may have to
experiment with the MESA_RGB_VISUAL environment variable if you have this
problem.
Subject 4: Installing Mesa (on Unix systems)
After you've compiled the Mesa library files, as seen in
Mesa/lib
, you should probably move them and the include
files to a more appropriate location. I suggest copying the
Mesa/lib
files to /usr/local/lib
and copying
the Mesa/include/GL
directory to
/usr/local/include
.-I/usr/local/include
to your C compiler flags and add
-L/usr/local/lib
to your linker flags.
ln -s /usr/local/include/GL /usr/include/GL
ln -s /usr/local/lib/libMesaGL.a /usr/lib/libGL.a
ln -s /usr/local/lib/libMesaGLU.a /usr/lib/libGLU.a
NOTE: if you've made shared Mesa libraries the symbolic links will probably
have different names: .so
suffix instead of .a
suffix, for example. If you do this you may also have to run a special
program such as ldconfig -v
on Linux to make things work.-lGL
and -lGLU
when linking
your Mesa application and be confident that it will also compile successfully
on other systems which may have real OpenGL libraries.Subject 5: Remote display of OpenGL apps
Normally, X11-based OpenGL applications can only be displayed on X servers
which have the GLX extension. The GLX extension decodes the GLX protocol
(which is sent within the X protocol stream) and executes the appropriate
OpenGL rendering operations. You can check if your display server has
this extension by examining the output of running xdpyinfo.
Using either of these methods, The application should now be displayable
on almost any X server since the OpenGL API calls will effectively be
translated into ordinary X protocol by Mesa.-lGL
with -lMesaGL
in the
Makefile. The application should now be displayable on almost any X
server.man -k
library
should turn up something.
ln -s libMesaGL.so libGL.so
in the Mesa/lib directory. Note that you could just rename the
Mesa library instead of making a symbolic link, if you prefer._RLD_LIST
environment variable:
setenv _RLD_LIST "mesalibdir/libGL.so:DEFAULT"
where
mesalibdir is the full path to the location of the symbolic link
you made previously.
Back to the Mesa home page
Last updated on January 19, 1996 by brianp@ssec.wisc.edu.