MATLAB Answers

1

Why does my Linux hardware OpenGL not work properly?

I would like to know why the patches of my surface are rendered in the wrong order.
I also receive a warning when I try to use OpenGL in Linux.
Calling any 3-D plotting commands results in the following error:
Warning: OpenGL not available. Using ZBuffer.
> In $MATLAB/toolbox/matlab/graphics/opengl.m at line 47
I also receive this error when I type
opengl info
This issue has been observed most commonly with NVIDIA drivers on Linux.

Products

1 Answer

Answer by MathWorks Support Team on 10 Sep 2012
 Accepted Answer

This enhancement has been incorporated in Release 14 Service Pack 2 (R14SP2). For previous product releases, read below for any possible workarounds:
This problem is likely being caused by graphics library versions that are not compatible or supported in MATLAB.
GL (libGL) and GLU (libGLU) are graphics libraries that are used by OpenGL. The only version combinations that will work in MATLAB 6.0 (R12) and later versions are:
libGL.so.1.2.x
libGLU.so.1.2.x
or
libGL.so.1.2.x
libGLU.so.1.3.x
You can get the correct version of these libraries by setting up MATLAB to use your native Linux "libGL.so" file and the generic "libGLU.so" file that is shipped with MATLAB in the $MATLABROOT/sys/opengl/lib/glnx86 directory (where $MATLAB is the root MATLAB directory).
Consult your system documentation to identify the location of your native Linux OpenGL libraries. They are files or symbolic links called "libGL.so" and they are usually located in a directory such as /usr/lib or a similar directory. This native library may indicate Mesa software OpenGL, or may indicate a library that is specifically accelerated for your hardware. Later in this resolution, you will see how to determine which MATLAB is using.
Once you have identified these libraries, for example:
/usr/lib/libGL.so
/usr/matlab/sys/opengl/lib/glnx86/libGLU.so
you can create symbolic links in some_directory to these respective libraries using the UNIX linking utility. For example, assuming your native OpenGL Linux library "libGL.so" is located in /usr/lib and your MATLAB is installed in /usr/matlab, you would then do something such as this:
cd /usr/some_directory
ln -s /usr/lib/libGL.so libGL.so
ln -s /usr/matlab/sys/opengl/lib/glnx86/libGLU.so libGLU.so
Next you must add some_directory to your library path so that MATLAB will find it first:
setenv LD_LIBRARY_PATH /usr/some_directory: $LD_LIBRARY_PATH
You can verify which OpenGL library file MATLAB is using by using the "ldd" command:
ldd /usr/matlab/bin/glnx86/glren.so
You can verify which renderer the libraries actually indicate by using the following command in MATLAB:
opengl info
If MATLAB is using the Mesa software OpenGL, then you should see the following output for MATLAB 6.0 (R12) and later versions:
Version = 1.2 Mesa 3.0
Vendor = Brian Paul
Renderer = Mesa X11
MaxTextureSize = 1024
Extensions = GL_EXT_blend_color GL_EXT_blend_minmax GL_EXT_blend_logic_op GL_EXT_blend_subtract GL_EXT_paletted_texture GL_EXT_point_parameters GL_EXT_polygon_offset GL_EXT_vertex_array GL_EXT_texture_object GL_EXT_texture3D GL_MESA_window_pos GL_MESA_resize_buffers GL_EXT_shared_texture_palette GL_EXT_rescale_normal GL_EXT_abgr GL_SGIS_texture_edge_clamp GL_SGIS_multitexture GL_EXT_multitexture
If MATLAB is using hardware, then you will see different output, such as the following:
Version = 1.2 Mesa 3.4.2
Vendor = VA Linux Systems Inc.
Renderer = Mesa DRI G400 20010321 AGP 1x x86/MMX/SSE
MaxTextureSize = 512
Extensions = GL_ARB_multitexture GL_ARB_transpose_matrix GL_EXT_abgr
GL_EXT_blend_func_separate GL_EXT_clip_volume_hint GL_EXT_compiled_vertex_array
GL_EXT_histogram GL_EXT_packed_pixels GL_EXT_polygon_offset GL_EXT_rescale_normal
GL_EXT_stencil_wrap GL_EXT_texture3D GL_EXT_texture_env_add GL_EXT_texture_object
GL_EXT_vertex_array GL_MESA_window_pos GL_MESA_resize_buffers GL_NV_texgen_reflection
GL_PGI_misc_hints GL_SGIS_pixel_texture GL_SGIS_texture_edge_clamp
The "Renderer" line will indicate whether you are using software or hardware. In the example above, G400 indicates the graphics card that is being used. Determining what your own machine is using may require some investigation.
If you are still experiencing difficulties, such as incorrectly sorted surface patches or error messages, then most likely MATLAB is not using the appropriate XVisual for figure OpenGL graphics. To resolve that problem, follow these instructions:
First verify that you are using hardware OpenGL by obtaining information using the "opengl info" MATLAB command as discussed above.
After you have determined what you are using for hardware, check which XVisual your MATLAB figure is using. You can use the following MATLAB commands:
hf=figure;
set(hf,'renderer','opengl');
get(hf,'xvisual')
ans =
0x23 (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff)
Now cross-reference this number against the output of the UNIX command, glxinfo:
!glxinfo
visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat
----------------------------------------------------------------------
0x23 24 tc 0 24 0 r y . 8 8 8 8 0 0 0 0 0 0 0 0 0 None
0x24 24 tc 0 24 0 r . . 8 8 8 8 0 0 0 0 0 0 0 0 0 None
0x25 24 tc 0 24 0 r y . 8 8 8 8 0 24 8 0 0 0 0 0 0 None
0x26 24 tc 0 24 0 r . . 8 8 8 8 0 24 8 0 0 0 0 0 0 None
0x27 24 tc 0 24 0 r y . 8 8 8 8 0 0 0 16 16 16 0 0 0 Slow
0x28 24 tc 0 24 0 r . . 8 8 8 8 0 0 0 16 16 16 0 0 0 Slow
0x29 24 tc 0 24 0 r y . 8 8 8 8 0 24 8 16 16 16 0 0 0 Slow
0x2a 24 tc 0 24 0 r . . 8 8 8 8 0 24 8 16 16 16 0 0 0 Slow
0x2b 24 dc 0 24 0 r y . 8 8 8 8 0 0 0 0 0 0 0 0 0 None
0x2c 24 dc 0 24 0 r . . 8 8 8 8 0 0 0 0 0 0 0 0 0 None
0x2d 24 dc 0 24 0 r y . 8 8 8 8 0 24 8 0 0 0 0 0 0 None
0x2e 24 dc 0 24 0 r . . 8 8 8 8 0 24 8 0 0 0 0 0 0 None
0x2f 24 dc 0 24 0 r y . 8 8 8 8 0 0 0 16 16 16 0 0 0 Slow
0x30 24 dc 0 24 0 r . . 8 8 8 8 0 0 0 16 16 16 0 0 0 Slow
0x31 24 dc 0 24 0 r y . 8 8 8 8 0 24 8 16 16 16 0 0 0 Slow
0x32 24 dc 0 24 0 r . . 8 8 8 8 0 24 8 16 16 16 0 0 0 Slow
You can see that a visual id of 0x23 has a depth ("dp th") of 0. This indicates that the patches do not get rendered in the proper order. The renderer is not paying attention to their depth within the monitor.
To fix this, choose the best TrueColor visual that has a depth and that has double buffering. A TrueColor visual has a "visual cl" value of "tc", and a double buffering visual has a "d b" value of "y".
In this case visual 0x25 has TrueColor, double buffering, 24bit Zbuffer ("bfsz"), and is not "slow".
The following code shows how to set this visual to all MATLAB figures. You may wish to put this line of code in a "startup.m" file:
set(0,'defaultfigurexvisual','0x25');
For more information on "startup.m" files, see the following online documentation:

  2 Comments

Hi. I have some questions.
The first relies on the variable using the setenv command
'LD_LIBRARY_PATH'
. Is this just a representation to the path in my computer or MATLAB do use this variable name?
The other question relies on the test of which xvisual MATLAB is using. Using exactly the same example, there was no property with that tag.
The following error appears:
>> get(hf, 'xvisual')
Error using matlab.ui.Figure/get
There is no xvisual property on the Figure class.
But when I type
get(hf)
I have all the properties listed, and the Renderer is 'Quadro P400/PCIe/SSE2'.
The third question regards about the software and hardware property by typing opengl info. I have a NVIDIA Quadro 4000 here, and matlab is using the hardware, as the property's output is 'false'. Is there any difference in performance when changing from hard to software?
I'm using matlab 2012a in Linux Ubuntu, with the mentioned GPU.
--
After all, I didn't succeed as it's unclear how to set the path for matlab:
setenv LD_LIBRARY_PATH /usr/matlab_lib: $LD_LIBRARY_PATH
I rather have to use the command tcsh because setenv was not found in the linux repository, but don't know how to proceed. Can anybody help?
Hello,
If you are still facing issues, I would suggest contacting MathWorks Technical Support at
who may be able to assist further.
-Narmada

Sign in to comment.