kusano 7d535a

Initializing GLEW

kusano 7d535a

kusano 7d535a
First you need to create a valid OpenGL rendering context and call
kusano 7d535a
<tt>glewInit()</tt> to initialize the extension entry points.  If
kusano 7d535a
<tt>glewInit()</tt> returns <tt>GLEW_OK</tt>, the initialization
kusano 7d535a
succeeded and you can use the available extensions as well as core
kusano 7d535a
OpenGL functionality. For example:
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
#include <GL/glew.h>
kusano 7d535a
#include <GL/glut.h>
kusano 7d535a
...
kusano 7d535a
glutInit(&argc, argv);
kusano 7d535a
glutCreateWindow("GLEW Test");
kusano 7d535a
GLenum err = glewInit();
kusano 7d535a
if (GLEW_OK != err)
kusano 7d535a
{
kusano 7d535a
  /* Problem: glewInit failed, something is seriously wrong. */
kusano 7d535a
  fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
kusano 7d535a
  ...
kusano 7d535a
}
kusano 7d535a
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
kusano 7d535a

kusano 7d535a
kusano 7d535a

Checking for Extensions

kusano 7d535a
kusano 7d535a

kusano 7d535a
Starting from GLEW 1.1.0, you can find out if a particular extension
kusano 7d535a
is available on your platform by querying globally defined variables
kusano 7d535a
of the form <tt>GLEW_{extension_name}</tt>:
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
if (GLEW_ARB_vertex_program)
kusano 7d535a
{
kusano 7d535a
  /* It is safe to use the ARB_vertex_program extension here. */
kusano 7d535a
  glGenProgramsARB(...);
kusano 7d535a
}
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
In GLEW 1.0.x, a global structure was used for this task. To ensure
kusano 7d535a
binary compatibility between releases, the struct was replaced with a
kusano 7d535a
set of variables.
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
You can also check for core OpenGL functionality.  For example, to
kusano 7d535a
see if OpenGL 1.3 is supported, do the following:
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
if (GLEW_VERSION_1_3)
kusano 7d535a
{
kusano 7d535a
  /* Yay! OpenGL 1.3 is supported! */
kusano 7d535a
}
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
In general, you can check if <tt>GLEW_{extension_name}</tt> or
kusano 7d535a
<tt>GLEW_VERSION_{version}</tt> is true or false.
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
It is also possible to perform extension checks from string
kusano 7d535a
input. Starting from the 1.3.0 release, use <tt>glewIsSupported</tt>
kusano 7d535a
to check if the required core or extension functionality is
kusano 7d535a
available:
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
if (glewIsSupported("GL_VERSION_1_4  GL_ARB_point_sprite"))
kusano 7d535a
{
kusano 7d535a
  /* Great, we have OpenGL 1.4 + point sprites. */
kusano 7d535a
}
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
For extensions only, <tt>glewGetExtension</tt> provides a slower alternative
kusano 7d535a
(GLEW 1.0.x-1.2.x). Note that in the 1.3.0 release 
kusano 7d535a
<tt>glewGetExtension</tt> was replaced with 
kusano 7d535a
<tt>glewIsSupported</tt>.
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
if (glewGetExtension("GL_ARB_fragment_program"))
kusano 7d535a
{
kusano 7d535a
  /* Looks like ARB_fragment_program is supported. */
kusano 7d535a
}
kusano 7d535a

kusano 7d535a
kusano 7d535a

Experimental Drivers

kusano 7d535a
kusano 7d535a

kusano 7d535a
GLEW obtains information on the supported extensions from the graphics
kusano 7d535a
driver.  Experimental or pre-release drivers, however, might not
kusano 7d535a
report every available extension through the standard mechanism, in
kusano 7d535a
which case GLEW will report it unsupported.  To circumvent this
kusano 7d535a
situation, the <tt>glewExperimental</tt> global switch can be turned
kusano 7d535a
on by setting it to <tt>GL_TRUE</tt> before calling
kusano 7d535a
<tt>glewInit()</tt>, which ensures that all extensions with valid
kusano 7d535a
entry points will be exposed.
kusano 7d535a

kusano 7d535a
kusano 7d535a

Platform Specific Extensions

kusano 7d535a
kusano 7d535a

kusano 7d535a
Platform specific extensions are separated into two header files:
kusano 7d535a
<tt>wglew.h</tt> and <tt>glxew.h</tt>, which define the available
kusano 7d535a
<tt>WGL</tt> and <tt>GLX</tt> extensions.  To determine if a certain
kusano 7d535a
extension is supported, query <tt>WGLEW_{extension name}</tt> or
kusano 7d535a
<tt>GLXEW_{extension_name}</tt>.  For example:
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
#include <GL/wglew.h>
kusano 7d535a

kusano 7d535a
if (WGLEW_ARB_pbuffer)
kusano 7d535a
{
kusano 7d535a
  /* OK, we can use pbuffers. */
kusano 7d535a
}
kusano 7d535a
else
kusano 7d535a
{
kusano 7d535a
  /* Sorry, pbuffers will not work on this platform. */
kusano 7d535a
}
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
Alternatively, use <tt>wglewIsSupported</tt> or
kusano 7d535a
<tt>glxewIsSupported</tt> to check for extensions from a string:
kusano 7d535a

kusano 7d535a
kusano 7d535a

kusano 7d535a
if (wglewIsSupported("WGL_ARB_pbuffer"))
kusano 7d535a
{
kusano 7d535a
  /* OK, we can use pbuffers. */
kusano 7d535a
}
kusano 7d535a

kusano 7d535a
kusano 7d535a

Utilities

kusano 7d535a
kusano 7d535a

kusano 7d535a
GLEW provides two command-line utilities: one for creating a list of
kusano 7d535a
available extensions and visuals; and another for verifying extension
kusano 7d535a
entry points.
kusano 7d535a

kusano 7d535a
kusano 7d535a

visualinfo: extensions and visuals

kusano 7d535a
kusano 7d535a

kusano 7d535a
<tt>visualinfo</tt> is an extended version of <tt>glxinfo</tt>. The
kusano 7d535a
Windows version creates a file called <tt>visualinfo.txt</tt>, which
kusano 7d535a
contains a list of available OpenGL, WGL, and GLU extensions as well
kusano 7d535a
as a table of visuals aka. pixel formats. Pbuffer and MRT capable
kusano 7d535a
visuals are also included. For additional usage information, type
kusano 7d535a
<tt>visualinfo -h</tt>.
kusano 7d535a

kusano 7d535a
kusano 7d535a

glewinfo: extension verification utility

kusano 7d535a
kusano 7d535a

kusano 7d535a
<tt>glewinfo</tt> allows you to verify the entry points for the
kusano 7d535a
extensions supported on your platform. The Windows version
kusano 7d535a
reports the results to a text file called <tt>glewinfo.txt</tt>. The
kusano 7d535a
Unix version prints the results to <tt>stdout</tt>.
kusano 7d535a

kusano 7d535a
kusano 7d535a

Windows usage:

kusano 7d535a
 
glewinfo [-pf <id>]
kusano 7d535a
kusano 7d535a

where <tt><id></tt> is the pixel format id for which the

kusano 7d535a
capabilities are displayed.

kusano 7d535a
kusano 7d535a

Unix usage:

kusano 7d535a
glewinfo [-display <dpy>] [-visual <id>]
kusano 7d535a
kusano 7d535a

where <tt><dpy></tt> is the X11 display and <tt><id></tt> is

kusano 7d535a
the visual id for which the capabilities are displayed.

kusano 7d535a