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

Function main

examples/shader/Shader.cpp:378–519  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

376///
377////////////////////////////////////////////////////////////
378int main()
379{
380 // Exit early if shaders are not available
381 if (!sf::Shader::isAvailable())
382 {
383 std::cerr << "Shaders not supported on current system, aborting" << std::endl;
384 return EXIT_FAILURE;
385 }
386
387 // Create the main window
388 sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML Shader", sf::Style::Titlebar | sf::Style::Close);
389 window.setVerticalSyncEnabled(true);
390
391 // Open the application font
392 const sf::Font font("resources/tuffy.ttf");
393
394 // Create the effects
395 std::optional pixelateEffect = tryLoadPixelate();
396 std::optional waveBlurEffect = tryLoadWaveBlur(font);
397 std::optional stormBlinkEffect = tryLoadStormBlink();
398 std::optional edgeEffect = tryLoadEdge();
399 std::optional geometryEffect = tryLoadGeometry();
400
401 const auto optionalToPtr = [](auto& effect) -> Effect* { return effect.has_value() ? &*effect : nullptr; };
402
403 const std::array<Effect*, 5> effects{optionalToPtr(pixelateEffect),
404 optionalToPtr(waveBlurEffect),
405 optionalToPtr(stormBlinkEffect),
406 optionalToPtr(edgeEffect),
407 optionalToPtr(geometryEffect)};
408
409 const std::array<std::string, 5>
410 effectNames{"Pixelate", "Wave + Blur", "Storm + Blink", "Edge Post-effect", "Geometry Shader Billboards"};
411
412 // Index of currently selected effect
413 std::size_t current = 0;
414
415 // Create the messages background
416 const sf::Texture textBackgroundTexture("resources/text-background.png");
417 sf::Sprite textBackground(textBackgroundTexture);
418 textBackground.setPosition({0.f, 520.f});
419 textBackground.setColor(sf::Color(255, 255, 255, 200));
420
421 // Create the description text
422 sf::Text description(font, "Current effect: " + effectNames[current], 20);
423 description.setPosition({10.f, 530.f});
424 description.setFillColor(sf::Color(80, 80, 80));
425
426 // Create the instructions text
427 sf::Text instructions(font, "Press left and right arrows to change the current shader", 20);
428 instructions.setPosition({280.f, 555.f});
429 instructions.setFillColor(sf::Color(80, 80, 80));
430
431 // Start the game loop
432 const sf::Clock clock;
433 while (window.isOpen())
434 {
435 // Process events

Callers

nothing calls this directly

Calls 15

tryLoadPixelateFunction · 0.85
tryLoadWaveBlurFunction · 0.85
tryLoadStormBlinkFunction · 0.85
tryLoadEdgeFunction · 0.85
tryLoadGeometryFunction · 0.85
setColorMethod · 0.80
isOpenMethod · 0.80
getElapsedTimeMethod · 0.80
isAvailableFunction · 0.50
VideoModeClass · 0.50
ColorClass · 0.50
getPositionFunction · 0.50

Tested by

no test coverage detected