An open API service indexing awesome lists of open source software.

https://github.com/onebit5/onetek-engine-2

C++ game engine with multi-API rendering support.
https://github.com/onebit5/onetek-engine-2

cpp cpp20 engine game game-development game-engine gamedev gameengine

Last synced: 7 months ago
JSON representation

C++ game engine with multi-API rendering support.

Awesome Lists containing this project

README

          

# OneTek Engine 2

C++ game engine with multi-API rendering support.

## Features

### Core Systems
- **Multi-API Rendering**: Support for Vulkan, DirectX 12, and OpenGL
- **Entity Component System**: Flexible game object architecture
- **Physics Integration**: NVIDIA PhysX for realistic physics simulation
- **Asset Pipeline**: Comprehensive asset loading and management
- **Input System**: Cross-platform input handling via SDL2
- **AI Navigation**: Recast & Detour integration for pathfinding
- **GUI System**: Dear ImGui for development tools and debugging
- **Audio System**: 3D spatial audio support
- **Math Library**: Optimized vector, matrix, and quaternion operations

### Rendering Features
- Modern graphics pipeline with shader support
- Material system with PBR support
- Post-processing effects
- Shadow mapping
- Frustum culling
- Level of Detail (LOD) system
- Debug visualization tools

### Platform Support
- **Windows** (10/11)
- **Linux** (Ubuntu 20.04+, Debian, Arch)
- **macOS** (10.15+)

## Dependencies

The engine relies on the following third-party libraries:

| Library | Version | Purpose | Required |
|---------|---------|---------|----------|
| **SDL2** | 2.28.5+ | Window management, input | Yes |
| **nlohmann_json** | 3.11.2+ | JSON configuration files | Yes |
| **STB** | Latest | Image loading (header-only) | Yes |
| **Assimp** | 5.3.1+ | 3D model loading | Yes |
| **FreeType** | 2.13.2+ | Font rendering | Yes |
| **Dear ImGui** | 1.90.1+ | Development GUI | Recommended |
| **Vulkan SDK** | 1.3+ | Vulkan rendering | Optional |
| **DirectX Headers** | Latest | DirectX 12 support | Optional (Windows) |
| **PhysX** | 5.x | Physics simulation | Optional |
| **Recast & Detour** | 1.6.0+ | AI navigation mesh | Optional |

## Building the Engine

### Prerequisites

#### Build Tools
- **CMake** 3.20 or higher
- **C++20** compatible compiler:
- Windows: Visual Studio 2019+ or Clang 12+
- Linux: GCC 10+ or Clang 12+
- macOS: Xcode 12+ or Clang 12+
- **Ninja** (recommended) or Make

### Quick Start

```bash
# Clone the repository
git clone https://github.com/Onebit5/OneTek-Engine-2 OneTek-Engine-2
cd OneTek-Engine-2

# Create build directory
mkdir build
cd build

# Configure with CMake
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build
cmake --build . --config Release -j8

# Run example
./bin/BasicExample
```

### Platform-Specific Instructions

#### Windows (Visual Studio)

```powershell
# Configure for Visual Studio
cmake -B build -G "Visual Studio 16 2019" -A x64

# Build
cmake --build build --config Release

# Or open in Visual Studio
start build/OneTekEngine2.sln
```

#### Linux (Ubuntu/Debian)

```bash
# Install dependencies
sudo apt update
sudo apt install -y \
build-essential cmake ninja-build \
libsdl2-dev libfreetype6-dev libassimp-dev \
nlohmann-json3-dev libvulkan-dev

# Build
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
```

#### macOS

```bash
# Install dependencies via Homebrew
brew install cmake ninja sdl2 freetype assimp nlohmann-json
brew install --cask vulkan-sdk # Optional

# Build
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
```

### CMake Options

| Option | Default | Description |
|--------|---------|-------------|
| `OTE_BUILD_EXAMPLES` | ON | Build example applications |
| `OTE_BUILD_TESTS` | OFF | Build unit tests |
| `OTE_USE_VULKAN` | ON | Enable Vulkan renderer |
| `OTE_USE_DIRECTX12` | OFF | Enable DirectX 12 renderer (Windows) |
| `OTE_ENABLE_PROFILING` | OFF | Enable performance profiling |
| `OTE_STATIC_LINKING` | OFF | Use static linking |

Example configuration:

```bash
cmake -B build \
-DCMAKE_BUILD_TYPE=Release \
-DOTE_BUILD_EXAMPLES=ON \
-DOTE_USE_VULKAN=ON \
-DOTE_USE_DIRECTX12=OFF
```

## Using the Engine

### Basic Application

```cpp
#include "Engine/OneTekEngine.h"
#include

using namespace OneTek;

class MyGame : public Application {
public:
bool Initialize() override {
// Setup your game
return true;
}

void Update(float deltaTime) override {
// Update game logic
}

void Render() override {
// Render your scene
}

void Shutdown() override {
// Cleanup
}
};

int main() {
Engine engine;

if (!engine.Initialize("config.json")) {
return -1;
}

auto game = std::make_unique();
engine.Run(std::move(game));

return 0;
}
```

### Configuration

Create an `engine.json` file to configure the engine:

```json
{
"window": {
"title": "My Game",
"width": 1920,
"height": 1080,
"fullscreen": false,
"vsync": true
},
"renderer": {
"api": "vulkan",
"validation": true,
"msaa_samples": 4
},
"physics": {
"gravity": [0.0, -9.81, 0.0],
"fixed_timestep": 0.016667
}
}
```

## Project Structure

```
OneTek-Engine-2/
├── Engine/ # Engine source code
│ ├── Core/ # Core systems (Engine, Timer, Logger)
│ ├── Renderer/ # Rendering system
│ ├── Physics/ # Physics integration
│ ├── Assets/ # Asset management
│ ├── AI/ # AI and navigation
│ ├── Audio/ # Audio system
│ ├── Input/ # Input handling
│ ├── GUI/ # ImGui integration
│ ├── Math/ # Math library
│ ├── Platform/ # Platform abstraction
│ └── Utils/ # Utility functions
├── Examples/ # Example applications
├── Tests/ # Unit tests
├── Documentation/ # Detailed documentation
├── ThirdParty/ # External dependencies
└── Assets/ # Game assets
```

## Modifying the Engine

### Adding a New System

1. Create header and source files in appropriate directory:
```cpp
// Engine/MySystem/MySystem.h
#pragma once

namespace OneTek {
class MySystem {
public:
bool Initialize();
void Update(float deltaTime);
void Shutdown();
};
}
```

2. Add to CMakeLists.txt:
```cmake
target_sources(OneTekEngine2 PRIVATE
MySystem/MySystem.cpp
)
```

3. Integrate with Engine class:
```cpp
// Engine/Core/Engine.cpp
#include "MySystem/MySystem.h"

bool Engine::Initialize() {
m_mySystem = std::make_unique();
return m_mySystem->Initialize();
}
```

### Extending the Renderer

To add support for a new rendering API:

1. Create API-specific implementation in `Engine/Renderer/[API]/`
2. Inherit from base classes (RenderDevice, RenderContext, etc.)
3. Add CMake configuration option
4. Update RenderDevice initialization logic

### Custom Assets

To support new asset types:

1. Create loader in `Engine/Assets/Loaders/`
2. Register with AssetManager
3. Define asset data structure
4. Implement loading/unloading logic

## Examples

The engine includes several example projects:

| Example | Description |
|---------|-------------|
| **BasicExample** | Minimal engine setup and rendering |
| **SimpleExample** | SDL window with 3D math demonstrations |
| **DirectXRenderExample** | DirectX 12 rendering pipeline |
| **VulkanRenderExample** | Vulkan rendering with colored triangle |

Build and run examples:

```bash
# Build all examples
cmake --build build --target BasicExample

# Run
./build/bin/BasicExample
```

## Documentation

Detailed documentation is available in the `Documentation/` directory:

- **[Architecture.md](Documentation/Architecture.md)** - System design and architecture
- **[Building.md](Documentation/Building.md)** - Detailed build instructions
- **[Rendering.md](Documentation/Rendering.md)** - Rendering system documentation
- **[Physics.md](Documentation/Physics.md)** - Physics integration guide
- **[Assets.md](Documentation/Assets.md)** - Asset pipeline documentation

## Testing

Run the test suite:

```bash
# Build tests
cmake -B build -DOTE_BUILD_TESTS=ON
cmake --build build

# Run tests
cd build
ctest --output-on-failure
```

## Contributing

Contributions are welcome! Please follow these guidelines:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Follow the existing code style (use clang-format)
4. Add tests for new functionality
5. Update documentation as needed
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

### Code Style

- Use modern C++ features (C++20)
- Follow RAII principles
- Prefer `std::unique_ptr` for ownership
- Use `#pragma once` for header guards
- Document public APIs

## Performance Tips

- **Debug vs Release**: Always build in Release mode for performance testing
- **Profiling**: Enable `OTE_ENABLE_PROFILING` to identify bottlenecks
- **Batching**: Minimize draw calls by batching similar objects
- **LOD**: Use Level of Detail system for distant objects
- **Culling**: Frustum culling is automatic, ensure bounding boxes are correct

## Troubleshooting

### Common Issues

**CMake can't find dependencies**
- Ensure all required libraries are installed
- Set environment variables (e.g., `VULKAN_SDK`)
- Use vcpkg or package manager for dependency management

**Linker errors**
- Check that all dependencies are built with the same compiler
- Verify CMake found all libraries correctly
- Ensure matching runtime libraries (Debug/Release)

**Vulkan validation errors**
- Install Vulkan SDK with validation layers
- Set `VK_LAYER_PATH` environment variable
- Check GPU driver compatibility

**Performance issues**
- Build in Release mode (`-DCMAKE_BUILD_TYPE=Release`)
- Disable validation in production
- Profile with appropriate tools (RenderDoc, NSight, etc.)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- **NVIDIA** for PhysX physics engine
- **Khronos Group** for Vulkan specifications
- **SDL** contributors for cross-platform windowing
- **Dear ImGui** for the immediate mode GUI library
- **Assimp** team for 3D model loading
- All open-source contributors

## Contact

- **GitHub Issues**: For bug reports and feature requests
- **Discussions**: For questions and community support

---

Built with ❤️ by Onebit