Gama C Library
Gama C API Documentation
project.h File Reference

Implements the software rasterizer for projecting 3D meshes onto a 2D gm3Image. More...

#include "../color.h"
#include "../position.h"
#include "image.h"
#include "light.h"
#include "mesh.h"
#include "mtl.h"
#include "position.h"
#include "scene.h"
#include "transform.h"
#include <stddef.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

int gm3_project (gm3Image *output, const gm3Mesh *mesh, const gm3Transform *transform, const gm3Scene *scene)
 Projects a 3D mesh onto a 2D image buffer, applying transformations, lighting, and culling.

Detailed Description

Implements the software rasterizer for projecting 3D meshes onto a 2D gm3Image.

This file contains the core logic for the 3D rendering pipeline, including lighting calculations, vertex transformation, clipping, backface culling, and triangle assembly for the gm3Image output.

Function Documentation

◆ gm3_project()

int gm3_project ( gm3Image * output,
const gm3Mesh * mesh,
const gm3Transform * transform,
const gm3Scene * scene )

Projects a 3D mesh onto a 2D image buffer, applying transformations, lighting, and culling.

This function performs the core 3D to 2D rendering pipeline:

  • Transforms mesh vertices from model space to world space, then to screen space.
  • Stores world-space vertex positions for lighting and culling.
  • Performs basic frustum clipping and backface culling.
  • Calculates lighting for each visible face using the Blinn-Phong model.
  • Assembles the projected 2D triangles, colors, and depth values into the gm3Image output.
Parameters
outputA pointer to the gm3Image struct where the projected 2D scene data will be stored.
meshA pointer to the gm3Mesh to project.
transformA pointer to the gm3Transform to apply to the mesh (can be NULL for identity).
sceneA pointer to the gm3Scene containing camera and light settings (can be NULL for defaults).
Returns
0 on success, -1 on memory allocation failure, or if the mesh is invalid.