Graphics programming has quite a high barrier to entry, especially if you want to use a low-level library like OpenGL. You have to learn the abstractions and conventions of the API which can be quite tough. On the other hand your mistakes as well as your achievements are always quite visual. Jay Barnson wrote a great blog post about his first experiences with the Sony Playstation that comes to mind.

“It’s a black triangle,” she said in an amused but sarcastic voice. One of the engine programmers tried to explain, but she shook her head and went back to her office. I could almost hear her thoughts… “We’ve got ten months to deliver two games to Sony, and they are cheering over a black triangle? THAT took them nearly a month to develop?”

I had a lot of fun getting into OpenGL and implementing some basic OpenGL exercises for a master’s level course with professor D’Ambrosio at the University of Calabria. This post shows off those examples. In the course of the course of programming these small OpenGL applications I also celebrated quite a view visually pleasing small victories, which is maybe why I am so keen on showing them to people.

a minimalist particle system



This first example is a very simple particle system. It consists of 100,000 particles which are confined to a cube and a movable cone of red light. Each particle starts out at a random position and moves in a random direction. If particle hits one of the walls of the cube, it will bounce off, conserving it’s momentum.

The particles are drawn as single grey pixels, but if they are within the cone of light that pixel will be colored red instead. The particles are not properly depth sorted before drawing, so I think far away ones can cover up closer ones.

The camera location can be moved around the cube using the mouse and the cone of light can be moved using ‘WASD’. Currently the movement of the particles is calculated on the CPU. It would be a nice addition to do this on the GPU using a compute shader.

I’m sorry for the horrible artifacting in the video. This is at least partly my own fault, because I recorded at 1024x1024, which YouTube downscaled do 720p. Additionally single colored pixels don’t play nice with compression formats meant for more realistic video.

a dynamically lit first person scene



Here you can see a simple 3d scene, with an infinite tiled floor and some colored cubes in it. The white cube in the middle represents a colored light source which affects the lighting of the scene dynamically. You can navigate the scene in classical FPS fashion and there’s some basic collision detection. You’re not colliding with the floor though. I cheated here by making it impossible to move up and down along the y-axis. In computer graphics, this kind of cheating is encouraged. There’s no need to collide with the floor if you don’t allow the viewer to move along that axis.

The scene is illuminated using Phong shading. You can see that the color and position of the light changes gradually. Sometimes a cube changes color, because the color of the light and the color of the cube don’t overlap completely. Sometimes cubes also disappear completely, because the color of the light and the color of the cube don’t overlap at all.

Nice additions to this scene would be some shadows and the light cube changing it’s color in sync with the light color.

visualization for volcanic activity data



This final scene is a visualization of volcanic activity using a satellite image and height profile of a region with lava temperature and lava height data overlaid on top of it. This time the camera is not constrained to a specific height on the y-axis and can move around freely along all axes. There was some more pre-processing of the input data required for this one, but other than that and processing the temperature data in the shaders there is not a lot more going on here than in the previous example.