JNGL
Classes | Enumerations | Functions
jngl Namespace Reference

JNGL's main namespace. More...

Classes

class  App
 There can only be one instance of this class which should be created before the window is shown. More...
 
struct  AppParameters
 Parameters used to initialize the main window. More...
 
class  Color
 Object representing a RGB color. More...
 
class  Container
 
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
 
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  Job
 Background job which stays part of the main loop independent of the active jngl::Work. More...
 
class  Label
 
class  Shader
 Fragment or vertex GLSL shader. More...
 
class  ShaderProgram
 Linked vertex and fragment shaders. 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  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...
 

Enumerations

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

Functions

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)
 
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 (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.
 
int getLineHeight ()
 Get line height used py print() in pixel.
 
void setLineHeight (int)
 Set line height used by print() in pixel.
 
double getTextWidth (const std::string &text)
 Calculates the width of text in 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)
 
bool isMouseVisible ()
 
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.
 
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()
 
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. App::mainLoop() calls this before Work::step()
 
void swapBuffers ()
 Swaps back and front buffer. App::mainLoop() calls this after Work::draw()
 
void quit ()
 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 ()
 
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 readPixel (int x, int y, unsigned char &red, unsigned char &green, unsigned char &blue)
 
void setAntiAliasing (bool enabled)
 
bool getAntiAliasing ()
 
void setVerticalSync (bool enabled)
 
bool getVerticalSync ()
 
void setIcon (const std::string &filename)
 Sets the icon for the window (Desktop-only). Only works with PNG files for now.
 
void setPrefix (const std::string &path)
 
std::string getPrefix ()
 
void setConfigPath (const std::string &path)
 
std::string getConfigPath ()
 Returns the directory where to store configuration files and save games. More...
 
std::string getBinaryPath ()
 Returns the directory of the currently running binary.
 
void setArgs (std::vector< std::string >)
 
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...
 
double getScaleFactor ()
 Size of one screen pixel in actual pixels.
 
void setScaleFactor (double)
 
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 (jngl::Color rgb)
 Sets the color which should be used to draw primitives. More...
 
void setColor (jngl::Color, unsigned char alpha)
 
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)
 
void drawLine (double xstart, double ystart, double xend, double yend)
 
void drawEllipse (float xmid, float ymid, float width, float height, float startAngle=0)
 
void drawEllipse (Vec2, float width, float height, float startAngle=0)
 
void drawCircle (Vec2, float radius, float startAngle=0)
 
void drawPoint (double x, double y)
 
void drawTriangle (Vec2 a, Vec2 b, Vec2 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...
 
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. More...
 
bool isOpenALInstalled ()
 
void setPlaybackSpeed (float speed)
 
void setVolume (float volume)
 
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 drawScaled (const std::string &filename, double xposition, double yposition, float xfactor, float yfactor)
 
void drawScaled (const std::string &filename, double xposition, double yposition, float factor)
 
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 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...
 
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.
 
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)
 
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.
 
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()
 
void setWork (Work *)
 
void resetFrameLimiter ()
 Resets the automatic frame limiter of App::mainLoop(). More...
 

Detailed Description

JNGL's main namespace.

Function Documentation

◆ setBackgroundColor()

void jngl::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.

◆ getFont()

std::string jngl::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 jngl::setFont ( const std::string filename)

Sets the currently active font to filename.

This can either be a TTF or OTF file.

◆ setFontByName()

void jngl::setFontByName ( const std::string name)

Sets the currently active font by a font name.

jngl::setFontByName("monospace");

◆ setFontColor()

void jngl::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).

◆ getTouchPositions()

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

Returns all positions where a finger touches the screen.

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

◆ getMouseX()

int jngl::getMouseX ( )

Retrieve mouse position in pixels.

Deprecated:
Use jngl::getMousePos() instead

◆ getMouseY()

int jngl::getMouseY ( )

Retrieve mouse position in pixels.

Deprecated:
Use jngl::getMousePos() instead

◆ getConnectedControllers()

std::vector<std::shared_ptr<Controller> > jngl::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 jngl::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.

◆ translate()

void jngl::translate ( Vect  v)

Multiplies the global ModelView matrix with a translation matrix.

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

Definition at line 18 of file matrix.hpp.

◆ scale()

void jngl::scale ( double  factor)

Multiplies the global ModelView matrix by a scaling matrix.

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

◆ printMessage()

void jngl::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.

◆ getConfigPath()

std::string jngl::getConfigPath ( )

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 jngl::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 jngl::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)

◆ setColor()

void jngl::setColor ( jngl::Color  rgb)

Sets the color which should be used to draw primitives.

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

◆ drawRect()

void jngl::drawRect ( Vec2  position,
Vec2  size 
)

Draws a rectangle at position.

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

◆ isPlaying()

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

◆ loop()

std::shared_ptr<SoundFile> jngl::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.

◆ load()

Finally jngl::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 jngl::sleep ( int  milliseconds)

Sleep current thread for milliseconds.

Deprecated:
Use std::this_thread::sleep_for instead

◆ setWork()

void jngl::setWork ( Work )

◆ resetFrameLimiter()

void jngl::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.

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