MCPcopy Create free account
hub / github.com/SFML/SFML / main

Function main

examples/sound_effects/SoundEffects.cpp:1075–1242  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// Entry point of application \return Application exit code ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

1073///
1074////////////////////////////////////////////////////////////
1075int main()
1076{
1077 // Create the main window
1078 sf::RenderWindow window(sf::VideoMode({windowWidth, windowHeight}),
1079 "SFML Sound Effects",
1080 sf::Style::Titlebar | sf::Style::Close);
1081 window.setVerticalSyncEnabled(true);
1082
1083 // Open the application font and pass it to the Effect class
1084 const sf::Font font(resourcesDir() / "tuffy.ttf");
1085 Effect::setFont(font);
1086
1087 // Create the effects
1088 Surround surroundEffect;
1089 PitchVolume pitchVolumeEffect;
1090 Attenuation attenuationEffect;
1091 Tone toneEffect;
1092 Doppler dopplerEffect;
1093 HighPassFilter highPassFilterEffect;
1094 LowPassFilter lowPassFilterEffect;
1095 Echo echoEffect;
1096 Reverb reverbEffect;
1097
1098 const std::array<Effect*, 9> effects{&surroundEffect,
1099 &pitchVolumeEffect,
1100 &attenuationEffect,
1101 &toneEffect,
1102 &dopplerEffect,
1103 &highPassFilterEffect,
1104 &lowPassFilterEffect,
1105 &echoEffect,
1106 &reverbEffect};
1107
1108 std::size_t current = 0;
1109
1110 effects[current]->start();
1111
1112 // Create the messages background
1113 const sf::Texture textBackgroundTexture(resourcesDir() / "text-background.png");
1114 sf::Sprite textBackground(textBackgroundTexture);
1115 textBackground.setPosition({0.f, 520.f});
1116 textBackground.setColor(sf::Color(255, 255, 255, 200));
1117
1118 // Create the description text
1119 sf::Text description(font, "Current effect: " + effects[current]->getName(), 20);
1120 description.setPosition({10.f, 522.f});
1121 description.setFillColor(sf::Color(80, 80, 80));
1122
1123 // Create the instructions text
1124 sf::Text instructions(font, "Press left and right arrows to change the current effect", 20);
1125 instructions.setPosition({280.f, 544.f});
1126 instructions.setFillColor(sf::Color(80, 80, 80));
1127
1128 // Create the playback device text
1129 auto playbackDeviceName = sf::PlaybackDevice::getDevice();
1130 sf::Text playbackDevice(font, "Current playback device: " + playbackDeviceName.value_or("None"), 20);
1131 playbackDevice.setPosition({10.f, 566.f});
1132 playbackDevice.setFillColor(sf::Color(80, 80, 80));

Callers

nothing calls this directly

Calls 15

getDeviceFunction · 0.85
getAvailableDevicesFunction · 0.85
setDeviceFunction · 0.85
setColorMethod · 0.80
getNameMethod · 0.80
isOpenMethod · 0.80
handleKeyMethod · 0.80
getElapsedTimeMethod · 0.80
resourcesDirFunction · 0.70
VideoModeClass · 0.50
ColorClass · 0.50
getPositionFunction · 0.50

Tested by

no test coverage detected