Skip to content

1ndevelopment/opengl-3d-object-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenGL 3D Object Manipulator

A C/OpenGL application that provides an interactive 3D environment for manipulating objects. This demo showcases real-time 3D object transformation with two UI options: a simple GLUT-based interface and a full Clay UI interface.

Features

  • 3D Object Manipulation: Transform cubes and spheres in real-time
  • Dual UI Options: Simple GLUT UI (default) or full Clay UI interface
  • Interactive Camera: Mouse-controlled camera rotation and zoom
  • Multiple Objects: Switch between cube and sphere manipulation
  • Real-time Updates: Immediate visual feedback for all transformations
  • Wireframe Mode: Toggle between solid and wireframe rendering
  • Coordinate System: Visual reference axes for orientation

UI Versions

Simple UI (Default)

  • Built-in GLUT interface: No external UI dependencies
  • Keyboard controls: Arrow keys for object manipulation
  • Mode switching: Tab key to cycle through Position/Rotation/Scale/Color modes
  • On-screen display: Real-time property values and controls

Full UI (Optional)

  • Clay UI integration: Modern, responsive user interface controls
  • Slider controls: Direct manipulation of object properties
  • Advanced features: More sophisticated UI layout and interactions

Controls

Mouse Controls (Both Versions)

  • Left Click + Drag: Rotate camera around the scene
  • Right Click + Drag: Zoom in/out

Simple UI Keyboard Controls

  • 1/2: Select cube/sphere
  • Tab: Cycle through modes (Position → Rotation → Scale → Color)
  • Arrow Keys: Modify selected property in current mode
  • Shift + Arrow Keys: Fine adjustment
  • W: Toggle wireframe mode
  • R: Reset selected object
  • H: Hide/show UI overlay
  • ESC: Exit application

Full UI Controls

  • Clay UI Panel: Sliders for position, rotation, scale, and color
  • Object Selector: Dropdown to choose between objects
  • Reset Button: Reset object to default state
  • Wireframe Toggle: Checkbox for rendering mode

Installation

Prerequisites

  • GCC compiler
  • Make build system (or CMake)
  • OpenGL development libraries

Installing Dependencies

Ubuntu/Debian:

make install-deps

Fedora/RHEL:

make install-deps-fedora

Arch Linux:

make install-deps-arch

Manual Installation:

# Ubuntu/Debian
sudo apt-get install freeglut3-dev libgl1-mesa-dev libglu1-mesa-dev build-essential

# Fedora/RHEL
sudo dnf install freeglut-devel mesa-libGL-devel mesa-libGLU-devel gcc make

# Arch Linux
sudo pacman -S freeglut mesa gcc make

Optional: Clay UI (for Full Version)

make install-clay

Building and Running

Using Make (Recommended)

Build Simple Version (Default)

make
# or
make simple

Build Full Version (requires Clay UI)

make full

Run Simple Version

make run
# or
./opengl_demo_simple

Run Full Version

make run-full
# or
./opengl_demo

Use Demo Script

./demo.sh

Debug Build

make debug

Clean Build Artifacts

make clean

Using CMake (Alternative)

Build the Application

mkdir build
cd build
cmake ..
make

Run the Application

make run

Or directly:

./opengl_demo

Clean Build

make clean-all

Project Structure

cpp-opengl-demo/
├── main.c              # Full version with Clay UI
├── main_simple.c       # Simple version with GLUT UI
├── opengl_utils.h      # Header file with utility functions
├── opengl_utils.c      # OpenGL utility functions
├── Makefile            # Make build configuration
├── CMakeLists.txt      # CMake build configuration
├── demo.sh             # Demo script for easy testing
└── README.md           # This file

Quick Start

  1. Install dependencies:

    make install-deps
  2. Build the simple version:

    make
  3. Run the demo:

    ./demo.sh
  4. Start manipulating objects:

    • Press 1 or 2 to select cube or sphere
    • Press Tab to cycle through modes
    • Use arrow keys to modify properties
    • Use mouse to rotate and zoom the camera
    • Press W to toggle wireframe mode
    • Press R to reset objects

Technical Details

OpenGL Features

  • Lighting: Ambient and diffuse lighting with a single light source
  • Depth Testing: Proper 3D depth rendering
  • Material Properties: Color material for realistic object appearance
  • Perspective Projection: 45-degree field of view

UI Integration

  • Simple UI: Built-in GLUT text rendering and keyboard handling
  • Full UI: Clay UI framework integration with event handling
  • Responsive Design: UI adapts to window resizing

3D Objects

  • Cube: 6-sided polyhedron with proper normals
  • Sphere: UV sphere with configurable resolution
  • Transformations: Position, rotation, and scale support

Troubleshooting

Common Issues

  1. Clay library not found (Full version only):

    • Install Clay UI: make install-clay
    • Or use the simple version: make simple
  2. OpenGL context creation failed:

    • Verify graphics drivers are installed
    • Check that Mesa or proprietary drivers are working
  3. Compilation errors:

    • Ensure all development packages are installed
    • Check GCC version compatibility
    • Try using CMake instead of Make if issues persist

Debug Mode

Run with debug flags for additional information:

make debug
./opengl_demo_simple

Alternative Build Systems

If Make doesn't work, try CMake:

mkdir build && cd build
cmake ..
make

Development

Adding New Objects

  1. Define a new Object3D structure in opengl_utils.h
  2. Add rendering function (e.g., draw_torus()) in opengl_utils.c
  3. Update UI controls in both main.c and main_simple.c
  4. Add object selection logic

Extending the UI

  1. Simple UI: Add new keyboard controls in main_simple.c
  2. Full UI: Create new Clay widgets in main.c
  3. Update the UI layout as needed

Performance Optimization

  • Adjust sphere resolution for better performance
  • Implement object culling for large scenes
  • Use display lists for static geometry

License

This project is provided as a demonstration of OpenGL and UI integration. Feel free to modify and extend for your own projects.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

About

demo showcasing real-time 3D object transformation with UI options

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published