Window that can serve as a target for 2D drawing.
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.
RenderWindow is derived from Window, thus it inherits all its features: events, window management, OpenGL rendering, etc. See the documentation of Window for a more complete description of all these features, as well as code examples.
On top of that, RenderWindow adds more features related to 2D drawing with the graphics module (see its base class RenderTarget for more details). Here is a typical rendering and event loop with a RenderWindow:
import sfml.window.{Event, VideoMode}
val sprite: Sprite = ???
val circle: CircleShape = ???
val text: Text = ???
// Declare and create a new render-window
val window = RenderWindow(VideoMode(800, 600), "SFML window")
// Limit the framerate to 60 frames per second (this step is optional)
window.framerateLimit = 60;
// The main loop - ends as soon as the window is closed
while window.isOpen() do
// Event processing
for event <- window.pollEvent() do
event match
// Request for closing the window
case Event.Closed() => window.close()
case _ => ()
// Clear the whole window before rendering a new frame
window.clear()
// Draw some graphical entities
window.draw(sprite)
window.draw(circle)
window.draw(text)
// End the current frame and display its contents on screen
window.display()
Attributes
- Companion
- object
- Graph
-
- Supertypes
Members list
- no keywords
- override
- Not inherited
- RenderTarget
- Window
Value members
Concrete methods
Get the size of the rendering region of the window.
Get the size of the rendering region of the window.
The size doesn't include the titlebar and borders of the window.
Attributes
- Returns
-
Size in pixels
- Definition Classes
Inherited methods
Clear the entire target with a single color.
Clear the entire target with a single color.
This function is usually called once every frame, to clear the previous contents of the target.
Value parameters
- color
-
Fill color to use to clear the render target
Attributes
- Inherited from:
- RenderTarget
Get the default view of the render target.
Get the default view of the render target.
The default view has the initial size of the render target, and never changes after the target has been created.
Attributes
- Returns
-
The default view of the render target
- See also
- Inherited from:
- RenderTarget
Display on screen what has been rendered to the window so far.
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.
Attributes
- Inherited from:
- Window
Draw a drawable object to the render target.
Draw a drawable object to the render target.
Value parameters
- drawable
-
Object to draw states Render states to use for drawing
Attributes
- Inherited from:
- RenderTarget
Attributes
- Inherited from:
- Window
Limit the framerate to a maximum fixed frequency.
Limit the framerate to a maximum fixed frequency.
If a limit is set, the window will use a small delay after each call to display to ensure that the current frame lasted long enough to match the framerate limit. SFML will try to match the given limit as much as it can, but since it internally uses sleep, whose precision depends on the underlying OS, the results may be a little unprecise as well (for example, you can get 65 FPS when requesting 60).
Value parameters
- limit
-
Framerate limit, in frames per seconds (use 0 to disable limit)
Attributes
- Inherited from:
- Window
Tell whether or not the window is open.
Tell whether or not the window is open.
This function returns whether or not the window exists.
Attributes
- Returns
-
True if the window is open, false if it has been closed
- Inherited from:
- Window
Convert a point from target coordinates to world coordinates.
Convert a point from target coordinates to world coordinates.
This function finds the 2D position that matches the given pixel of the render target. In other words, it does the inverse of what the graphics card does, to find the initial position of a rendered pixel.
Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render target, this assertion is not true anymore, i.e. a point located at (10, 50) in your render target may map to the point (150, 75) in your 2D world – if the view is translated by (140, 25).
For render-windows, this function is typically used to find which point (or object) is located below the mouse cursor.
This version uses a custom view for calculations, see the other overload of the function if you want to use the current view of the render target.
Value parameters
- point
-
Pixel to convert
- view
-
The view to use for converting the point
Attributes
- Returns
-
The converted point, in "world" units
- Inherited from:
- RenderTarget
Convert a point from target coordinates to world coordinates, using the current view.
Convert a point from target coordinates to world coordinates, using the current view.
This function is an overload of the mapPixelToCoords function that implicitly uses the current view. It is equivalent to:
import sfml.system.Vector2
val target: RenderTarget = ???
val point: Vector2[Int] = ???
target.mapPixelToCoords(point, target.view)
Value parameters
- point
-
Pixel to convert
Attributes
- Returns
-
The converted point, in "world" coordinates
- Inherited from:
- RenderTarget
Attributes
- Inherited from:
- Window
Show or hide the mouse cursor.
Show or hide the mouse cursor.
The mouse cursor is visible by default.
Value parameters
- visible
-
True to show the mouse cursor, false to hide it
Attributes
- Inherited from:
- Window
Pop the event on top of the event queue, if any, and return it.
Pop the event on top of the event queue, if any, and return it.
This function is not blocking: if there's no pending event then the list of events is empty.
val window: Window = ???
for event <- window.pollEvent() do
event match
// process event...
case _ => ()
Value parameters
- event
-
Event to be returned
Attributes
- Returns
-
A lazy list of events
- Inherited from:
- Window
Attributes
- Inherited from:
- Window
Enable or disable vertical synchronization.
Enable or disable vertical synchronization.
Activating vertical synchronization will limit the number of frames displayed to the refresh rate of the monitor. This can avoid some visual artifacts, and limit the framerate to a good value (but not constant across different computers).
Vertical synchronization is disabled by default.
Value parameters
- enabled
-
True to enable v-sync, false to deactivate it
Attributes
- Inherited from:
- Window
Get the view currently in use in the render target.
Get the view currently in use in the render target.
Attributes
- Returns
-
The view object that is currently used
- See also
- Inherited from:
- RenderTarget
Change the current active view.
Change the current active view.
The view is like a 2D camera, it controls which part of the 2D scene is visible, and how it is viewed in the render target. The new view will affect everything that is drawn, until another view is set. The render target keeps its own copy of the view object, so it is not necessary to keep the original one alive after calling this function. To restore the original view of the target, you can pass the result of defaultView to this function.
Value parameters
- view
-
New view to use
Attributes
- See also
- Inherited from:
- RenderTarget
Get the viewport of a view, applied to this render target.
Get the viewport of a view, applied to this render target.
The viewport is defined in the view as a ratio, this function simply applies this ratio to the current dimensions of the render target to calculate the pixels rectangle that the viewport actually covers in the target.
Value parameters
- view
-
The view for which we want to compute the viewport
Attributes
- Returns
-
Viewport rectangle, expressed in pixels
- Inherited from:
- RenderTarget