How Beginners Can Start Writing a 3D System in C++

It can be divided into four main areas: core language fundamentals, mathematical foundations, graphics APIs, and tools and libraries. Phase One: Solidify Core C++ Fundamentals
Before you start engaging with any 3D concepts, you must have a solid understanding of C++. 3D programming has high demands for performance and resource management.
1. Modern C++ (at least C++11/14/17)
· Why? Old C++ (like C++98) is cumbersome and prone to errors. Modern C++ provides safer and more efficient tools.
· Key things to learn:
· Smart pointers (std::unique_ptr, std::shared_ptr): Powerful tools for automatic memory management that greatly reduce the risk of memory leaks. This is crucial!
· Standard Template Library (STL): Proficient use of containers like std::vector, std::array, std::map, and the algorithm library. std::vector will be your best friend for storing vertices, indices, and other data.
· Automatic type deduction (auto): Makes code cleaner, especially in template and iterator scenarios.
· Lambda expressions: Very useful, especially when setting up callback functions.
· Move semantics and rvalue references: Understand how to avoid unnecessary copies to improve performance.
2. Object-Oriented Programming (OOP)
· Objects in the 3D world (like models, lights, cameras) are naturally suited for abstraction using objects. Master classes, inheritance, polymorphism, and encapsulation.
3. Basic data structures and algorithms
· Understand the basic operations and performance characteristics of arrays, linked lists, trees (like scene graphs typically use tree structures).
Learning suggestion: Don’t just read books; make sure to practice coding as you learn. You can try writing some simple 2D games (like Snake, Tetris) to reinforce these concepts.
Phase Two: Master Necessary Mathematical Knowledge
3D graphics are essentially applied mathematics. You don’t need to become a mathematician, but knowledge in the following three areas is absolutely essential:
1. Linear Algebra – The core of the core
· Vectors: Represent points, directions, colors. You must master vector addition, subtraction, dot product, cross product, and normalization.
· Matrices: Represent transformations (translation, rotation, scaling). You must understand matrix multiplication, identity matrices, inverse matrices, and transposition.
· Coordinate Systems: Model space, world space, view space (camera space), clipping space. Understand how they transform into each other through matrix transformations.
2. Geometry
· Representation and intersection detection of geometric shapes like rays, planes, spheres (used for mouse picking, etc.).
3. Trigonometry
· Sine, cosine, etc., commonly used for angle calculations and rotations.
Learning suggestion: Combine theory with practice. You can find a good math library (like glm mentioned later) and implement effects in code while learning math, such as manually calculating the rotation of a point, which will deepen your understanding.
Phase Three: Choose and Learn a Graphics API
This is the “language” you use to communicate with the GPU (graphics card). Choose one and study it in depth.
1. OpenGL (recommended for beginners)
· Advantages:
· Cross-platform (Windows, Linux, macOS).
· Extremely rich resources, large community, very suitable for beginners.
· Has a programmable pipeline that allows you to understand every step of modern graphics rendering.
· Learning resources:
· LearnOpenGL (website): Absolutely the best OpenGL beginner tutorial in the world, bar none. The Chinese translation is also very comprehensive.
· “OpenGL Programming Guide” (the red book): A classic authoritative reference book.
2. Vulkan
· Advantages: High performance, low overhead, explicit control (more precise hardware control).
· Disadvantages: Extremely complex, steep learning curve, not suitable for beginners. It is recommended to consider it after mastering OpenGL and high-performance programming.
3. DirectX 12 (Windows only)
· Similar to Vulkan, it is Microsoft’s high-performance graphics API, also complex. Strongly recommended to start with OpenGL.
During your learning process, you will encounter:
· Rendering Pipeline
· Vertex Buffer Objects (VBO), Vertex Array Objects (VAO), Index Buffer Objects (EBO)
· Shaders: Writing Vertex Shaders and Fragment Shaders (using GLSL)
· Textures
· Transformations (model, view, projection matrices)
Phase Four: Prepare Tools and Libraries
No one writes everything from scratch; wisely using third-party libraries is a mark of professionalism.
1. Integrated Development Environment (IDE)
· Visual Studio (Windows): Strong ecosystem, unbeatable debugging features.
· CLion (cross-platform): An excellent C++ IDE.
· VSCode + CMake + plugins (cross-platform): A lightweight and highly customizable option.
2. Key dependency libraries
· GLFW or SDL2: Used for creating windows, handling input (keyboard, mouse), and managing contexts. More modern than the old GLUT.
· GLAD or GLEW: Used for loading OpenGL function pointers (since OpenGL is a standard, drivers implement it, and function addresses need to be obtained at runtime).
· GLM (OpenGL Mathematics): A header-only math library that perfectly simulates GLSL syntax, providing types and operations for vectors, matrices, etc. Essential!
· Assimp: A powerful model loading library that supports dozens of model formats (.obj, .fbx, .gltf, etc.), helping you load model files into vertex, index, and material data.
· stb_image: A single-header library for loading images (like JPEG, PNG) as texture data.
· Dear ImGui: An immediate mode GUI library that allows you to easily create debugging interfaces (sliders, buttons, windows) to adjust parameters in real-time, invaluable for 3D development.
3. Version Control
· Git: Learn to use Git (and GitHub/Gitee) to manage your code. For such complex projects, version control is a must.
Learning Path Suggestions
1. Step One: Solidify C++ fundamentals (1-2 months). Write some small programs.
2. Step Two: Concurrently learn the basics of linear algebra (ongoing).
3. Step Three: Follow the tutorial sequence on LearnOpenGL.com:
· Set up the development environment (GLFW + GLAD + GLM).
· Draw a triangle (this is your “Hello, World!”).
· Draw rectangles and cubes.
· Learn about shaders and textures.
· Learn transformations to make the cube rotate.
· Learn about coordinate systems and cameras.
· Learn model loading using Assimp to load a complex model.
· Learn lighting models (Phong lighting).
· …
4. Step Four: Start your own project based on the tutorials.
· Don’t set your goals too high: don’t aim to create an “AAA open-world game” right from the start.
· Start small: Create a simple 3D scene with a movable camera, a few rotating cubes, and a light. Then try loading a robot or spaceship model.
· Iterative development: Add a new feature to your small project every time you learn something new.

Leave a Comment