Brenta Engine 1.0
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:102
Engine setup.
Definition engine.hpp:59

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::GetResource("WireframeResource");
if (wireframe == nullptr) return;
GL::SetPoligonMode(!wireframe->enabled);
wireframe->enabled = !wireframe->enabled;
};
Input::AddkeyboardCallback(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::RemoveKeyboardCallback and Brenta::Input::RemoveMousePosCallback.

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::LoadAudio("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::CreateStream("music");

And finally play the "guitar" audio like so:

Audio::PlayAudio("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::PauseStream and Brenta::Audio::ResumeStream, set the volume and stop it. You can find the API in Brenta::Audio.

Particles

You can create and customize particles via the Brenta::ParticleEmitter 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:

ParticleEmitter emitter = ParticleEmitter::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_timeToLive(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.updateParticles(Time::GetDeltaTime());
emitter.renderParticles();

Logger

The logger is a simple logging system that allows you to log messages with different levels. The levels are:

  • DEBUG
  • INFO
  • WARNING
  • ERROR
  • OUTPUT
  • DISABLED

The logger will only log messages with a level equal or higher than the one you set. You can also set a log file where the messages will be written, the default is ./logs/log.txt.

This is an example on how to log a message:

Brenta::Logger::Log(Brenta::Types::LogLevel::DEBUG, "This is a debug message:
", "hello"); DEBUG("This is a debug message with macro: ", "hello");

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::RenderText("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.