JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
other.hpp
Go to the documentation of this file.
1// Copyright 2014-2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Finally.hpp"
8#include "Vec2.hpp"
9
10#include <cstdint>
11#include <sstream>
12#include <string>
13#include <vector>
14
15namespace jngl {
16
18bool running();
19
25
30
35
39bool canQuit();
40
45void quit() noexcept;
46
53void forceQuit(uint8_t exitcode);
54
57
61[[deprecated("Not really intuitive or robust, use your own calculations instead")]] double getFPS();
62
64unsigned int getStepsPerSecond();
65
67float getDelta();
68
70void setStepsPerSecond(unsigned int);
71
75void setAntiAliasing(bool enabled);
76
79
81void setVerticalSync(bool enabled);
82
85
91Finally scissor(Vec2 position, Vec2 size);
92
94void setIcon(const std::string& filename);
95
97void setPrefix(const std::string& path);
98
100std::string getPrefix();
101
103void setConfigPath(const std::string& path);
104
112[[deprecated("use jngl::writeConfig and jngl::readConfig instead")]] std::string getConfigPath();
113
116
120std::vector<std::string> getArgs();
121
123std::stringstream readAsset(const std::string& filename);
124
132std::string readConfig(const std::string& key);
133
140void writeConfig(const std::string& key, const std::string& value);
141
144
146void openURL(const std::string&);
147
149int round(double v);
150
152int round(float v);
153
155int utf8Length(std::string_view);
156
157namespace internal {
158
161
169
170} // namespace internal
171
172} // namespace jngl
Contains jngl::Finally class.
Contains jngl::Vec2 class.
Helper class which calls a function when being destroyed.
Definition Finally.hpp:22
Two-dimensional vector.
Definition Vec2.hpp:36
JNGL's main namespace.
std::string readConfig(const std::string &key)
Read in a configuration value which has been saved under key.
unsigned int getStepsPerSecond()
How many times Work::step is called per second (default: 60)
void clearBackBuffer()
Clears the back buffer and resets the ModelView matrix, see jngl::reset()
void swapBuffers()
Swaps back and front buffer.
void setPrefix(const std::string &path)
Sets a global prefix which will be prepended whenever images or sounds are loaded.
double getFPS()
Calculates FPS if called once per frame.
std::stringstream readAsset(const std::string &filename)
Returns a stringstream containing the whole file. This will read from the .apk on Android.
void cancelQuit()
Undo quit() or ignore a quit event caused by the user closing the main window.
bool canQuit()
Some platforms (e.g.
int round(double v)
Rounds a double to an integer, just like std::lround.
void openURL(const std::string &)
Opens a link (e.g. https://bixense.com) in the browser.
float getDelta()
Time in seconds of a step, i.e. 1 / getStepsPerSecond()
std::string getConfigPath()
void forceQuit(uint8_t exitcode)
Exit main loop with and let the OS process return exitcode.
int utf8Length(std::string_view)
Returns the number of characters in the UTF-8 string.
void writeConfig(const std::string &key, const std::string &value)
Write value into the persistent storage which can be read in again using jngl::readConfig(key)
void setVerticalSync(bool enabled)
Toggles V-SYNC.
bool getVerticalSync()
Returns whether V-SYNC is enabled. Many devices always enable V-SYNC with no way to turn it off.
void setStepsPerSecond(unsigned int)
How many times Work::step should be called per second (default: 60)
bool running()
Returns true until the main window is closed or quit() has been called.
Finally scissor(Vec2 position, Vec2 size)
Enables scissor testing, clipping all rendering to the rectangle from position to position + size in ...
bool getAntiAliasing()
Returns whether MSAA is enabled. If the device doesn't support it, it will always return false.
std::string getPrefix()
Returns the global prefix set by jngl::setPrefix.
std::string getBinaryPath()
Returns the directory of the currently running binary.
std::string getPreferredLanguage()
Returns user preferred language, i.e. "en" for English, "de" for German.
std::vector< std::string > getArgs()
Returns the command line arguments passed to the executable (empty when there are no arguments)
void setConfigPath(const std::string &path)
void quit() noexcept
Emit a quit event (i.e.
void updateInput()
Updates the input state.
void setIcon(const std::string &filename)
Sets the icon for the window (Desktop-only)
void setAntiAliasing(bool enabled)
Toggles Multisample anti-aliasing (MSAA)
void setArgs(std::vector< std::string >)
Called by JNGL_MAIN_BEGIN to set command line arguments.