O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering SFML Game Development

Book Description

Create complex and visually stunning games using all the advanced features available in SFML development

About This Book

  • Build custom tools, designed to work with your specific game.
  • Use raw modern OpenGL and go beyond SFML.
  • Revamp your code for better structural design, faster rendering, and flashier graphics.
  • Use advanced lighting techniques to add that extra touch of sophistication.
  • Implement a very fast and efficient particle system by using a cache-friendly design.

Who This Book Is For

This book is ideal for game developers who have some basic knowledge of SFML and also are familiar with C++ coding in general. No knowledge of OpenGL or even more advanced rendering techniques is required. You will be guided through every bit of code step by step.

What You Will Learn

  • Dive deep into creating complex and visually stunning games using SFML, as well as advanced OpenGL rendering and shading techniques
  • Build an advanced, dynamic lighting and shadowing system to add an extra graphical kick to your games and make them feel a lot more dynamic
  • Craft your own custom tools for editing game media, such as maps, and speed up the process of content creation
  • Optimize your code to make it blazing fast and robust for the users, even with visually demanding scenes
  • Get a complete grip on the best practices and industry grade game development design patterns used for AAA projects

In Detail

SFML is a cross-platform software development library written in C++ with bindings available for many programming languages. It provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications.

This book will help you become an expert of SFML by using all of its features to its full potential. It begins by going over some of the foundational code necessary in order to make our RPG project run. By the end of chapter 3, we will have successfully picked up and deployed a fast and efficient particle system that makes the game look much more "alive". Throughout the next couple of chapters, you will be successfully editing the game maps with ease, all thanks to the custom tools we"re going to be building. From this point on, it"s all about making the game look good. After being introduced to the use of shaders and raw OpenGL, you will be guided through implementing dynamic scene lighting, the use of normal and specular maps, and dynamic soft shadows. However, no project is complete without being optimized first. The very last chapter will wrap up our project by making it lightning fast and efficient.

Style and approach

This book uses a step by step approach by breaking the problems down into smaller, much more manageable obstacles, and guiding the reader through them with verified, flexible, and autonomous solutions.

Table of Contents

  1. Mastering SFML Game Development
    1. Mastering SFML Game Development
    2. Credits
    3. About the Author
    4. About the Reviewer
    5. www.PacktPub.com
      1. Why subscribe?
    6. Customer Feedback
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Under the Hood - Setting up the Backend
      1. Introduction
      2. Pacing and source code examples
      3. Common utility functions
        1. The Linux version
        2. Other miscellaneous helper functions
        3. Generating random numbers
      4. Service locator pattern
      5. Entity component system core
      6. Resource management
      7. Windows system
      8. Application states
        1. Loading state
        2. File loader
        3. Implementing the loading state
      9. Managing application events
        1. Event manager interface
      10. Use of graphical user interfaces
      11. Representing a 2D map
      12. Sprite system
      13. Sound system
      14. Summary
    9. 2. Its Game Time! - Designing the Project
      1. Use of copyrighted resources
      2. Entity placement and rendering
        1. The drawable side of things
        2. Rendering system
      3. Entity kinematics
        1. Movement system
      4. Handling collisions
        1. Collision system
      5. Controlling entities
        1. Control system
      6. Entity states
        1. State system
      7. Sheet animation system
      8. Entity sounds
        1. Sound system
      9. Implementing the menu state
      10. Implementing the game state
      11. The main game class
      12. The final bit of code
      13. Summary
    10. 3. Make It Rain! - Building a Particle System
      1. Use of copyrighted resources
      2. Particle system basics
        1. Array of structs versus struct of arrays
        2. Storing particles
        3. Particle system architecture
          1. The generator
          2. The emitter
            1. Implementing emitter
          3. The updater
          4. Force applicators
      3. Building the particle system class
        1. Implementing the particle system
      4. Creating updaters
        1. Spatial updater
        2. Drawable updater
        3. Lifespan updater
        4. Interpolator
        5. Force updater
        6. Collision updater
      5. Particle generators
        1. Point position
        2. Area position
        3. Line position
        4. Particle properties
        5. Random color
        6. Color range
        7. Random lifespan
        8. Random size
        9. Random velocity
        10. Rotation range
        11. Size range
        12. Texture generator
      6. Using the particle system
      7. Summary
    11. 4. Have Thy Gear Ready - Building Game Tools
      1. Use of copyrighted resources
      2. File management
        1. File manager interface
          1. Implementing the file manager
        2. Loading files in a separate thread
          1. Implementing the file loader
        3. The loading state
          1. Implementing the loading state
      3. Creating the map editor state
        1. Implementing the state
      4. Building the control mechanism
        1. Implementing controls
      5. Summary
    12. 5. Filling the Tool Belt - a few More Gadgets
      1. Planning the selection options
        1. Implementing selection options
      2. Building the tile selector
        1. Implementing the tile selector
      3. Summary
    13. 6. Adding Some Finishing Touches - Using Shaders
      1. Understanding shaders
        1. Shader examples
        2. SFML and shaders
      2. Localizing rendering
        1. Implementing the renderer
      3. Integrating the Renderer class
        1. Adapting existing classes
          1. Updating the ParticleSystem
          2. Updating entity and map rendering
      4. Creating a day/night cycle
        1. Updating the Map class
        2. Writing the shaders
      5. Summary
    14. 7. One Step Forward, One Level Down - OpenGL Basics
      1. Use of copyrighted resources
      2. Setting up OpenGL
        1. Setting up a Visual Studio project
      3. Using GLEW
      4. The rendering pipeline
        1. Fixed function pipeline
        2. Programmable pipeline
      5. Storing and drawing primitives
        1. Vertex storage
        2. The model class
          1. Implementing the model class
      6. Using shaders
        1. Loading shader files
        2. Creating shader programs
          1. Implementing the shader class
        3. Writing basic shaders
      7. Drawing our first triangle
      8. Using textures
        1. The texture class
          1. Implementing the texture class
        2. Model and shader class changes
        3. Updating the shaders
        4. Using a texture
      9. Applying transformations
        1. Matrix basics
        2. The world space
        3. The transform class
          1. Implementing the transform class
        4. Updating the shader class
        5. Manipulating the triangle
      10. Creating a camera
        1. View projection essentials
        2. The camera class
          1. Implementing the camera class
        3. Updating the rest of the code
      11. Moving the camera around
      12. Drawing with vertex indices
      13. Face culling and depth buffer
      14. Back face culling
      15. Summary
    15. 8. Let There Be Light - An Introduction to Advanced Lighting
      1. Using third-party software
      2. Deferred rendering
        1. Modifying the renderer
          1. Implementing changes in the Renderer class
        2. A minimal example
          1. Shader code
      3. Attenuating light
      4. Multi-pass shading
        1. Modifying the light pass shader
        2. Changes in the C++ code
      5. Managing light input
        1. Interface for light users
        2. The light manager class
          1. Implementing the light manager
          2. Integrating the light manager class
      6. Adapting classes to use lights
        1. The Map class
        2. The entity renderer system
        3. The particle system
      7. Preparing for additional materials
        1. Preparing the texture manager
        2. Material pass shaders
      8. Normal maps
        1. Implementing normal map rendering
        2. Changing the lighting shader
      9. Specular maps
        1. Adding support for specularity
        2. Changing the lighting shader
      10. Height maps
        1. Adapting the existing code
        2. Writing the height pass shader
        3. Changing the lighting shader
      11. Summary
    16. 9. The Speed of Dark - Lighting and Shadows
      1. Use of third-party software
      2. Theory behind shadowing techniques
        1. Shadow mapping
        2. Omni-directional point lights
          1. Cubemap textures
      3. Preparations for rendering
        1. Representing shadow casters
          1. Implementing the shadow caster structure
        2. Creating the transform class
        3. Creating a camera class
        4. Defining a cube texture class
          1. Implementing the cube texture class
            1. Rendering to an off-screen buffer
      4. Rendering the shadow maps
        1. Modifying the light manager
          1. Implementing the light manager changes
            1. Drawing the actual shadow maps
        2. The shadow pass shaders
        3. Results
      5. Adapting the light pass
        1. Replacing the m_fullScreenQuad
          1. Defining a generic frame buffer object
            1. Implementing a generic frame buffer object
        2. Rendering from a buffer to another buffer in OpenGL
          1. Creating a basic quad primitive
            1. Implementing the quad primitive class
        3. Making the changes to the light manager
          1. Implementing light manager changes
            1. Re-working the light pass
            2. Submitting light uniforms to the shader
            3. The new and improved light pass shaders
      6. Adding shadow casters to entities
        1. Adding the shadow caster component
        2. Creating the shadow system
      7. Integrating the changes made
      8. Potential issues and how to address them
        1. Percentage closer filtering
      9. Summary
    17. 10. A Chapter You Shouldnt Skip - Final Optimizations
      1. Use of third-party software
      2. The devil's in the details
      3. Profiling basics
        1. Time-based sampling
        2. Sampling our application
        3. Finding GPU bottlenecks
      4. Improving CPU code performance
        1. Optimizing the three most obvious bottlenecks
          1. GL_Transform optimizations
          2. Particle system optimizations
          3. Light culling
      5. Summary