Thirteen is a header-only C++ library that initializes a DirectX 12 window and gives you a pointer to RGBA uint8 pixels to write to, which are copied to the screen every time you call Render().
It is inspired by the simplicity of the Mode 13h days where you initialized the graphics mode and then started writing pixels directly to the screen. Just include the header, initialize, and start drawing!
#include "thirteen.h"
int main()
{
unsigned char* pixels = Thirteen::Init(800, 600);
if (!pixels)
return 1;
unsigned int frameIndex = 0;
// Go until window is closed or escape is pressed
while (Thirteen::Render() && !Thirteen::GetKey(VK_ESCAPE))
{
// Write to pixels (RGBA format, 4 bytes per pixel)
for (int i = 0; i < 800 * 600 * 4; i += 4)
{
pixels[i + 0] = 255; // Red
pixels[i + 1] = unsigned char(frameIndex); // Green
pixels[i + 2] = unsigned char(frameIndex / 2); // Blue
pixels[i + 3] = 255; // Alpha
}
frameIndex++;
}
Thirteen::Shutdown();
return 0;
}A basic example showing the fundamentals of Thirteen. View source code
A Mandelbrot set fractal visualizer with interactive navigation. View source code
A classic Minesweeper game implementation. View source code
Initializes the window and DirectX 12 renderer.
Parameters:
width- Width of the rendering surface in pixels (default: 1024)height- Height of the rendering surface in pixels (default: 768)fullscreen- Whether to start in fullscreen mode (default: false)
Returns: Pointer to the pixel buffer (RGBA format, 4 bytes per pixel) on success, or nullptr on failure.
Processes window messages, updates input state, tracks frame timing, and copies the pixel buffer to the screen.
Returns: true to continue rendering, false when the application should quit (e.g., window closed).
Cleans up all DirectX resources and destroys the window. Call this before exiting your application.
Enables or disables vertical synchronization.
Parameters:
enabled-trueto enable vsync (limit to monitor refresh rate),falseto disable
Returns: true if vsync is enabled, false otherwise.
Switches between windowed and fullscreen mode.
Parameters:
fullscreen-trueto switch to fullscreen (borderless window),falsefor windowed mode
Returns: true if currently in fullscreen mode, false if windowed.
Returns: The current width of the rendering surface in pixels.
Returns: The current height of the rendering surface in pixels.
Resizes the rendering surface to the specified dimensions. This changes the window size, recreates internal DirectX buffers and reallocates the pixel buffer.
Parameters:
width- New width in pixelsheight- New height in pixels
Returns: Pointer to the pixel buffer (which may be different from the pointer returned by Init()) on success, or nullptr if the resize failed.
Note: Always use the returned pointer as the pixel buffer address may change after resizing.
Sets the application name displayed in the window title bar (along with FPS).
Parameters:
name- The name to display in the title bar
Returns: The duration of the previous frame in seconds. Useful for frame-independent movement and animation.
Gets the current mouse position relative to the window.
Parameters:
x- Reference to store the X coordinate in pixelsy- Reference to store the Y coordinate in pixels
Gets the mouse position from the previous frame.
Parameters:
x- Reference to store the X coordinate in pixelsy- Reference to store the Y coordinate in pixels
Checks if a mouse button is currently pressed.
Parameters:
button- Button to check:0= left,1= right,2= middle
Returns: true if the button is currently pressed.
Checks if a mouse button was pressed in the previous frame.
Parameters:
button- Button to check:0= left,1= right,2= middle
Returns: true if the button was pressed in the previous frame.
Checks if a keyboard key is currently pressed.
Parameters:
keyCode- Windows virtual key code (e.g.,VK_ESCAPE,VK_SPACE,'A', etc.)
Returns: true if the key is currently pressed.
Checks if a keyboard key was pressed in the previous frame.
Parameters:
keyCode- Windows virtual key code
Returns: true if the key was pressed in the previous frame.
To detect a single key press or button click (not held down), compare current and previous frame states:
// Detect key just pressed this frame
bool keyPressed = Thirteen::GetKey(VK_SPACE) && !Thirteen::GetKeyLastFrame(VK_SPACE);
// Detect key just released this frame
bool keyReleased = !Thirteen::GetKey(VK_SPACE) && Thirteen::GetKeyLastFrame(VK_SPACE);
// Same pattern works for mouse buttons
bool clicked = Thirteen::GetMouseButton(0) && !Thirteen::GetMouseButtonLastFrame(0);

