Alex Leet

Back to Projects

OpenGL Nightstand Scene

Stack: C++, OpenGL, GLSL

Overview

This project features a fully interactive 3D scene built with modern OpenGL and C++. It recreates the top of a nightstand using low-polygon shapes, realistic textures, and simple dynamic lighting.

I chose a nightstand so I could combine familiar objects while practicing core graphics skills: textures, materials, lighting, and camera controls. The four main objects are:

  • A lamp with a pull chain and glowing bulb
  • A bottled water with a transparent texture and ridged body
  • A digital clock with a seven-segment style display
  • A book made from simple boxes with a leather texture

Features

Object Modeling

  • Built from basic shapes: plane, box, sphere, cylinder, tapered cylinder
  • Composite models (e.g., lamp, bottle) combine multiple primitives
  • Custom material values (diffuse, specular, shininess)

Textures & Materials

  • Materials include brass, fabric, leather, plastic, and woodgrain
  • Transparent textures and UV scaling for simple realism
  • Custom material values (diffuse, specular, shininess)

Lighting & Effects

  • Spotlight for the lamp beam
  • Point light for the bulb glow with a subtle flicker
  • Fill light for ambient room light
  • Phong shading (ambient, diffuse, specular)
  • Toggle lamp on/off with the L key

Camera Navigation

  • WASD to move (X/Z), Q/E for vertical (Y)
  • Mouse to look around; scroll wheel adjusts movement speed
  • Switch between Perspective (P) and Orthographic (O) views
  • R resets the camera

Code Structure


├── MainCode.cpp             # Entry point; initializes OpenGL and main loop
├── SceneManager.cpp         # Prepares and renders 3D scene elements
├── SceneManager.h           # SceneManager class interface
├── ViewManager.cpp          # Handles camera movement and projection modes
├── ViewManager.h            # ViewManager class interface
├── LightTypes.h             # Structs for spotlights and point lights
├── ShaderManager.*          # Shader handling
├── textures/                # Image files for scene materials
├── shaders/                 # Vertex and fragment GLSL shaders
        

Full source code available on GitHub.

Controls

Movement (WASD + Vertical)

ActionInput
Move ForwardW
Move BackwardS
Strafe LeftA
Strafe RightD
Move UpQ
Move DownE

Camera Interaction

ActionInput
Look AroundMouse Movement
Adjust Move SpeedMouse Scroll

View & Toggles

ActionInput
Toggle PerspectiveP
Toggle OrthographicO
Reset CameraR
Toggle Lamp LightL

Screenshots