Installing cgltf Library Установка библиотеки cgltf
A step-by-step guide to downloading, extracting, and configuring the cgltf single-file C glTF library on Windows and Ubuntu. Пошаговое руководство по скачиванию, распаковке и настройке однофайловой C-библиотеки glTF cgltf в Windows и Ubuntu.
Step 1: Download Source Code Шаг 1: Скачивание исходного кода
Download the latest release zip archive directly from GitHub Releases: Скачайте zip-архив последнего релиза напрямую из GitHub Releases:
Download cgltf Releases Скачать релизы cgltf
For Ubuntu, you can download version 1.15 via wget in terminal:
В Ubuntu вы можете скачать архив версии 1.15 с помощью wget через терминал:
sudo apt update && sudo apt install -y wget unzip
cd ~
wget https://github.com/jkuhlmann/cgltf/archive/refs/tags/v1.15.zip -O cgltf-1.15.zip
Step 2: Extract the Library Шаг 2: Распаковка библиотеки
Option A: Windows Вариант A: Windows
Unzip the downloaded archive so that the header files are located in C:\libs\cgltf-1.15.
Распакуйте скачанный архив так, чтобы заголовочные файлы находились в папке C:\libs\cgltf-1.15.
Option B: Ubuntu Вариант B: Ubuntu
Unzip the archive into the ~/libs directory:
Распакуйте архив в директорию ~/libs:
mkdir -p ~/libs
unzip -o cgltf-1.15.zip -d ~/libs/
rm -f cgltf-1.15.zip
This will extract the headers into ~/libs/cgltf-1.15.
Заголовочные файлы будут распакованы по пути ~/libs/cgltf-1.15.
Step 3: Create Project Directory Шаг 3: Создание директории проекта
Create a workspace folder and a new directory for your cgltf test project: Создайте рабочую папку для проектов и новую директорию для вашего тестового проекта cgltf:
Windows (Command Prompt / PowerShell)
mkdir C:\projects\cgltf-test
cd C:\projects\cgltf-test
Ubuntu (Terminal)
mkdir -p ~/projects/cgltf-test
cd ~/projects/cgltf-test
Step 4: Create Source Files (main.c & CMakeLists.txt) Шаг 4: Создание исходных файлов (main.c и CMakeLists.txt)
You can create these files using Notepad / Sublime Text on Windows, or nano in Ubuntu terminal:
Вы можете создать эти файлы через Блокнот / Sublime Text в Windows или с помощью nano в терминале Ubuntu:
Windows (Terminal / Notepad)
notepad main.c
notepad CMakeLists.txt
Ubuntu (Terminal / Nano)
nano main.c
nano CMakeLists.txt
1. File Contents for main.c 1. Содержимое файла main.c
#include <stdio.h>
#define CGLTF_IMPLEMENTATION
#include "cgltf.h"
int main(int argc, char *argv[]) {
cgltf_options options = {0};
cgltf_data* data = NULL;
/* Example non-existent file call to verify cgltf linkage and compilation */
cgltf_result result = cgltf_parse_file(&options, "model.gltf", &data);
if (result == cgltf_result_file_not_found) {
printf("cgltf header loaded successfully! (file model.gltf not found, as expected)\n");
} else if (result == cgltf_result_success) {
printf("Successfully parsed model.gltf!\n");
cgltf_free(data);
} else {
printf("cgltf initialized, returned code: %d\n", result);
}
return 0;
}
2. File Contents for CMakeLists.txt 2. Содержимое файла CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(cgltf_test C)
add_executable(app main.c)
if(WIN32)
target_include_directories(app PRIVATE C:/libs/cgltf-1.15)
else()
target_include_directories(app PRIVATE $ENV{HOME}/libs/cgltf-1.15)
endif()
Step 5: Create Build & Execution Scripts Шаг 5: Создание скриптов сборки и запуска
Windows (MinGW / Batch Scripts)
config-exe.bat
cmake -G Ninja -S . -B dist/win
build-exe.bat
cmake --build dist/win
run-exe.bat
@echo off
.\dist\win\app.exe
Run the scripts sequentially in Command Prompt or PowerShell: Последовательно запустите скрипты в командной строке или PowerShell:
config-exe.bat
build-exe.bat
run-exe.bat
Ubuntu (Bash Scripts)
config-bin.sh
#!/usr/bin/env bash
set -e
cmake -G Ninja -S . -B dist/linux
build-bin.sh
#!/usr/bin/env bash
set -e
cmake --build dist/linux
run-bin.sh
#!/usr/bin/env bash
set -e
./dist/linux/app
Grant execute permissions on Ubuntu before running: Предоставьте права на выполнение в Ubuntu перед запуском:
chmod +x config-bin.sh build-bin.sh run-bin.sh
./config-bin.sh
./build-bin.sh
./run-bin.sh
Support My Work Поддержать проект
If these tutorials helped you, consider buying me a coffee! Если эти туториалы вам помогли, вы можете поддержать автора.
Sberbank (Russia only) Сбербанк (только для РФ)
Direct transfer via phone number (Russia only) Перевод по номеру телефона (только для РФ)
USDT TRC20
Support via Cryptocurrency Поддержка криптовалютой