This video documents a real-time programming challenge where the creator attempts to build a functional clone of Microsoft Paint in C++ within a two-hour time limit. Using ImGui for the user interface and modern OpenGL for rendering, he opts for a GPU-based approach, implementing the core drawing logic with compute shaders. A significant portion of the challenge is spent on initial project setup and overcoming a frustrating 20-minute bug caused by a single-character typo in an OpenGL format specifier. Despite this setback, he successfully implements all the core requirements: a drawable canvas, a color picker, adjustable brush sizes, a tool to switch between circle and square brushes, and a function to save the final image as a PNG file using the STB library.
Creating a C++ Paint Application in Two Hours
0:21 The Challenge Begins: The creator unboxes the challenge: create an MS Paint clone in C++ in under two hours. The core requirements are a drawable canvas, a color picker, a brush with at least two sizes, and a simple shape tool. He decides to use the ImGui library for the UI and OpenGL for rendering.
1:54 GPU Compute Shader Approach: He chooses to implement the drawing functionality on the GPU using compute shaders rather than a simpler CPU-based pixel array. This involves writing GLSL code to modify a texture that acts as the canvas, offering a more advanced and performant solution.
6:33 Project Setup & Technical Hurdles: A significant amount of time is spent setting up the project. To use modern OpenGL features like compute shaders, he has to integrate the Glad library, which was not part of the initial ImGui example project.
16:35 The 20-Minute Bug: The creator gets stuck on a major issue where the canvas remains black instead of rendering the chosen color. After nearly 20 minutes of debugging, he discovers the cause was a simple typo in the OpenGL texture format specifier (GL_RGBA instead of GL_RGBA8).
18:08 Implementing Core Drawing Logic: With the rendering pipeline fixed, he implements the main painting feature. He captures the mouse coordinates relative to the viewport window and passes them to the compute shader, which colors the pixels around the cursor based on the selected brush size and shape.
22:04 Adding Essential UI Controls: He adds the required UI elements using ImGui, including a color picker to select the drawing color, a slider to control the brush size, and a "Clear" button to wipe the canvas clean.
26:26 Shape Tool and Brush Preview: To fulfill the "shape tool" requirement, he implements a toggle between a circular and a square brush. He also adds a helpful overlay that draws an outline of the current brush shape and size directly on the cursor for better user feedback.
26:37 Acknowledging Limitations: When drawing quickly, the brush creates a series of dots instead of a continuous line. He acknowledges this and deems implementing interpolation to fix it a "flashy" feature that is outside the scope of the two-hour challenge.
28:48 Saving the Artwork: As a final feature, he integrates the STB Image Write library to allow saving the canvas as a PNG file. This requires reading the pixel data back from the GPU texture and fixing an issue where the image was initially saved upside-down.
31:20 Final Result and Demonstration: He successfully completes the challenge within the time limit. The final application has a drawable canvas, color/size controls, shape tools, and a save function. He demonstrates its functionality by drawing his channel logo.