A C++ application that demonstrates rendering a 3D cube using OpenGL, with a basic user interface provided by ImGui. The project includes camera controls for navigating the 3D scene.
- Renders a 3D cube with basic lighting.
- Integrates ImGui for potential UI elements.
- Interactive camera controls:
- Movement (Forward, Backward, Left, Right, Up, Down)
- Mouse-based orientation (Pitch and Yaw)
- Zoom (Field of View adjustment)
- Cross-platform build system using CMake.
- Dependencies managed via submodules or download scripts.
The project relies on the following libraries:
- OpenGL (version 3.3 or higher): For 3D graphics rendering.
- GLFW: For window creation and input handling.
- GLAD: To load OpenGL function pointers.
- GLM (OpenGL Mathematics): For vector and matrix operations.
- ImGui (Dear ImGui): For creating graphical user interfaces.
- CMake (version 3.10 or higher): For building the project.
- A C++17 compatible compiler (e.g., GCC, Clang, MSVC).
-
Clone the repository:
git clone <repository_url> cd opengl_imgui-main
-
Run the setup script: This script will attempt to clone GLFW and ImGui into the
third_partydirectory.bash setup.sh
Note for GLAD: The
setup.shscript will prompt you to download GLAD manually. Please follow these instructions:- Go to https://glad.dav1d.de/
- Set the language to C/C++.
- Set the specification to OpenGL.
- Set the API
glversion to 3.3 (or higher, matchingmain.cppandCMakeLists.txt). - Set the profile to Core.
- Ensure Generate a loader is checked.
- Click Generate.
- Download the generated zip file.
- Extract the contents (
includeandsrcfolders) into thethird_party/glad/directory. The structure should be:third_party/ glad/ include/ glad/glad.h KHR/khrplatform.h src/ glad.c
-
Install system dependencies: The
setup.shscript also lists mandatory packages for Debian/Ubuntu-based systems. You might need to install them using your system's package manager. For example:sudo apt-get update sudo apt-get install build-essential cmake libglfw3-dev libglm-dev libgl1-mesa-dev libglu1-mesa-dev xorg-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxkbcommon-dev
Adjust these commands based on your Linux distribution or operating system.
-
Create a build directory and configure CMake:
mkdir build cd build cmake .. -
Compile the project:
make
(Or use
nmakeor your chosen build system if not using Makefiles).
After successful compilation, the executable opengl_imgui will be located in the build directory.
./opengl_imgui- W, S, A, D: Move the camera forward, backward, left, and right respectively.
- E, Q: Move the camera up and down respectively.
- Mouse Right Click + Move: Rotate the camera (look around).
- Mouse Scroll Wheel: Zoom in/out (adjusts the camera's Field of View).
- ESC: Close the application.
opengl_imgui-main/
├── CMakeLists.txt # Main CMake build script
├── main.cpp # Application entry point, GLFW/ImGui setup, render loop
├── readme.md # This file
├── setup.sh # Script to help set up dependencies
├── build/ # (Created during build) Build artifacts
├── shaders/ # GLSL shader files
│ ├── cube.frag # Fragment shader for the cube
│ └── cube.vert # Vertex shader for the cube
├── src/ # Source code files
│ ├── Camera.cpp # Camera implementation
│ ├── Camera.h # Camera class header
│ ├── Cube.cpp # Cube object implementation
│ ├── Cube.h # Cube class header
│ ├── Renderer.cpp # OpenGL rendering logic
│ └── Renderer.h # Renderer class header
└── third_party/ # External libraries
├── glad/ # GLAD library files (manual setup required)
├── glfw/ # GLFW library (cloned by setup.sh)
└── imgui/ # ImGui library (cloned by setup.sh)
- The application window is currently fixed at 800x600 and is not resizable.
- Shaders (
cube.vert,cube.frag) are copied to the build directory by CMake.