OpenGL扩展库使用手册《GLEW—The OpenGL Extension Wrangler Library》

来源:互联网 发布:光子脱毛 知乎 编辑:程序博客网 时间:2024/05/18 02:11

初始化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:
  首先,您需要创建一个有效的OpenGL渲染环境(着色描述表),并调用glewInit()来初始化扩展入口点。如果glewInit()返回GLEW_OK,初始化成功,您可以使用可用的扩展以及核心的OpenGL功能。例如:

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

检查扩展

  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 GLEW_{extension_name}:
  从GLEW1.1.0开始,您能够通过查询全局定义的变量,来查明一个特定的扩展在你的平台上是否可用,其形式如GLEW_{extension_name}:

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

  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.
  再GLEW 1.0.x中,这个任务使用了一个全局结构体。为了确保版本之间的二进制兼容性,使用了一组变量来替代结构体。
  You can also check for core OpenGL functionality. For example, to see if OpenGL 1.3 is supported, do the following:
  你也可以检查核心的OpenGL功能。例如,要查看是否支持OpenGL1.3,可以执行以下操作:

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

  In general, you can check if GLEW_{extension_name} or GLEW_VERSION_{version} is true or false.
  通常来说,您可以检查GLEW_{extension_name} 或者 GLEW_VERSION_{version} 是true还是false。
  It is also possible to perform extension checks from string input. Starting from the 1.3.0 release, use glewIsSupported to check if the required core or extension functionality is available:
  还可以从输入的字符串来执行扩展检查。从1.3.0版本开始,使用glewSupported来检查所需要的核心或扩展功能是否可用:

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

  For extensions only, glewGetExtension provides a slower alternative (GLEW 1.0.x-1.2.x). Note that in the 1.3.0 release glewGetExtension was replaced with glewIsSupported.
  仅对于扩展来说,glewGetExtension提供了一种较慢的替代方法(GLEW 1.0.x-1.2.x)。注意,在1.3.0版本中,glewGetExtension被替换为glewIsSupported。

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

试验驱动

  GLEW obtains information on the supported extensions from the graphics driver.
  GLEW从图形驱动程序获取能被支持的扩展的信息。
  Experimental or pre-release drivers, however, might not report every available extension through the standard mechanism, in which case GLEW will report it unsupported.
  然而,试验性或预发布的驱动程序可能不会通过标准机制报告每个可用的扩展,在这种情况下,GLEW将报告它不支持。
  To circumvent this situation, the glewExperimental global switch can be turned on by setting it to GL_TRUE before calling glewInit(), which ensures that all extensions with valid entry points will be exposed.
  为了避免这种情况,可以打开glewExperimental 全局开关,只需要在调用glewInit()之前将其设置为GL_TRUE即可,从而确保所有具有有效入口点的扩展都将被公开。


平台特定的扩展

  Platform specific extensions are separated into two header files: wglew.h and glxew.h, which define the available WGL and GLX extensions.
  平台特定的扩展被分为两个头文件:wglew.h 和 glxew.h,其分别定义了可用的WGL和GLX扩展。
  To determine if a certain extension is supported, query WGLEW_{extension name} or GLXEW_{extension_name}. For example:
  为了确定是否支持某个扩展,查询WGLEW_{extension name} 或者 GLXEW_{extension_name}。例如:

#include <GL/wglew.h>if (WGLEW_ARB_pbuffer){  /* OK, we can use pbuffers. */}else{  /* Sorry, pbuffers will not work on this platform. */}

  
  Alternatively, use wglewIsSupported or glxewIsSupported to check for extensions from a string:
  或者,使用wglewsSupported 或者 glxewIsSupported 从一个字符串来检查扩展:

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

实用工具

  GLEW provides two command-line utilities: one for creating a list of available extensions and visuals; and another for verifying extension entry points.
  GLEW提供了两个命令行实用工具:一个用来创建可用的扩展和可视化的列表;另一个用于验证扩展入口点。
  
visualinfo: extensions and visuals 扩展和可视化  
  visualinfo is an extended version of glxinfo.
  visualinfo 是glxinfo的一个扩展版本。
  The Windows version creates a file called visualinfo.txt, which contains a list of available OpenGL, WGL, and GLU extensions as well as a table of visuals aka. pixel formats.
  Windows版本创建了一个名为visualinfo.txt的文件夹,其包含了一个可用的OpenGL,WGL和OpenGL扩展的列表,还有一个可视化的表格,像素格式。
  Pbuffer and MRT capable visuals are also included. For additional usage information, type visualinfo -h.
  Pbuffer 和 MRT 的视觉效果也包括在内。要获得使用信息,请输入 visualinfo -h;
  
glewinfo: extension verification utility 扩展验证工具  
  glewinfo allows you to verify the entry points for the extensions supported on your platform.
  glewinfo允许您验证平台上支持扩展的入口点。
  The Windows version reports the results to a text file called glewinfo.txt. The Unix version prints the results to stdout.

  Windows usage:

glewinfo [-pf <id>]

where is the pixel format id for which the capabilities are displayed.
其中是显示出的功能的像素格式id。

  Unix usage:

glewinfo [-display <dpy>] [-visual <id>]

where is the X11 display and is the visual id for which the capabilities are displayed.
其中是X11显示,是显示出的功能的可视id。