A 3D ASCII-art rendering engine that uses CUDA for GPU-accelerated computation and renders textured 3D cubes directly to the Windows Command Prompt using ANSI escape sequences.
This project is a 3D ASCII-art renderer that combines:
- CUDA GPU computing for high-performance 3D transformations and rasterization
- Windows Console output with ANSI color codes for real-time 3D visualization
- BMP texture mapping for applying textures to 3D cubes
- Real-time input handling for interactive camera movement
The engine renders 3D textured cubes as ASCII characters in the terminal, with each character colored using the 256-color ANSI palette based on the underlying texture.
- 🎮 Real-time 3D Rendering: GPU-accelerated 3D transformations and rasterization
- 🖼️ Texture Mapping: BMP image loading and texture application to 3D objects
- 🎨 ASCII Art Output: Converts 3D scenes to colored ASCII characters in the terminal
- ⌨️ Interactive Controls: WASD movement, arrow keys for camera control
- 🚀 CUDA Acceleration: Parallel processing for vertex transformations and pixel operations
- 🪟 Windows Console: Optimized for Windows Command Prompt with ANSI color support
-
CUDA Kernels (
gpu_cuda/kernel.cu):- Vertex transformation and rotation
- Texture sampling and rasterization
- Parallel pixel buffer operations
-
BMP Reader (
tools/bmpread.cpp):- Custom BMP file parser
- Texture data extraction for GPU upload
-
Console Output (
cmd_output/output.cpp):- ANSI escape sequence generation
- Optimized console buffer rendering
- Real-time input handling
-
Main Engine (
game.cpp):- Application entry point and main loop
BMP Textures → CUDA Memory → 3D Transformations → Rasterization → ASCII Conversion → Console Output
- Windows 10/11 (required for ANSI console support)
- NVIDIA GPU with CUDA support (Compute Capability 3.5+)
- CUDA Toolkit 12.8 or compatible version
- Visual Studio 2022 with C++ build tools
- Windows Console with ANSI escape sequence support enabled
-
Clone the repository:
git clone https://github.com/NikitaKonkov/CMD_CUDA_3D_ENGINE.git cd CMD_CUDA_3D_ENGINE -
Run the build script:
install.bat
This script will:
- Set up the Visual Studio build environment
- Compile CUDA kernels with
nvcc - Link C++ source files with CUDA runtime
- Generate the executable
run.exe
-
Run the engine:
run.exe
| Key | Action |
|---|---|
W |
Move camera forward |
S |
Move camera backward |
A |
Move camera left |
D |
Move camera right |
Q |
Increase movement speed |
E |
Decrease movement speed |
↑ |
Move object away |
↓ |
Move object closer |
← |
Move object left |
→ |
Move object right |
Edit header.h to modify rendering resolution:
const int WIDTH = 238; // Console width in characters
const int HEIGHT = 143; // Console height in charactersTextures are loaded from the images/ directory. The engine supports:
- 128x128 BMP files for optimal performance
- 256-color palette mapping to ANSI codes
- Multiple texture formats (see
images/folder)
CMD_CUDA_3D_ENGINE/
├── 📁 gpu_cuda/ # CUDA kernels and GPU code
│ ├── kernel.cu # Main rendering kernels
│ ├── shapes.cu # 3D shape definitions
│ └── test.cu # CUDA testing utilities
├── 📁 cmd_output/ # Console output and input handling
│ └── output.cpp # ANSI rendering and controls
├── 📁 tools/ # Utility functions
│ └── bmpread.cpp # BMP file reader
├── 📁 images/ # Texture assets
│ ├── *.bmp # Various texture files
│ └── 128xNUM/ # Numbered textures
├── header.h # Main header with declarations
├── game.cpp # Application entry point
├── install.bat # Build script
└── README.md # This file
- Resolution: 238×143 characters (~34,000 pixels)
- Frame Rate: Depends on GPU performance and texture complexity
- Memory Usage: Optimized CUDA constant memory for textures
- Console Output: Efficient ANSI sequence batching
- CUDA not found: Ensure CUDA Toolkit is installed and
CUDA_PATHis correct ininstall.bat - Visual Studio errors: Verify VS 2022 Community is installed with C++ build tools
- Linking errors: Check that
cudart.libis available in the CUDA lib directory
- No output: Enable ANSI support in Windows Console or use Windows Terminal
- Poor performance: Ensure you have a CUDA-compatible NVIDIA GPU
- Texture errors: Verify BMP files are in the correct format and path
- Convert images to 128×128 BMP format
- Place in
images/directory - Update texture loading paths in
kernel.cu
Edit the vertex and face definitions in gpu_cuda/kernel.cu:
const Face h_CUBE_FACES[6] = {
// Define your 3D object faces here
};- Fork the repository
- Create a feature branch
- Make your changes
- Test with
install.bat - Submit a pull request
This project is open source. See LICENSE file for details.
- NVIDIA CUDA for GPU computing framework
- Windows Console ANSI support for colored terminal output
- ASCII art rendering techniques and optimization strategies
