TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Graphics Namespace Reference

Give the GameScene and Entities something to display, Text, Sprites and AnimatedSprites help bring the world to life. More...

Classes

class  AnimationSequence
 
class  AnimatedSprite
 
class  PolygonShape
 
class  OutlinedPolygonShape
 
class  BoxShape
 
class  QuadShape
 
class  OutlinedBoxShape
 
class  FullScreenQuad
 
class  CircleShape
 
class  OutlinedCircleShape
 
class  Camera
 
class  Color
 
class  Graphic
 
class  GraphicList
 
class  LineContainer
 
class  Line
 
class  RenderTarget
 
struct  SpriteFrame
 
class  Sprite
 
class  SpriteManager
 
class  SpriteMap
 
class  SpriteSheet
 
class  Text
 
class  TextureManager
 

Typedefs

using AnchorLocation = Anchor
 
using FontSize = tbCore::uint16
 
using TexelSpace = float
 
using PixelSpace = tbCore::uint16
 
using TextureHandle = TurtleBrains::Core::ResourceHandle< Implementation::TextureHandleSaver >
 

Enumerations

enum class  Anchor {
  Center = 0 , TopLeft , TopCenter , TopRight ,
  CenterLeft , CenterRight , BottomLeft , BottomCenter ,
  BottomRight
}
 
enum class  GifOutputSize { Full , Half }
 
enum class  TextureFormat : tbCore::uint8 {
  ColorARGB8 , FloatRGB10A2 , FloatR11G11B10 , FloatARGB16 ,
  Depth16 , Depth24 , Depth24_Stencil8 , InvalidFormat
}
 
enum class  TextureWrapMode : tbCore::uint8 { Repeat , MirroredRepeat , ClampToEdge }
 
enum class  TextureFilter : tbCore::uint8 { Closest , Linear , DepthCompare }
 

Functions

std::ostream & operator<< (std::ostream &output, const AnchorLocation &anchor)
 
std::istream & operator>> (std::istream &input, AnchorLocation &anchor)
 
void SetActiveCamera (Camera &camera)
 
void SetActiveCamera (Camera *camera)
 
CameraGetActiveCamera (void)
 
void GifPerformCapture (const float deltaTime, const bool toggleCapture, const GifOutputSize &outputSize=GifOutputSize::Half)
 
void GifCaptureCleanup (void)
 
PixelSpace ScreenWidth (void)
 
PixelSpace ScreenHeight (void)
 
tbMath::Vector2 ScreenSize (void)
 
float ScreenAspectRatio (void)
 
tbMath::Vector2 ScreenCenter (void)
 
tbMath::Vector2 GetAnchorPositionOfScreen (const tbGraphics::AnchorLocation &anchor, const float offsetX, const float offsetY)
 
tbMath::Vector2 GetAnchorPositionOfScreen (const tbGraphics::AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero())
 
TextureHandle InvalidTexture (void)
 

Variables

SpriteManager theSpriteManager
 
const TextureHandlekBlankTexture
 
TextureManagertheTextureManager
 

Detailed Description

TODO: TurtleBrains: Documentation: This is still early in development and the Graphics framework is still being designed.

Requirements:
TurtleBrains::Application

Typedef Documentation

◆ PixelSpace

Represents a measurement in pixel space be it the width/height of an image in pixels, or the location on the screen or texture in pixels.

◆ TexelSpace

using TurtleBrains::Graphics::TexelSpace = typedef float

Represents a value from 0 to 1 in texture space for the width/height or location on a texture.

◆ TextureHandle

A TextureHandle is a unique value for each unique texture created with the TextureManager. Use the handle to access the textures properties and to destroy any resources associated.

Enumeration Type Documentation

◆ Anchor

These locations are used in the Sprite::SetOrigin() which takes an AnchorLocation.

Enumerator
Center 

This anchor will set the origin to the center of the Sprite horizontally and vertically.

TopLeft 

This anchor will set the origin to the top-left corner, effectively: SetOrigin(0.0f, 0.0f).

TopCenter 

This anchor will set the origin to the top and horizontal center of the Sprite.

TopRight 

This anchor will set the origin to the top and right most corner of the Sprite.

CenterLeft 

This anchor will set the origin to the center vertically and left most edge of the Sprite.

CenterRight 

This anchor will set the origin to the center vertically and right most edge of the Sprite.

BottomLeft 

This anchor will set the origin to the bottom and left most corner of the Sprite.

BottomCenter 

This anchor will set the origin to the bottom edge and horizontal center of the Sprite.

BottomRight 

This anchor will set the origin to the bottom and right most corner of the Sprite.

◆ TextureFilter

Enumerator
DepthCompare 

Depth compare with <=, used for ShadowMaps, may not actually be a filter as much as a state.

◆ TextureFormat

Selects the format the texture should be stored as; some formats may be incompatible with certain use cases.

Enumerator
ColorARGB8 

32 bits per pixel, colored texture with alpha, red, green, blue channels each having 8 bits.

Depth16 

16 bits per pixel, depth texture.

Depth24 

24 bits per pixel, depth texture.

◆ TextureWrapMode

Choose a wrap-mode for how the texture coordinates behave outside the 0 to 1 range.

Enumerator
Repeat 

Set the texture to repeat, ignoring the integral part of the U or V coordinate.

MirroredRepeat 

Mirrored repeat, ignoring the integral part of the U or V coordinate only when even.

ClampToEdge 

ClampToEdge wrap mode will keep the U or V coordinate within 0 to 1 top stop at texture edge.

Function Documentation

◆ GetActiveCamera()

Camera& TurtleBrains::Graphics::GetActiveCamera ( void  )

Retrieves the currently active camera, which there can only ever be one active camera and there is always an active camera.

◆ GetAnchorPositionOfScreen() [1/2]

tbMath::Vector2 TurtleBrains::Graphics::GetAnchorPositionOfScreen ( const tbGraphics::AnchorLocation anchor,
const float  offsetX,
const float  offsetY 
)

Finds the location of anchor point to the screen/window and adds the offset provided. This won't be correct if you are using a RenderTarget that has a different size than the screen.

Parameters
anchorThe anchor position to retrieve from screenspace.
offsetThe offset from that anchor position to automatically add to the the returned value.

◆ GetAnchorPositionOfScreen() [2/2]

tbMath::Vector2 TurtleBrains::Graphics::GetAnchorPositionOfScreen ( const tbGraphics::AnchorLocation anchor,
const tbMath::Vector2 offset = tbMath::Vector2::Zero() 
)

Finds the location of anchor point to the screen/window and adds the offset provided. This won't be correct if you are using a RenderTarget that has a different size than the screen.

Parameters
anchorThe anchor position to retrieve from screenspace.
offsetThe offset from that anchor position to automatically add to the the returned value.

◆ GifCaptureCleanup()

void TurtleBrains::Graphics::GifCaptureCleanup ( void  )

This should be called during shutdown if GifPerformCapture had been called as it will wait until any worker threads cleanly end and join back to main thread.

◆ GifPerformCapture()

void TurtleBrains::Graphics::GifPerformCapture ( const float  deltaTime,
const bool  toggleCapture,
const GifOutputSize &  outputSize = GifOutputSize::Half 
)

This is the only function that needs to be called, once per frame during Update().

Parameters
deltaTimeThe amount of time since the previous call to PerformCapture.
toggleCaptureTrue if the capture state should be toggled on/off or off/on depending on the current state. Typically this would be a value from IsKeyPressed().
outputSizeWill change the size of the GIF that is exported from FULL, to Half to reduce size for social media platforms, at the cost of reduced quality.
Note
if tb_without_threading is defined, or tb_web is defined, then there will be no gif capture support and this will effectively do nothing.

◆ InvalidTexture()

TextureHandle TurtleBrains::Graphics::InvalidTexture ( void  )

Grabs a value that no valid texture handle will be.

◆ ScreenAspectRatio()

float TurtleBrains::Graphics::ScreenAspectRatio ( void  )

Computes and returns the aspect ratio of the screen, width/height. 1920/1080 ~= 1.77778.

◆ ScreenCenter()

tbMath::Vector2 TurtleBrains::Graphics::ScreenCenter ( void  )

Creates and returns a Vector2 object of the location of the center of the screen, half width / height.

◆ ScreenHeight()

PixelSpace TurtleBrains::Graphics::ScreenHeight ( void  )

Returns the height of the screen/window in pixels.

◆ ScreenSize()

tbMath::Vector2 TurtleBrains::Graphics::ScreenSize ( void  )

Creates and returns a Vector2 object of the size of the screen, width and height.

◆ ScreenWidth()

PixelSpace TurtleBrains::Graphics::ScreenWidth ( void  )

Returns the width of the screen/window in pixels.

◆ SetActiveCamera() [1/2]

void TurtleBrains::Graphics::SetActiveCamera ( Camera camera)

Sets the current camera to be inactive and sets the provided camera as an active camera that will not be cleaned up. It is expected the camera object provided will be in existance until it is no longer the active camera.

Parameters
cameraThe newly activated camera ready to apply to the view.

◆ SetActiveCamera() [2/2]

void TurtleBrains::Graphics::SetActiveCamera ( Camera camera)

Sets the current camera to be inactive and sets the provided camera as an active camera that will automatically be cleaned up by calling delete on the object once a new camera becomes active.

Parameters
cameraA pointer to a camera object that was allocated with new. This object will become the active camera ready to apply to the view, and will automatically get deleted once a new camera is activated.

Variable Documentation

◆ kBlankTexture

const TextureHandle& TurtleBrains::Graphics::kBlankTexture
extern

This is a small, white texture that is automatically loaded for rendering Lines without a separate shader.

Note
This is only valid after a Graphics Context has been created, and before it has been destroyed.

◆ theSpriteManager

SpriteManager TurtleBrains::Graphics::theSpriteManager
extern

Instead of creating your own SpriteManager object, this is a way to access it as a singleton. This may turn into a pointer to the object, although the SpriteManager api will remain the same.

◆ theTextureManager

TextureManager& TurtleBrains::Graphics::theTextureManager
extern

Instead of creating your own TextureManager object, this is a way to access it as a singleton. This may turn into a pointer to the object, although the TextureManager API will remain the same.