JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
jngl Namespace Reference

JNGL's main namespace. More...

Classes

struct  Achievement
 
class  Alpha
 Object representing only the Alpha Channel in an RGBA color. More...
 
struct  AppParameters
 Parameters used to initialize the main window. More...
 
class  Color
 Object representing a RGB color. More...
 
class  Container
 Helper class to handle multiple instances of Widget. More...
 
class  Controller
 Object representing one Gamepad controller. More...
 
class  Drawable
 Base class for drawable objects with a position and a rectangle size. More...
 
class  Effect
 Base class for effects that can be applied to jngl::Widget. More...
 
class  Executor
 Executes a specific action, e.g. removes the Widget. More...
 
class  Finally
 Helper class which calls a function when being destroyed. More...
 
class  Font
 Font loaded from a TTF or OTF file. More...
 
class  FrameBuffer
 Image framebuffer object which can be rendered on. More...
 
class  ImageData
 Containing the pixel data of an image file. More...
 
class  Job
 Background job which stays part of the main loop independent of the active jngl::Work. More...
 
class  Label
 Simple Widget displaying a line of text. More...
 
class  Mat3
 3x3 matrix More...
 
class  Mat4
 4x4 matrix More...
 
class  Move
 
class  Pixels
 Scale-dependent pixels, corresponds to actual pixels on the screen. More...
 
class  Rgb
 Object representing a RGB color, new version of jngl::Color (which will be deprecated in the future) More...
 
class  Rgba
 Object representing a RGBA color. More...
 
class  ScaleablePixels
 Scale-independent pixels, also called "screen pixels". More...
 
class  Shader
 Fragment or vertex GLSL shader. More...
 
class  ShaderProgram
 Linked vertex and fragment shaders. More...
 
class  Singleton
 Inherit from this class to create a singleton that will be destroyed when your games exits. More...
 
class  SoundFile
 Sound loaded from an OGG file. More...
 
class  Sprite
 Higher-level representation of an image. More...
 
class  Text
 Rectangle shaped text block. More...
 
class  TextLine
 Rectangle shaped text (in contrast to jngl::Text this only represents one line) More...
 
class  Vec2
 Two-dimensional vector. More...
 
struct  Vertex
 Position and texture coordinates. More...
 
class  Video
 Ogg Theory video file. More...
 
class  Widget
 
class  Work
 Active state of the game, e.g. a menu or the game itself. More...
 
class  WorkFactory
 
class  Zoom
 Scales the ModelView matrix. More...
 

Enumerations

enum  KeyboardType { Default , Numpad }
 Whether a normal or a numbers-only keyboard should appear. More...
 
enum class  Alignment { LEFT , RIGHT , CENTER }
 How multiple lines should be aligned in a text block. More...
 
enum class  Cursor { ARROW , I }
 

Functions

Color interpolate (Color a, Color b, float t)
 Returns a color mix between a (t == 0) and b (t == 1)
 
void setBackgroundColor (jngl::Color)
 Sets the screen's background color which is visible when nothing is drawn.
 
void setBackgroundColor (unsigned char red, unsigned char green, unsigned char blue)
 Sets the screen's background color which is visible when nothing is drawn. More...
 
template<class T >
void debug (const T &t)
 
template<class T >
void debugLn (const T &t)
 
template<class Box >
bool contains (const Box &box, const Vec2 point)
 Pass any class that implements getX(), getY(), getWidth() and getHeight() More...
 
void print (const std::string &text, jngl::Vec2 position)
 Print text at position.
 
void print (const std::string &text, int xposition, int yposition)
 Print text at { xposition, yposition }.
 
int getFontSize ()
 Get the font size used by print()
 
void setFontSize (int size)
 Change the font size used by print()
 
std::string getFont ()
 Returns the currently active font name. More...
 
void setFont (const std::string &filename)
 Sets the currently active font to filename. More...
 
void setFontByName (const std::string &name)
 Sets the currently active font by a font name. More...
 
void setFontColor (jngl::Color)
 Sets the color of the currently active font.
 
void setFontColor (Color, float alpha)
 Sets the color of the currently active font and the alpha value. More...
 
void setFontColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
 Sets the color of the currently active font. More...
 
void pushFontColor (unsigned char red, unsigned char green, unsigned char blue)
 Pushes the currently active font color on a stack and sets a new one.
 
void popFontColor ()
 Resets the font color on the top of stack which is used by jngl::pushFontColor.
 
double getLineHeight ()
 Get line height used py print() in scale-independent pixel.
 
void setLineHeight (double)
 Set line height used by print() in scale-independent pixel.
 
double getTextWidth (const std::string &text)
 Calculates the width of text in scale-independent pixels if it would be drawn with the currently active font.
 
void setKeyboardVisible (bool)
 Display onscreen keyboard for touch devices.
 
void setKeyboardType (KeyboardType)
 Type of the onscreen keyboard.
 
KeyboardType getKeyboardType ()
 Currently active type of onscreen keyboard.
 
void setKeyPressed (const std::string &key, bool)
 Overwrite what keyPressed() should return.
 
void setKeyPressed (key::KeyType key, bool)
 Overwrite what keyPressed() should return.
 
bool keyDown (key::KeyType key)
 Whether key is down.
 
bool keyDown (char key)
 Whether key is down.
 
bool keyDown (const std::string &key)
 Whether key is down, where key should be exactly one UTF-8 character.
 
bool keyPressed (key::KeyType key)
 Whether key has been pressed since the next to last call to updateInput()
 
bool keyPressed (char key)
 Whether key has been pressed since the next to last call to updateInput()
 
bool keyPressed (const std::string &key)
 Whether key has been pressed since the next to last call to updateInput(), where key should be exactly one UTF-8 character.
 
void setRelativeMouseMode (bool relative)
 
bool getRelativeMouseMode ()
 
void setMouseVisible (bool visible)
 By default the mouse cursor of the OS is visible and can be hidden by passing false.
 
bool isMouseVisible ()
 Returns whether the mouse cursor of the OS is currently visible. More...
 
bool isMultitouch ()
 Returns true when there's more than one finger touching the screen.
 
std::vector< jngl::Vec2getTouchPositions ()
 Returns all positions where a finger touches the screen. More...
 
Vec2 getMousePos ()
 Mouse position in screen coordinates. More...
 
optional< Vec2getCursorPos ()
 Returns the position of the mouse pointer if a mouse is connected/available.
 
int getMouseX ()
 Retrieve mouse position in pixels. More...
 
int getMouseY ()
 Retrieve mouse position in pixels. More...
 
double getMouseWheel ()
 Returns mouse wheel movement between -100 and 100 (0 if the mousewheel doesn't move)
 
bool mouseDown (mouse::Button button=mouse::Left)
 Returns whether button is currently held down.
 
void setMouseDown (mouse::Button button, bool)
 Overwrite what mouseDown() should return.
 
bool mousePressed (mouse::Button button=mouse::Left)
 Whether button has been pressed since the next to last call to updateInput()
 
void setMousePressed (jngl::mouse::Button, bool)
 Overwrite what mouseDown() should return.
 
void setMouse (Vec2 position)
 Moves the mouse (does nothing on iOS and Android)
 
std::vector< std::shared_ptr< Controller > > getConnectedControllers ()
 Returns all controllers (gamepads) that are connected. More...
 
void onControllerChanged (std::function< void()> callback)
 Specify a function which gets called, whenever a controller gets added or removed. More...
 
std::string getTextInput ()
 Returns a string of characters that have been pressed since the last call to updateInput()
 
void addJob (std::shared_ptr< Job > job)
 Add a new Job which will be always be stepped and drawn by App::mainLoop()
 
template<class T , class... Args>
void addJob (Args &&... args)
 The same as addJob(std::shared_ptr<Job>) but creates the Job for you. More...
 
void removeJob (Job *)
 Removes the passed Job after all Jobs have been stepped. More...
 
std::shared_ptr< JobgetJob (const std::function< bool(Job &)> &predicate)
 Returns the first Job for which predicate returned true.
 
template<class T >
std::shared_ptr< T > getJob ()
 Returns the first Job that is a T. More...
 
jngl::Mat3 modelview ()
 Returns a copy of the global ModelView matrix. More...
 
void rotate (double degree)
 Multiplies the global ModelView matrix with a rotation matrix.
 
void translate (double x, double y)
 Multiplies the global ModelView matrix with a translation matrix.
 
template<class Vect >
void translate (Vect v)
 Multiplies the global ModelView matrix with a translation matrix. More...
 
void scale (double factor)
 Multiplies the global ModelView matrix by a scaling matrix. More...
 
void scale (double xfactor, double yfactor)
 Multiplies the global ModelView matrix by a scaling matrix.
 
void pushMatrix ()
 Pushes the current ModelView matrix on a global stack.
 
void popMatrix ()
 Replaces the current ModelView matrix with the top element of the global stack.
 
void reset ()
 Resets the global ModelView matrix to the identity matrix.
 
void errorMessage (const std::string &text)
 Shows a message box with an error text.
 
void printMessage (const std::string &text)
 Prints text on stdout. More...
 
bool running ()
 Returns true until the main window is closed or quit() has been called.
 
void updateInput ()
 Updates the input state. More...
 
void swapBuffers ()
 Swaps back and front buffer. More...
 
void clearBackBuffer ()
 Clears the back buffer and resets the ModelView matrix, see jngl::reset() More...
 
bool canQuit ()
 Some platforms (e.g. More...
 
void quit () noexcept
 Emit a quit event which will exit App::mainLoop() and set running() to false. More...
 
void cancelQuit ()
 Undo quit() or ignore a quit event caused by the user closing the main window.
 
double getFPS ()
 Calculates FPS if called once per frame. More...
 
unsigned int getStepsPerSecond ()
 How many times Work::step is called per second (default: 60)
 
void setStepsPerSecond (unsigned int)
 How many times Work::step should be called per second (default: 60)
 
void setAntiAliasing (bool enabled)
 Toggles Multisample anti-aliasing (MSAA) More...
 
bool getAntiAliasing ()
 Returns whether MSAA is enabled. If the device doesn't support it, it will always return false.
 
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 setIcon (const std::string &filename)
 Sets the icon for the window (Desktop-only)
 
void setPrefix (const std::string &path)
 Sets a global prefix which will be prepended whenever images or sounds are loaded.
 
std::string getPrefix ()
 Returns the global prefix set by jngl::setPrefix.
 
void setConfigPath (const std::string &path)
 
std::string getConfigPath ()
 
std::string getBinaryPath ()
 Returns the directory of the currently running binary.
 
void setArgs (std::vector< std::string >)
 Called by JNGL_MAIN_BEGIN to set command line arguments.
 
std::vector< std::stringgetArgs ()
 Returns the command line arguments passed to the executable.
 
std::stringstream readAsset (const std::string &filename)
 Returns a stringstream containing the whole file. This will read from the .apk on Android.
 
std::string readConfig (const std::string &key)
 Read in a configuration value which has been saved under key. More...
 
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) More...
 
std::string getPreferredLanguage ()
 Returns user preferred language, i.e. "en" for English, "de" for German.
 
void openURL (const std::string &)
 Opens a link (e.g. https://bixense.com) in the browser.
 
int round (double v)
 Rounds a double to an integer, just like std::lround.
 
bool operator> (jngl::Pixels, jngl::Pixels)
 
Pixels operator/ (Pixels, float)
 
Rgb interpolate (Rgb a, Rgb b, float t)
 Returns a color mix between a (t == 0) and b (t == 1)
 
Rgba interpolate (Rgba a, Rgba b, float t)
 Returns a color mix between a (t == 0) and b (t == 1)
 
double getScaleFactor ()
 Size of one screen pixel in actual pixels.
 
void setScaleFactor (double)
 Overwrite the size of one screen pixel. More...
 
double getScreenWidth ()
 jngl::getScreenSize().x
 
double getScreenHeight ()
 jngl::getScreenSize().y
 
Vec2 getScreenSize ()
 Returns the size of the useable draw area (excluding letter-boxing) in screen pixels.
 
void setUniform (int location, float v0, float v1)
 
void setColor (Rgb rgb)
 Sets the color which should be used to draw primitives. More...
 
void setColor (Rgb, unsigned char alpha)
 Sets the color and alpha which should be used to draw primitives. More...
 
void setColor (unsigned char red, unsigned char green, unsigned char blue)
 
void setColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
 
void setAlpha (uint8_t alpha)
 Sets the alpha value which should be used to draw primitives (0 = fully transparent, 255 = fully opaque)
 
void pushAlpha (unsigned char alpha)
 
void popAlpha ()
 
void setLineWidth (float width)
 
void drawLine (Vec2 start, Vec2 end)
 Draws a line from start to end, the width can be set using setLineWidth.
 
void drawLine (double xstart, double ystart, double xend, double yend)
 
void drawLine (const Mat3 &modelview, Vec2 end)
 Draws a line from (0, 0) to end.
 
void drawEllipse (float xmid, float ymid, float width, float height, float startAngle=0)
 
void drawEllipse (Vec2, float width, float height, float startAngle=0)
 
void drawEllipse (Mat3 modelview, float width, float height, float startAngle=0)
 
void drawCircle (Vec2, float radius, float startAngle=0)
 Angles in radian.
 
void drawCircle (Mat3 modelview, float radius, float startAngle)
 
void drawCircle (Mat3 modelview, float radius)
 
void drawCircle (Mat3 modelview, float radius, Rgba color)
 Draws a circle at (0, 0) with radius in color.
 
void drawPoint (double x, double y)
 
void drawTriangle (Vec2 a, Vec2 b, Vec2 c)
 Draws the triangle a -> b -> c.
 
void drawTriangle (double A_x, double A_y, double B_x, double B_y, double C_x, double C_y)
 
void drawRect (double xposition, double yposition, double width, double height)
 
void drawRect (Vec2 position, Vec2 size)
 Draws a rectangle at position. More...
 
void drawRect (const Mat3 &modelview, Vec2 size, Color)
 Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color. More...
 
void drawRect (const Mat3 &modelview, Vec2 size, Rgba color)
 Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color. More...
 
template<class Vect >
void drawRect (Vect pos, Vect size)
 
float getVolume ()
 
void play (const std::string &filename)
 Play an OGG audio file once. More...
 
void stop (const std::string &filename)
 Stop an OGG audio file if it's currently playing.
 
bool isPlaying (const std::string &filename)
 
std::shared_ptr< SoundFileloop (const std::string &filename)
 Play an OGG audio file in a loop. More...
 
void setPlaybackSpeed (float speed)
 Set global pitch in (0.0f, ∞]. Default is 1.0f.
 
void setVolume (float volume)
 Set global volume in [0, ∞]. Default is 1.0f.
 
Finally pauseAudio ()
 Pauses the playback of all audio; destroying the returned Finally object will resume again. More...
 
void draw (const std::string &filename, double x, double y)
 
template<class Vect >
void draw (const std::string &filename, Vect pos)
 
Finally load (const std::string &filename)
 Starts a thread to load filename and returns a Finally which will join it. More...
 
void unload (const std::string &filename)
 
void unloadAll ()
 
void drawClipped (const std::string &filename, double xposition, double yposition, float xstart, float xend, float ystart, float yend)
 
void setSpriteColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
 
void setSpriteColor (unsigned char red, unsigned char green, unsigned char blue)
 
void setSpriteColor (Rgb)
 Sets the global color used for drawing Sprites, leaves the alpha value untouched.
 
void setSpriteAlpha (unsigned char alpha)
 
void pushSpriteAlpha (unsigned char alpha=255)
 
void popSpriteAlpha ()
 
int getWidth (const std::string &filename)
 
int getHeight (const std::string &filename)
 
Finally disableBlending ()
 
double getTime ()
 Returns seconds that have passed since program start.
 
void sleep (int milliseconds)
 Sleep current thread for milliseconds. More...
 
std::ostreamoperator<< (std::ostream &, const Vec2 &)
 Prints the vector like this: [x=…, y=…].
 
void showWindow (const std::string &title, int width, int height, bool fullscreen=false, std::pair< int, int > minAspectRatio={ 4, 3 }, std::pair< int, int > maxAspectRatio={ 16, 9 })
 Creates the main window.
 
void hideWindow ()
 Cleans up the window and unloads everything. More...
 
void atExit (std::function< void()>)
 Call this function once when the window is hidden. More...
 
int getWindowWidth ()
 Returns the width of the window in actual pixels (i.e. ignoring jngl::getScaleFactor)
 
int getWindowHeight ()
 Returns the height of the window in actual pixels (i.e. ignoring jngl::getScaleFactor)
 
std::array< Pixels, 2 > getWindowSize ()
 Returns {width, height} of the window in actual pixels.
 
int getDesktopWidth ()
 Returns the width of the main display in actual pixels.
 
int getDesktopHeight ()
 Returns the height of the main display in actual pixels.
 
bool getFullscreen ()
 If the window is displayed fullscreen (always true on mobile devices)
 
void setFullscreen (bool)
 Toggle fullscreen window mode.
 
void setTitle (const std::string &title)
 Sets the main window title.
 
void setCursor (Cursor)
 
std::vector< float > readPixels ()
 Read red, green and blue values of the whole window frame buffer.
 
std::shared_ptr< WorkgetWork ()
 Returns the current active Work or nullptr if none has been set.
 
void setWork (std::shared_ptr< Work > work)
 Sets the passed Work to be active in App::mainLoop()
 
template<class T , class... Args>
void setWork (Args &&... args)
 The same as setWork(std::shared_ptr<Work>) but creates the Work for you. More...
 
void setWork (Work *)
 
void resetFrameLimiter ()
 Resets the automatic frame limiter of App::mainLoop(). More...
 

Detailed Description

JNGL's main namespace.

Enumeration Type Documentation

◆ KeyboardType

Whether a normal or a numbers-only keyboard should appear.

Definition at line 75 of file input.hpp.

◆ Alignment

enum class Alignment
strong

How multiple lines should be aligned in a text block.

Definition at line 16 of file text.hpp.

◆ Cursor

enum class Cursor
strong

Definition at line 62 of file window.hpp.

Function Documentation

◆ setBackgroundColor()

void setBackgroundColor ( unsigned char  red,
unsigned char  green,
unsigned char  blue 
)

Sets the screen's background color which is visible when nothing is drawn.

Deprecated:
Use setBackgroundColor(jngl::Color) instead.

◆ debug()

void debug ( const T &  t)

Definition at line 19 of file debug.hpp.

◆ debugLn()

void debugLn ( const T &  t)

Definition at line 30 of file debug.hpp.

◆ contains()

bool contains ( const Box &  box,
const Vec2  point 
)

Pass any class that implements getX(), getY(), getWidth() and getHeight()

Definition at line 90 of file Drawable.hpp.

◆ getFont()

std::string getFont ( )

Returns the currently active font name.

This will either return a font name if jngl::setFont was used or a font name if jngl::setFontByName was used.

◆ setFont()

void setFont ( const std::string filename)

Sets the currently active font to filename.

This can either be a TTF or OTF file.

◆ setFontByName()

void setFontByName ( const std::string name)

Sets the currently active font by a font name.

jngl::setFontByName("monospace");
void setFontByName(const std::string &name)
Sets the currently active font by a font name.

◆ setFontColor() [1/2]

void setFontColor ( Color  ,
float  alpha 
)

Sets the color of the currently active font and the alpha value.

alpha goes from 0.0f to 1.0f (opaque). It's automatically clamped to these values.

◆ setFontColor() [2/2]

void setFontColor ( unsigned char  red,
unsigned char  green,
unsigned char  blue,
unsigned char  alpha = 255 
)

Sets the color of the currently active font.

If the alpha value isn't specified, it will be set to 255 (opaque).

◆ isMouseVisible()

bool isMouseVisible ( )

Returns whether the mouse cursor of the OS is currently visible.

Even when this method returns true, it could still be visible outside of the window or hidden by the OS for other means (e.g. while the user is typing).

◆ getTouchPositions()

std::vector< jngl::Vec2 > getTouchPositions ( )

Returns all positions where a finger touches the screen.

Includes the mouse position if the primary mouse button is down.

◆ getMousePos()

Vec2 getMousePos ( )

Mouse position in screen coordinates.

If no mouse is connected will return the last touch position. See jngl::getCursorPos() if you really want the position of the mouse only.

◆ getMouseX()

int getMouseX ( )

Retrieve mouse position in pixels.

Deprecated:
Use jngl::getMousePos() instead

◆ getMouseY()

int getMouseY ( )

Retrieve mouse position in pixels.

Deprecated:
Use jngl::getMousePos() instead

◆ getConnectedControllers()

std::vector< std::shared_ptr< Controller > > getConnectedControllers ( )

Returns all controllers (gamepads) that are connected.

Don't call this function every frame for performance reasons, use jngl::onControllerChanged instead to get notified when controlles are being connected or removed.

◆ onControllerChanged()

void onControllerChanged ( std::function< void()>  callback)

Specify a function which gets called, whenever a controller gets added or removed.

Whenever the return value of jngl::getConnectedControllers would change, callback gets called.

◆ addJob()

void addJob ( Args &&...  args)

The same as addJob(std::shared_ptr<Job>) but creates the Job for you.

Definition at line 54 of file job.hpp.

◆ removeJob()

void removeJob ( Job )

Removes the passed Job after all Jobs have been stepped.

If the Job isn't found, nothing happens.

◆ getJob()

std::shared_ptr< T > getJob ( )

Returns the first Job that is a T.

Definition at line 67 of file job.hpp.

◆ modelview()

jngl::Mat3 modelview ( )

Returns a copy of the global ModelView matrix.

This is the matrix which is used in all of JNGL's shaders to position objects. Using this function you can get a local copy of it. This allows you to more precisely position an object without affecting any global state.

A common use-case where you actually want to modify the ModelView matrix for all objects is the camera. So in your drawing loop you would do:

void MyGame::draw() const {
jngl::translate(cameraPosition);
{
auto mv = jngl::modelview();
sprite.draw(mv.translate(position1);
} // mv which is translated by position1 gets discarded
{
auto mv = jngl::modelview();
sprite.draw(mv.translate(position2);
}
}
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.
void translate(double x, double y)
Multiplies the global ModelView matrix with a translation matrix.

◆ translate()

void translate ( Vect  v)

Multiplies the global ModelView matrix with a translation matrix.

Equivalent to calling jngl::translate(v.x, v.y);.

Definition at line 43 of file matrix.hpp.

◆ scale()

void scale ( double  factor)

Multiplies the global ModelView matrix by a scaling matrix.

Equivalent to calling jngl::scale(factor, factor).

◆ printMessage()

void printMessage ( const std::string text)

Prints text on stdout.

Normally this is the same as std::cout << text << std::flush;. On Android this will use __android_log_print for example.

◆ updateInput()

void updateInput ( )

Updates the input state.

App::mainLoop() calls this before Work::step()

Normally you shouldn't call this yourself at all, unless you want to implement your own game loop.

◆ swapBuffers()

void swapBuffers ( )

Swaps back and front buffer.

App::mainLoop() calls this after Work::draw()

Also clears the back buffer using jngl::clearBackBuffer().

◆ clearBackBuffer()

void clearBackBuffer ( )

Clears the back buffer and resets the ModelView matrix, see jngl::reset()

jngl::swapBuffers() calls this so there isn't any reason to call this manually most of the time.

◆ canQuit()

bool canQuit ( )

Some platforms (e.g.

iOS) don't allow apps to quit themselves

If this returns false you should hide any "Quit Game" menu buttons.

◆ quit()

void quit ( )
noexcept

Emit a quit event which will exit App::mainLoop() and set running() to false.

If the window hasn't been created yet or the loop is already about to quit, this function does nothing

◆ getFPS()

double getFPS ( )

Calculates FPS if called once per frame.

Deprecated:
Not really intuitive or robust, use your own calculations instead

◆ setAntiAliasing()

void setAntiAliasing ( bool  enabled)

Toggles Multisample anti-aliasing (MSAA)

Many devices don't support this, so this function will do nothing.

◆ setConfigPath()

void setConfigPath ( const std::string path)

◆ getConfigPath()

std::string getConfigPath ( )
Deprecated:
Use jngl::writeConfig and jngl::readConfig instead.

Returns the directory where to store configuration files and save games.

  • Windows: %AppData%/Display Name/
  • Linux: ~/.config/Display Name/
  • macOS: ~/Library/Application Support/Display Name/
  • Android/iOS: Data path provided by the OS

◆ readConfig()

std::string readConfig ( const std::string key)

Read in a configuration value which has been saved under key.

On most platforms this will read the contents of a file named key in getConfigPath(). On iOS or tvOS it will use the key/value store provided by the OS.

Returns
Value saved by jngl::writeConfig. Empty string if an error occured or key doesn't exist.

◆ writeConfig()

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)

Exceptions
std::ifstream::failureif the value couldn't be saved (e.g. jngl::getConfigPath() is read-only)
std::runtime_errorif key is invalid (it must be a relative file path)

◆ setScaleFactor()

void setScaleFactor ( double  )

Overwrite the size of one screen pixel.

Normally you wouldn't use this, but set AppParameters::screenSize to a lower value instead.

◆ setColor() [1/2]

void setColor ( Rgb  rgb)

Sets the color which should be used to draw primitives.

Doesn't change the alpha value currently set by setAlpha()

◆ setColor() [2/2]

void setColor ( Rgb  ,
unsigned char  alpha 
)

Sets the color and alpha which should be used to draw primitives.

Parameters
alpha[0...255]

◆ pushAlpha()

void pushAlpha ( unsigned char  alpha)
Deprecated:
Use setAlpha instead

◆ popAlpha()

void popAlpha ( )
Deprecated:
Use setAlpha instead

◆ setLineWidth()

void setLineWidth ( float  width)
Deprecated:
Use drawRectangle instead

◆ drawLine()

void drawLine ( double  xstart,
double  ystart,
double  xend,
double  yend 
)

◆ drawEllipse()

void drawEllipse ( float  xmid,
float  ymid,
float  width,
float  height,
float  startAngle = 0 
)
Deprecated:
Use drawEllipse(Mat3, float, float, float) instead

◆ drawPoint()

void drawPoint ( double  x,
double  y 
)
Deprecated:
Use drawCircle instead

◆ drawTriangle()

void drawTriangle ( double  A_x,
double  A_y,
double  B_x,
double  B_y,
double  C_x,
double  C_y 
)

◆ drawRect() [1/4]

void drawRect ( Vec2  position,
Vec2  size 
)

Draws a rectangle at position.

Use setColor(Rgb) to change the color and setAlpha(uint8_t) to change the translucency.

◆ drawRect() [2/4]

void drawRect ( const Mat3 modelview,
Vec2  size,
Color   
)

Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color.

Use setAlpha to set the opacity.

◆ drawRect() [3/4]

void drawRect ( const Mat3 modelview,
Vec2  size,
Rgba  color 
)

Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color.

Use setAlpha to set the opacity.

◆ drawRect() [4/4]

void drawRect ( Vect  pos,
Vect  size 
)

Definition at line 104 of file shapes.hpp.

◆ play()

void play ( const std::string filename)

Play an OGG audio file once.

Might block if the file hasn't been played before. To avoid that use jngl::load before.

◆ isPlaying()

bool isPlaying ( const std::string filename)
Returns
whether filename is currently playing

When playing a SoundFile multiple times (i.e. calling jngl::play multiple times), this will return true if at least one SoundFile is still playing (i.e. hasn't finished and wasn't stopped).

Note
Unaffected by jngl::pauseAudio

◆ loop()

std::shared_ptr< SoundFile > loop ( const std::string filename)

Play an OGG audio file in a loop.

If it's already playing, this function won't play it twice, but simply set it to loop and return a pointer to the same SoundFile.

◆ pauseAudio()

Finally pauseAudio ( )

Pauses the playback of all audio; destroying the returned Finally object will resume again.

Note that this doesn't change the status of jngl::isPlaying as that only depends on the status of the SoundFile.

Example where you want to pause all audio in a menu:

class PauseMenu : public jngl::Work {
jngl::Finally paused;
public:
PauseMenu() : paused(jngl::pauseAudio()) {}
void step() override { /* ... */ }
void draw() const override { /* ... */ }
};
Helper class which calls a function when being destroyed.
Definition: Finally.hpp:22
Active state of the game, e.g. a menu or the game itself.
Definition: work.hpp:13
JNGL's main namespace.
Definition: Achievement.hpp:10
Finally pauseAudio()
Pauses the playback of all audio; destroying the returned Finally object will resume again.

Or if you want to toggle pausing audio using Space:

class PauseExample : public jngl::Work {
public:
void step() override {
if (jngl::keyPressed(jngl::key::Space)) {
if (paused) {
paused = {}; // calls ~Finally() and resumes playback
} else {
paused = jngl::pauseAudio();
}
}
}
void draw() const override { /* ... */ }
};
bool keyPressed(key::KeyType key)
Whether key has been pressed since the next to last call to updateInput()

◆ draw()

void draw ( const std::string filename,
Vect  pos 
)

Definition at line 167 of file sprite.hpp.

◆ load()

Finally load ( const std::string filename)

Starts a thread to load filename and returns a Finally which will join it.

Parameters
filenameName of an image file (extension is optional) or a .ogg sound file.

◆ sleep()

void sleep ( int  milliseconds)

Sleep current thread for milliseconds.

Deprecated:
Use std::this_thread::sleep_for(std::chrono::milliseconds(...)) instead

◆ hideWindow()

void hideWindow ( )

Cleans up the window and unloads everything.

Will delete all instances of Singleton before starting to unload everything.

◆ atExit()

void atExit ( std::function< void()>  )

Call this function once when the window is hidden.

The function will be called at the next hideWindow() call, if there is a currently active window.

Use this function for any cleanup tasks when you game exits. Note that on Android, the process doesn't exit necessarely and the main function can be reentered - so C functions like atexit or destructors of global objects won't work.

◆ setWork() [1/2]

void setWork ( Args &&...  args)

The same as setWork(std::shared_ptr<Work>) but creates the Work for you.

Definition at line 51 of file work.hpp.

◆ setWork() [2/2]

void setWork ( Work )

◆ resetFrameLimiter()

void resetFrameLimiter ( )

Resets the automatic frame limiter of App::mainLoop().

This is useful after you have done a huge amount of work in Work::draw, e.g. after loading screens.