Skip to content

Getting Started

Find the project on GitHub here for the source code.

WARNING: blahajEngine is very incomplete and is on pause due to other projects and issues improving the rendering pipeline

blahajEngine Basics:

This engine is designed to be ran on linux first and is made on a linux desktop. What is funny though is the engine preforms better with a windows build ran on wine.

All engine code is made with modern C++ and you will be using lua to make your game but there are some small differences. This engine exposes all engine objects as direct pointers to lua. That means if you miss handle a pointer the engine will crash.

This is by design as I want high level laguage programers to feel my pain of endless segfaults I was kinda stoopid when making this and I should refactor this soon.

The engine uses Vulkan 1.2 for the rendering pipeline and in lua you will have to manually load textures and pipelines with attached vertex and fragment shaders into slots to be attached to game objects with scripts.

Every object takes a separate draw call and instanced rendering is in the works to fix this but every attempt has causes severe epilepsy inducing bugs.

Starting a new project

If you really want to use this engine you can download a release from GitHub and unzip it or follow build instructions.

Put your inage files into the assets folder and open scripts/init.lua and do not remove assets/null.png as this is the default "missing texture" image.

init.lua is a special script file that is executed before everything else on the engine and lets you load the first set of textures and pipelines and other things.

You will want to put everything into the Init() function and as an example this is a minimal setup. The functions will be described in the API reference.

function Init()
    setProgramName(engine, "My Game")
    setTargetFPS(engine, 900000)

    -- addPipeline(engine, pipelineID, vertexShader, fragmentShader)
    addPipeline(engine, 1, "spv/debug.vert.spv", "spv/debug.frag.spv")

    -- addTexture(engine, textureID, texture)
    addTexture(engine, 1, "assets/null.png")

    -- addGameObject(engine, posX, posY, posZ, rotX, rotY, rotZ, scale, pipelineID, textureID, scriptPath)
    addGameObject(engine, 0, 0.6, 0, 0, 0, 0, 0.5, 1, 1, nil)
    addGameObject(engine, 0, 0, 0, 0, 0, 0, 0.1, 1, 1, "scripts/player.lua")
end

This will setup the engine by setting the program name and uncapping FPS and then loading some shaders and textures and spawning an object with the script at scripts/player.lua

You will now want to of course fill in that player script with something. The example projects version has too many extra things on it than you might want for your game so here is an example of a minimal top down 2D character controller that uses WASD

local function normalizeVelocity(velocityX, velocityY)
    local magnitude = math.sqrt(velocityX^2 + velocityY^2)

    if magnitude > 0 then
        velocityX = velocityX / magnitude
        velocityY = velocityY / magnitude
    end

    return velocityX, velocityY
end

local function sign(value)
    if value > 0 then
        return 1
    elseif value < 0 then
        return -1
    else
        return 0
    end
end

function Update()
    if NotFirstRun == nil then
        X = 0
        Y = 0
        NotFirstRun = true
    end

    local speed = 1
    local movementStep = 0.0005
    local velocityX = 0
    local velocityY = 0

    if getKeyPressed(engine, "W") then
        velocityY = velocityY + 1
    end
    if getKeyPressed(engine, "A") then
        velocityX = velocityX - 1
    end
    if getKeyPressed(engine, "S") then
        velocityY = velocityY - 1
    end
    if getKeyPressed(engine, "D") then
        velocityX = velocityX + 1
    end

    velocityX, velocityY = normalizeVelocity(velocityX, velocityY)

    local maxIterations = 100
    X = X + velocityX * speed * delta_time
    moveGameObject(object, X, Y, 2)

    if AABB2D_intersectsAll(engine, object) then
        local iterations = 0
        while AABB2D_intersectsAll(engine, object) do
            X = X - movementStep * sign(velocityX)
            moveGameObject(object, X, Y, 2)
            iterations = iterations + 1
            if iterations >= maxIterations then
                X, Y = 0, 0
                moveGameObject(object, X, Y, 2)
                break
            end
        end
    end

    Y = Y + velocityY * speed * delta_time
    moveGameObject(object, X, Y, 2)

    if AABB2D_intersectsAll(engine, object) then
        local iterations = 0
        while AABB2D_intersectsAll(engine, object) do
            Y = Y - movementStep * sign(velocityY)
            moveGameObject(object, X, Y, 2)
            iterations = iterations + 1
            if iterations >= maxIterations then
                X, Y = 0, 0
                moveGameObject(object, X, Y, 2)
                break
            end
        end
    end

    camLookAtGameObject(engine, object)
end

You should now have a very bare bones minimal blahajEngine project! The engine while limited can still do some funny things.
I have once managed to get a video playing by using ffmpeg to split into a ton of frames and a seperate audio file and then swapping out the textures and objects really fast to play it at 30FPS and call a system audio player to play the audio file in the background

If you make something cool please contact me to let me know and if the engine is missing any features tell me so i can add them!

Build Instructions

You will need the following packages for building on Arch Linux

  • base-devel
  • vulkan-devel
  • glfw
  • glm
  • stb
  • lua

You will need the following packages for building on Windows using msys2/mingw64 (You may also want the LunarG Vulkan SDK)

  • base-devel
  • mingw-w64-x86_64-toolchain
  • mingw-w64-x86_64-vulkan-devel
  • mingw-w64-x86_64-shaderc
  • mingw-w64-x86_64-glfw
  • mingw-w64-x86_64-glm
  • mingw-w64-x86_64-stb
  • mingw-w64-x86_64-lua

With the correct packages installed you can just run make with the included Makefile to compile the program and the shaders