Skip to content
Jonah edited this page Jan 17, 2020 · 1 revision

Display

The Display class is where JEngine renders everything to.

Basic Usage

The Display constructor is as follows:

JEngine::Display(int width, int height, std::string title, bool resizeable);

The window won't run on its own just from the constructor, there's a couple more steps

Run the window

The window run function:

void Display::run(std::function<void(Matrix4f)> renderfn, std::function<void(float)> updatefn);

To allow the window to run and render anything, the run function must be called. Two lambda functions need to be created: the render loop, and the update loop. The render loop requires a Matrix which acts as the screen variable, which some render functions require to draw correctly. The update loop has a delta variable, which is the time difference between the current frame and the last one. This allows transforms to apply at a constant speed over time instead of relying on framerate for speed.

Example window code

#include <JEngine/JEngine.h>
#include <JEngine/Graphics/Display.h>

int main()
{
    JEngine::Display window(800, 600, "Title", false);

    auto render = [&](Matrix4f screen) {
        window.clear(128, 128, 128);
        // TODO: render code
    };

    auto update = [&](float delta) {
        // TODO: transform/update code
    };

    window.run(render, update);
    return 0;
}

Other functions

Clone this wiki locally