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

Function main

examples/window/Window.cpp:26–189  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

24///
25////////////////////////////////////////////////////////////
26int main()
27{
28 // Request a 24-bits depth buffer when creating the window
29 sf::ContextSettings contextSettings;
30 contextSettings.depthBits = 24;
31
32 // Create the main window
33 sf::Window window(sf::VideoMode({640, 480}), "SFML window with OpenGL", sf::Style::Default, sf::State::Windowed, contextSettings);
34
35 // Make it the active window for OpenGL calls
36 if (!window.setActive())
37 {
38 std::cerr << "Failed to set the window as active" << std::endl;
39 return EXIT_FAILURE;
40 }
41
42 // Load OpenGL or OpenGL ES entry points using glad
43#ifdef SFML_OPENGL_ES
44 gladLoadGLES1(sf::Context::getFunction);
45#else
46 gladLoadGL(sf::Context::getFunction);
47#endif
48
49 // Set the color and depth clear values
50#ifdef SFML_OPENGL_ES
51 glClearDepthf(1.f);
52#else
53 glClearDepth(1.f);
54#endif
55 glClearColor(0.f, 0.f, 0.f, 1.f);
56
57 // Enable Z-buffer read and write
58 glEnable(GL_DEPTH_TEST);
59 glDepthMask(GL_TRUE);
60
61 // Disable lighting and texturing
62 glDisable(GL_LIGHTING);
63 glDisable(GL_TEXTURE_2D);
64
65 // Configure the viewport (the same size as the window)
66 glViewport(0, 0, static_cast<GLsizei>(window.getSize().x), static_cast<GLsizei>(window.getSize().y));
67
68 // Setup a perspective projection
69 glMatrixMode(GL_PROJECTION);
70 glLoadIdentity();
71 const GLfloat ratio = static_cast<float>(window.getSize().x) / static_cast<float>(window.getSize().y);
72#ifdef SFML_OPENGL_ES
73 glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
74#else
75 glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
76#endif
77
78 // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
79 // clang-format off
80 constexpr std::array<GLfloat, 252> cube =
81 {
82 // positions // colors (r, g, b, a)
83 -50, -50, -50, 0, 0, 1, 1,

Callers

nothing calls this directly

Calls 10

gladLoadGLES1Function · 0.85
gladLoadGLFunction · 0.85
isOpenMethod · 0.80
getElapsedTimeMethod · 0.80
VideoModeClass · 0.50
setActiveMethod · 0.45
getSizeMethod · 0.45
pollEventMethod · 0.45
closeMethod · 0.45
displayMethod · 0.45

Tested by

no test coverage detected