You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.1KB

  1. <h2>Initializing GLEW</h2>
  2. <p>
  3. First you need to create a valid OpenGL rendering context and call
  4. <tt>glewInit()</tt> to initialize the extension entry points. If
  5. <tt>glewInit()</tt> returns <tt>GLEW_OK</tt>, the initialization
  6. succeeded and you can use the available extensions as well as core
  7. OpenGL functionality. For example:
  8. </p>
  9. <p class="pre">
  10. #include &lt;GL/glew.h&gt;<br>
  11. #include &lt;GL/glut.h&gt;<br>
  12. ...<br>
  13. glutInit(&amp;argc, argv);<br>
  14. glutCreateWindow("GLEW Test");<br>
  15. GLenum err = glewInit();<br>
  16. if (GLEW_OK != err)<br>
  17. {<br>
  18. &nbsp;&nbsp;/* Problem: glewInit failed, something is seriously wrong. */<br>
  19. &nbsp;&nbsp;fprintf(stderr, "Error: %s\n", glewGetErrorString(err));<br>
  20. &nbsp;&nbsp;...<br>
  21. }<br>
  22. fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));<br>
  23. </p>
  24. <h2>Checking for Extensions</h2>
  25. <p>
  26. Starting from GLEW 1.1.0, you can find out if a particular extension
  27. is available on your platform by querying globally defined variables
  28. of the form <tt>GLEW_{extension_name}</tt>:
  29. </p>
  30. <p class="pre">
  31. if (GLEW_ARB_vertex_program)<br>
  32. {<br>
  33. &nbsp;&nbsp;/* It is safe to use the ARB_vertex_program extension here. */<br>
  34. &nbsp;&nbsp;glGenProgramsARB(...);<br>
  35. }<br>
  36. </p>
  37. <p>
  38. <b>In GLEW 1.0.x, a global structure was used for this task. To ensure
  39. binary compatibility between releases, the struct was replaced with a
  40. set of variables.</b>
  41. </p>
  42. <p>
  43. You can also check for core OpenGL functionality. For example, to
  44. see if OpenGL 1.3 is supported, do the following:
  45. </p>
  46. <p class="pre">
  47. if (GLEW_VERSION_1_3)<br>
  48. {<br>
  49. &nbsp;&nbsp;/* Yay! OpenGL 1.3 is supported! */<br>
  50. }<br>
  51. </p>
  52. <p>
  53. In general, you can check if <tt>GLEW_{extension_name}</tt> or
  54. <tt>GLEW_VERSION_{version}</tt> is true or false.
  55. </p>
  56. <p>
  57. It is also possible to perform extension checks from string
  58. input. Starting from the 1.3.0 release, use <tt>glewIsSupported</tt>
  59. to check if the required core or extension functionality is
  60. available:
  61. </p>
  62. <p class="pre">
  63. if (glewIsSupported("GL_VERSION_1_4&nbsp;&nbsp;GL_ARB_point_sprite"))<br>
  64. {<br>
  65. &nbsp;&nbsp;/* Great, we have OpenGL 1.4 + point sprites. */<br>
  66. }<br>
  67. </p>
  68. <p>
  69. For extensions only, <tt>glewGetExtension</tt> provides a slower alternative
  70. (GLEW 1.0.x-1.2.x). <b>Note that in the 1.3.0 release </b>
  71. <tt>glewGetExtension</tt> <b>was replaced with </b>
  72. <tt>glewIsSupported</tt>.
  73. </p>
  74. <p class="pre">
  75. if (glewGetExtension("GL_ARB_fragment_program"))<br>
  76. {<br>
  77. &nbsp;&nbsp;/* Looks like ARB_fragment_program is supported. */<br>
  78. }<br>
  79. </p>
  80. <h2>Experimental Drivers</h2>
  81. <p>
  82. GLEW obtains information on the supported extensions from the graphics
  83. driver. Experimental or pre-release drivers, however, might not
  84. report every available extension through the standard mechanism, in
  85. which case GLEW will report it unsupported. To circumvent this
  86. situation, the <tt>glewExperimental</tt> global switch can be turned
  87. on by setting it to <tt>GL_TRUE</tt> before calling
  88. <tt>glewInit()</tt>, which ensures that all extensions with valid
  89. entry points will be exposed.
  90. </p>
  91. <h2>Platform Specific Extensions</h2>
  92. <p>
  93. Platform specific extensions are separated into two header files:
  94. <tt>wglew.h</tt> and <tt>glxew.h</tt>, which define the available
  95. <tt>WGL</tt> and <tt>GLX</tt> extensions. To determine if a certain
  96. extension is supported, query <tt>WGLEW_{extension name}</tt> or
  97. <tt>GLXEW_{extension_name}</tt>. For example:
  98. </p>
  99. <p class="pre">
  100. #include &lt;GL/wglew.h&gt;<br>
  101. <br>
  102. if (WGLEW_ARB_pbuffer)<br>
  103. {<br>
  104. &nbsp;&nbsp;/* OK, we can use pbuffers. */<br>
  105. }<br>
  106. else<br>
  107. {<br>
  108. &nbsp;&nbsp;/* Sorry, pbuffers will not work on this platform. */<br>
  109. }<br>
  110. </p>
  111. <p>
  112. Alternatively, use <tt>wglewIsSupported</tt> or
  113. <tt>glxewIsSupported</tt> to check for extensions from a string:
  114. </p>
  115. <p class="pre">
  116. if (wglewIsSupported("WGL_ARB_pbuffer"))<br>
  117. {<br>
  118. &nbsp;&nbsp;/* OK, we can use pbuffers. */<br>
  119. }<br>
  120. </p>
  121. <h2>Utilities</h2>
  122. <p>
  123. GLEW provides two command-line utilities: one for creating a list of
  124. available extensions and visuals; and another for verifying extension
  125. entry points.
  126. </p>
  127. <h3>visualinfo: extensions and visuals</h3>
  128. <p>
  129. <tt>visualinfo</tt> is an extended version of <tt>glxinfo</tt>. The
  130. Windows version creates a file called <tt>visualinfo.txt</tt>, which
  131. contains a list of available OpenGL, WGL, and GLU extensions as well
  132. as a table of visuals aka. pixel formats. Pbuffer and MRT capable
  133. visuals are also included. For additional usage information, type
  134. <tt>visualinfo -h</tt>.
  135. </p>
  136. <h3>glewinfo: extension verification utility</h3>
  137. <p>
  138. <tt>glewinfo</tt> allows you to verify the entry points for the
  139. extensions supported on your platform. The Windows version
  140. reports the results to a text file called <tt>glewinfo.txt</tt>. The
  141. Unix version prints the results to <tt>stdout</tt>.
  142. </p>
  143. <p>Windows usage:</p>
  144. <blockquote><pre>glewinfo [-pf &lt;id&gt;]</pre></blockquote>
  145. <p>where <tt>&lt;id&gt;</tt> is the pixel format id for which the
  146. capabilities are displayed.</p>
  147. <p>Unix usage:</p>
  148. <blockquote><pre>glewinfo [-display &lt;dpy&gt;] [-visual &lt;id&gt;]</pre></blockquote>
  149. <p>where <tt>&lt;dpy&gt;</tt> is the X11 display and <tt>&lt;id&gt;</tt> is
  150. the visual id for which the capabilities are displayed.</p>