> For the complete documentation index, see [llms.txt](https://azuriohs-organization.gitbook.io/r-type/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://azuriohs-organization.gitbook.io/r-type/how-to-create-your-own-game/step-6-render-the-window.md).

# Step 6 - Render the window

Now that we have created our window and sprite, it’s time to draw them on the screen.

**1. Open the Window**

To keep the window open, start a loop that runs while the window is active:

```cpp
while (windowComponent->IsOpen()) {
}
```

**2. Handle the Main Loop**

Inside this loop, we will add four main methods:

```cpp
windowComponent->HandleEvents();
windowComponent->ClearWindow(Subsystems::Render::IWindow::BLACK_COLOR);

// Draw all entities
RenderScene(*windowComponent, GameEngine.ListEntities(), renderLoader);

windowComponent->DisplayWindow();
```

Here’s what each line does:

* HandleEvents() — processes input and window events
* ClearWindow() — clears the window with a chosen color (here, black)
* RenderScene() — draws all entities that contain renderable components
* DisplayWindow() — displays the final rendered frame

**3. Rendering the Scene**

To draw the sprites, define the following function:

```cpp
void RenderScene(Subsystems::Render::IWindow& window, std::vector<Engine::Entity>& entities, LibraryLoader::DLLoader<Subsystems::Render::IRender> &renderLoader)
{
    Subsystems::Render::IRender *render = renderLoader.GetInstance();
    auto& spritePool = Engine::ComponentPool<Subsystems::Render::ISprite>::GetInstance();
    auto& textPool = Engine::ComponentPool<Subsystems::Render::IText>::GetInstance();

    for (auto& entity : entities) {
        auto *sprite = spritePool.Get(entity.GetId());
        auto *text = textPool.Get(entity.GetId());

        if (sprite) {
            render->UpdateSprite(*sprite, nullptr, nullptr);
            window.Draw(*sprite);
        }
    }
}
```

**4. Rendering Logic Explained**

* The function loops through all entities.
* For each entity, it checks if there is a sprite component or a text component.
* If a sprite is found:

```cpp
render->UpdateSprite(*sprite, nullptr, nullptr);
window.Draw(*sprite);
```

* UpdateSprite() updates the sprite’s data (position, scale).
* Draw() renders it to the window.
