Tag Archives: cpp

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

For vs For Each

I’ve been curious for a while now about the performance of the MS for each C++ extension compared to the traditional for loop. So a couple of weeks ago I dug up and old performance testing framework I’d put together and found out for myself.

The Framework works by running a specified piece of code (using a function pointer) a specified number of times. It uses Microsoft’s Query Performance Counter (QPC) to time the code each run and reports the average time as well as some other stats. I used it to run a number of different For and For each loops on the same data/container to see which one performs best. A reset function can be specified and used to reset data between each test run. The Full framework used can be found Here. Continue reading For vs For Each