# Offscreen rendering

**URL:** <https://discourse.libsdl.org/t/offscreen-rendering/27467>\
**Category:** SDL Development\
**Created:** [April 10, 2020, 1:30am UTC](https://discourse.libsdl.org/t/offscreen-rendering/27467 "2020-04-10T01:30:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sc63](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@sc63](https://discourse.libsdl.org/u/sc63)\
**Post date:** [April 10, 2020, 1:30am UTC](https://discourse.libsdl.org/t/offscreen-rendering/27467/1 "2020-04-10T01:30:11Z")

</div>

# Render and capture offscreen?

I am trying to render to an offscreen buffer for automated testing purposes to save to a video file. [This diff](https://hg.libsdl.org/SDL/rev/9692ad570003) from Sept 2019 adds offscreen rendering. It looks like exactly what I’m looking for, but I’m having trouble getting it to work. How do I enable it?

## what I have tried

- I was able to modify `CMakeLists.txt` (set `VIDEO_OFFSCREEN` to `ON`), run cmake, then build libSDL2. The SDL objects it built had offscreen enabled, but after running `SDL_VideoInit("offscreen")`, I ended up with the error `Could not find a valid EGL device to initialize` (from [SDL\_egl.c](https://github.com/SDL-mirror/SDL/blob/master/src/video/SDL_egl.c#L598)).
- Before using SDL, I was able to successfully use offscreen mesa to render offscreen, so I know this is possible. However, I need to use SDL, but can’t get it working. I can’t find any documentation regarding offscreen.

---

<div class="post-metadata">

**Author:** ![bschaefer](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/bschaefer/32/2802_2.png) [@bschaefer](https://discourse.libsdl.org/u/bschaefer)\
**Post date:** [April 10, 2020, 2:32am UTC](https://discourse.libsdl.org/t/offscreen-rendering/27467/2 "2020-04-10T02:32:41Z")

</div>

Hmmm not sure off the top of my head. I would double check a few of the tests are working, mainly try to run these two tests:

[https://hg.libsdl.org/SDL/file/30ce6dd90b8f/test/testgles2.c](https://hg.libsdl.org/SDL/file/30ce6dd90b8f/test/testgles2.c)

and

[https://hg.libsdl.org/SDL/file/30ce6dd90b8f/test/testoffscreen.c](https://hg.libsdl.org/SDL/file/30ce6dd90b8f/test/testoffscreen.c)

If testgles2.c works, but testoffscreen fails then may need to dig a little bit into the loop to see where its failing. ie. Is it finding devices to iterate on? If so, is it failing to eglInit? If thats the case you can try to dump what the eglGetError is there and see if you can figure some more out around there!

[https://hg.libsdl.org/SDL/file/30ce6dd90b8f/src/video/SDL\_egl.c#l572](https://hg.libsdl.org/SDL/file/30ce6dd90b8f/src/video/SDL_egl.c#l572)

---

<div class="post-metadata">

**Author:** ![sc63](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@sc63](https://discourse.libsdl.org/u/sc63)\
**Post date:** [April 10, 2020, 3:27am UTC](https://discourse.libsdl.org/t/offscreen-rendering/27467/3 "2020-04-10T03:27:18Z")

</div>

> Is it finding devices to iterate on?

No it’s not. I put some print statements in, and `num_egl_devices` is [zero after querying devices](https://github.com/SDL-mirror/SDL/blob/master/src/video/SDL_egl.c#L550).

---

<div class="post-metadata">

**Author:** ![sc63](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@sc63](https://discourse.libsdl.org/u/sc63)\
**Post date:** [April 10, 2020, 8:01pm UTC](https://discourse.libsdl.org/t/offscreen-rendering/27467/4 "2020-04-10T20:01:28Z")

</div>

Looks like I don’t have any egl devices because I did not compile mesa with egl or dri. I don’t think this will work on my setup because I’m not running with a gpu or X windowing.
