mirror of
https://github.com/nigels-com/glew.git
synced 2024-11-11 16:53:49 +00:00
181 lines
5.1 KiB
HTML
181 lines
5.1 KiB
HTML
|
<h2>Initializing GLEW</h2>
|
||
|
<p>
|
||
|
First you need to create a valid OpenGL rendering context and call
|
||
|
<tt>glewInit()</tt> to initialize the extension entry points. If
|
||
|
<tt>glewInit()</tt> returns <tt>GLEW_OK</tt>, the initialization
|
||
|
succeeded and you can use the available extensions as well as core
|
||
|
OpenGL functionality. For example:
|
||
|
</p>
|
||
|
|
||
|
<p class="pre">
|
||
|
#include <GL/glew.h><br>
|
||
|
#include <GL/glut.h><br>
|
||
|
...<br>
|
||
|
glutInit(&argc, argv);<br>
|
||
|
glutCreateWindow("GLEW Test");<br>
|
||
|
GLenum err = glewInit();<br>
|
||
|
if (GLEW_OK != err)<br>
|
||
|
{<br>
|
||
|
/* Problem: glewInit failed, something is seriously wrong. */<br>
|
||
|
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));<br>
|
||
|
...<br>
|
||
|
}<br>
|
||
|
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));<br>
|
||
|
</p>
|
||
|
|
||
|
<h2>Checking for Extensions</h2>
|
||
|
|
||
|
<p>
|
||
|
Starting from GLEW 1.1.0, you can find out if a particular extension
|
||
|
is available on your platform by querying globally defined variables
|
||
|
of the form <tt>GLEW_{extension_name}</tt>:
|
||
|
</p>
|
||
|
|
||
|
<p class="pre">
|
||
|
if (GLEW_ARB_vertex_program)<br>
|
||
|
{<br>
|
||
|
/* It is safe to use the ARB_vertex_program extension here. */<br>
|
||
|
glGenProgramsARB(...);<br>
|
||
|
}<br>
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
|
<b>In GLEW 1.0.x, a global structure was used for this task. To ensure
|
||
|
binary compatibility between releases, the struct was replaced with a
|
||
|
set of variables.</b>
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
|
You can also check for core OpenGL functionality. For example, to
|
||
|
see if OpenGL 1.3 is supported, do the following:
|
||
|
</p>
|
||
|
|
||
|
<p class="pre">
|
||
|
if (GLEW_VERSION_1_3)<br>
|
||
|
{<br>
|
||
|
/* Yay! OpenGL 1.3 is supported! */<br>
|
||
|
}<br>
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
|
In general, you can check if <tt>GLEW_{extension_name}</tt> or
|
||
|
<tt>GLEW_VERSION_{version}</tt> is true or false.
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
|
It is also possible to perform extension checks from string
|
||
|
input. Starting from the 1.3.0 release, use <tt>glewIsSupported</tt>
|
||
|
to check if the required core or extension functionality is
|
||
|
available:
|
||
|
</p>
|
||
|
|
||
|
<p class="pre">
|
||
|
if (glewIsSupported("GL_VERSION_1_4 GL_ARB_point_sprite"))<br>
|
||
|
{<br>
|
||
|
/* Great, we have OpenGL 1.4 + point sprites. */<br>
|
||
|
}<br>
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
|
For extensions only, <tt>glewGetExtension</tt> provides a slower alternative
|
||
|
(GLEW 1.0.x-1.2.x). <b>Note that in the 1.3.0 release </b>
|
||
|
<tt>glewGetExtension</tt> <b>was replaced with </b>
|
||
|
<tt>glewIsSupported</tt>.
|
||
|
</p>
|
||
|
|
||
|
<p class="pre">
|
||
|
if (glewGetExtension("GL_ARB_fragment_program"))<br>
|
||
|
{<br>
|
||
|
/* Looks like ARB_fragment_program is supported. */<br>
|
||
|
}<br>
|
||
|
</p>
|
||
|
|
||
|
<h2>Experimental Drivers</h2>
|
||
|
|
||
|
<p>
|
||
|
GLEW obtains information on the supported extensions from the graphics
|
||
|
driver. Experimental or pre-release 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 <tt>glewExperimental</tt> global switch can be turned
|
||
|
on by setting it to <tt>GL_TRUE</tt> before calling
|
||
|
<tt>glewInit()</tt>, which ensures that all extensions with valid
|
||
|
entry points will be exposed.
|
||
|
</p>
|
||
|
|
||
|
<h2>Platform Specific Extensions</h2>
|
||
|
|
||
|
<p>
|
||
|
Platform specific extensions are separated into two header files:
|
||
|
<tt>wglew.h</tt> and <tt>glxew.h</tt>, which define the available
|
||
|
<tt>WGL</tt> and <tt>GLX</tt> extensions. To determine if a certain
|
||
|
extension is supported, query <tt>WGLEW_{extension name}</tt> or
|
||
|
<tt>GLXEW_{extension_name}</tt>. For example:
|
||
|
</p>
|
||
|
|
||
|
<p class="pre">
|
||
|
#include <GL/wglew.h><br>
|
||
|
<br>
|
||
|
if (WGLEW_ARB_pbuffer)<br>
|
||
|
{<br>
|
||
|
/* OK, we can use pbuffers. */<br>
|
||
|
}<br>
|
||
|
else<br>
|
||
|
{<br>
|
||
|
/* Sorry, pbuffers will not work on this platform. */<br>
|
||
|
}<br>
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
|
Alternatively, use <tt>wglewIsSupported</tt> or
|
||
|
<tt>glxewIsSupported</tt> to check for extensions from a string:
|
||
|
</p>
|
||
|
|
||
|
<p class="pre">
|
||
|
if (wglewIsSupported("WGL_ARB_pbuffer"))<br>
|
||
|
{<br>
|
||
|
/* OK, we can use pbuffers. */<br>
|
||
|
}<br>
|
||
|
</p>
|
||
|
|
||
|
<h2>Utilities</h2>
|
||
|
|
||
|
<p>
|
||
|
GLEW provides two command-line utilities: one for creating a list of
|
||
|
available extensions and visuals; and another for verifying extension
|
||
|
entry points.
|
||
|
</p>
|
||
|
|
||
|
<h3>visualinfo: extensions and visuals</h3>
|
||
|
|
||
|
<p>
|
||
|
<tt>visualinfo</tt> is an extended version of <tt>glxinfo</tt>. The
|
||
|
Windows version creates a file called <tt>visualinfo.txt</tt>, which
|
||
|
contains a list of available OpenGL, WGL, and GLU extensions as well
|
||
|
as a table of visuals aka. pixel formats. Pbuffer and MRT capable
|
||
|
visuals are also included. For additional usage information, type
|
||
|
<tt>visualinfo -h</tt>.
|
||
|
</p>
|
||
|
|
||
|
<h3>glewinfo: extension verification utility</h3>
|
||
|
|
||
|
<p>
|
||
|
<tt>glewinfo</tt> allows you to verify the entry points for the
|
||
|
extensions supported on your platform. The Windows version
|
||
|
reports the results to a text file called <tt>glewinfo.txt</tt>. The
|
||
|
Unix version prints the results to <tt>stdout</tt>.
|
||
|
</p>
|
||
|
|
||
|
<p>Windows usage:</p>
|
||
|
<blockquote><pre>glewinfo [-pf <id>]</pre></blockquote>
|
||
|
|
||
|
<p>where <tt><id></tt> is the pixel format id for which the
|
||
|
capabilities are displayed.</p>
|
||
|
|
||
|
<p>Unix usage:</p>
|
||
|
<blockquote><pre>glewinfo [-display <dpy>] [-visual <id>]</pre></blockquote>
|
||
|
|
||
|
<p>where <tt><dpy></tt> is the X11 display and <tt><id></tt> is
|
||
|
the visual id for which the capabilities are displayed.</p>
|
||
|
|