Filament is an amazing 3D rendering library started by Google. This example shows how to use Filament with GLFW and my feature-get-texture-id branch to use Filament with a shared OpenGL context.
I assume that you have already setup a development environment on both Linux and Windows. Some tools that you want to install:
- CMake
- Visual Studio 2019
With the current master branch (2020-06-02) I run into an issue
when I try to compile Filament. The paths that some of the
dependencies are too long. Currently you have to make sure to
clone this repository in e.g. c:\tmp\
which I used while
testing. To build this example simply run release.bat
from the
build directory; this will take care of everything and once
compiled you should see something as the image below.
cd c:\
[email protected]:roxlu/filament-with-glfw.git tmp
cd tmp
cd build
release.bat
In this example I'm building the repository from a tmp
dir in your $HOME. Similar to the Windows build I've provided
a release.sh
file which you can run. Once Filament has
been compiled you'll see a something as in the image below.
cd ~/
[email protected]:roxlu/filament-with-glfw.git tmp
cd tmp
cd build
./release.sh
This example uses my feature-get-texture-id
which allows you to
retrieve the native texture id from a filament::Texture
. As
this example was created to show how to use a shared OpenGL
context it makes sense that we actually use some of the shared
resources. See test-shared-gl-context-with-fbo.cpp
where we
render the scene into a framebuffer and use the FBO texture in
our main OpenGL context.
-
Make sure that your main OpenGL context (e.g. the GLFW one) is not current when you create the
Filament::Engine
instance and pass the shared context intofilament::Engine::create()
-
When you pass a shared GL context, make sure to use the
filament::Engine::createSwapChain(int width, int height, int flags)
version which creates a headless swapchain. Note that there is also afilament::Engine::createSwapChain(void* nativeWindow)
version. -
When passing a native window handle, use
glfwGetX11Window()
and notglfwGetGLXWindow()
to retrieve the correct handle. You can directly cast these handles into avoid*
.