Skip to content

A C++ OpenGL project rendering a textured nightstand scene with custom lighting, materials, and camera controls.

Notifications You must be signed in to change notification settings

AlexLeetDev/opengl-nightstand-scene

Repository files navigation

🧱 Nightstand 3D Scene - CS-330 Final Project

This project is a culmination of my work in CS-330: Computational Graphics and Visualization. It features a fully interactive 3D scene built using modern OpenGL and C++, designed to replicate the top of a nightstand with common objects modeled using low-polygon primitives, realistic textures, and dynamic lighting.

🖼️ Project Overview

I chose to model a nightstand because it allowed me to combine several recognizable objects—each constructed using basic shapes—while showcasing OpenGL features like textures, materials, lighting, and camera interactivity. The four primary objects include:

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

✨ Features

✅ Object Modeling

  • Build using basic 3D shapes: Plane, Box, Sphere, Cylinder, and Tapered Cylinder
  • Composite models (like the lamp and bottle) combine multiple primitives
  • Modular design through reusable transformation and drawing functions

🖌️ Textures & Materials

  • Textures used: brass, fabric, leather, plastic, and woodgrain
  • Transparent textures and UV scaling for realism
  • Custom materials defined with diffuse/specular/shininess values

💡 Lighting & Effects

  • Spotlight simulates lamp beam
  • Point Light simulates bulb glow with flickering effect
  • Fill light provides ambient room light
  • Full support for Phong shading (ambient, diffuse, specular)
  • Toggle lamp on/off with L key

🕹️ Camera Navigation

  • WASD for movement (X/Z), Q/E for vertical (Y) movement
  • Mouse controls yaw and pitch
  • Scroll wheel adjusts movement speed
  • Switch between Perspective (P) and Orthographic (O) projection views
  • R key resets camera to default

🧠 Design Decisions

Each object was chosen to highlight specific OpenGL skills:

  • Lamp: Detailed multi-part object using several primitives. Enabled spotlight, point light, and interactive toggling.
  • Bottle: Transparent texture with stacked ridges, showing UV scaling and material usage.
  • Clock: Modular functions (DrawDigit, DrawColon) created a reusable seven-segment display.
  • Book: Created using two box meshes to represent the cover and the page block. Though simple in structure, it helped round out the scene and reinforced the theme of everyday bedside items.

🔧 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 (GLSL loading, uniforms)
├── textures/                # Image files for scene materials
├── shaders/                 # Vertex and fragment GLSL shaders
├── FinalProject.exe         # Prebuilt executable for demonstration

Modular functions like SetTransformations(), SetShaderMaterial(), SetShaderTexture(), and DrawDigit() improved readability and reusability across the scene.


🎮 Controls

🔼 Movement (WASD + Vertical)

🕹️ Action ⌨️ Input
Move Forward W
Move Backward S
Strafe Left A
Strafe Right D
Move Up Q
Move Down E

🖱️ Camera Interaction

🕹️ Action 🖱️ Input
Look Around Mouse Movement
Adjust Move Speed Mouse Scroll

🔄 View & Toggles

🕹️ Action ⌨️ Input
Toggle Perspective P
Toggle Orthographic O
Reset Camera R
Toggle Lamp Light L

📸 Preview

Full Scene Overview

Lamp On (Light Activated)

Lamp Off (Light Deactivated)

Water Bottle Detail

Clock Display

Book Cutaway


🧠 Reflection

How do I approach designing software?

When I design software, I like to plan things out first by breaking everything down into smaller parts. For this project, I thought about what objects I needed for the nightstand scene and figured out how to build each one using simple shapes. I worked one step at a time, building and improving the models as I went. This approach helped me stay organized and made it easier to fix problems when they came up. In the future, I’ll keep using this idea of building simple first and adding more detail later.

How do I approach developing programs?

My way of developing programs is to start with something simple that works, then add features little by little. For this project, I used a lot of small functions to handle things like transformations, textures, and drawing shapes, which kept my code clean and easier to manage. I tested the scene often while building it, which made it easier to catch mistakes early. Over time, I learned how important it is to keep my code modular and organized, especially when working on bigger projects like this.

How can computer science help me in reaching my goals?

Computer science gives me the skills to solve real-world problems and build projects I’m excited about. Working with 3D graphics has taught me how to think both visually and logically, which will help me in classes, jobs, and future projects. Learning about things like transformations, lighting, and textures gave me a better understanding of how visual simulations work, and it opened up more possibilities for careers in areas like game development, simulations, and VR/AR.


About

A C++ OpenGL project rendering a textured nightstand scene with custom lighting, materials, and camera controls.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published