Skip to content

Creating a basic project

In this example we will create a simple triangle. The same sample code can be used in any platform.

File organization tree

  • πŸ“‚ engine
    • πŸ“ core
    • πŸ“ libs
    • πŸ“ renders
    • πŸ“ shaders
  • πŸ“‚ platform
    • πŸ“ android
    • πŸ“ apple
    • πŸ“ emscripten
    • πŸ“ glfw
    • πŸ“ sokol
  • πŸ“‚ project (your project here)
    • πŸ“ assets
    • πŸ“‚ lua
      • main.lua
    • main.cpp
  • πŸ“‚ tools
    • πŸ“ bin
    • πŸ“ binshaders
    • πŸ“ shaderlib
  • πŸ“‚ workspaces
    • πŸ“ androidstudio
    • πŸ“ xcode

1. Using C++

In Supernova file tree there is a main.cpp file located in project/ folder. This file is used to start the game development in C++. As you can see, there is a call for supernova.h, that will call init() function when game started.

Edit it with the code:

#include "Supernova.h"
using namespace Supernova;

#include "Polygon.h"

Scene scene;
Polygon triangle(&scene);

void init(){
    triangle.addVertex(0, -100);
    triangle.addVertex(-50, 50);
    triangle.addVertex(50, 50);

    triangle.setPosition(Vector3(300,300,0));
    triangle.setColor(0.6, 0.2, 0.6, 1);

    Engine::setCanvasSize(1000,480);
    Engine::setScene(&scene);
}

2. Using Lua

In Supernova file tree there is a main.lua file located in project/lua/ folder. This file is used to start the game development in Lua. You can call any other Lua files by this.

Edit it with the code:

scene = Scene()
triangle = Polygon(scene)

triangle:addVertex(0, -100)
triangle:addVertex(-50, 50)
triangle:addVertex(Vector3(50, 50,0))

triangle.position = Vector3(300,300,0)
triangle:setColor(0.6, 0.2, 0.6, 1)

Engine.setCanvasSize(1000,480)
Engine.setScene(scene)

Now you can run to see the result.

Warning

If you have both Lua and C++ calling Supernova static method setScene(), the last call will be from C++, so Lua code will not work. Use NO_CPP_INIT or NO_LUA_INIT macro to avoid init to be called.

For example, to build with NO_CPP_INIT:

  • CMake: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DNO_CPP_INIT=1 -G "Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX:PATH=instdir
  • Build tool: python3 supernova.py --build --platform windows --no-cpp-init

See Building for more.

3. Running the Project

Considering you have built and installed the project, you can run it by going to instdir/bin and opening the executable there.

After you make changes to the code, you have to build and install it again.