Skip to main content

Overview

This guide will walk you through creating your first Filament application. We’ll render a simple spinning colored triangle to demonstrate the core concepts of the Filament rendering engine.
Before starting, make sure you have Filament installed on your platform. See the Installation Guide for details.

Choose Your Platform

This example works on Linux, macOS, and Windows using the native C++ API.

Prerequisites

  • CMake 3.22.1 or higher
  • Clang 16.0 or higher
  • Filament SDK installed
  • SDL2 (included with Filament samples)

Core Concepts

A Filament application requires these essential components:
1

Create an Engine

The Engine is the main entry point and manages all Filament resources.
Engine* engine = Engine::create();
2

Create a SwapChain

The SwapChain connects Filament to your native window.
SwapChain* swapChain = engine->createSwapChain(nativeWindow);
3

Create a Renderer

The Renderer handles the actual rendering commands.
Renderer* renderer = engine->createRenderer();
4

Set up View, Scene, and Camera

These define what and how you render.
Camera* camera = engine->createCamera(EntityManager::get().create());
View* view = engine->createView();
Scene* scene = engine->createScene();

view->setCamera(camera);
view->setScene(scene);

Complete Hello Triangle Example

Here’s a complete working example from the Filament samples:
samples/hellotriangle.cpp
#include <filament/Camera.h>
#include <filament/Engine.h>
#include <filament/IndexBuffer.h>
#include <filament/Material.h>
#include <filament/RenderableManager.h>
#include <filament/Scene.h>
#include <filament/VertexBuffer.h>
#include <filament/View.h>
#include <utils/EntityManager.h>

using namespace filament;
using utils::Entity;
using utils::EntityManager;

// Define vertex structure
struct Vertex {
    filament::math::float2 position;
    uint32_t color;
};

// Triangle vertices (colored RGB)
static const Vertex TRIANGLE_VERTICES[3] = {
    {{1, 0}, 0xffff0000u},  // Red
    {{cos(M_PI * 2 / 3), sin(M_PI * 2 / 3)}, 0xff00ff00u},  // Green
    {{cos(M_PI * 4 / 3), sin(M_PI * 4 / 3)}, 0xff0000ffu},  // Blue
};

static constexpr uint16_t TRIANGLE_INDICES[3] = { 0, 1, 2 };

// Setup function
auto setup = [](Engine* engine, View* view, Scene* scene) {
    // Create a simple skybox
    Skybox* skybox = Skybox::Builder()
        .color({0.1, 0.125, 0.25, 1.0})
        .build(*engine);
    scene->setSkybox(skybox);
    
    // Create vertex buffer
    VertexBuffer* vb = VertexBuffer::Builder()
        .vertexCount(3)
        .bufferCount(1)
        .attribute(VertexAttribute::POSITION, 0, 
                  VertexBuffer::AttributeType::FLOAT2, 0, 12)
        .attribute(VertexAttribute::COLOR, 0, 
                  VertexBuffer::AttributeType::UBYTE4, 8, 12)
        .normalized(VertexAttribute::COLOR)
        .build(*engine);
    vb->setBufferAt(*engine, 0,
        VertexBuffer::BufferDescriptor(TRIANGLE_VERTICES, 36, nullptr));
    
    // Create index buffer
    IndexBuffer* ib = IndexBuffer::Builder()
        .indexCount(3)
        .bufferType(IndexBuffer::IndexType::USHORT)
        .build(*engine);
    ib->setBuffer(*engine,
        IndexBuffer::BufferDescriptor(TRIANGLE_INDICES, 6, nullptr));
    
    // Create material (using pre-compiled material)
    Material* mat = Material::Builder()
        .package((void*) BAKED_MATERIAL_PACKAGE, sizeof(BAKED_MATERIAL_PACKAGE))
        .build(*engine);
    
    // Create renderable entity
    Entity renderable = EntityManager::get().create();
    RenderableManager::Builder(1)
        .boundingBox({{ -1, -1, -1 }, { 1, 1, 1 }})
        .material(0, mat->getDefaultInstance())
        .geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vb, ib, 0, 3)
        .culling(false)
        .receiveShadows(false)
        .castShadows(false)
        .build(*engine, renderable);
    scene->addEntity(renderable);
};

// Render loop
if (renderer->beginFrame(swapChain)) {
    renderer->render(view);
    renderer->endFrame();
}

Building and Running

1

Clone the repository

git clone https://github.com/google/filament.git
cd filament
2

Build Filament

./build.sh release
3

Run the hello triangle sample

./out/cmake-release/samples/hellotriangle

Understanding the Code

Entity Component System

Filament uses an Entity Component System (ECS) architecture:
  • Entities are lightweight identifiers (just integers)
  • Components store data and behavior (like RenderableManager, TransformManager)
  • Systems process components (handled internally by Filament)
// Create an entity
Entity entity = EntityManager::get().create();

// Add a renderable component to it
RenderableManager::Builder(1)
    .geometry(0, ...)
    .build(*engine, entity);

Vertex Buffers

Vertex buffers define the geometry:
VertexBuffer* vb = VertexBuffer::Builder()
    .vertexCount(3)                    // 3 vertices
    .bufferCount(1)                     // 1 interleaved buffer
    .attribute(VertexAttribute::POSITION, 0, AttributeType::FLOAT2, 0, 12)
    .attribute(VertexAttribute::COLOR, 0, AttributeType::UBYTE4, 8, 12)
    .normalized(VertexAttribute::COLOR) // Normalize color to 0-1 range
    .build(*engine);

Materials

Materials in Filament are compiled using the matc tool. For quick prototyping, you can use pre-compiled materials included with the samples.
See the Materials Guide for details on creating custom materials.

Next Steps

Load 3D Models

Learn how to load glTF 2.0 models with the gltfio library

Materials

Create custom materials with the material system

Lighting

Add lights and image-based lighting to your scene

Camera Controls

Implement camera movement and controls

Build docs developers (and LLMs) love