1. Products
  2.   3D
  3.   GO
  4.   FauxGL
 
  

Free Go Library for 3D Rendering & Transformation

Leading Open Source Go 3D Graphics Library for Working with 3D Meshes, Custom Shading and Materials, 3D Transformations, Multithreaded Rendering, Anti-aliasing and So on.

What is FauxGL Library?

FauxGL is an innovative open source graphics library created by Michael Fogleman, designed to provide software-based 3D rendering capabilities in Go. This lightweight yet powerful library offers a pure Go implementation of 3D rendering without requiring any external dependencies, making it an excellent choice for developers who need portable 3D graphics solutions. Despite its lightweight nature, FauxGL supports many core 3D graphics and rendering features such as vertex transformations, importing and manipulating 3D meshes, custom shading and materials, perspective and camera control, depth buffering and hidden surface removal, triangle rasterization, depth buffering, color interpolation, texture mapping, wireframe rendering and many more.

Unlike OpenGL or DirectX, which rely on GPU hardware, the FauxGL library processes everything on the CPU. This makes it suitable for environments where hardware acceleration isn't available, or where developers want fine control over the rendering pipeline. While unsuitable for high-framerate games due to its CPU-bound nature, FauxGL is surprisingly capable and finds use cases in offline rendering, generating visualizations, testing algorithms, educational purposes, or running in environments where GPU access is unavailable or undesirable. It natively loads several common 3D file formats such as STL, OBJ, PLY, 3DS and many more. It provides functions to easily create basic shapes like planes, spheres, cubes, cylinders, and cones, useful for testing or constructing simple scenes. FauxGL is a testament to the power and expressiveness of Go. It's a well-crafted library that elegantly demonstrates the principles of 3D graphics rendering on the CPU.

Previous Next

Getting Started with FauxGL

The recommend way to install FauxGL is using GitHub. Please use the following command for a smooth installation.

Install FauxGL API via Get command

go get github.com/fogleman/fauxgl 

You can download the compiled shared library from Github repository.

Pure CPU-Based Rendering via Go API

The open source FauxGL library supports Pure CPU-Based Rendering and does not use the GPU at all. Every triangle, every pixel, and every transformation is computed purely on the CPU. This makes it a perfect choice for headless rendering environments (like servers) or simple graphics processing tasks without GPU dependency. The following code script shows how to setting up a scene inside Go applications.

How to Set Up a Scene for Pure CPU-Based Rendering via Go Library?

import "github.com/fogleman/fauxgl"

const (
    width  = 1024
    height = 768
)

func main() {
    context := fauxgl.NewContext(width, height)
    context.ClearColorBufferWithColor(fauxgl.Black)
    context.ClearDepthBuffer()

    // Now you can start drawing models or primitives!
}

3D Model Loading and Transformation

The open source FauxGL library has provided complete support for loading and working 3D models inside Go applications. Once loaded, you can easily apply transformations like scaling, rotation, resizing, and translation. Here is a simple example that demonstrates how software developers can load Wavefront OBJ formats, one of the most common 3D model file formats and apply transformation to it using Go library.

How to Load a 3D Model and Applying Transformations via Go Library?

mesh, err := fauxgl.LoadOBJ("model.obj")
if err != nil {
    panic(err)
}

// Apply transformations
matrix := fauxgl.Identity().
    Scale(fauxgl.Vector{1, 1, 1}).
    Rotate(fauxgl.V(0, 1, 0), fauxgl.Radians(45)).
    Translate(fauxgl.Vector{0, 0, -5})

mesh.Transform(matrix)

Vector Operations via Go Library

The MathGL library provides extensive support for vector and matrix mathematics, including operations for 2D, 3D, and 4D vectors and matrices. These are essential for handling positions, directions, velocities, and other spatial data. It provides support for Add, Sub, Dot, Cross, Normalize, etc. and multiple precision types (mgl32 for float32, mgl64 for float64). Here is a simple example that demonstrates how software developers can perform different vector operations inside their Go applications.

How to Perform Vector Operations via Go Library?

package main

import (
	"fmt"
	"github.com/go-gl/mathgl/mgl32"
)

func main() {
	// Create two 3D vectors
	v1 := mgl32.Vec3{1, 2, 3}
	v2 := mgl32.Vec3{4, 5, 6}

	// Vector addition
	sum := v1.Add(v2)
	fmt.Println("Vector sum:", sum) // [5 7 9]

	// Dot product
	dot := v1.Dot(v2)
	fmt.Println("Dot product:", dot) // 32

	// Cross product
	cross := v1.Cross(v2)
	fmt.Println("Cross product:", cross) // [-3 6 -3]
}

Custom Shading and Materials via Go

You can define how objects are shaded using customizable shaders inside Go applications. The open source FauxGL library provides a flexible system for writing your own shading logic — allowing you to control color, lighting, and even custom effects at the pixel level. The following shows how software developers can perform simple flat shading inside Go applications.

How to Perform Simple Flat Shading inside Go Apps?

shader := func(vertex fauxgl.Vertex) fauxgl.Color {
    normal := vertex.Normal.Normalize()
    light := fauxgl.Vector{1, 1, 1}.Normalize()
    intensity := normal.Dot(light)
    baseColor := fauxgl.HexColor(0x3498db) // Light blue color
    return baseColor.MulScalar(intensity)
}

context.Shader = shader
context.DrawMesh(mesh)