The OpenGL Extension Wrangler Library | ||||||||||||
|
||||||||||||
Introduction | ||||||||||||
The goal of the OpenGL Extension Wrangler Library (GLEW) is to assist
C/C++ OpenGL developers with two tedious tasks: initializing and
using extensions and writing portable applications. GLEW provides
an efficient run-time mechanism to determine whether a certain
extension is supported by the driver or not. OpenGL core and
extension functionality is exposed via a single header file. GLEW
currently supports the products of two commodity graphics card
vendors, NVIDIA and ATI, on two operating systems, Windows and Linux.
|
||||||||||||
Obtaining GLEW | ||||||||||||
The source and precompiled binaries are available at the project website.
|
||||||||||||
Supported Extensions | ||||||||||||
|
||||||||||||
How to Build Your Project with GLEW | ||||||||||||
There are two ways to build your project with GLEW.
Including the source files / project file The simpler but less flexible way is to include glew.h and glew.c into your project and define the GLEW_STATIC preprocessor constant for the static library or executable you are building together with GLEW. You also need to replace <GL/gl.h> and <GL/glu.h> with <glew.h> and set the appropriate include flag (-I) to tell the compiler where to look for it. For example: Note that if you are using GLEW together with GLUT, you have to include glew.h first. In addition, glew.h includes glu.h, so you don't need to include it separately.#include <glew.h> #include <GL/glut.h> <gl, glu, and glut functionality is available here> On Windows you can also add the supplied project file (glew.dsp or glew.vcproj) to your workspace or solution and compile it together with your other projects. In this case you need to change the GLEW_BUILD preprocessor constant to GLEW_STATIC, otherwise you get build errors. Note that GLEW does not use the C runtime library, so it does not matter which version (single-threaded, multi-threaded or multi-threaded DLL) it is linked with. Using GLEW as a shared library Alternatively, you can use the provided project files / makefile to build a separate shared library you can link your projects with later. In this case the best practice is to install glew.h, glew32.lib, and glew32.dll / libGLEW.so to where the OpenGL equivalents gl.h, opengl32.lib, and opengl32.dll / libGL.so are located. Note that you need administrative privileges to do this. If you do not have administrator access and your system administrator will not do it for you, you can install GLEW into your own lib and include subdirectories and tell the compiler where to find it. Then you can just replace <GL/gl.h> with <GL/glew.h> in your program: or:#include <GL/glew.h> #include <GL/glut.h> <gl, glu, and glut functionality is available here> #include <GL/glew.h> <gl and glu functionality is available here> Don't forget to link your project with glew32.lib, glu32.lib, and opengl32.lib on Windows and libGLEW.so, libGLU.so, and libGL.so on Linux (-lGLEW -lGLU -lGL). It is important to keep in mind that glew.h includes neither windows.h nor gl.h. Also, GLEW will warn you by issuing a preprocessor error in case you have included gl.h, glext.h, or glATI.h before glew.h.
|
||||||||||||
How to Install GLEW | ||||||||||||
To install the shared library version of GLEW you need to copy the headers and libraries into their destination directories. On Windows this boils down to copying (no, we will not write a Windows installer for you).
where {VC Root} is your Visual C++ directory, typically C:/Program Files/Microsoft Visual Studio/VC98 for Visual Studio 6.0 or C:/Program Files/Microsoft Visual Studio/Vc7/PlatformSDK for Visual Studio .NET. However, if you build GLEW with Visual Studio .NET, the project file will automatically install it into these directories, so you don't have to worry about installation at all. On Linux, typing "make install" will attempt to install GLEW into /usr/include/GL and /usr/lib. You can customize the installation target via the GLEW_TARGET environment variable if you do not have write access to these directories.
|
||||||||||||
How to Use GLEW | ||||||||||||
Initializing GLEW
First you need to create a valid OpenGL rendering context and call glewInit() to initialize the extension entry points. If glewInit() returns GLEW_OK the initialization succeeded and you can use the available extensions as well as core OpenGL functionality. For example: #include <GL/glew.h> #include <GL/glut.h> ... glutInit(&argc, argv); glutCreateWindow("GLEW Test"); int err = glewInit(); if (GLEW_OK != err) { /* problem: glewInit failed, something is seriously wrong */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); ... } Querying the available OpenGL extensions To find out if a particular extension is available on your platform, use the globally defined structure glew: You can also check for core OpenGL functionality. For example, to see if OpenGL 1.3 is supported you can use the following:if (glew.ARB_vertex_program) { /* it is safe to use the ARB_vertex_program extension here */ glGenProgramsARB(...); } In general, you can check if glew.{extension_name} or glew.GL_{version} is set or not. For extensions glewGetExtension provides a slower alternative:if (glew.GL_13) { /* Yay! OpenGL 1.3 is supported! */ } if (GL_TRUE == glewGetExtension("GL_ARB_fragment_program")) { /* Looks like ARB_fragment_program is supported. */ } Experimental drivers GLEW works by querying the supported extensions from the graphics driver. Experimental drivers, however, might not report every available extension through the standard mechanism, in which case GLEW will report it unsupported. To circumvent this situation, the glewExperimental global switch can be turned on by setting it to GL_TRUE before calling glewInit(). This makes sure that all extensions with valid entry points will be exposed. Platform specific extensions Platform specific extensions are separated into two header files: wglew.h and glxew.h. These files define the available WGL and GLX extensions as well as the global wglew and glxew structs, which work similarly to the glew structure. To determine if a given WGL or GLX extension is supported, query wglew.{extension name} or glxew.{extension_name}. For example: #include <GL/wglew.h> if (wglew.ARB_pbuffer) { /* OK, we can use pbuffers */ } else { /* Sorry, pbuffers will not work on this platform */ } glewinfo: a command line extension reporting utility GLEW comes with a command line utility called glewinfo that allows you to make a list of the extensions supported on your platform. The glewinfo utility uses GLEW to find out which extensions and entry points are available and reports the results to a text file called glewinfo.txt.
|
||||||||||||
Known Issues | ||||||||||||
GLEW requires GLX 1.2 to assure compatibility with GLUT. In addition,
the SGI GLX video extensions are not supported, because they depend on
external libraries.
Note that according to the WGL documentation you have to initialize the entry points for every rendering context you create. GLEW ignores this requirement, and does not define per context entry points. This means that you need to call glewInit() only once in your program, or more precisely once per process. We have not noticed any problems so far from ignoring the specification.
|
||||||||||||
Credits, Copyright | ||||||||||||
GLEW was developed by Milan Ikits. He also performs occasional
maintainance to make sure that it stays in mint condition. Aaron
Lefohn, Joe Kniss, and Chris Wyman were the first users and also
assisted with the design and debugging process. The acronym
originates from Aaron Lefohn.
GLEW is derived from the EXTGL project by Lev Povalahev. It is licensed under the LGPL, the BSD license, the SGI Free Software License B, and the GLX Public License. We encourage those who are not in favor of the LGPL to read this excellent tutorial. | ||||||||||||
|