Lambdas: What are they and When to use them!

I’ve always know that Lambdas existed and had some idea as to what they were (inline functions right?); but I never really bothered to learn how to use them (and the few times I came across them i had no idea what I was looking at). It wasn’t until recently, while reading about the new c++11 features, that I finally came to understand what they are and how to use them.  With my more recent discovery that (unlike most new c++11 features) they can be used in Visual Studio 2010 I thought I’d share my new insight.

Because it took me a while to get my head around them I’ve tried to make this explanation as simple as possible so a relative newcomer to c++ can understand them. However I will point out that if you don’t know what function pointers are and how to use them your going to struggle with the lambdas.

Continue reading Lambdas: What are they and When to use them!

Advertisements

Tutorial: Multiple Windows with GLFW3 and GLEW MX

Introduction

I recently wrote a short demo program on how to setup a Multi-window Multi-context OpenGL demo using GLFW3. I thought I’d write a tutorial on how to setup this demo for yourself.

The tutorial is specific to MS Visual Studio 2012, however all the code and 3rd party libs are platform independent, so it shouldn’t be hard to port this to Mac/Linux.

The full source code is available here.

Update: Full source code for Visual Studio 2013 can be found here.

Background

GLFW3, the successor to the popular GLFW2 cross-platform window management framework is nearing release. Update: GLFW3 was release some time ago now. Among it’s new features is support for multiple windows (each with a separate OpenGL context). Seeing this i decided to give it a go.

The Goal is to draw the same scene to two different windows, giving each window a separate camera so they can see the scene from different angles.  for the demo we’ll use a simple rotating quad as the “scene”.

Using multiple windows involves solving several challenges, including:

  • Tracking which OpenGL Context is active.
  • Sharing Data between the different OpenGl Contexts (and therefor Window).
  • Being able to re-size each window individually and have the correct OpenGL Context update.
  • Closing windows at any time.

Continue reading Tutorial: Multiple Windows with GLFW3 and GLEW MX

OpenGL Multi-Window, Multi-Context Demo

 

A demo of a small demo I created showing off multiple OpenGL windows, each with its own context. Note that the lag is because I was recording it, normally it runs just fine.

The demo was created using GLFW3, GLEW (compiled with the GLEW_MX directive) and GLM. You can see the full code here.

I tried multi-threading the demo but the frame rate dropped to around 60 fps from what is shown in the video, it also caused the Nvidia drivers to crash.

See here for some general information on using multiple OpenGL contexts.