A custom 2D game engine built from scratch in Java, featuring a complete Entity Component System (ECS), batch rendering with OpenGL, an integrated Dear ImGui editor interface with docking, JBox2D physics, and scene serialization โ developed as a Semester 4 Object-Oriented Programming (OOPS) project at UPES.
- Entity Component System (ECS) โ Modular
GameObject/Component/Transformarchitecture - Scene Management โ
LevelEditorSceneandLevelScenewith hot-swapping support - Delta-Time Game Loop โ Consistent updates independent of frame rate
- Singleton Window Management โ GLFW-based window with input callbacks
- OpenGL 3.3 Core โ Vertex-array based batch rendering pipeline
- Custom GLSL Shaders โ Vertex + Fragment shader with a single-file
#typeparser - Sprite Rendering โ Color-based quads with dirty-flag optimization for GPU re-upload
- Framebuffer Object (FBO) โ Off-screen rendering to texture at 1920ร1080, displayed inside the editor viewport
- Camera System โ Orthographic projection with position-based scrolling
- Docking Layout โ Full-window ImGui dockspace (drag, resize, rearrange panels)
- Game Viewport โ Live FBO texture display with 16:9 aspect ratio preservation
- Scene Hierarchy โ Clickable tree-node list of all GameObjects in the active scene
- Inspector / Properties Panel โ Edit Transform (position, scale, rotation) and SpriteRenderer (color picker, z-index) in real-time
- Engine Info Panel โ Live FPS, frame time, and GameObject count
- Menu Bar โ File (Save/Load Scene, Exit) and GameObject (Create Empty)
- JBox2D Integration โ 2D rigid-body physics world stepping
- Collider Components โ
Box2DColliderandCircleCollider - RigidBody2D โ Dynamic, Static, and Kinematic body types
- GSON-based save/load of scene data to
level.json
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Main.java โ
โ (Entry Point) โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ jade.Window (Singleton) โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ GLFW โ โ OpenGL โ โ ImGuiLayer โ โ
โ โ Context โ โ Renderer โ โ (Editor UI) โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโดโโโโโโโโโโโโ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ Scene (Active) โ โ Framebuffer โ
โ โโโโโโโโโโโโโโ โ โ (Off-screen) โ
โ โ GameObject โ โ โโโโโโโโโโโโโโโโโโโโ
โ โ โโโโโโโโโโ โ โ
โ โ โCompnentโ โ โ
โ โ โโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโ โ
โ โ Renderer โ โ
โ โ (Batching) โ โ
โ โโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโ
Game Engine In Java/
โโโ assets/
โ โโโ images/ # Spritesheets and textures
โ โโโ shaders/
โ โ โโโ default.glsl # Vertex + Fragment shader
โ โโโ sounds/ # Audio assets
โโโ src/
โ โโโ main/java/
โ โโโ Main.java # Entry point
โ โโโ jade/ # Core engine package
โ โ โโโ Window.java # GLFW window + game loop
โ โ โโโ Camera.java # Orthographic camera
โ โ โโโ GameObject.java # Entity container
โ โ โโโ Component.java # Base component class
โ โ โโโ Transform.java # Position, scale, rotation
โ โ โโโ KeyListener.java # Keyboard input
โ โ โโโ MouseListener.java # Mouse input
โ โ โโโ Prefabs.java # Factory methods
โ โ โโโ scenes/
โ โ โโโ Scene.java # Abstract scene base
โ โ โโโ LevelEditorScene.java # Editor workspace
โ โ โโโ LevelScene.java # Runtime scene
โ โโโ renderer/ # OpenGL rendering
โ โ โโโ Shader.java # GLSL compiler & uploader
โ โ โโโ RenderBatch.java # Batched sprite renderer
โ โ โโโ Renderer.java # Batch manager
โ โ โโโ Framebuffer.java # FBO for editor viewport
โ โ โโโ Texture.java # Texture wrapper
โ โโโ editor/ # Dear ImGui editor panels
โ โ โโโ ImGuiLayer.java # ImGui lifecycle + dockspace
โ โ โโโ GameViewWindow.java # FBO viewport display
โ โ โโโ SceneHierarchyWindow.java # GameObject tree
โ โ โโโ PropertiesWindow.java # Inspector panel
โ โโโ components/ # Game components
โ โ โโโ SpriteRenderer.java # Color quad rendering
โ โ โโโ Spritesheet.java # Sprite atlas parsing
โ โ โโโ StateMachine.java # Animation states
โ โ โโโ PlayerController.java # Player input handler
โ โ โโโ Blocks.java # Block behaviors
โ โ โโโ GoombaAI.java # Enemy AI
โ โ โโโ TurtleAI.java # Enemy AI
โ โ โโโ ComponentDeserializer.java # GSON type adapter
โ โโโ physics2d/ # Physics engine
โ โ โโโ Physics2D.java # JBox2D world wrapper
โ โ โโโ RaycastInfo.java # Raycast result data
โ โ โโโ components/
โ โ โโโ RigidBody2D.java # Physics body
โ โ โโโ Box2DCollider.java # AABB collider
โ โ โโโ CircleCollider.java # Circle collider
โ โโโ util/ # Utilities
โ โโโ Settings.java # Engine constants
โ โโโ Time.java # Time utilities
โ โโโ AssetPool.java # Resource caching
โโโ pom.xml # Maven build config
โโโ build.cmd # Build script
โโโ run_jar.bat # Run script
โโโ level.json # Saved scene data
| Tool | Version | Purpose |
|---|---|---|
| JDK | 17+ | Compilation & runtime |
| Maven | 3.9+ (bundled via mvnw.cmd) |
Dependency management |
| Windows | 10/11 | Native ImGui & LWJGL binaries |
# Clone the repository
git clone https://github.com/mayankmalik263/Game-Engine-In-Java.git
cd "Game Engine In Java"
# Build the fat JAR (includes all dependencies)
.\mvnw.cmd clean package -DskipTests# Option 1: Direct Java command
java --enable-native-access=ALL-UNNAMED -jar target\jade-engine-1.0.0-jar-with-dependencies.jar
# Option 2: Use the provided batch script
.\run_jar.batNote: The
--enable-native-access=ALL-UNNAMEDflag prevents JDK 17+ warnings related to LWJGL native library access.
| Action | How |
|---|---|
| Select GameObject | Click on a name in the Scene Hierarchy panel |
| Edit Transform | Drag the Position / Scale / Rotation fields in the Inspector |
| Change Color | Click the color swatch in the Inspector under SpriteRenderer |
| Create New Object | Menu Bar โ GameObject โ Create Empty |
| Save Scene | Menu Bar โ File โ Save Scene |
| Load Scene | Menu Bar โ File โ Load Scene |
| Rearrange Panels | Drag any panel tab to dock it anywhere |
This project serves as a practical demonstration of core Object-Oriented Programming concepts:
| Principle | Implementation |
|---|---|
| Encapsulation | Window singleton hides GLFW internals; Framebuffer encapsulates OpenGL FBO state |
| Inheritance | Scene โ LevelEditorScene / LevelScene; Component โ SpriteRenderer / RigidBody2D / PlayerController |
| Polymorphism | scene.update(dt) dispatches to the correct scene subclass; component.update(dt) dispatches per-component |
| Abstraction | Component defines a contract (start(), update()); Scene abstracts initialization via init() |
| Library | Version | Purpose |
|---|---|---|
| LWJGL | 3.3.3 | OpenGL, GLFW windowing, STB image loading |
| imgui-java | 1.86.11 | Dear ImGui bindings for Java (GLFW + GL3 backend) |
| JOML | 1.10.8 | Math library (matrices, vectors) |
| JBox2D | 2.2.1.1 | 2D rigid-body physics simulation |
| GSON | 2.11.0 | JSON serialization for scene save/load |
| JUnit 5 | 5.11.0 | Unit testing framework |
# Run the unit test suite
.\mvnw.cmd testTests cover core systems including GameObject, Transform, Camera, and Physics2D.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Game Loop โ
โ โ
โ 1. glfwPollEvents() โ
โ โ
โ 2. โโโโ PASS 1: Scene โ Framebuffer โโโโโโโโโโ โ
โ โ framebuffer.bind() โ โ
โ โ glClear(COLOR | DEPTH) โ โ
โ โ scene.update(dt) โ โ
โ โ โโ renderer.render(camera) โ โ
โ โ โโ for each RenderBatch: โ โ
โ โ shader.use() โ โ
โ โ upload projection & view โ โ
โ โ glDrawElements(...) โ โ
โ โ framebuffer.unbind() โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ 3. โโโโ PASS 2: ImGui โ Screen โโโโโโโโโโโโโโโ โ
โ โ glClear(COLOR) โ โ
โ โ imGuiLayer.update(dt, scene, textureId) โ โ
โ โ โโ dockSpaceOverViewport() โ โ
โ โ โโ GameViewWindow (FBO texture) โ โ
โ โ โโ SceneHierarchyWindow โ โ
โ โ โโ PropertiesWindow โ โ
โ โ โโ Engine Info โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ 4. glfwSwapBuffers() โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
This project is developed for educational purposes as part of a university course. Feel free to use it as a learning resource.
- GamesWithGabe โ The original tutorial series that inspired this engine's architecture
- LWJGL โ Lightweight Java Game Library
- Dear ImGui โ Immediate-mode GUI library by Omar Cornut
- SpaiR/imgui-java โ Java bindings for Dear ImGui
Built with โ Java | ๐ UPES Semester 4 OOP Project