Home > Releases > Simple2D 1.06 now available

Simple2D 1.06 now available

February 18, 2013 Leave a comment Go to comments

The latest version of my Direct2D-based graphics library Simple2D is now available.

The main changes are targeting of Direct2D 1.1 and Direct3D 11.1 (and support of new features provided by these), improvements to geometry and window handling, migration of the library source code to Visual Studio 2012, new demos and a new installer. Run-time support for Windows Vista and compile-time support for Visual Studio 2010 is dropped (although it still compiles with warnings).

IMPORTANT! Uninstall any previous versions of Simple2D you are using first. Simple2D 1.06 introduces a new installer architecture which is not compatible with the previous versions.

System requirements

  • Windows 7 Service Pack 1 with Platform Update for Windows 7
  • Windows Server 2008 R2 Service Pack 1 with Platform Update for Windows 7
  • Windows 8

The installer will download and install Platform Update for Windows 7 for you if you don’t have it already.

Important changes

  • Breaking change: The source code to the main library now targets Visual Studio 2012. It will still compile under Visual Studio 2010 but with warnings.
  • Breaking change: The pre-compiled .lib files included are now statically linked with the Visual C++ run-time library (versions 1.05 and below used dynamic linking). You must re-build your applications using static linking (/MT or /MTd linker arguments) instead of dynamic linking in order for them to link properly (in Visual Studio, right-click your project, choose Properties and navigate to C++ -> Code Generation -> Runtime Library to configure this option).
  • Breaking change: Simple2D now targets Direct2D 1.1 as used in Windows 8 and Windows 7 Service Pack 1 with Platform Update for Windows 7. Windows Vista is no longer supported.
  • Breaking change: LastUpdateTime has been removed. Use LastUpdateTime64, LastFrameTime and PerformanceFrequency to retrieve timing information (see below)
  • Important change: Rendering is no longer tied to v-sync. Frames will now be rendered as fast as the end-user hardware allows.
  • Important change: Simple2D now renders to a Direct3D surface. The behaviour of window re-sizing has changed such that the render target size remains the same and is scaled to the new window client area size.

Improvements and bug fixes


  • Position in an animation can now be changed while it is running (Animation::SetPos)

Images, bitmaps and sprites:

  • You can now create a blank bitmap with Simple2D::MakeEmptyImage(). You can specify the width, height, Direct2D pixel format (D2D1_PIXEL_FORMAT) and Direct2D bitmap creation options (D2D1_BITMAP_OPTIONS). These items are also added to the constructor of ImageObject.
  • ImageObject / Image uses ID2D1Bitmap1 instead of ID2D1Bitmap to allow access to new image-processing features in Direct2D 1.1.
  • Bug fix: ImageObject::DrawPart was not respecting the current render target world transform.


  • New function Geometry::GetIntersectedGeometry returns a path geometry (Geometry) which is the intersection of the geometry object called and the geometry object supplied in the argument, optionally transformed by a specified matrix.
  • The current matrix transform of a geometry can now be retrieved with Geometry::GetTransform().
  • Simple2D::MakeRectangleGeometry is now overloaded to accept a D2D1_RECT_F as its creation argument.
  • Geometry::ContainsPoint is now overloaded to accept float arguments.
  • Geometry::Move is now overloaded to accept float arguments.
  • Bug fix: Creating elliptical and rectangular geometries with Simple2D::MakeEllipseGeometry or Simple2D::MakeRectangleGeometry no longer sets the default transform point to the centre or top-left of the object respectively. This was causing problems with matrix transforms later.
  • Bug fix: Geometry::RotateGeometry::Scale and Geometry::Skew were incorrectly using the un-transformed bounding boxes of the geometry to calculate the transform point instead of the current bounding box.

Helper functions and members:

  • StringToWCHAR helper function added
  • Use of GetTickCount() for frame-rate and performance timing has been dropped in favour of QueryPerformanceCounter(). LastUpdateTime64 stores the count on the last frame update, PerformanceFrequency stores the number of counts per second on the end-user’s processor, and LastFrameTime stores the number of counts taken to process the previous frame.

Window handling:

  • Custom window message processing can now be performed by overriding the new member function OnWindowsMessage() in your derived application class.
  • The application window handle HWND can now be fetched via Simple2D::GetWindow().
  • The application window title can now be changed with Simple2D::SetWindowTitle().
  • Bug fix: Client window now allows standard Windows controls to be rendered on top of the Direct2D surface (they were previously clipped and obscured).

Updates to COM object management:

  • The factory objects exposed by Simple2D are updated as followsDirect2D 1.1 (ID2D1Factory1), DirectWrite 1.1 (IDWriteFactory1), Windows Imaging Component (WIC) 1.2 (IWICImagingFactory2).
  • The following additional COM objects are exposed: Direct3D 11.1 device (Simple2D::Direct3DDevice), Direct3D 11.1 device context (Simple2D::Direct3DContext), Direct2D 1.1 device (Simple2D::Direct2DDevice), DXGI 1.1 swap chain (Simple2D::DXGISwapChain), Direct2D rendering surface (bitmap) linked to DXGI back buffer (Simple2D::Direct2DBackBuffer).

New example applications

NOTE: Starting with Simple2D 1.06, all example applications are statically linked to the Visual C++ run-time library, so you no longer need the Visual C++ Runtime Redistributable Package installed to try the example EXEs if you do not have Visual C++ installed.


Download link (always download the latest version)

Please be aware that Simple2D is very much a work in progress, and that changes from version to version can break older code, although I try to maintain backwards compatibility as much as possible. The code is currently undergoing significant re-factoring with each new version.

I hope you find Simple2D useful!

For setup and installation instructions, follow the Simple2D Installation Tutorial.

Previous version release notes (1.05)

  1. February 21, 2013 at 14:47

    Your framework is good but you do need to put “ValidateRect( hwnd, NULL )” before any call to “DrawScene” (or after, but before is better IMHO). Without “ValidateRect” you have extremelly high CPU comsumption in all your examples.

    • February 21, 2013 at 17:17

      Hi Yury!

      ValidateRect(hwnd, NULL) is called after the call to Simple2D::onRender() (which calls DrawScene()) in the WM_PAINT handler:

      // Render window
      case WM_PAINT:
      ValidateRect(hwnd, NULL);
      result = 0;
      wasHandled = true;

      The CPU usage on my box is 12-13% for the example. If I’ve made a mistake here, please let me know 🙂

      • February 21, 2013 at 18:12

        Yes, your examples show a stable CPU comsumption around 10-20%. Even for rendering a static image like in “MSDN Direct2D Demo”. It’s abnormal, for sure:)
        Today I made my own implementation for a new Direct2D 1.1 and have created the same “Direct2D Demo” on top of it. I have 0% of CPU. Feel free to check: http://www.strozhevsky.com/free_docs/YS_Product_N1.exe

        So, something wrong in your code, please check it. For the moment I am not so acquainted with it 🙂

        • February 21, 2013 at 18:56

          I will check it for sure, have you got the source code to your demo so I can compare?

  2. February 21, 2013 at 19:05

    Hmm, sorry but I can not provide my code – it’s will be a part of commercial software.

    I think that the problem place in your code is Windows messaging handling. That is why I said you about “ValidateRect”. Or, probably, something related to animation (I’ve seen something related to it).

    Maybe I will have a time this weekend to observe your sample code and digg into it. Will see 🙂

    • February 21, 2013 at 19:32

      Yes, my suspicion was right – the problem in your message handling, in this func:

      // Message loop
      void Simple2D::RunMessageLoop()
      MSG msg;

      while (!killbit)
      BOOL process;

      // Stall the message loop if the window is minimized to save CPU time (GetMessage is a blocking function)
      if (ResolutionX != 0 && ResolutionY != 0)
      process = PeekMessage(&msg, 0, 0, 0, PM_REMOVE);
      process = GetMessage(&msg, NULL, 0, 0);

      if (process)

      if (!killbit)

      Here you have “OnRender” without a “ValidateRect”. I have no idea why do you need “OnRender” here 🙂

      • February 21, 2013 at 19:39

        I have changed the func to common:

        while (GetMessage(&msg, NULL, 0, 0))

        if( killbit )

        and everything goes well – 0% CPU 🙂 Please do not play with “PeekMessage” – it is non-waiting function. Or try to insert into “while( killbit){ … Sleep(1); … }”.

        • February 22, 2013 at 02:05

          Okay, I checked the code. The reason it uses PeekMessage() is because the scene needs to be rendered even if no Windows messages have arrived. If you use GetMessage() alone, the client area doesn’t update except as a response to keyboard, mouse input etc. WM_PAINT is only triggered when the window is first opened, or maximized after a minimize, hence the call to OnRender() from two different places.

          What is the frame rate of your example code? The Release build of the MSDN-Direct2D demo on the current version of Simple2D runs at about 3800 fps on my system and consumes 12% CPU when left idle. If you clamp to V-sync then it runs at the expected 60 fps and uses 0-1% CPU. That could be why you are experiencing a difference between your code and mine. Adding ValidateRect() before or after the non-WM_PAINT call to OnRender() has no discernible effect on CPU utilisation.

          In short, I couldn’t find any real problems. It is reasonable for a 3000 fps refresh speed to consume some CPU resources (the next release will have the option to set the V-sync clamping interval, ie. the first parameter to Present1()). The code to ignore rendering when minimized is broken though as ResolutionX and ResolutionY no longer get updated in sync with the visible client area. I will fix that.

  3. February 22, 2013 at 04:45

    My code used to have 0-1 FPS 🙂 Its a static picture, no animations etc. Hence I am re-drawing window only when I do need this. Meantime FPS is 0.
    If you do need to render static picture so many times per second – it’s OK and up to you. IMHO you just need to create a time and decrease FPS to 60 – optimal FPS value which will cause a much less CPU comsumption 🙂

    • February 22, 2013 at 04:46

      Oh, wrong spelling – I meant “…create a timer..”, of course.

      • February 22, 2013 at 07:29

        Of course, and for MSDN’s Direct2D intro demo or a static picture, there is no need to keep re-rendering it. Simple2D operates on the assumption that people will be creating games and animations that will need repeated updates 🙂 As mentioned, I will add the option to clamp the frame rate to the next release 🙂

  1. February 24, 2013 at 02:53
  2. February 24, 2013 at 02:59

Share your thoughts! Note: to post source code, enclose it in [code lang=...] [/code] tags. Valid values for 'lang' are cpp, csharp, xml, javascript, php etc. To post compiler errors or other text that is best read monospaced, use 'text' as the value for lang.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: