| 1 |
================================================================================ |
|---|
| 2 |
DerelictGL |
|---|
| 3 |
================================================================================ |
|---|
| 4 |
DerelictGL is a D package which allows you to use OpenGL in your D programs |
|---|
| 5 |
without the need to link to an import library. This gives you control over how |
|---|
| 6 |
to handle the case where the OpenGL shared library is not available on the |
|---|
| 7 |
user's machine. DerelictGL also exposes all avaialable core OpenGL functions |
|---|
| 8 |
and extensions up to version 1.5 through Joel Anderson's port of Ben Woodhouse's |
|---|
| 9 |
GL Easy Extensions (GLee) library. |
|---|
| 10 |
|
|---|
| 11 |
Please note that the Linux version is not yet implemented. Anyone who would like |
|---|
| 12 |
to do so please let me know in the forum! |
|---|
| 13 |
|
|---|
| 14 |
-------------------------------------------------------------------------------- |
|---|
| 15 |
USING |
|---|
| 16 |
-------------------------------------------------------------------------------- |
|---|
| 17 |
You can use DerelictGL in your project by first adding the Derelict source path |
|---|
| 18 |
to your compile command line with the -I switch (-I<derelict_dir>/DerelictGL) and |
|---|
| 19 |
either by adding all the source/obj files to your makefile, or by building and |
|---|
| 20 |
linking with derelictGL.lib (see the section entitled 'BUILDING' below for build |
|---|
| 21 |
instructions). |
|---|
| 22 |
|
|---|
| 23 |
If you link to derelictGL.lib or the glee.d object file (one of which you must |
|---|
| 24 |
do to make use of extensions), then you need to also use the supplied go.bat |
|---|
| 25 |
file to build glee.lib with DMC and link with it as well. If you do not need |
|---|
| 26 |
OpenGL functionality beyond version 1.1 *and* have no need for extensions, then |
|---|
| 27 |
simply compile and link gl.d as part of your project and ignore glee.d and |
|---|
| 28 |
the lib files. |
|---|
| 29 |
|
|---|
| 30 |
In your code, you need to import the derelict.opengl.gl module. To make use |
|---|
| 31 |
of extensions, import glee; |
|---|
| 32 |
|
|---|
| 33 |
++++++++++++++++++++++++++ CODE +++++++++++++++++++++++++++++++++++++++++++++ |
|---|
| 34 |
|
|---|
| 35 |
import derelict.opengl.gl; // core GL 1.1 functions |
|---|
| 36 |
import glee; // Core GL functions up to 1.5 plus extensions |
|---|
| 37 |
|
|---|
| 38 |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|---|
| 39 |
|
|---|
| 40 |
During initialization of your application, you need to make a call to |
|---|
| 41 |
dglLoad. This will load the shared library, platform-specific core gl functions |
|---|
| 42 |
(such as the wgl* functions on Windows), and all core GL 1.1 functions. If |
|---|
| 43 |
you only require OpenGL 1.1, then you are finished initializing DerelictGL and |
|---|
| 44 |
can go on about your business. |
|---|
| 45 |
|
|---|
| 46 |
If you require the functionality of OpenGL 1.2+ or any extensions, then you'll |
|---|
| 47 |
need to make a call to GLeeInit. The catch is that you must first create |
|---|
| 48 |
and activate an OpenGL context (if you aren't sure what I'm talking about, take |
|---|
| 49 |
a gander at the nehe.gamedev.net OpenGL tutorials). OpenGL requires that a GL |
|---|
| 50 |
context be active before querying for extensions. This is why dglLoad only loads |
|---|
| 51 |
the core 1.1 functions. Once your context is activated, calling GLeeInit |
|---|
| 52 |
will load all available core OpenGL 1.5 functions as well as all available |
|---|
| 53 |
extensions. |
|---|
| 54 |
|
|---|
| 55 |
++++++++++++++++++++++++++ CODE +++++++++++++++++++++++++++++++++++++++++++++ |
|---|
| 56 |
|
|---|
| 57 |
// load the shared library and Core 1.1 functions via DerelictGL |
|---|
| 58 |
dglLoad(); |
|---|
| 59 |
|
|---|
| 60 |
// app-specific code to init an OpenGL context goes here |
|---|
| 61 |
... |
|---|
| 62 |
|
|---|
| 63 |
// load extensions via GLee |
|---|
| 64 |
GLeeInit(); |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|---|
| 68 |
|
|---|
| 69 |
Once the extensions are loaded, you can query for the availability of those |
|---|
| 70 |
you need via GLee's extension flags. These take the same form as the extension |
|---|
| 71 |
names, except that the 'GL_' in the names is replaced with 'GLEE_'. So, for |
|---|
| 72 |
example, GL_ARB_vertex_program becomes GLEE_ARB_vertex_program. |
|---|
| 73 |
|
|---|
| 74 |
Platform-specific extensions, such as the 'WGL_' extensions, follow a different |
|---|
| 75 |
naming convention in that 'GLEE_' is prefixed to the extension name such that |
|---|
| 76 |
WGL_ARB_buffer_region becomes GLEE_WGL_ARB_buffer_region. |
|---|
| 77 |
|
|---|
| 78 |
And finally, variables for querying the version of OpenGL available beyond 1.1 |
|---|
| 79 |
take the form of 'GLEE_VERSION_(major)_(minor)', such as 'GLEE_VERSION_1_2'. |
|---|
| 80 |
|
|---|
| 81 |
The query variables will be set to 0 if the extension or version is unavailable. |
|---|
| 82 |
|
|---|
| 83 |
++++++++++++++++++++++++++ CODE +++++++++++++++++++++++++++++++++++++++++++++ |
|---|
| 84 |
|
|---|
| 85 |
// querying for specific GL versions |
|---|
| 86 |
if(GLEE_VERSION_1_5) |
|---|
| 87 |
// do GL 1.5 stuff |
|---|
| 88 |
else if(GLEE_VERSION_1_4) |
|---|
| 89 |
// do GL 1.4 stuff |
|---|
| 90 |
|
|---|
| 91 |
// querying for specific extensions |
|---|
| 92 |
if(GLEE_ARB_vertex_program) |
|---|
| 93 |
... |
|---|
| 94 |
|
|---|
| 95 |
if(GLEE_EXT_abgr) |
|---|
| 96 |
... |
|---|
| 97 |
|
|---|
| 98 |
if(GLEE_WGL_ARB_pbuffer) |
|---|
| 99 |
... |
|---|
| 100 |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|---|
| 101 |
|
|---|
| 102 |
If you need to get the actual version/extension strings (or any other gl strings, |
|---|
| 103 |
such as the vendor string) you can use glGetString as normal. Note, however, that |
|---|
| 104 |
GLee provides some convenience functions which can be used to get standard and |
|---|
| 105 |
platform-specific extension, as well as error, strings: |
|---|
| 106 |
|
|---|
| 107 |
GLeeGetExtStrGL(); |
|---|
| 108 |
GLeeGetExtStrWGL(); // windows |
|---|
| 109 |
GLeeGetExtStrGLX(); // linux |
|---|
| 110 |
GLeeGetErrorString() |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
-------------------------------------------------------------------------------- |
|---|
| 114 |
BUILDING |
|---|
| 115 |
-------------------------------------------------------------------------------- |
|---|
| 116 |
|
|---|
| 117 |
To build DerelictGL on Windows: |
|---|
| 118 |
|
|---|
| 119 |
1) ensure that both dmd\bin and dm\bin are on your path |
|---|
| 120 |
2) from a command prompt, cd to <derelict_dir>\src\derelict\opengl |
|---|
| 121 |
3) type 'make' or 'make lib' to build derelictGL.lib |
|---|
| 122 |
4) optionally type 'make clean' to delete all object files OR |
|---|
| 123 |
optionally type 'make cleanall' to delete all object, lib and bak files |
|---|
| 124 |
5) run go.bat to build the C library glee.lib - this only need be done once but |
|---|
| 125 |
is required to make use of GLee. |
|---|