The source code comes with a VS2012 solution that has two projects:


Based on the Direct2D App (XAML) template in VS2012. This project demonstrates how to use the gl2dx library and how to integrate it with XAML UI elements.


This is the OpenGL wrapper library. The first version supports about 25 OpenGL methods. The rest are commented out in gl2dx/gl.h. If you are using a method that is not supported by gl2dx, then just uncomment it in gl2dx/gl.h and implement it.

The general approach for using gl2dx in your project would be to remove any reference to the opengl32.lib and glu32.lib libraries and change your Additional Include directories in your Project Properties -> C/C++ -> General to point to the gl2dx folder so that your code can include gl2dx's version of the "gl.h" file. You'll also need to add a reference to the gl2dx project. The included DirectXApp is already setup like this, so it would be ideal to just start with that project and extend it to fit your needs.

Initializing gl2dx

Initialization is done by calling gl2dxInit and passing in the ID3D11Device and ID3D11DeviceContext objects. Check the included DirectXApp project to see how to create those DirectX objects. Note that you will have to include gl2dx.h here since that is where the gl2dxInit function is defined.

#include "gl2dx.h"

void Init(ID3D11Device* device, ID3D11DeviceContext* context)
   gl2dxInit(device, context);

Drawing with gl2dx

When using the gl2dx wrapper, you'll need to surround your OpenGL drawing code with a call to gl2dxStartFrame and gl2dxEndFrame. This is another case where you'll have to include "gl2dx.h" since that is where the two functions are defined.

#include "gl2dx.h"

void Draw()

   // OpenGL Drawing code goes here


Last edited Oct 10, 2012 at 9:03 PM by average, version 10


No comments yet.