dsfml.graphics.renderwindow

$(U RenderWindow) is the main class of the Graphics package. It defines an OS window that can be painted using the other classes of the graphics module.

$(U RenderWindow) is derived from $(WINDOW_LINK), thus it inherits all its features : events, window management, OpenGL rendering, etc. See the documentation of $(WINDOW_LINK) for a more complete description of all these features, as well as code examples.

On top of that, $(U RenderWindow) adds more features related to 2D drawing with the graphics module (see its base class $(RENDERTARGET_LINK) for more details).

Here is a typical rendering and event loop with a $(U RenderWindow):

1 // Declare and create a new render-window
2 auto window = new RenderWindow(VideoMode(800, 600), "DSFML window");
3 
4 // Limit the framerate to 60 frames per second (this step is optional)
5 window.setFramerateLimit(60);
6 
7 // The main loop - ends as soon as the window is closed
8 while (window.isOpen())
9 {
10   // Event processing
11   Event event;
12   while (window.pollEvent(event))
13   {
14       // Request for closing the window
15       if (event.type == Event.EventType.Closed)
16           window.close();
17   }
18 
19   // Clear the whole window before rendering a new frame
20   window.clear();
21 
22   // Draw some graphical entities
23   window.draw(sprite);
24   window.draw(circle);
25   window.draw(text);
26 
27   // End the current frame and display its contents on screen
28   window.display();
29 }

$(PARA Like $(WINDOW_LINK), $(U RenderWindow) is still able to render direct OpenGL stuff. It is even possible to mix together OpenGL calls and regular DSFML drawing commands.)

1 // Create the render window
2 auto window = new RenderWindow(VideoMode(800, 600), "DSFML OpenGL");
3 
4 // Create a sprite and a text to display
5 auto sprite = new Sprite();
6 auto text = new Text();
7 ...
8 
9 // Perform OpenGL initializations
10 glMatrixMode(GL_PROJECTION);
11 ...
12 
13 // Start the rendering loop
14 while (window.isOpen())
15 {
16    // Process events
17    ...
18 
19    // Draw a background sprite
20    window.pushGLStates();
21    window.draw(sprite);
22    window.popGLStates();
23 
24    // Draw a 3D object using OpenGL
25    glBegin(GL_QUADS);
26        glVertex3f(...);
27        ...
28    glEnd();
29 
30    // Draw text on top of the 3D object
31    window.pushGLStates();
32    window.draw(text);
33    window.popGLStates();
34 
35    // Finally, display the rendered frame on screen
36    window.display();
37 }

Members

Classes

RenderWindow
class RenderWindow

Window that can serve as a target for 2D drawing.

See Also

$(WINDOW_LINK), $(RENDERTARGET_LINK), $(RENDERTEXTURE_LINK), $(VIEW_LINK)

Meta