\page depth_camera Depth camera

This example shows how to use the depth camera.

## Install prerequisites

In order to compile this tutorial, you need to install some prerequisites :

```bash
# Linux
sudo apt-get install build-essential freeglut3-dev libglew-dev

# Windows (via conda)
conda install glew --channel conda-forge
```

## Compile and run the example

Clone the source code, create a build directory and use `cmake` and `make` to compile the code:

```{.sh}
git clone https://github.com/gazebosim/gz-rendering
cd gz-rendering/examples/depth_camera
mkdir build
cd build
cmake ..
# On Linux
cmake --build .
# On Windows
cmake --build . --config Release
```

Execute the example:

```{.sh}
# Linux
./depth_camera ogre

# Windows
.\Release\depth_camera.exe ogre
```

You'll see:

```{.sh}
[Msg] Loading plugin [gz-rendering-ogre]
===============================
  ESC - Exit
===============================
```

@image html img/depth_camera_ogre.png

## Code

Most of the code is adapted from \ref simple_demo, here we outline the key differences.

The function `buildScene()` is responsible for creating and configuring the depth camera.
The main points to note are:

- The image format is set to `PixelFormat::PF_FLOAT32_RGBA`,
- Anti-alising is enabled,
- The depth texture is created after configuration is modified from defaults.

\snippet examples/depth_camera/Main.cc create camera

The window updating code is in `GlutWindow.cc`. The function `initCamera()`
registers a callback with the camera that captures a copy of
the depth image each frame. This will later be drawn to the window in
the main update loop.

\snippet examples/depth_camera/GlutWindow.cc init camera

The depth camera is capable of generating both color and depth data.
This example shows how to connect and receive depth data in the
`OnNewDepthFrame()` callback function.

\snippet examples/depth_camera/GlutWindow.cc depth frame callback

It converts the depth image to a RGB grayscale format and copies it from the
depth camera to a memory reserved in a globally scoped `Image`.

\snippet examples/depth_camera/GlutWindow.cc convert depth to image

The other option is the [ConnectNewRgbPointCloud](https://github.com/gazebosim/gz-rendering/blob/gz-rendering10/include/gz/rendering/DepthCamera.hh#L58) call that receives colored point cloud data on callback.

The reason for setting the camera image format to `PixelFormat::PF_FLOAT32_RGBA`
is to ensure that when the `Image` is created it reserves a buffer of the
correct size so that it is able to pack both color and depth data.
