Implementing a Rubik's Cube with OpenGL.
Here, I put together the OpenGL tutorial and game engine series to practice. Feel free to use this code however you want, although you shouldn't trust it too much... If you have any questions or ideas, please don't hesitate to contact me.
The OpenGL tutorial specifies the following libraries as requirements:
cmake make g++ libx11-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxrandr-dev libxext-dev libxcursor-dev libxinerama-dev libxi-dev
Additionally, your graphics card must support OpenGL 4.6. Yvo Menezes made the branch osx
with some changes to use OpenGL 4.1 on MacOS. If in doubt, just follow the steps below and the tests will tell you whether the OpenGL context can be created successfully or not.
- Clone this repo:
git clone https://github.com/idiasdas/rubiks_cube.git
- Initialize the submodules:
git submodule update --init
- Configure CMake:
# You can also use -DCMAKE_BUILD_TYPE=Release to have more performance
# You can specify a directory different than "build" if you want it for some reason
cmake -B build -DCMAKE_BUILD_TYPE=Debug
- Build the project:
# In the directory build/
make
- Run tests:
# In the directory build/
ctest
- Run executable
# In the directory build/
./rubiks_cube
Note
You need to run the executable from within the build directory you specified in step 3. When you build this project, it saves the relative path from the chosen build directory to the utils/
directory. This allows the program to load the shaders during runtime. I should do something better than this but yeah...
This project uses:
- glad
- glfw
- glm
- spdlog
You can find all external software in ext/.
The following are the commands you can use:
Keys | Action |
---|---|
Esc | Close program |
Mouse 1 | Click and drag to select and rotate a face |
Mouse 2 | Click and drag to move the camera |
Mouse Scroll | Control zoom |
NumPad 2 | Rotate bottom face clockwise |
NumPad 8 | Rotate top face clockwise |
NumPad 4 | Rotate left face clockwise |
NumPad 6 | Rotate right face clockwise |
NumPad 5 | Rotate front face clockwise |
NumPad 0 | Rotate back face clockwise |
Left Shift + NumPad 0, 2, 4, 5, 6, 8 | Rotate face counterclockwise |
R | Reset cube to initial state |
- Render Cube
- Fly around
- Move pieces
- Movement animation
- Animation queue
- Dynamic resize
- Event system
- Log system
- ImGui control and debug window
- Varying move animation speed
- GIF generator
- Solver
- Rotate faces with the mouse
- Ray cast
- Ray picking (RAY OBB intersection)
- Face rotation with mouse vector
- Rotation rounding
- New camera: Before, the camera was free so you could fly around. Now, it is always looking at the cube's center. It moves on the sphere centered at the cube. Hold
Mouse 2
and move the mouse to move the camera. Use theMouse Scroll
to control the distance between the camera and the cube.
- Mouse control: Select a face with
mouse 1
and drag it to rotate. Incomplete rotations are automatically completed.