Application

Photon main class, contains functions that control creation of the display, setting the OpenGL view, input handling, timing, and State management.

Application is a Singleton and therefore should be accessed through Application::getInstance().  (Application Singleton is created/destroyed automatically)

Summary
Photon main class, contains functions that control creation of the display, setting the OpenGL view, input handling, timing, and State management.
Default constructor, initializes the internal state & dependencies.
Default destructor, shuts down dependencies.
Runs application until a quit is requested either via the operating system (ex.
Sets Quit flag, terminating application.
Access the application’s update TaskManager, Tasks registered with this TaskManager are executed after the current State::update.
Access the application’s render TaskManager, Tasks registered with this TaskManager are executed after the current State::render.
Checks if application is active, which on most systems simply means it has focus.
This function attempts to create a display with the given parameters.
This function attempts to create a display with the given parameters.
Sets title of application that shows up in title bar.
Get the width of the display.
Get the height of the display.
Sets new ortho viewport within a rectangular portion of the screen.
Sets entire screen as current viewport with a given ortho perspective.
Sets entire screen as current viewport with a 1:1 perspective.
Creates a viewport with a given 3D perspective inside of a rectangular portion of the screen.
Sets entire screen as current viewport with a given 3D perspective.
These functions are called by the above Ortho/Perspective functions, very rarely do they need to be called directly.
Set the current viewport rectangle within the screen.
Sets an orthographic projection matrix.
Sets a perspective projection matrix.
Toggle depth testing and clearing of depth buffer.
Check if a given key is currently pressed.
Obtain a list of all keys which are currently pressed.
Check if a given mouse button is currently pressed.
Gets current x location of mouse with respect to screen coordinates.
Gets current y location of mouse with respect to screen coordinates.
Gets current location of mouse wheel, treated as if wheel describes a third axis of movement for the mouse.
Get time, in seconds, that application has been running.
Sets number of frames used to smooth the timeDelta so that minor jitters in frramerate do not cause severe stuttering.
Finds the amount of time passed between frames, or average of a number of frames if setFrameTimeSmoothing has been called.
Gets number of frames per second the application is currently processing subject to smoothing by setFrameTimeSmoothing.
Sets a fixed timestep to be used in calls to the current State’s update method.
Set the current Application State, removing all other States.
Push a new State, does not remove old State.
Pop the current State, returning to the prior State on the stack.
Get the Application’s AudioCore, should only be called after initAudioCore.
Initialize the AudioCore, should be done before attempting to access it via getAudioCore.

(Con/ De)structors

Application

Application(const std::string &arg0)

Default constructor, initializes the internal state & dependencies.

~Application

virtual ~Application()

Default destructor, shuts down dependencies.

General

run

void run()

Runs application until a quit is requested either via the operating system (ex.  Alt-F4) or through a call to quit.

Should not be called before a State has been set and a display has been created via createDisplay.

quit

void quit()

Sets Quit flag, terminating application.

getUpdateTaskManager

util::TaskManager& getUpdateTaskManager()

Access the application’s update TaskManager, Tasks registered with this TaskManager are executed after the current State::update.

Returns

Reference to “Update TaskManager”

getRenderTaskManager

util::TaskManager& getRenderTaskManager()

Access the application’s render TaskManager, Tasks registered with this TaskManager are executed after the current State::render.

Returns

Reference to “Render TaskManager”

isActive

bool isActive()

Checks if application is active, which on most systems simply means it has focus.

Returns

True if application is active, false otherwise.

Window

createDisplay

void createDisplay(uint width,  
uint height,  
uint redBits,  
uint greenBits,  
uint blueBits,  
uint alphaBits,  
uint depthBits,  
uint stencilBits,  
bool fullscreen,  
const std::string &title = "Photon App")

This function attempts to create a display with the given parameters.

Parameters

widthdesired width of display
heightdesired height of display
redBitsdesired bits per pixel for red value
greenBitsdesired bits per pixel for green value
blueBitsdesired bits per pixel for blue value
alphaBitsdesired bits per pixel for alpha value
depthBitsdesired bitdepth of depth buffer
stencilBitsdesired bitdepth of stencil buffer
fullscreentrue: fullscreen, false: windowed
[titletitle of application, optional]

createDisplay

void createDisplay(uint width,  
uint height,  
uint bpp,  
uint depthBits,  
uint stencilBits,  
bool fullscreen,  
const std::string &title = "Photon App")

This function attempts to create a display with the given parameters.

Parameters

widthdesired width of display
heightdesired height of display
bppdesired bits per pixel (aka bitdepth) of display
depthBitsdesired bitdepth of depth buffer
stencilBitsdesired bitdepth of stencil buffer
fullscreentrue: fullscreen, false: windowed
[titletitle of application, optional]

setTitle

void setTitle(const std::string &title)

Sets title of application that shows up in title bar.

Parameters

titleNew title of application.

getDisplayWidth

uint getDisplayWidth()

Get the width of the display.

Returns

Width of display in pixels.

getDisplayHeight

uint getDisplayHeight()

Get the height of the display.

Returns

Height of display in pixels.

Ortho

setOrthoView

void setOrthoView(int x,
int y,
int viewWidth,
int viewHeight,
scalar orthoWidth,
scalar orthoHeight)

Sets new ortho viewport within a rectangular portion of the screen.  All drawing is relative to the rectangle, x,y becomes 0,0 and anything drawn outside rect is clipped.

Parameters

xX coord for top left corner of new viewport.
yY coord for top left corner of new viewport.
viewWidthWidth of new viewport.
viewHeightHeight of new viewport.
orthoWidthWidth of ortho perspective.
orthoHeightHeight of ortho perspective.

setOrthoView

void setOrthoView(scalar width,
scalar height)

Sets entire screen as current viewport with a given ortho perspective.

Parameters

widthWidth of view.
heightHeight of view.

setOrthoView

void setOrthoView()

Sets entire screen as current viewport with a 1:1 perspective.

Perspective

setPerspectiveView

void setPerspectiveView(int x,
int y,
int width,
int height,
scalar fovy,
scalar zNear,
scalar zFar)

Creates a viewport with a given 3D perspective inside of a rectangular portion of the screen.

Note that <setDepthTestMode>(true) will be called as a side effect.

Parameters

xX coord for top left corner of new viewport.
yY coord for top left corner of new viewport.
widthWidth of new viewport.
heightHeight of new viewport.
fovyThe y axis field of view angle, in degrees.
zNearDistance from viewer to near clipping plane.
zFarDistance from viewer to far clipping plane.

setPerspectiveView

void setPerspectiveView(scalar fovy,
scalar zNear,
scalar zFar)

Sets entire screen as current viewport with a given 3D perspective.

Note that <setDepthTestMode>(true) will be called as a side effect.

Parameters

fovyThe y axis field of view angle, in degrees.
zNearDistance from viewer to near clipping plane.
zFarDistance from viewer to far clipping plane.

Viewport/ Projection

These functions are called by the above Ortho/Perspective functions, very rarely do they need to be called directly.

setViewport

void setViewport(int x,
int y,
int width,
int height)

Set the current viewport rectangle within the screen.

setOrthoProjection

void setOrthoProjection(scalar width,
scalar height)

Sets an orthographic projection matrix.

Parameters

widthWidth of view.
heightHeight of view.

setPerspectiveProjection

void setPerspectiveProjection(scalar fovy,
scalar zNear,
scalar zFar)

Sets a perspective projection matrix.

Note that <setDepthTestMode>(true) will be called as a side effect.

Parameters

fovyThe y axis field of view angle, in degrees.
zNearDistance from viewer to near clipping plane.
zFarDistance from viewer to far clipping plane.

setDepthBufferParams

void setDepthBufferParams(bool enable,  
scalar depth = 1)

Toggle depth testing and clearing of depth buffer.

Parameters

enableif true, testing/clearing depth buffer is enabled, if false testing and clearing of depth buffer will be disabled.
depthoptional clear depth amount, clamped [0..1], default is 1

Input

keyPressed

bool keyPressed(KeyCode key)

Check if a given key is currently pressed.

Parameters

keyKeyCode of key to determine status of.

Returns

true: key is pressed, false: key isn’t pressed

getPressedKeys

std::vector<KeyCode> getPressedKeys()

Obtain a list of all keys which are currently pressed.

Returns

std::vector of KeyCodes of any pressed keys.

mouseButtonPressed

bool mouseButtonPressed(MouseButton button)

Check if a given mouse button is currently pressed.

Parameters

buttonMouseButton to determine status of.

Returns

true: button is pressed, false: button isn’t pressed

getMouseX

int getMouseX()

Gets current x location of mouse with respect to screen coordinates.

Returns

Mouse x-coordinate, with respect to screen coordinates.

getMouseY

int getMouseY()

Gets current y location of mouse with respect to screen coordinates.

Returns

Mouse y-coordinate, with respect to screen coordinates.

getMouseWheelPos

int getMouseWheelPos()

Gets current location of mouse wheel, treated as if wheel describes a third axis of movement for the mouse.

Returns

Mouse wheel position, zero assumed to be starting position.

Timing

getTime

scalar getTime()

Get time, in seconds, that application has been running.

Returns

Time, represented as a floating-point number in seconds, application has been running.

setFrameTimeSmoothing

void setFrameTimeSmoothing(int numFrames)

Sets number of frames used to smooth the timeDelta so that minor jitters in frramerate do not cause severe stuttering.

Parameters

numFramesNumber of frames to average, setting to <= 1 turns off smoothing of timeDelta.  (Recommend something >= 50, <= 500)

getElapsedTime

double getElapsedTime()

Finds the amount of time passed between frames, or average of a number of frames if setFrameTimeSmoothing has been called.

Returns

Time (or average time) between frames.

getFramerate

double getFramerate()

Gets number of frames per second the application is currently processing subject to smoothing by setFrameTimeSmoothing.

Returns

Calculated number of frames per second.

setFixedUpdateStep

void setFixedUpdateStep(bool enable,  
scalar fixedStep,  
scalar maxStep = )

Sets a fixed timestep to be used in calls to the current State’s update method.  This allows stability in physics systems.

Parameters

enableif true, will enable fixed timestepping (if false will disable)
fixedStepthe timestep to use for the fixed step, ignored if disabling
maxStepif somehow the update portion get signifigantly behind the render portion, to avoid executing a large number of steps (hanging the program) an optional maxStep can be specified.  [default = 5*fixedStep]

State Management

setState

template<class StateT> void setState()

Set the current Application State, removing all other States.

Template Parameters

StateTClass derived from State to set as current.

pushState

template<class StateT> void pushState()

Push a new State, does not remove old State.

Template Parameters

StateTClass derived from State to push.

popState

void popState()

Pop the current State, returning to the prior State on the stack.

AudioCore

getAudioCore

audio::AudioCore& getAudioCore()

Get the Application’s AudioCore, should only be called after initAudioCore.

Return

Reference to the AudioCore.

initAudioCore

void initAudioCore(const std::string &deviceName = "")

Initialize the AudioCore, should be done before attempting to access it via getAudioCore.

Arguments

deviceNameOptional name for desired Audio device, will use default device if none specified.
Pure virtual State class, used as base class for Photon’s state system.
Application(const std::string &arg0)
Default constructor, initializes the internal state & dependencies.
virtual ~Application()
Default destructor, shuts down dependencies.
void run()
Runs application until a quit is requested either via the operating system (ex.
void quit()
Sets Quit flag, terminating application.
util::TaskManager& getUpdateTaskManager()
Access the application’s update TaskManager, Tasks registered with this TaskManager are executed after the current State::update.
TaskManager class, maintains a list of Tasks and manages their status, handles adding, deleting, pausing, and unpausing tasks.
virtual void update(scalar timeDelta)
All of a state’s logic should go in update, it is called every frame before the rendering process begins.
util::TaskManager& getRenderTaskManager()
Access the application’s render TaskManager, Tasks registered with this TaskManager are executed after the current State::render.
virtual void render()=0
The only required member of State, anything that should be drawn to the screen while the State is active should be drawn in render.
bool isActive()
Checks if application is active, which on most systems simply means it has focus.
void createDisplay(uint width,  
uint height,  
uint redBits,  
uint greenBits,  
uint blueBits,  
uint alphaBits,  
uint depthBits,  
uint stencilBits,  
bool fullscreen,  
const std::string &title = "Photon App")
This function attempts to create a display with the given parameters.
void setTitle(const std::string &title)
Sets title of application that shows up in title bar.
uint getDisplayWidth()
Get the width of the display.
uint getDisplayHeight()
Get the height of the display.
void setOrthoView(int x,
int y,
int viewWidth,
int viewHeight,
scalar orthoWidth,
scalar orthoHeight)
Sets new ortho viewport within a rectangular portion of the screen.
void setPerspectiveView(int x,
int y,
int width,
int height,
scalar fovy,
scalar zNear,
scalar zFar)
Creates a viewport with a given 3D perspective inside of a rectangular portion of the screen.
void setViewport(int x,
int y,
int width,
int height)
Set the current viewport rectangle within the screen.
void setOrthoProjection(scalar width,
scalar height)
Sets an orthographic projection matrix.
void setPerspectiveProjection(scalar fovy,
scalar zNear,
scalar zFar)
Sets a perspective projection matrix.
void setDepthBufferParams(bool enable,  
scalar depth = 1)
Toggle depth testing and clearing of depth buffer.
bool keyPressed(KeyCode key)
Check if a given key is currently pressed.
std::vector<KeyCode> getPressedKeys()
Obtain a list of all keys which are currently pressed.
bool mouseButtonPressed(MouseButton button)
Check if a given mouse button is currently pressed.
int getMouseX()
Gets current x location of mouse with respect to screen coordinates.
int getMouseY()
Gets current y location of mouse with respect to screen coordinates.
int getMouseWheelPos()
Gets current location of mouse wheel, treated as if wheel describes a third axis of movement for the mouse.
scalar getTime()
Get time, in seconds, that application has been running.
void setFrameTimeSmoothing(int numFrames)
Sets number of frames used to smooth the timeDelta so that minor jitters in frramerate do not cause severe stuttering.
double getElapsedTime()
Finds the amount of time passed between frames, or average of a number of frames if setFrameTimeSmoothing has been called.
double getFramerate()
Gets number of frames per second the application is currently processing subject to smoothing by setFrameTimeSmoothing.
void setFixedUpdateStep(bool enable,  
scalar fixedStep,  
scalar maxStep = )
Sets a fixed timestep to be used in calls to the current State’s update method.
template<class StateT> void setState()
Set the current Application State, removing all other States.
template<class StateT> void pushState()
Push a new State, does not remove old State.
void popState()
Pop the current State, returning to the prior State on the stack.
audio::AudioCore& getAudioCore()
Get the Application’s AudioCore, should only be called after initAudioCore.
void initAudioCore(const std::string &deviceName = "")
Initialize the AudioCore, should be done before attempting to access it via getAudioCore.
Template class for singleton pattern.
Enumeration defining keys, used in Application::keyPressed.
Enumeration defining buttons, used in Application::mouseButtonPressed.