# GLFW and Cairo Use

**URL:** <https://discourse.glfw.org/t/glfw-and-cairo-use/1697>\
**Category:** meta\
**Created:** [November 19, 2020, 11:27am UTC](https://discourse.glfw.org/t/glfw-and-cairo-use/1697 "2020-11-19T11:27:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafal](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@Rafal](https://discourse.glfw.org/u/Rafal)\
**Post date:** [November 19, 2020, 11:27am UTC](https://discourse.glfw.org/t/glfw-and-cairo-use/1697/1 "2020-11-19T11:27:18Z")

</div>

Hi,

GLFW and Cairo  
There is little information on this, if someone has something to say at this point, please tell me, pros and cons combinations of these two libraries.

Kind regards,  
Rafał

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 19, 2020, 3:16pm UTC](https://discourse.glfw.org/t/glfw-and-cairo-use/1697/2 "2020-11-19T15:16:36Z")

</div>

Hi @Rafal, welcome to the GLFW forum,

**GLFW** is an Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop. It provides a simple API for creating windows, contexts and surfaces, receiving input and events.

Cairo is a 2D canvas drawing API, primarily focussed on the CPU doing the rendering. You can combine Cairo and OpenGL (or Vulkan), as per their documentation:

> **[Using cairo with OpenGL](https://www.cairographics.org/OpenGL/)**

I would personally not use Cairo in combination with OpenGL/Vulkan, butwould instead use an API designed for use with GPU rendering APIs directly, such as [NanoVG](https://github.com/memononen/nanovg) or [Dear ImGui](https://github.com/ocornut/imgui).

Cheers,

Doug.

---

<div class="post-metadata">

**Author:** ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)\
**Post date:** [January 25, 2022, 10:01pm UTC](https://discourse.glfw.org/t/glfw-and-cairo-use/1697/6 "2022-01-25T22:01:57Z")

</div>

Alternative to xlib backed cairo surface would be to do regular image surface with `cairo_image_surface_create` and then uploading it with glTexImage2D (or similar GL functions) and rendering with OpenGL primitives. That would integrate better with OpenGL applications and allow better performance as image upload happens in background OpenGL driver thread. It would also allow better portability (which is glfw goal) - as xlib works only on Linux, but image surface would work on any OS, Windows, macOS, Linux.

---

<div class="post-metadata">

**Author:** ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)\
**Post date:** [January 26, 2022, 8:46am UTC](https://discourse.glfw.org/t/glfw-and-cairo-use/1697/9 "2022-01-26T08:46:11Z")

</div>

Only reason is performance reason, so you have more control of how/when the cairo result is uploaded to OpenGL texture and used. With xlib you don’t have control over that. If you plan to use OpenGL then sooner or later you will want control over that, otherwise there’s no reason to use OpenGL.
