/////////////////////////////////////////////////////// Draw the OpenGL scene (a rotating cube) into the specified view \param window Target window for rendering \param elapsedTime Time elapsed since the last draw \return True if operation was successful, false otherwise ///////////////////////////////////////////////////////
| 74 | /// |
| 75 | //////////////////////////////////////////////////////////// |
| 76 | [[nodiscard]] bool draw(sf::Window& window, float elapsedTime) |
| 77 | { |
| 78 | // Activate the window |
| 79 | if (!window.setActive()) |
| 80 | { |
| 81 | std::cerr << "Failed to set the window as active" << std::endl; |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | // Clear color and depth buffers |
| 86 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 87 | |
| 88 | // Apply some transformations |
| 89 | glMatrixMode(GL_MODELVIEW); |
| 90 | glLoadIdentity(); |
| 91 | glTranslatef(0.f, 0.f, -200.f); |
| 92 | glRotatef(elapsedTime * 10.f, 1.f, 0.f, 0.f); |
| 93 | glRotatef(elapsedTime * 6.f, 0.f, 1.f, 0.f); |
| 94 | glRotatef(elapsedTime * 18.f, 0.f, 0.f, 1.f); |
| 95 | |
| 96 | // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices) |
| 97 | // clang-format off |
| 98 | constexpr std::array<GLfloat, 216> cube = |
| 99 | { |
| 100 | // positions // colors |
| 101 | -50, -50, -50, 1, 1, 0, |
| 102 | -50, 50, -50, 1, 1, 0, |
| 103 | -50, -50, 50, 1, 1, 0, |
| 104 | -50, -50, 50, 1, 1, 0, |
| 105 | -50, 50, -50, 1, 1, 0, |
| 106 | -50, 50, 50, 1, 1, 0, |
| 107 | |
| 108 | 50, -50, -50, 1, 1, 0, |
| 109 | 50, 50, -50, 1, 1, 0, |
| 110 | 50, -50, 50, 1, 1, 0, |
| 111 | 50, -50, 50, 1, 1, 0, |
| 112 | 50, 50, -50, 1, 1, 0, |
| 113 | 50, 50, 50, 1, 1, 0, |
| 114 | |
| 115 | -50, -50, -50, 1, 0, 1, |
| 116 | 50, -50, -50, 1, 0, 1, |
| 117 | -50, -50, 50, 1, 0, 1, |
| 118 | -50, -50, 50, 1, 0, 1, |
| 119 | 50, -50, -50, 1, 0, 1, |
| 120 | 50, -50, 50, 1, 0, 1, |
| 121 | |
| 122 | -50, 50, -50, 1, 0, 1, |
| 123 | 50, 50, -50, 1, 0, 1, |
| 124 | -50, 50, 50, 1, 0, 1, |
| 125 | -50, 50, 50, 1, 0, 1, |
| 126 | 50, 50, -50, 1, 0, 1, |
| 127 | 50, 50, 50, 1, 0, 1, |
| 128 | |
| 129 | -50, -50, -50, 0, 1, 1, |
| 130 | 50, -50, -50, 0, 1, 1, |
| 131 | -50, 50, -50, 0, 1, 1, |
| 132 | -50, 50, -50, 0, 1, 1, |
| 133 | 50, -50, -50, 0, 1, 1, |