Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Public Member Functions | List of all members
gf::RenderWindow Class Reference

A window that can serve as a target for 2D drawing. More...

#include <gf/RenderWindow.h>

Inheritance diagram for gf::RenderWindow:
Inheritance graph
[legend]

Public Member Functions

 RenderWindow (Window &window)
 Constructor. More...
 
virtual Vector2u getSize () const override
 Return the size of the rendering region of the target. More...
 
void setActive ()
 Activate the target for rendering. More...
 
void display ()
 Display on screen what has been rendered to the window so far. More...
 
Image capture () const
 Copy the current contents of the render window to an image. More...
 
- Public Member Functions inherited from gf::RenderTarget
 RenderTarget ()=default
 Default constructor. More...
 
virtual ~RenderTarget ()
 Destructor. More...
 
 RenderTarget (const RenderTarget &)=delete
 Deleted copy constructor. More...
 
RenderTargetoperator= (const RenderTarget &)=delete
 Deleted copy assignment. More...
 
bool getScissorTest ()
 Tell if the scissor test is enabled. More...
 
void setScissorTest (bool scissor=true)
 Enable or disable the scissor test. More...
 
RectI getScissoBox ()
 Get the current scissor box. More...
 
void setScissorBox (const RectI &box)
 Define the scissor box. More...
 
void clear (const Color4f &color)
 Clear the entire target with a single color. More...
 
void clear ()
 Clear the entire target. More...
 
RangeF getAliasedLineWidthRange () const
 Get the range for aliased line width. More...
 
float getLineWidth () const
 Get the line width. More...
 
void draw (const Vertex *vertices, std::size_t count, PrimitiveType type, const RenderStates &states=RenderStates())
 Draw primitives defined by an array of vertices. More...
 
void draw (const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type, const RenderStates &states=RenderStates())
 Draw primitives defined by an array of vertices and their indices. More...
 
void draw (const Vertex *vertices, int *first, const std::size_t *count, std::size_t primcount, PrimitiveType type, const RenderStates &states=RenderStates())
 Draw primitives defined by an array of vertices. More...
 
void draw (const Vertex *vertices, const uint16_t **indices, const std::size_t *count, std::size_t primcount, PrimitiveType type, const RenderStates &states=RenderStates())
 Draw primitives defined by an array of vertices and their indices. More...
 
void draw (const VertexBuffer &buffer, const RenderStates &states=RenderStates())
 Draw a vertex buffer to the render target. More...
 
void draw (Drawable &drawable, const RenderStates &states=RenderStates())
 Draw a drawable object to the render target. More...
 
void setView (const View &view)
 Change the current active view. More...
 
const ViewgetView () const
 Get the view currently in use in the render target. More...
 
RectI getViewport (const View &view) const
 Get the viewport of a view, applied to this render target. More...
 
Vector2f mapPixelToCoords (Vector2i point, const View &view) const
 Convert a point from target coordinates to world coordinates. More...
 
Vector2f mapPixelToCoords (Vector2i point) const
 Convert a point from target coordinates to world coordinates, using the current view. More...
 
Vector2i mapCoordsToPixel (Vector2f point, const View &view) const
 Convert a point from world coordinates to target coordinates. More...
 
Vector2i mapCoordsToPixel (Vector2f point) const
 Convert a point from world coordinates to target coordinates, using the current view. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gf::RenderTarget
void initialize ()
 Performs the common initialization step after creation. More...
 
Image captureFramebuffer (unsigned name) const
 Capture the given framebuffer. More...
 

Detailed Description

A window that can serve as a target for 2D drawing.

gf::RenderWindow is the main class of the graphics module. It defines an OS window that can be painted using the other classes of the graphics module.

Here is a typical rendering and event loop with a gf::RenderWindow:

// Declare and create a new render-window
gf::Window window("New window", { 800, 600 });
gf::RenderWindow renderer(window);
// The main loop - ends as soon as the window is closed
while (window.isOpen()) {
// Event processing
gf::Event event;
while (window.pollEvent(event)) {
// Request for closing the window
if (event.type == gf::EventType::Closed) {
window.close();
}
}
// Clear the whole window before rendering a new frame
renderer.clear();
// Draw some graphical entities
renderer.draw(sprite);
renderer.draw(circle);
renderer.draw(text);
// End the current frame and display its contents on screen
renderer.display();
}
See also
gf::Window, gf::RenderTarget, gf::RenderTexture, gf::View

Constructor & Destructor Documentation

gf::RenderWindow::RenderWindow ( Window window)

Constructor.

Parameters
windowThe window to render to

Member Function Documentation

Image gf::RenderWindow::capture ( ) const

Copy the current contents of the render window to an image.

This is a slow operation, whose main purpose is to make screenshots of the application.

void gf::RenderWindow::display ( )

Display on screen what has been rendered to the window so far.

This function is typically called after all OpenGL rendering has been done for the current frame, in order to show it on screen.

See also
Window::display()
virtual Vector2u gf::RenderWindow::getSize ( ) const
overridevirtual

Return the size of the rendering region of the target.

Returns
Size in pixels

Implements gf::RenderTarget.

void gf::RenderWindow::setActive ( )

Activate the target for rendering.

This function activates the render-window so that all draw calls are targeted to the window. You should call this function before you want to draw something to the target.