In this post I will be talking about P0267R0: A Proposal to Add 2D Graphics Rendering and Display to C++. This proposal will be discussed next week at the next ISO C++ Standardization meeting in Jacksonville.
P0267R0 comes out of C++’s SG13 HMI: Development of new proposals in selected human-machine interaction such as low-level graphics/pointing I/O primitives.
SG13 was created by Herb Sutter after the One C++ keynote talk he gave at GoingNative 2013.
I started programming twenty years ago in high school. Back then I didn’t even have my own computer Below you have the cover of the book that was used to teach us Turbo Pascal:
Please notice the graphics on the book’s cover. That drawing was presented as an example in the book by the means of Borland Graphics Interface (BGI).
A couple of years ago I had to port a car navigation engine to an Unix-like operating system. The target computer had support for OpenGL ES, the navigation engine could display images on the map, but none of them came with a 2D graphics engine.
I ended up porting Cairo Graphics just to render some text into PNG images, and to rotate a car image on the map.
SG13 also used Cairo Graphics as base for their first proposal - N3888. In the meantime the proposal matured as P0267R0, and the API has changed a bit.
The implementation has Visual C++ project files with pre-compiled binaries for Windows, and autotools support for Linux. This is due to the fact that Cairo Graphics comes from Linux world and they provide a makefile to compile on Windows. Michael McLaughlin has documented his work to build Cairo Graphics for Windows. Shiver.
As it turns out the application code Michael B. McLaughlin used to test the implementation doesn’t compile out of the box. So I decided to write a simple “Hello World” application.
io2d doesn’t have support for PNG graphics files, or other graphics file format for that matter. So I had to come up with something easy. I choose the TGA file format, because one just has to write a 18 bytes header and then dump the raw image bytes. And no, BMP file format is not easy
The code used to save the TGA file is bigger than the code used to render the image
CMakeLists.txt file looks like this:
hello.exe I ended up with
hello.tga which looks like
this when opened with The GIMP:
From Michael Wong’s blog post: C++17 content (a prediction) we can see that Graphics TS is not meant to be included in C++17
I really do hope that SG13’s Graphics TS will be part of C++ sooner than later, because graphics programming is so much fun!