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

Function main

examples/opengl/OpenGL.cpp:41–338  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

39///
40////////////////////////////////////////////////////////////
41int main()
42{
43 bool exit = false;
44 bool sRgb = false;
45
46 while (!exit)
47 {
48 // Request a 24-bits depth buffer when creating the window
49 sf::ContextSettings contextSettings;
50 contextSettings.depthBits = 24;
51 contextSettings.sRgbCapable = sRgb;
52
53 // Create the main window
54 sf::RenderWindow window(sf::VideoMode({800, 600}),
55 "SFML graphics with OpenGL",
56 sf::Style::Default,
57 sf::State::Windowed,
58 contextSettings);
59 window.setVerticalSyncEnabled(true);
60 window.setMinimumSize(sf::Vector2u(400, 300));
61 window.setMaximumSize(sf::Vector2u(1200, 900));
62
63 // Create a sprite for the background
64 const sf::Texture backgroundTexture(resourcesDir() / "background.jpg", sRgb);
65 const sf::Sprite background(backgroundTexture);
66
67 // Create some text to draw on top of our OpenGL object
68 const sf::Font font(resourcesDir() / "tuffy.ttf");
69
70 sf::Text text(font, "SFML / OpenGL demo");
71 sf::Text sRgbInstructions(font, "Press space to toggle sRGB conversion");
72 sf::Text mipmapInstructions(font, "Press return to toggle mipmapping");
73 text.setFillColor(sf::Color(255, 255, 255, 170));
74 sRgbInstructions.setFillColor(sf::Color(255, 255, 255, 170));
75 mipmapInstructions.setFillColor(sf::Color(255, 255, 255, 170));
76 text.setPosition({280.f, 450.f});
77 sRgbInstructions.setPosition({175.f, 500.f});
78 mipmapInstructions.setPosition({200.f, 550.f});
79
80 // Load a texture to apply to our 3D cube
81 sf::Texture texture(resourcesDir() / "logo.png");
82
83 // Attempt to generate a mipmap for our cube texture
84 // We don't check the return value here since
85 // mipmapping is purely optional in this example
86 (void)texture.generateMipmap();
87
88 // Make the window the active window for OpenGL calls
89 if (!window.setActive(true))
90 {
91 std::cerr << "Failed to set window to active" << std::endl;
92 return EXIT_FAILURE;
93 }
94
95 // Load OpenGL or OpenGL ES entry points using glad
96#ifdef SFML_OPENGL_ES
97 gladLoadGLES1(sf::Context::getFunction);
98#else

Callers

nothing calls this directly

Calls 15

gladLoadGLES1Function · 0.85
gladLoadGLFunction · 0.85
isOpenMethod · 0.80
setCenterMethod · 0.80
setViewMethod · 0.80
pushGLStatesMethod · 0.80
popGLStatesMethod · 0.80
getElapsedTimeMethod · 0.80
resourcesDirFunction · 0.70
VideoModeClass · 0.50
ColorClass · 0.50
TextureClass · 0.50

Tested by

no test coverage detected