It’s working!

Screenshot of a Rubik's Cube I showed you a 3D cube the other day — a cube modeled in OpenGL. I’ve now refined the cube so that it looks much better, and I have combined 27 of them into a Rubik’s Cube. You can rotate the cube as a unit, and you can rotate the individual sides. It’s actually pretty cool :-)

The cube is fully illuminated by a single light in the scene, and the individual cubes have their normals defined for all vertexes, so that they can reflect the light faithfully. The colored sides doesn’t shine very much, whereas the black, rounded edges have more intense highlights. At first I was somewhat confused by all the parameters that control the lighting in OpenGL, but it turned out to be pretty easy to work with.

Screenshot of a Rubik's Cube You can download the source right here: /downloads/rubik/. You should be able to compile the code if you have a C++ compiler (such as g++) and the OpenGL library together with GLUT which is available for both Linux (that’s what I’ve been using) and Windows.

The program is still in a kind of pre-alpha state :-) It is my first attempt at learning OpenGL and C++. So far, I really like both OpenGL and C++. I’ve been very positively surprised by C++ — it behaves just as you would expect, and it has all sorts of advanced and cool features like template functions and classes, full support for object-oriented programming and the Standard Library.

One Comment

  1. Thomas:

    When will we see the python version of this? :)

Leave a comment