A minimal Direct3D 12 example that draws an animated triangle, written entirely in C-style C++, and all taking place inside a single function.

Related tags

Graphics d3d12
Overview

Direct3D 12 in C-Style C++

A minimal Direct3D 12 example that draws an animated triangle, written entirely in C-style C++, and all taking place inside a single function.

Fruity Frustration

Once upon a time (~10 days ago), I wanted to draw a lonely triangle using the mysterious Direct3D 12. I looked in the wild for a clear example to follow but couldn't find any. I yearned for one that would provide a head start and get out of the way immediately, but instead I was met with all manner of verbose and cryptic messes. Each one demanded a pursuit of its own right, which is distined to be littered with dread and meaningless struggle, just to understand what it does; and, should I refuse, it threatened to take away all my precious enthusiasm and hope to one day witness my very own three-sided creation upon the screen... Long story short, this program is the fruit of that very frustration!

What Is Different?

The program draws an animated triangle on the screen as expected, with the bare minimum amout of work it could get away with. All this work is expressed in clear, C-style C++; no OOP ornamentation or modern C++ spaghetti. In addition to that, the entire program is simply a set of steps laid out in a natural linear fashion, which all take place inside the WinMain() function.

See it in motion.

screenshot

The Code Layout

The program is made up of two files.

  • hello.cxx -- sets up Direct3D 12 and uses it to feed the GPU with three vertices and a contrived texture.

  • shaders.hlsl -- holds the shaders which receive that data and manipulate it to produce the final result.

As long as both files are located in the same directory, all you have to do to build it is feed the C++ file to the compiler. Alternatively you can run the accompanied build script to avoid extraneous typing.

Examples by Other People

This program is primarily inspired by the work of @mmozeiko. His Direct3D 11 in C example is the first program I come across that is written in this linear fashion, all inside a single function.

Other examples:

Official Resources

Direct3D 12 Programming Guide

DirectX Graphics Samples

Microsoft DirectX 12 and Graphics Education

Owner
Taoufik Rida Bouftass
Taoufik Rida Bouftass
Single-header single-function C/C++ immediate-mode camera for your graphics demos

Single-header single-function C/C++ immediate-mode camera for your graphics demos

Nicolas Guillemot 107 Apr 28, 2022
Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal

Low Level Graphics Library (LLGL) Documentation NOTE: This repository receives bug fixes only, but no major updates. Pull requests may still be accept

Lukas Hermanns 1.4k Jun 19, 2022
Direct3D to OpenGL abstraction layer

TOGL Direct3D -> OpenGL translation layer. Taken directly from the DOTA2 source tree; supports: Limited subset of Direct3D 9.0c Bytecode-level HLSL ->

Valve Software 2k Jun 26, 2022
Easy to integrate memory allocation library for Direct3D 12

D3D12 Memory Allocator Easy to integrate memory allocation library for Direct3D 12. Documentation: Browse online: D3D12 Memory Allocator (generated fr

GPUOpen Libraries & SDKs 428 Jun 23, 2022
Direct3D 12.0 quick reference guide

Direct3D 12.0 quick reference guide

Alessio1989 50 Mar 24, 2022
Vizzu is a free, open-source Javascript/C++ library for animated data visualizations and data stories.

Vizzu is a free, open-source Javascript/C++ library utilizing a generic dataviz engine that generates many types of charts and seamlessly animates between them

Vizzu 1.5k Jun 24, 2022
Minimal raytracing example with a combination of embree and tinyobjloader

embree-tinyobj-example minimal raytracing example with a combination of embree and tinyobjloader Requirements CMake (>=3.20) Embree (>=3) OpenMP (Opti

yumcyawiz 2 Apr 7, 2022
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.

bgfx - Cross-platform rendering library GitHub Discussions Discord Chat What is it? Cross-platform, graphics API agnostic, "Bring Your Own Engine/Fram

Бранимир Караџић 11.8k Jul 2, 2022
A 3D Printable Retro-style Raspberry Pi HQ Camera

3D Printable Retro-style Raspberry Pi HQ Camera

Ping-Hsun 401 Jun 26, 2022
Legion Low Level Rendering Interface provides a graphics API agnostic rendering interface with minimal CPU overhead and low level access to verbose GPU operations.

Legion-LLRI Legion-LLRI, or “Legion Low Level Rendering Interface” is a rendering API that aims to provide a graphics API agnostic approach to graphic

Rythe Interactive 25 Mar 8, 2022
FFVideo - an example FFmpeg lib, and wxWidgets Player with video filters and face detection

An example FFmpeg lib, and wxWidgets Player application with video filters and face detection, it is a no-audio video player intended for video experiments and developers learning how to code media applications.

Blake Senftner 20 Mar 26, 2022
Minimal A* implementation in C. No dynamic memory allocation.

Micro A Star Path Finder This is a minimal A* path finder implementation in C, without any dynamic memory allocation. Usage The maximum size of the ma

Felipe da Silva 76 Jun 11, 2022
Minimal pathtracer using Vulkan RayTracing

Single File Vulkan Pathtracing Minimal pathtracer using Vulkan RayTracing Environment Vulkan SDK 1.2.162.0 GPU / Driver that support Vulkan Ray Tracin

Yuki Nishidate 25 May 8, 2022
Vulkan Minimal Hybrid Rendering

Vulkan Minimal Hybrid Rendering A minimal hybrid rendering sample using ray query Features Rasterization Raytraced shadow Environment Vulkan SDK 1.2.1

Yuki Nishidate 7 Aug 16, 2021
Epoxy is a library for handling OpenGL function pointer management for you

Epoxy is a library for handling OpenGL function pointer management for you. It hides the complexity of dlopen(), dlsym(), glXGetProcAddress(), eglGetP

Eric Anholt 545 Jun 27, 2022
A C++ port of Wave Function Collapse Tiling

Wave Function Collapse in C++ This is a C++ port of https://github.com/mxgmn/WaveFunctionCollapse. All sample images come from https://github.com/mxgm

Emil Ernerfeldt 280 Jun 28, 2022
HARFANG®3D is an all-in-one 3D visualization library usable in C++, Python, Lua and Go.

HARFANG® 3D engine HARFANG®3D is an all-in-one 3D visualization library usable in C++, Python, Lua and Go. Table of contents About Features Screenshot

HARFANG® 3D 133 Jun 30, 2022
Cocos2d-x is a suite of open-source, cross-platform, game-development tools used by millions of developers all over the world.

Cocos2d-x is a suite of open-source, cross-platform, game-development tools used by millions of developers all over the world.

cocos2d 16.2k Jul 3, 2022
A simple single point light shadow mapping with OpenGL 3.3 and C++

omni-directional-light-example Using OpenGL 3.3 with C++ Basically a single light map, no lighting model was used Usage Build the executable outside A

Mohammad Issawi 4 Feb 10, 2022