Skip to content

cstom4994/vtf.hpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vtf.hpp

A tiny, dependency-free C++ VTF (Valve Texture Format) loader/decoder.

This repo provides a single header (vtf.hpp) plus a small example program that decodes a VTF and writes a PPM image.

Features

  • Header-only, standard C++ (C++17+)
  • Parses VTF headers (tested for VTF 7.x; accepts 7.0–7.5)
  • Decodes the largest mip level of a chosen frame into RGBA8
  • Supported formats:
    • Uncompressed: RGBA8888, ARGB8888, ABGR8888, BGRA8888, RGB888, BGR888
    • Compressed: DXT1, DXT3, DXT5

Non-goals / limitations

  • Not a full VTF implementation (no cubemaps, no volume textures, no normal-map special handling)
  • Only decodes the largest mip level (mip 0)
  • Only reads the high-res image resource; other resources are ignored

Build the example

cmake -S . -B build
cmake --build build --config Release

Run the example

./build/vtf_to_ppm <input.vtf> <output.ppm> [frameIndex]

Example:

./build/vtf_to_ppm my_texture.vtf out.ppm 0

The example writes a binary PPM (P6). Alpha is dropped.

Quick usage

#include "vtf.hpp"

vtf::Image img;
if (!img.load_from_file("foo.vtf")) {
    // img.error()
}

if (!img.decode_rgba8(0)) {
    // img.error()
}

auto& header = img.header();
auto& rgba   = img.rgba8(); // width * height * 4

License

MIT

About

A tiny, dependency-free C++ VTF (Valve Texture Format) loader/decoder.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors