sfml / sfml-game-development-book Goto Github PK
View Code? Open in Web Editor NEWFull and up-to-date source code of the chapters of the "SFML Game Development" book
License: Other
Full and up-to-date source code of the chapters of the "SFML Game Development" book
License: Other
##################### SFML Game Development Code Base ##################### This file explains how to build the code accompanying the book SFML Game Development. There are 10 directories that correspond to each of the chapters in the book. For example, 02_Resources contains the code for Chapter 2. The code for all chapters can be built at once. ================ I. Install CMake ================ Install CMake, preferably CMake-GUI (www.cmake.org or the cmake-gui package in Linux). ================ II. Install SFML ================ Download SFML 2 (www.sfml-dev.org). We recommend using a precompiled version of SFML which can be directly downloaded. It is also possible to build SFML yourself, in this case make sure that it is *installed* (make install, or compile the INSTALL project). Refer to the online tutorials for more details. Eventually, you should have a directory with at least the subdirectories "include" and "lib" that contain headers and binaries of the SFML library, for example C:\SFML in Windows or /usr/local in Linux. ===================================== III. Generate the build configuration ===================================== 1. Start cmake-gui. 2. In the field "Where is the source code", enter the path of the directory containing this ReadMe.txt file. Use forward slashes. 3. In the field "Where to build the binaries", enter a different path, where you want the intermediate build files of the book's code to be generated. 4. Click "Configure" and choose your compiler. 5. After, an error message might appear, telling that SFML is not found. This is intended. In order to fix it, enter the path to SFML in the field next to the SFML_ROOT variable. This is the directory mentioned in step II with the "lib" and "include" subdirectories (e.g. C:/SFML or /usr/local). 6. Choose your build configuration by setting CMAKE_BUILD_TYPE to either "Release" or "Debug". We recommend "Release" (it should be the default). 7. In Windows, check the box next to SFML_STATIC_LIBRARIES if you want to link SFML statically. Leave it unchecked if you prefer linking SFML dynamically and using DLL files. 8. Set the CMAKE_INSTALL_PREFIX to the path where you want the executables of the book's code to be installed. Choose a different directory (it can be a subdirectory of this one). 9. Click again "Configure". Now, there should be no more error messages. 10. Click "Generate". ==================== IV. Compile the code ==================== 1. Switch to the build directory (the one you entered in "Where to build the binaries"). 2. Now you should see the files required to compile the code. For g++ or clang, this will be a Makefile. In the terminal, type "make install". If you use MinGW on Windows, you might have to type "mingw32-make install" instead. For Visual Studio, you will see a .sln solution. Open it, choose the correct build configuration ("Release" or "Debug") and build the INSTALL project. For other integrated development environments, it will be similar. Compile the INSTALL project. 3. After compiling, the executables and media files should be output to the directory you specified with CMAKE_INSTALL_PREFIX. ========== V. Results ========== The executables for each chapter are located in the install directory (CMAKE_INSTALL_PREFIX). If you like to inspect the code itself, the current directory comes with 10 subdirectories, each containing the source and header files of the corresponding chapter. Also, the media files can be found for each chapter.
Building book examples against SFML latest (2.4.2) results in a few deprecation warnings. These warnings can be broken down into two cases:
Diff at pastebin updates code base to remove warnings during compile.
get this warning when configuring cmake:
CMake Deprecation Warning at CMakeLists.txt:2 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.
Editing CMakeLists.txt:2 to "cmake_minimum_required(VERSION 2.8...3.5)" prevents the error message,
but the compatibility issues are not solves.
At the SFML-Game-Development-Book-master\CMake directory there is a FindSFML.cmake file,
which is said to no longer be supported anymore, but rather SFMLConfig.cmake is now used instead.
This problem is persisting even after writing the code by myself, and compiling it from your provided source. How can I solve it? Please help.
No SceneNode class contains a virtual destructor declaration, while it is a base class with many other virtual functions. I suppose it is a bug, causing memory leaks.
template <typename GameObject, typename Function>
Command::Action derivedAction(Function fn)
{
return [=] (SceneNode& node, sf::Time dt)
{
// Check if cast is safe
assert(dynamic_cast<GameObject*>(&node) != nullptr);
// Downcast node and invoke function on it
fn(static_cast<GameObject&>(node), dt);
};
}
This function produces a compiler error C3848 in VS2013 Express on Windows 7.
It's line 33
fn(static_cast<GameObject&>(node), dt);
a non-const function is invoked by const function
sample code compiled with visual studio 2017 fails to load shader, to fix change Brightness.frag line 12
from:
sourceFragment *= clamp(luminance - Threshold, 0.0, 1.0) * Factor;
to:
sourceFragment *= clamp(luminance - Threshold, 0.f, 1.f) * Factor;
Line 10 of SoundNode.cpp
As ${SFML_LIBRARIES}
, ${SFML_DEPENDENCIES}
and ${SFML_INCLUDE_DIR}
were removed from SFML after v2.5,
you can't build the example as-is, on the latest stable version.
I had to do some workaround on my fork (copyrat90@928f347), in order to build it properly.
It would be nice if you can build the example without messing around the CMake script.
Not an issue, just a question.
SFML don't support high dpi and the only solution right now is to set NSHighResolutionCapable to false, that way we get low resolution but the actual window size.
I'm not really interested in making my own games, but I'm very interested in reading this book!
Is there a way that you can edit CMakeList to support creating an app bundle for OSX?
Right now I'm on a MacBook Pro and it is imposible to work through the book, sadly I don't have the knowledge to edit the CMake files myself and share it with other people.
Thanks!
The CMake script provides the SFML_ROOT
variable to provide the location of SFML when installed outside of the system's default locations. However, find_path()
is implemented to look in system default location first, and looks in the custom paths provided in PATHS
only if no match is found in the system default. This means that if the system contains a version of SFML but the user has a (supposedly newer) version manually installed somewhere else that they want to use instead, the (older) system version will always be picked first.
To fix this, I would suggest specifying SFML_ROOT
in HINTS
instead of PATHS
. Indeed, contrary to PATHS
, HINTS
are looked up before the system locations.
# find the SFML include directory
find_path(SFML_INCLUDE_DIR SFML/Config.hpp
PATH_SUFFIXES include
HINTS ${SFML_ROOT} $ENV{SFML_ROOT}
PATHS ${FIND_SFML_PATHS})
The same should then be done for the find_library()
calls, and SFML_ROOT
should be removed from FIND_SFML_PATHS
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.