Gosu
Public Member Functions | Static Public Member Functions | List of all members
Gosu::Graphics Class Reference

Serves as the target of all drawing and provides primitive drawing functionality. More...

Public Member Functions

 Graphics (unsigned physical_width, unsigned physical_height)
 
 ~Graphics ()
 
void set_resolution (unsigned logical_width, unsigned logical_height, double black_bar_width=0, double black_bar_height=0)
 
unsigned width () const
 
unsigned height () const
 
void frame (const std::function< void()> &f)
 Prepares the graphics object for drawing and then runs the rendering code in f. More...
 
void set_physical_resolution (unsigned physical_width, unsigned physical_height)
 For internal use only. More...
 

Static Public Member Functions

static void flush ()
 Flushes the Z queue to the screen and starts a new one. More...
 
static void gl (const std::function< void()> &f)
 Finishes all pending Gosu drawing operations and executes the code in f in a clean OpenGL environment. More...
 
static void gl (ZPos z, const std::function< void()> &f)
 Schedules a custom GL functor to be executed at a certain Z level. More...
 
static void clip_to (double x, double y, double width, double height, const std::function< void()> &f)
 Renders everything drawn in f clipped to a rectangle on the screen. More...
 
static std::unique_ptr< Gosu::ImageDatarecord (int width, int height, const std::function< void()> &f)
 Records a macro and returns it as an ImageData instance. More...
 
static void transform (const Transform &transform, const std::function< void()> &f)
 Pushes one transformation onto the transformation stack. More...
 
static void draw_line (double x1, double y1, Color c1, double x2, double y2, Color c2, ZPos z, AlphaMode mode=AM_DEFAULT)
 Draws a line from one point to another (last pixel exclusive). More...
 
static void draw_triangle (double x1, double y1, Color c1, double x2, double y2, Color c2, double x3, double y3, Color c3, ZPos z, AlphaMode mode=AM_DEFAULT)
 
static void draw_quad (double x1, double y1, Color c1, double x2, double y2, Color c2, double x3, double y3, Color c3, double x4, double y4, Color c4, ZPos z, AlphaMode mode=AM_DEFAULT)
 
static void draw_rect (double x, double y, double width, double height, Color c, ZPos z, AlphaMode mode=AM_DEFAULT)
 
static void schedule_draw_op (const DrawOp &op)
 For internal use only. More...
 
static std::unique_ptr< ImageDatacreate_image (const Bitmap &src, unsigned src_x, unsigned src_y, unsigned src_width, unsigned src_height, unsigned image_flags)
 Turns a portion of a bitmap into something that can be drawn on a Graphics object. More...
 

Detailed Description

Serves as the target of all drawing and provides primitive drawing functionality.

Usually created internally by Gosu::Window.

Definition at line 24 of file Graphics.hpp.

Constructor & Destructor Documentation

◆ Graphics()

Gosu::Graphics::Graphics ( unsigned  physical_width,
unsigned  physical_height 
)

◆ ~Graphics()

Gosu::Graphics::~Graphics ( )

Member Function Documentation

◆ clip_to()

static void Gosu::Graphics::clip_to ( double  x,
double  y,
double  width,
double  height,
const std::function< void()> &  f 
)
static

Renders everything drawn in f clipped to a rectangle on the screen.

◆ create_image()

static std::unique_ptr<ImageData> Gosu::Graphics::create_image ( const Bitmap src,
unsigned  src_x,
unsigned  src_y,
unsigned  src_width,
unsigned  src_height,
unsigned  image_flags 
)
static

Turns a portion of a bitmap into something that can be drawn on a Graphics object.

◆ draw_line()

static void Gosu::Graphics::draw_line ( double  x1,
double  y1,
Color  c1,
double  x2,
double  y2,
Color  c2,
ZPos  z,
AlphaMode  mode = AM_DEFAULT 
)
static

Draws a line from one point to another (last pixel exclusive).

Note: OpenGL lines are not reliable at all and may have a missing pixel at the start or end point. Please only use this for debugging purposes. Otherwise, use a quad or image to simulate lines, or contribute a better draw_line to Gosu.

◆ draw_quad()

static void Gosu::Graphics::draw_quad ( double  x1,
double  y1,
Color  c1,
double  x2,
double  y2,
Color  c2,
double  x3,
double  y3,
Color  c3,
double  x4,
double  y4,
Color  c4,
ZPos  z,
AlphaMode  mode = AM_DEFAULT 
)
static

◆ draw_rect()

static void Gosu::Graphics::draw_rect ( double  x,
double  y,
double  width,
double  height,
Color  c,
ZPos  z,
AlphaMode  mode = AM_DEFAULT 
)
static

◆ draw_triangle()

static void Gosu::Graphics::draw_triangle ( double  x1,
double  y1,
Color  c1,
double  x2,
double  y2,
Color  c2,
double  x3,
double  y3,
Color  c3,
ZPos  z,
AlphaMode  mode = AM_DEFAULT 
)
static

◆ flush()

static void Gosu::Graphics::flush ( )
static

Flushes the Z queue to the screen and starts a new one.

This can be useful to separate the Z queues of two parts of the game, e.g. the two halves of a game that runs in split-screen mode.

◆ frame()

void Gosu::Graphics::frame ( const std::function< void()> &  f)

Prepares the graphics object for drawing and then runs the rendering code in f.

Nothing must be drawn outside of frame() and record().

◆ gl() [1/2]

static void Gosu::Graphics::gl ( const std::function< void()> &  f)
static

Finishes all pending Gosu drawing operations and executes the code in f in a clean OpenGL environment.

◆ gl() [2/2]

static void Gosu::Graphics::gl ( ZPos  z,
const std::function< void()> &  f 
)
static

Schedules a custom GL functor to be executed at a certain Z level.

The functor f is run in a clean GL context. Note: You may not call any Gosu rendering functions from within the functor.

◆ height()

unsigned Gosu::Graphics::height ( ) const

◆ record()

static std::unique_ptr<Gosu::ImageData> Gosu::Graphics::record ( int  width,
int  height,
const std::function< void()> &  f 
)
static

Records a macro and returns it as an ImageData instance.

Usually, the return value is passed to Image::Image(). Cannot be nested.

◆ schedule_draw_op()

static void Gosu::Graphics::schedule_draw_op ( const DrawOp &  op)
static

For internal use only.

◆ set_physical_resolution()

void Gosu::Graphics::set_physical_resolution ( unsigned  physical_width,
unsigned  physical_height 
)

For internal use only.

◆ set_resolution()

void Gosu::Graphics::set_resolution ( unsigned  logical_width,
unsigned  logical_height,
double  black_bar_width = 0,
double  black_bar_height = 0 
)

◆ transform()

static void Gosu::Graphics::transform ( const Transform transform,
const std::function< void()> &  f 
)
static

Pushes one transformation onto the transformation stack.

◆ width()

unsigned Gosu::Graphics::width ( ) const

The documentation for this class was generated from the following file: