Game Development Reference
In-Depth Information
Creating windows
The first thing you would probably want to do when you start developing a game is open a
window. In SFML, this couldn't have been made any easier. Only one line of code is neces-
sary to create a window:
Tip
Downloading the example code
You can download the example code files for all Packt topics you have purchased from
your account at
http://www.packtpub.com
.
If you purchased this topic elsewhere, you can
visit
http://www.packtpub.com/support
and register to have the files e-mailed directly to
you.
The only thing that the main function does is initialize the
window
variable by calling the
sf::Window
constructor, after which the program exits. There is an alternative way to
open a window by using the default constructor and calling
Window::create()
later
on. This function takes exactly the same arguments as the constructor, which we just went
through. If
Window::create()
is called on a window, which is already open, it closes
the window and reinitializes it with the new set of parameters.
In the example given in the preceding screenshot, notice that both
Window
and
VideoMode
are in the
sf
namespace. Every class in SFML is under that namespace,
which separates all the classes in SFML from the classes in other libraries.
If we run the code in the example, we won't see much. The program exits immediately after
it creates the window. That is because we just create a window without doing anything with