Brenta Engine 1.1
Loading...
Searching...
No Matches
Engine

In this section we will see how to use various features of the engine.

Engine Class

To initialize any subsystem, you can use the Engine class. This is not mandatory, you can initialize and destroy the subsystems manually, but the Engine class provides a nice way to do it.

To create an engine, you can use the Builder class:

.use_screen(true)
.use_audio(true)
.use_input(true)
.use_logger(true)
.use_text(true)
.use_ecs(true)
.set_screen_width(1280)
.set_screen_height(720)
// ...
.build();
Engine builder.
Definition engine.hpp:103
Engine setup.
Definition engine.hpp:61

You can read every option in the brenta::engine::builder class. Let's go through some subsystems.

Input

You can register callback functions for the input. Those functions are called when the specified key is pressed, or the mouse is moved, depending on the callback you register.

auto toggle_wireframe_callback = []() {
auto wireframe = world::get_resource("WireframeResource");
if (wireframe == nullptr) return;
gl::set_poligon_mode(!wireframe->enabled);
wireframe->enabled = !wireframe->enabled;
};
input::add_keyboard_callback(GLFW_KEY_F, toggle_wireframe_callback);

In this example we register a keyboard callback that toggles the wireframe mode when the F key is pressed. You can use Brenta::Input::AddMousePosCallback to register a mouse callback, this ill be called with the x and y position of the mouse.

You can also remove the callbacks with brenta::input::remove_keyboard_callback and brenta::input::remove_mouse_pos_callback.

Audio

The audio subsystem is very simple: there are audio streams and audio files, you can play an audio file on a stream (not more) and stop it, so you need to have multiple streams if you want to play multiple audio files at the same time.

You can load an audio file like so:

audio::load_audio("guitar", "assets/audio/guitar.wav");

We are identifying this audio file with the name guitar.

You can create a stream with the name "music" like so:

audio::create_stream("music");

And finally play the "guitar" audio like so:

sudio::play_audio("guitar", "music");

The subsystem will provide you a default stream named "default" if you don't want to create a stream.

You can Pause and Resume streams with brenta::audio::pause_stream and brenta::audio::resume_stream, set the volume and stop it. You can find the API in Brenta::Audio.

Particles

You can create and customize particles via the brenta::particle_emitter class. All the computation is done in the GPU so the engine can handle lots and lots of particles. Here's a quick look on the API:

particle_emitter emitter = particle_emitter::builder()
.set_starting_position(glm::vec3(0.0f, 0.0f, 5.0f))
.set_starting_velocity(glm::vec3(0.0f, 5.0f, 0.0f))
.set_starting_spread(glm::vec3(10.0f, 10.0f, 10.0f))
.set_starting_time_to_live(0.5f)
.set_num_particles(1000)
.set_spawn_rate(0.01f)
.set_scale(1.0f)
.set_atlas_path(std::filesystem::absolute(
"assets/textures/particle_atlas.png"
).string())
.set_atlas_width(8)
.set_atlas_height(8)
.set_atlas_index(45)
.build();
// Inside the game loop:
emitter.update_particles(time::get_delta_time());
emitter.render_particles();

Logger

Check out oak! The engine uses oak as the logger, you can set the log level and the log file in the engine builder. You can log messages like so:

oak::info("Hello, world!");

Oak has many more advanced features, I suggest you check out the repository.

Text

The brenta::text subsystem allows you to render text on the screen. You can set the font and font size of your text, and render it in the main loop like this:

text::render_text("Hello OpenGL!", x, y, scale, glm::vec3(r, g, b));

More

This is just a small part of the engine, you can find more features in the documentation of the classes. If you want to contribute to the engine, check out Contributing.