Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SFML Game Development.pdf
Скачиваний:
194
Добавлен:
28.03.2016
Размер:
4.19 Mб
Скачать

Chapter 8

downSampler.setParameter("source", input.getTexture()); downSampler.setParameter("sourceSize", sf::Vector2f(input.

getSize())); applyShader(downSampler, output); output.display();

}

void BloomEffect::add(const sf::RenderTexture& source, const sf::RenderTexture& bloom, sf::RenderTarget& output)

{

sf::Shader& adder = mShaders.get(Shaders::AddPass);

adder.setParameter("source", source.getTexture()); adder.setParameter("bloom", bloom.getTexture()); applyShader(adder, output);

}

If you find shaders interesting we recommend you read up on them. There is a lot of good information available on the subject, and it's a great tool to have to hand. Also definitely have a look at the shaders we have written.

Here's an example of a good and popular tutorial on GLSL:

http://www.lighthouse3d.com/tutorials/glsl-tutorial

Summary

Meanwhile, our aircraft shooter now deserves the name "game", as it is no longer some half-hearted sprites put together. We have seen a lot of modern graphical and rendering techniques and how they fit in our game. After an in-depth look at the rendering process (render targets, textures, vertices), we integrated a particle system for the missile, an animation for the explosion, and a shader for the bloom effect on the whole scene.

Note that there exist already implementations for many of the techniques shown in this chapter. In case you don't want to reinvent the wheel, you could have a look at the Thor library, which is developed by one of the authors of this book. Thor extends

SFML by providing fully configurable particle systems and animations. Other features include color gradients, input and resource handlers, timer utilities, and much more. The library is available at www.bromeon.ch/libraries/thor.

In the next chapter we will cover how to play audio using SFML's Audio module. We will go through both streaming music and sound effects.

[ 215 ]

www.it-ebooks.info

www.it-ebooks.info

Cranking Up the

Bass – Music and

Sound Effects

Since the beginning of video games, sound has been a central media in games. Many games can be recognized only by listening to them. In the last few years, game industries have chosen to neglect audio in favor of better graphics; yet audio takes a very important part in a wide range of games. Independent studios in particular often put a huge effort in making games unique in their art style, which includes audio, graphics, and story. If used appropriately, music themes and sounds can have a tremendous impact on the atmosphere conveyed by a game.

In this chapter, we are going to cover the technical background of embedding audio into a game, taking the opportunity to have a closer look at SFML's Audio module. We are going to do the following:

Play different music themes in the background

Play sound effects that correspond to game events such as explosions

Position sound effects in the 2D world to convey a feeling of spatial sound

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]