Class Context

Class Documentation

class nyx::Context

Context is how everything in Nyx is drawn. Contexts have multiple methods that are used to draw things, including primitives and textures. Each context has persistent state, meaning that when objects are added to them, they are kept buffered in OpenGL until the clear() method is called. This allows incredibly fast rendering as scenes don’t need to be redrawn every frame.

Public Functions

Context()

Create a new Context, should not be used directly, instead ask a Window to create a context for you.

~Context()
void clear()

Reset the state of the context, clearing the OpenGL buffers and all objects this Context currently draws to the screen.

void pixel(float x, float y, Color color)

Draw a pixel at (x, y) using the specified Color.

Parameters
  • x: x coordinate of the pixel

  • y: y coordinate of the pixel

  • color: the color to draw the pixel with

void line(float x1, float y1, float x2, float y2, Color color)

Draw a line from the point (x1, y1) to (x2, y2) using the specified Color.

Parameters
  • x1: x coordinate of first point

  • y1: y coordinate of first point

  • x2: x coordinate of second point

  • y2: y coordinate of second point

  • color: the color to draw the line with

void triangle(float x1, float y1, float x2, float y2, float x3, float y3, float angle, Color color)

Draw a triangle with the points (x1, y1), (x2, y2), and (x3, y3), rotated at angle, using the specified color.

Parameters
  • x1: x coordinate of first point

  • y1: y coordinate of first point

  • x2: x coordinate of second point

  • y2: y coordinate of second point

  • x3: x coordinate of third point

  • y3: y coordinate of third point

  • angle: angle in degrees

  • color: the color to draw the triangle with

void triangle(float x1, float y1, float x2, float y2, float x3, float y3, Color color)

Draw a triangle with the points (x1, y1), (x2, y2), and (x3, y3) using the specified color.

Parameters
  • x1: x coordinate of first point

  • y1: y coordinate of first point

  • x2: x coordinate of second point

  • y2: y coordinate of second point

  • x3: x coordinate of third point

  • y3: y coordinate of third point

  • color: the color to draw the triangle with

void rectangle(float x, float y, float w, float h, float angle, Color color)

Draw a rectangle at (x, y) with a size of (w, h), rotated at angle, using the specified color.

Parameters
  • x: the x coordinate

  • y: the y coordinate

  • w: the width

  • h: the height

  • angle: angle in degrees

  • color: the color to draw the rectangle with

void rectangle(float x, float y, float w, float h, Color color)

Draw a rectangle at (x, y) with a size of (w, h), using the specified color.

Parameters
  • x: the x coordinate

  • y: the y coordinate

  • w: the width

  • h: the height

  • color: the color to draw the rectangle with

void asset(std::string const &name, std::string const &path, Color mask, bool retro = false)

Load an asset (texture)

Parameters
  • name: the name to give the asset

  • path: the path to the asset

  • mask: the color mask to use with the asset

  • retro: if true, use nearest-neighbor filtering

void asset(std::string const &name, std::string const &path, bool retro = false)

Load an asset (texture), using color mask 0xff00ffff (magenta)

Parameters
  • name: the name to give the asset

  • path: the path to the asset

  • retro: if true, use nearest-neighbor filtering

void texture(std::string const &path, float x, float y, Color color = Color(0xffffffff))

Draw a texture at full size at (x, y)

Parameters
  • path: the name of the texture

  • x: the x coordinate

  • y: the y coordinate

  • color: the color to multiply into the texture

void texture(std::string const &path, float x, float y, float angle, Color color = Color(0xffffffff))

Draw a texture at full size at (x, y) at an angle.

Parameters
  • path: the name of the texture

  • x: the x coordinate

  • y: the y coordinate

  • angle: angle in degrees

  • color: the color to multiply into the texture

void texture(std::string const &path, float x, float y, float w, float h, Color color = Color(0xffffffff))

Draw a texture at (x, y) with size (w, h)

Parameters
  • path: the name of the texture

  • x: the x coordinate

  • y: the y coordinate

  • w: the width to scale to

  • h: the height to scale to

  • color: the color to multiply into the texture

void texture(std::string const &path, float x, float y, float w, float h, float angle, Color color = Color(0xffffffff))

Draw a texture at (x, y) with size (w, h) at an angle.

Parameters
  • path: the name of the texture

  • x: the x coordinate

  • y: the y coordinate

  • w: the width to scale to

  • h: the height to scale to

  • angle: angle in degrees

  • color: the color to multiply into the texture

void texture(std::string const &path, float x, float y, float sx, float sy, float sw, float sh, Color color = Color(0xffffffff))

Draw a portion of a texture at (x, y), using the portion at (sx, sy) with a size of (sw, sh)

Parameters
  • path: the name of the texture

  • x: the x coordinate

  • y: the y coordinate

  • sx: the source x

  • sy: the source y

  • sw: the source width

  • sh: the source height

  • color: the color to multiply into the texture

void texture(std::string const &path, float x, float y, float sx, float sy, float sw, float sh, float angle, Color color = Color(0xffffffff))

Draw a portion of a texture at (x, y), using the portion at (sx, sy) with a size of (sw, sh), at an angle.

Parameters
  • path: the name of the texture

  • x: the x coordinate

  • y: the y coordinate

  • sx: the source x

  • sy: the source y

  • sw: the source width

  • sh: the source height

  • angle: angle in degrees

  • color: the color to multiply into the texture

void texture(std::string const &path, float x, float y, float w, float h, float sx, float sy, float sw, float sh, Color color = Color(0xffffffff))

Draw a portion of a texture at (x, y) with a size of (w, h), using the portion at (sx, sy) with a size of (sw, sh)

Parameters
  • path: the name of the texture

  • x: the x coordinate

  • y: the y coordinate

  • w: the width to scale to

  • h: the height to scale to

  • sx: the source x

  • sy: the source y

  • sw: the source width

  • sh: the source height

  • color: the color to multiply into the texture

void texture(std::string const &path, float x, float y, float w, float h, float sx, float sy, float sw, float sh, float angle, Color color = Color(0xffffffff))

Draw a portion of a texture at (x, y) with a size of (w, h), using the portion at (sx, sy) with a size of (sw, sh), at an angle.

Parameters
  • path: the name of the texture

  • x: the x coordinate

  • y: the y coordinate

  • w: the width to scale to

  • h: the height to scale to

  • sx: the source x

  • sy: the source y

  • sw: the source width

  • sh: the source height

  • angle: angle in degrees

  • color: the color to multiply into the texture