Using OpenGL extensions with GLEW and Lua

The GLEW library handles the correct mapping of the OpenGL function's entry points. This way you won't have issues with calling nonexistent extension functions if that extension is not available on the current system.

Getting ready

Support for the GLEW library is included in the OpenGL wrapper module called GL. First, you need to include this library in the Lua environment with the following code:

local gl = require 'luagl'

The GLEW library is initialized with the call of the gl.InitGLEW function.

How to do it…

With the GLEW library initialized, you are able to query for the presence of the specified extension or the OpenGL version. To do this, you'll need to call the gl.IsSupported function. The only parameter of this function is an extension name or the GL_VERSION_{version} string. This function also accepts more than one string parameter delimited with space. It will return true if such a combination is supported on the current system, otherwise it will return false.

Let's take a look at how to determine whether your system supports point sprites:

local point_sprites_supported = gl.IsSupported("GL_VERSION_1_4 GL_ARB_point_sprite")

This is how you would determine whether there's support for the vertex program:

local vertex_shader_supported = gl.IsSupported("GL_ARB_vertex_shader")

Now, you can safely call functions that handle vertex shader programs.

How it works…

The GLEW library scans all the available extensions on initialization and makes appropriate dynamic bindings to OpenGL extension-specific functions. Without GLEW, this was usually done with the xxxGetProcAddress function that returns the function address. The three-letter prefix xxx is replaced with either wgl or glx, depending on the platform.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.69.199