Simple Game Graphics Library  1.0
Building your Project with SGG

Windows (Visual Studio 2019)

You can choose to develop your project in Visual Studio or through the command line. Keep in mind that the library is only provided for 64 bit systems. All the steps below assume the x64 Visual Studio configuration.

Setting up a Visual Studio project that uses SGG

There are 3 important things that a project requires in order to use SGG.

  • At compile time, it needs to know where to find the graphics.h and scancodes.h which contain the API of the SGG library.
  • At compile time, it needs to know where it can find the sgg.lib or sggd.lib that contain the implementation of the API.
  • At runtime it needs to have the dynamically linked library dependencies (.dll) in the same directory as the executable file in order to be able to load them successfully.

Let's create a Visual Studio project with a sample project that uses SGG. Let's call it Demo.

1) We create an Empty Project. We save the solution in whichever place on our computer we want. Visual Studio initially uses the same name for both the Solution and the Project. By default, Visual Studio creates a Demo directory for our solution and within it, a Demo directory for our Project.

2) We add to the Demo project a source file that will hold the main function. Let's call it Main.cpp. Copy the code provided in A Simple Example to Main.cpp.

3) It's time to properly setup the dependencies.

3.1) In our Solution Directory (Demo), create two folders, include and lib.

include will hold the header files for SGG and lib the sgg library.

3.2) From the sgg folder in the downloaded files, copy graphics.h and scancodes.h into the include folder of our Solution.

3.3) Similarly, copy all the files from the lib folder that was created when we built the SGG library (Building SGG) to the lib folder in our Solution directory.

3.4) Right click on the project and select properties. First, we set the Additional Include Directories, under C/C++ -> General, to have the include path from the solution. This can be done by setting $(SolutionDir)\include.

3.5) Then, for the libraries, under Linker -> General, we set the Additional Library Directories to have the lib path from our solution. This can be done by setting $(SolutionDir)\lib.

3.6) In the Linker -> Input, under Additional Dependencies we must include the name of the SGG library. For the Release configuration we should use sgg.lib and for the Debug configuration we should use sggd.lib. The input should look something like this sgg.lib;kernel32.lib;user32.lib;...

If we try to run our application it will compile successfully but before it starts, it will show an error about failing to find certain .dll files. These are the runtime dependencies we described above.

3.7) After building, our solution directory contains a folder named x64. Inside, there are folders for Debug and Release builds of our project depending on which one we chose. Our application executable is in here and for it to be able to find the required .dlls we need to copy them in here. This needs to be done both for the Release and the Debug folder. Copy all the contents (.dll files) from the 3rdparty\bin folder to both the x64\Release and the x64\Debug folder. Our application will now be able to use them.

3.8) By default when running our program from within Visual Studio, the executable looks for files inside the Project's directory. This can be validated if we go to the properties of our Project and look under Debugging. The working directory is set to $(ProjectDir). This practically means that when our executable tries to open external files (music, pictures, fonts e.t.c.), it will always look relative to this directory. Our sample code expects to find several files within an assets folder. Therefore, our last action is to copy the assets folder into the Project's folder.

After all the above steps, we have correctly configured our Visual Studio Project to use the SGG library. We are ready to develop our game within Visual Studio!

Compiling an application that uses SGG from the command line

First we need to set up the environment for using the MSVC compiler. In a command console, execute the script located in:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat

Execute cl /? to make sure your environment is set up.

After that, we are ready to use the MSVC compiler.

First, we cd to the directory of the SGG library. There, we create a directory named bin that will hold our executable:

mkdir bin

Then, we can build the Release version of the demo application with

cl /EHsc /O2 /MD /Isgg demo/demo.cpp /link /LIBPATH:lib /SUBSYSTEM:CONSOLE /MACHINE:X64 sgg.lib /OUT:bin/demo.exe

and the Debug version of the demo application with

cl /EHsc /Zi /MDd /DEBUG /D"_DEBUG" /Isgg demo/demo.cpp /link /LIBPATH:lib /SUBSYSTEM:CONSOLE /MACHINE:X64 sggd.lib /OUT:bin/demod.exe

The demo requires a few assets(images, sounds, fonts e.t.c.) at runtime which can be founnd in 3rdparty. Manually copy the assets folder to the bin directory so that our executable can find them when it runs.

We also require the dynamically linked libraries for our 3rd party libraries. These can be found in 3rdparty\bin. Copy all the contents(.dll files) of the 3rdparty\bin folder to the bin directory we previously created. Our application will now be able to use them.

Finally to run the program, change directory to bin with:

cd bin

and execute

demo.exe

or

demod.exe

There is also a script named build_demo_x64.bat that automatically executes the above steps for convenience. For your project, feel free to use or customize this build script according to your needs.

Linux (GCC)

The following commands should be executed in the top directory of the downloaded files.

First, create a bin directory that will hold our executable:

mkdir bin

The command to compile the demo sample for Release should look like this:

g++ -O2 -Llib -Isgg demo/demo.cpp -lsgg -lGL -lGLEW -lSDL2 -lSDL2_mixer -lfreetype -o bin/demo

and for Debug

g++ -Og -g -Llib -Isgg demo/demo.cpp -lsggd -lGL -lGLEW -lSDL2 -lSDL2_mixer -lfreetype -o bin/demod

The demo requires a few assets(images, sounds, fonts e.t.c.) at runtime which can be found in 3rdparty. Manually copy the assets folder to the bin directory so that our executable can find it when it runs.

Finally to run the program, change directory to bin with:

cd bin

and execute

./demo

or

./demod

There is also a script named build_demo_x64.sh that automatically executes the above steps for convenience. For your project, feel free to use or customize this build script according to your needs.

The library is very simple to use. The first thing to do is to include the graphics.h header file into your code (see supplementary example code):

#include "graphics.h"

All necessary functions are declared in the "graphics" namespace, so you need to either use the fully qualified function names or add:

using namespace graphics
graphics.h
graphics