SFML 3.0.0

- Main Page
- Topics
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | List of all members
sf::View Class Reference
Graphics module

2D camera that defines what region is shown on screen More...

`#include <SFML/Graphics/View.hpp>`

## Public Member Functions
| View ()=default
| Default constructor.
| View (const FloatRect &rectangle)
| Construct the view from a rectangle.
| View (Vector2f center, Vector2f size)
| Construct the view from its center and size.
void | setCenter (Vector2f center)
| Set the center of the view.
void | setSize (Vector2f size)
| Set the size of the view.
void | setRotation (Angle angle)
| Set the orientation of the view.
void | setViewport (const FloatRect &viewport)
| Set the target viewport.
void | setScissor (const FloatRect &scissor)
| Set the target scissor rectangle.
Vector2f | getCenter () const
| Get the center of the view.
Vector2f | getSize () const
| Get the size of the view.
Angle | getRotation () const
| Get the current orientation of the view.
const FloatRect & | getViewport () const
| Get the target viewport rectangle of the view.
const FloatRect & | getScissor () const
| Get the scissor rectangle of the view.
void | move (Vector2f offset)
| Move the view relatively to its current position.
void | rotate (Angle angle)
| Rotate the view relatively to its current orientation.
void | zoom (float factor)
| Resize the view rectangle relatively to its current size.
const Transform & | getTransform () const
| Get the projection transform of the view.
const Transform & | getInverseTransform () const
| Get the inverse projection transform of the view.

## Detailed Description

2D camera that defines what region is shown on screen

`sf::View` defines a camera in the 2D scene.

This is a very powerful concept: you can scroll, rotate or zoom the entire scene without altering the way that your drawable objects are drawn.

A view is composed of a source rectangle, which defines what part of the 2D scene is shown, and a target viewport, which defines where the contents of the source rectangle will be displayed on the render target (window or texture).

The viewport allows to map the scene to a custom part of the render target, and can be used for split-screen or for displaying a minimap, for example. If the source rectangle doesn't have the same size as the viewport, its contents will be stretched to fit in.

The scissor rectangle allows for specifying regions of the render target to which modifications can be made by draw and clear operations. Only pixels that are within the region will be able to be modified. Pixels outside of the region will not be modified by draw or clear operations.

Certain effects can be created by either using the viewport or scissor rectangle. While the results appear identical, there can be times where one method should be preferred over the other. Viewport transformations are applied during the vertex processing stage of the graphics pipeline, before the primitives are rasterized into fragments for fragment processing. Since viewport processing has to be performed and cannot be disabled, effects that are performed using the viewport transform are basically free performance-wise. Scissor testing is performed in the per-sample processing stage of the graphics pipeline, after fragment processing has been performed. Because per-sample processing is performed at the last stage of the pipeline, fragments that are discarded at this stage will cause the highest waste of GPU resources compared to any method that would have discarded vertices or fragments earlier in the pipeline. There are situations in which scissor testing has to be used to control whether fragments are discarded or not. An example of such a situation is when performing the viewport transform on vertices is necessary but a subset of the generated fragments should not have an effect on the stencil buffer or blend with the color buffer.

Definition at line 45 of file View.hpp.

## Constructor & Destructor Documentation

## ◆ View() [1/3]

sf::View::View | ( |  | ) |
| default

Default constructor.

This constructor creates a default view of (0, 0, 1000, 1000)

## ◆ View() [2/3]

sf::View::View | ( | const FloatRect & | rectangle | ) |
| explicit

Construct the view from a rectangle.

Parameters

  rectangle | Rectangle defining the zone to display

## ◆ View() [3/3]

sf::View::View | ( | Vector2f | center,
|  | Vector2f | size )

Construct the view from its center and size.

Parameters

  center | Center of the zone to display
  size | Size of zone to display

## Member Function Documentation

## ◆ getCenter()

Vector2f sf::View::getCenter | ( |  | ) | const
| nodiscard

Get the center of the view.

Returns
  Center of the view

See also
  `getSize`, `setCenter`

## ◆ getInverseTransform()

const Transform & sf::View::getInverseTransform | ( |  | ) | const
| nodiscard

Get the inverse projection transform of the view.

This function is meant for internal use only.

Returns
  Inverse of the projection transform defining the view

See also
  `getTransform`

## ◆ getRotation()

Angle sf::View::getRotation | ( |  | ) | const
| nodiscard

Get the current orientation of the view.

Returns
  Rotation angle of the view

See also
  `setRotation`

## ◆ getScissor()

const FloatRect & sf::View::getScissor | ( |  | ) | const
| nodiscard

Get the scissor rectangle of the view.

Returns
  Scissor rectangle, expressed as a factor of the target size

See also
  `setScissor`

## ◆ getSize()

Vector2f sf::View::getSize | ( |  | ) | const
| nodiscard

Get the size of the view.

Returns
  Size of the view

See also
  `getCenter`, `setSize`

## ◆ getTransform()

const Transform & sf::View::getTransform | ( |  | ) | const
| nodiscard

Get the projection transform of the view.

This function is meant for internal use only.

Returns
  Projection transform defining the view

See also
  `getInverseTransform`

## ◆ getViewport()

const FloatRect & sf::View::getViewport | ( |  | ) | const
| nodiscard

Get the target viewport rectangle of the view.

Returns
  Viewport rectangle, expressed as a factor of the target size

See also
  `setViewport`

## ◆ move()

void sf::View::move | ( | Vector2f | offset | ) |

Move the view relatively to its current position.

Parameters

  offset | Move offset

See also
  `setCenter`, `rotate`, `zoom`

## ◆ rotate()

void sf::View::rotate | ( | Angle | angle | ) |

Rotate the view relatively to its current orientation.

Parameters

  angle | Angle to rotate

See also
  `setRotation`, `move`, `zoom`

## ◆ setCenter()

void sf::View::setCenter | ( | Vector2f | center | ) |

Set the center of the view.

Parameters

  center | New center

See also
  `setSize`, `getCenter`

## ◆ setRotation()

void sf::View::setRotation | ( | Angle | angle | ) |

Set the orientation of the view.

The default rotation of a view is 0 degree.

Parameters

  angle | New angle

See also
  `getRotation`

## ◆ setScissor()

void sf::View::setScissor | ( | const FloatRect & | scissor | ) |

Set the target scissor rectangle.

The scissor rectangle, expressed as a factor (between 0 and 1) of the RenderTarget, specifies the region of the RenderTarget whose pixels are able to be modified by draw or clear operations. Any pixels which lie outside of the scissor rectangle will not be modified by draw or clear operations. For example, a scissor rectangle which only allows modifications to the right side of the target would be defined with `view.setScissor(sf::FloatRect({0.5f, 0.f}, {0.5f, 1.f}))`. By default, a view has a scissor rectangle which allows modifications to the entire target. This is equivalent to disabling the scissor test entirely. Passing the default scissor rectangle to this function will also disable scissor testing.

Parameters

  scissor | New scissor rectangle

See also
  `getScissor`

## ◆ setSize()

void sf::View::setSize | ( | Vector2f | size | ) |

Set the size of the view.

Parameters

  size | New size

See also
  `setCenter`, `getCenter`

## ◆ setViewport()

void sf::View::setViewport | ( | const FloatRect & | viewport | ) |

Set the target viewport.

The viewport is the rectangle into which the contents of the view are displayed, expressed as a factor (between 0 and 1) of the size of the RenderTarget to which the view is applied. For example, a view which takes the left side of the target would be defined with `view.setViewport(sf::FloatRect({0.f, 0.f}, {0.5f, 1.f}))`. By default, a view has a viewport which covers the entire target.

Parameters

  viewport | New viewport rectangle

See also
  `getViewport`

## ◆ zoom()

void sf::View::zoom | ( | float | factor | ) |

Resize the view rectangle relatively to its current size.

Resizing the view simulates a zoom, as the zone displayed on screen grows or shrinks. factor is a multiplier:

- 1 keeps the size unchanged
- > 1 makes the view bigger (objects appear smaller)
- < 1 makes the view smaller (objects appear bigger)

Parameters

  factor | Zoom factor to apply

See also
  `setSize`, `move`, `rotate`

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

- View.hpp