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
 Unlockable Achievement (also called Trophy) More...
 
class  Alpha
 Object representing only the Alpha Channel in an RGBA color. More...
 
struct  AppParameters
 Parameters used to initialize the main window. More...
 
class  Channel
 An audio channel, different channels could be for example: "Music", "Speech" and "Sound Effects". 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  OutlinedFont
 Same as jngl::Font but adds an outline. More...
 
class  Pixels
 Scale-dependent pixels, corresponds to actual pixels on the screen. More...
 
struct  Rect
 Simple struct for a rectangle, can be use with jngl::contains. 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  UpdateModelview
 
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 : uint8_t { Default , Numpad }
 Whether a normal or a numbers-only keyboard should appear. More...
 
enum class  Alignment : uint8_t { LEFT , RIGHT , CENTER }
 How multiple lines should be aligned in a text block. More...
 
enum class  Cursor : uint8_t { 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::Rgb)
 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.
 
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()
 
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 }.
 
void print (const Mat3 &modelview, const std::string &text)
 Print text using modelview.
 
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.
 
void setFont (const std::string &filename)
 Sets the currently active font to filename.
 
void setFontByName (const std::string &name)
 Sets the currently active font by a font name.
 
void setFontColor (Rgba)
 Sets the color and alpha value of the currently active font.
 
void setFontColor (Rgb, float alpha=1.f)
 Sets the color of the currently active font and the alpha value.
 
void setFontColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
 Sets the color of the currently active font.
 
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.
 
Finally hideMouse ()
 Hides the mouse cursor; destroying the returned Finally object will show it again.
 
bool isMouseVisible ()
 Returns whether the mouse cursor of the OS is currently visible.
 
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.
 
Vec2 getMousePos ()
 Mouse position in screen coordinates.
 
optional< Vec2getCursorPos ()
 Returns the position of the mouse pointer if a mouse is connected/available.
 
int getMouseX ()
 Retrieve mouse position in pixels.
 
int getMouseY ()
 Retrieve mouse position in pixels.
 
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.
 
void onControllerChanged (std::function< void()> callback)
 Specify a function which gets called, whenever a controller gets added or removed.
 
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.
 
void removeJob (Job *)
 Removes the passed Job after all Jobs have been stepped.
 
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.
 
void trace (const std::string &)
 
template<class... Args>
void trace (Args &&...)
 
void info (const std::string &)
 
template<class... Args>
void info (Args &&...)
 
void warn (const std::string &)
 
template<class... Args>
void warn (Args &&...)
 
void error (const std::string &)
 
template<class... Args>
void error (Args &&...)
 
jngl::Mat3 modelview ()
 Returns a copy of the global ModelView matrix.
 
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.
 
void scale (double factor)
 Multiplies the global ModelView matrix by a scaling matrix.
 
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.
 
bool running ()
 Returns true until the main window is closed or quit() has been called.
 
void updateInput ()
 Updates the input state.
 
void swapBuffers ()
 Swaps back and front buffer.
 
void clearBackBuffer ()
 Clears the back buffer and resets the ModelView matrix, see jngl::reset()
 
bool canQuit ()
 Some platforms (e.g.
 
void quit () noexcept
 Emit a quit event which will exit App::mainLoop() and set running() to false.
 
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.
 
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)
 
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.
 
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)
 
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.
 
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)
 Sets the color which should be used to draw primitives.
 
void setColor (Rgba)
 Sets the color (including alpha) which should be used to draw primitives.
 
void setColor (Rgb, unsigned char alpha)
 Sets the color and alpha which should be used to draw primitives.
 
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 (Mat3 modelview, Vec2 start, Vec2 end)
 Draws a line from start to end.
 
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 drawCircle (Mat3 modelview, Rgba color)
 Draws a circle at (0, 0) with radius of 1 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)
 Draws a rectangle at { xposition, yposition }.
 
void drawRect (Vec2 position, Vec2 size)
 Draws a rectangle at position.
 
void drawRect (const Mat3 &modelview, Vec2 size, Rgb)
 Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color.
 
void drawRect (Mat3 modelview, Vec2 size, Rgba color)
 Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color.
 
void drawSquare (const Mat3 &modelview, Rgba color)
 Draws a square of size 1x1 centered at (0, 0) with the specified color.
 
template<class Vect >
void drawRect (Vect pos, Vect size)
 
float getVolume ()
 
void play (const std::string &filename)
 Play an OGG audio file once.
 
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.
 
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.
 
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.
 
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 setSpriteColor (Rgba)
 Sets the global color used for drawing Sprites.
 
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.
 
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.
 
void atExit (std::function< void()>)
 Call this function once when the window is hidden.
 
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 the main loop.
 
template<class T , class... Args>
void setWork (Args &&... args)
 The same as setWork(std::shared_ptr<Work>) but creates the Work for you.
 
void setWork (Work *)
 
void resetFrameLimiter ()
 Resets the automatic frame limiter of App::mainLoop().
 

Detailed Description

JNGL's main namespace.

Enumeration Type Documentation

◆ KeyboardType

enum KeyboardType : uint8_t

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

Definition at line 76 of file input.hpp.

◆ Alignment

enum class Alignment : uint8_t
strong

How multiple lines should be aligned in a text block.

Definition at line 17 of file text.hpp.

◆ Cursor

enum class Cursor : uint8_t
strong

Definition at line 65 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::Rgb) instead.

◆ debug()

template<class T >
void debug ( const T & t)

Definition at line 19 of file debug.hpp.

◆ debugLn()

template<class T >
void debugLn ( const T & t)

Definition at line 30 of file debug.hpp.

◆ contains()

template<class Box >
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.

Exceptions
std::runtime_errorIf the font couldn't be found.
jngl::setFontByName("monospace");
void setFontByName(const std::string &name)
Sets the currently active font by a font name.
Note
Not supported on iOS, Switch, Xbox, and Web. Falls back to using "Arial.ttf" on those platforms.

◆ setFontColor() [1/2]

void setFontColor ( Rgb ,
float alpha = 1.f )

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).

◆ keyDown()

bool keyDown ( const std::string & key)

Whether key is down, where key should be exactly one UTF-8 character.

Example:

if (jngl::keyDown("a")) {
player1Pos.x += 1;
}
if (jngl::keyDown("s")) {
player1Pos.x -= 1;
}
if (jngl::keyDown("ö")) {
player2Pos.x += 1;
}
if (jngl::keyDown("ä")) {
player2Pos.x -= 1;
}
bool keyDown(key::KeyType key)
Whether key is down.

◆ 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).

◆ isMultitouch()

bool isMultitouch ( )

Returns true when there's more than one finger touching the screen.

Equivalent to jngl::getTouchPositions().size() > 1.

◆ 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.

◆ getCursorPos()

optional< Vec2 > getCursorPos ( )

Returns the position of the mouse pointer if a mouse is connected/available.

On Android, iOS and for the Nintendo Switch this will always return std::nullopt. While Android supports connecting mice this isn't supported by JNGL yet.

◆ 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() [1/2]

void addJob ( std::shared_ptr< Job > job)

Add a new Job which will be always be stepped and drawn by App::mainLoop()

Example:

class MyJob : public jngl::Job {
public:
MyJob();
// ...
};
// ...
params.start = []() {
// ...
};
return params;
}
Background job which stays part of the main loop independent of the active jngl::Work.
Definition job.hpp:20
jngl::AppParameters jnglInit()
Implement this function and set AppParameters::start.
void addJob(std::shared_ptr< Job > job)
Add a new Job which will be always be stepped and drawn by App::mainLoop()
Parameters used to initialize the main window.
std::function< std::shared_ptr< jngl::Work >()> start
A factory function which creates the first jngl::Work.

◆ addJob() [2/2]

template<class T , class... Args>
void addJob ( Args &&... args)

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

Example:

class MyJob : public jngl::Job {
public:
MyJob(int x, float y, std::string foo);
// ...
};
// ...
params.start = []() {
jngl::addJob<MyJob>(42, 3.14f, "Hello, World!");
// ...
};
return params;
}

Definition at line 103 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()

template<class T >
std::shared_ptr< T > getJob ( )

Returns the first Job that is a T.

Definition at line 116 of file job.hpp.

◆ trace()

template<class... Args>
void trace ( Args && ...)

Definition at line 21 of file log.hpp.

◆ info()

template<class... Args>
void info ( Args && ...)

Definition at line 31 of file log.hpp.

◆ warn()

template<class... Args>
void warn ( Args && ...)

Definition at line 41 of file log.hpp.

◆ error()

template<class... Args>
void error ( Args && ...)

Definition at line 51 of file log.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.

◆ rotate()

void rotate ( double degree)

Multiplies the global ModelView matrix with a rotation matrix.

Deprecated
use jngl::modelview().rotate instead

◆ translate()

template<class Vect >
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 45 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 )

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 drawRect 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/5]

void drawRect ( double xposition,
double yposition,
double width,
double height )

Draws a rectangle at { xposition, yposition }.

Deprecated
Use drawRect(const Mat3&, Vec2, Color) instead

◆ drawRect() [2/5]

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() [3/5]

void drawRect ( const Mat3 & modelview,
Vec2 size,
Rgb  )

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

Use setAlpha to set the opacity.

◆ drawRect() [4/5]

void drawRect ( 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.

◆ drawSquare()

void drawSquare ( const Mat3 & modelview,
Rgba color )

Draws a square of size 1x1 centered at (0, 0) with the specified color.

By squaling the modelview matrix you can change the size of the square, effectively turning it into a rectangle:

// draws a rectangle at (12 - 56 / 2, 34 - 78 / 2) with a size of 56x78 in red:
drawSquare(jngl::modelview().translate(12, 34).scale(56, 78), 0xff0000ff_rgba);
void drawSquare(const Mat3 &modelview, Rgba color)
Draws a square of size 1x1 centered at (0, 0) with the specified color.
void scale(double factor)
Multiplies the global ModelView matrix by a scaling matrix.

◆ drawRect() [5/5]

template<class Vect >
void drawRect ( Vect pos,
Vect size )

Definition at line 125 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.
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()

template<class Vect >
void draw ( const std::string & filename,
Vect pos )

Definition at line 261 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

◆ showWindow()

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.

If you haven't set a display name for your app using AppParameters::displayName, title will set for the display name.

◆ 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]

template<class T , class... Args>
void setWork ( Args &&... args)

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

Definition at line 85 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.