nudsfml.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):

// Declare and create a new render-window
auto window = new RenderWindow(VideoMode(800, 600), "DSFML window");

// Limit the framerate to 60 frames per second (this step is optional)
window.setFramerateLimit(60);

// The main loop - ends as soon as the window is closed
while (window.isOpen())
{
   // Event processing
   Event event;
   while (window.pollEvent(event))
   {
       // Request for closing the window
       if (event.type == Event.Type.Closed)
           window.close();
   }

   // 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();
}

$(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.)

// Create the render window
auto window = new RenderWindow(VideoMode(800, 600), "DSFML OpenGL");

// Create a sprite and a text to display
auto sprite = new Sprite();
auto text = new Text();
...

// Perform OpenGL initializations
glMatrixMode(GL_PROJECTION);
...

// Start the rendering loop
while (window.isOpen())
{
    // Process events
    ...

    // Draw a background sprite
    window.pushGLStates();
    window.draw(sprite);
    window.popGLStates();

    // Draw a 3D object using OpenGL
    glBegin(GL_QUADS);
        glVertex3f(...);
        ...
    glEnd();

    // Draw text on top of the 3D object
    window.pushGLStates();
    window.draw(text);
    window.popGLStates();

    // Finally, display the rendered frame on screen
    window.display();
}

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