Skip to content

DaKerboul/opengl_template

OpenGL ImGui Cube Renderer

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.

Features

  • 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.

Dependencies

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).

Setup and Build Instructions

  1. Clone the repository:

    git clone <repository_url>
    cd opengl_imgui-main
  2. Run the setup script: This script will attempt to clone GLFW and ImGui into the third_party directory.

    bash setup.sh

    Note for GLAD: The setup.sh script 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 gl version to 3.3 (or higher, matching main.cpp and CMakeLists.txt).
    • Set the profile to Core.
    • Ensure Generate a loader is checked.
    • Click Generate.
    • Download the generated zip file.
    • Extract the contents (include and src folders) into the third_party/glad/ directory. The structure should be:
      third_party/
          glad/
              include/
                  glad/glad.h
                  KHR/khrplatform.h
              src/
                  glad.c
      
  3. Install system dependencies: The setup.sh script 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.

  4. Create a build directory and configure CMake:

    mkdir build
    cd build
    cmake ..
  5. Compile the project:

    make

    (Or use nmake or your chosen build system if not using Makefiles).

Running the Application

After successful compilation, the executable opengl_imgui will be located in the build directory.

./opengl_imgui

Controls

  • 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.

Project Structure

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)

Notes

  • 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.

About

Portable Linux OpenGL application template, with ImGui support.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors