Skip to content

cf_draw3d_mips

Category: draw3d
GitHub: cute_draw3d.h


Gives the sprite atlas a mipmap chain, killing the pixel swimming of minified sprites.

void cf_draw3d_mips(int mip_count);
Parameters Description
mip_count Total mip levels including the base image. 1 (the default) disables mips;
4 is the recommended chain. Clamped to [1, 6].

Remarks

Without mips a sprite drawn smaller than its image -- at distance or at a steep angle in 3d -- point-samples a texel lattice denser than the screen grid, and every camera move re-rolls which texels win: the classic swimming-pixels shimmer. A mip chain gives the GPU pre-filtered smaller versions to sample instead. Flip it on once at init (cf_draw3d_mips(4)) and every atlased sprite benefits, in 3d and in zoomed-out 2d alike; pair it with cf_draw3d_anisotropy so oblique viewing angles keep their sharpness. Sprites at 1:1 scale are untouched -- mip level 0 is the original image.

Each level k is half the resolution of level k - 1, so mip_count of 4 covers minification cleanly down to ⅛ scale; past the chain's end the last level is reused (slight aliasing returns on far-off sprites, which are tiny by then). Deeper chains cost atlas space: images pack with a ring of 2^(mip_count - 2) transparent pixels so coarse mip texels never blend neighboring images together -- 4 pixels at the recommended 4 levels, doubling per extra level, which is why the count clamps at 6.

Calling this rebuilds the atlas from scratch, so call it at init (or at least between frames, never mid-draw). Premade atlases (cf_register_premade_atlas) registered while mips are on get a chain too, but pack no rings -- bake your own gutters between sub-images or their mips bleed into one another.

cf_draw3d_anisotropy
cf_draw3d_sprite
cf_draw3d_billboard
cf_draw3d_push_texture
cf_draw_set_atlas_dimensions