Archive for the ‘d’ category

Using glClipPlanes and plane equations


About a year ago, I searched for an OpenGL way of clipping a rectangle in 2D/3D space. To explain further: I’m making a GUI library with OpenGL, and I wanted a parent rectangle to be able to clip it’s child rectangles even if they were textured. I found glClipPlane, and tried it briefly. There was almost no documentation found, or it was very mathematical talking about plane equations without properly explaining how it should be transferred to code. I also could not find any coding examples of using them.

So, I spent about three months writing a system that would do this clipping in software. For flat rectangles this was easy, but for textured stuff it was very complex, as it was manipulating the texturecoords to get the clipping done. I somehow managed to write it, but the system was incomprehensible, added some software overhead, didn’t properly support my per widget zooming system, and I had to put all my OpenGL drawing inside this clipping subsystem. For about a year I was semi-satisfied with it, but as I changed to another way of drawing fonts, I needed either a new clipping system, or I’d have to adapt the external font code to my awful clipping system.

Then I did another search and found this page:

It’s dated 1989, and it’s another one of those mathematicians only explanations (I’m a pragmatic self-taught trial-by-error coder, with very poor mathematical knowledge, sorry). But for the first time it had something that looked a bit like pseudo-code and translated well into programming. So, I tested it and with a few first misses I was able to get the following code of it, that works for me. I’m not sure if this is the correct or best way of using plane equations, but it’s the only one that I’ve gotten working.

double[] planeEquation( float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
double[] eq = new double[4];
eq[0] = (y1*(z2 – z3)) + (y2*(z3 – z1)) + (y3*(z1 – z2));
eq[1] = (z1*(x2 – x3)) + (z2*(x3 – x1)) + (z3*(x1 – x2));
eq[2] = (x1*(y2 – y3)) + (x2*(y3 – y1)) + (x3*(y1 – y2));
eq[3] = -((x1*((y2*z3) – (y3*z2))) + (x2*((y3*z1) – (y1*z3))) + (x3*((y1*z2) – (y2*z1))));
return eq;

Horrible formatting there. I don’t know how to use wordpress to get the code looking correct…

Then I’m doing the following on each parent rectangle, just before starting to translate or draw the children:

double[] left_eq = planeEquation(ix1,iy1,iz, ix1,iy2,iz, ix1,iy2,iz+1.0f);

glClipPlane(GL_CLIP_PLANE0, left_eq.ptr);


delete left_eq;

double[] right_eq = planeEquation(ix2,iy1,iz, ix2,iy2,iz, ix2,iy2,iz-1.0f);

glClipPlane(GL_CLIP_PLANE1, right_eq.ptr);


delete right_eq;

double[] top_eq = planeEquation(ix1,iy1,iz, ix2,iy1,iz, ix2,iy1,iz-1.0f);

glClipPlane(GL_CLIP_PLANE2, top_eq.ptr);


delete top_eq;

double[] bottom_eq = planeEquation(ix1,iy2,iz, ix2,iy2,iz, ix2,iy2,iz+1.0f);

glClipPlane(GL_CLIP_PLANE3, bottom_eq.ptr);


delete bottom_eq;

So all you have to give to this planeEquation function is three points on the clipping plane. It seems that the order of them somehow dictates which side of it will be clipped and which side will be visible. In this example just changing the direction of the last Z from plus to minus, changes which side gets clipped.

I hope this is useful to someone trying to get some sense into glClipPlane and plane equations. This might all be just wrong, but it works for me! Any corrections and suggestions in the comments, please.

Rae GUI library first demo screencapture


I thought I’d keep a low profile until my new project was finished, but as it now seems that it is progressing quite slowly, I might as well make it public for others to see.

Rae is going to be a general purpose GUI library. It’s nowhere near finished, and it is not usable for anything but making nice little demos of it. (Well you could make something like a calculator with it. Or possibly a pictureviewer of some sort with some effort. So, it’s not entirely useless…)

The keywords go something like this: D programming language, OpenGL, X11/MIT licence, (GtkD, cairo, pango), Linux, OS X, Windows.

Here’s a link to the video:

Rae GUI first demo

Rae GUI first demo

And there’s also a project page at

The source in the repository is up to date, but a bigger example like seen on the video is missing. I might add it there later, when I get the time. But feel free to try and compile it. Shouldn’t be too easy. Lot’s of nasty big dependencies, that I’d want to drop later. The code is a bit hacky, but pragmatic, so if you prefer projects with perfect code, look elsewhere. One of the main features is that it uses 0% CPU when doing nothing. Yes, that’s just how it’s supposed to be, but not any of the OpenGL GUIs that I’ve seen, do that. It’s full of small graphic glithces, unfinished widgets and buggy behaviour and sometimes even bad design. But I’m willing to change all that if anyone wants to start participating in this weird and wonderful project. Progress is slow, as always, but there’s a start. Feel free to donate me time, hardware or anything useful. (I’d put a smiley here, but I’m trying to quit using them.)

Frequency/Bush demo is now available as a video


Frequency/Bush screenshot in

As I told earlier I had a little side project the other day, and wrote a demo called Frequency/Bush in D/OpenGL/SDL/gstreamerD/Linux.

Now you can watch it as a video in here.

It finished 7th in the Alternative Party 2007. Results. Get binary and the code (which is impossible to compile at the moment but is now final and closer to what was actually shown in the party). The binary is for Ubuntu Feisty (But should work with later Ubuntus and possibly other linuxes as well. Just install gstreamer-0.10-plugins-bad and other more obvious stuff). It’s not a good demo, but it’s my first, and made with D.

Pihlaja 003 alpha released


I tried to embed this video, but it didn’t work out, but you can click the link. It’s a small three minute example showing the Pihlaja user interface and even a crash in the middle.

Release notes for Pihlaja 003 alpha (”Well, it’s a start of some sort”)

Six months (or four years if you count the earlier versions) of work has culminated into this very buggy and crashy piece of software that is called Pihlaja. You can get the binary for Ubuntu Feisty Fawn from the sourceforge page. I really hope I haven’t forgotten anything in this busy process. The source is there too, and in the svn over Hope it works! Some more release notes will follow in the end of this post. But first for a small update on my life, and a small appeal:

This alpha release comes just before a weird period starts in my life: The Finnish state is putting me to prison for three weeks. I’m not kidding.

The reason for this is that in Finland there is an obligatory military service for all men (excluding Jehova’s witnesses), it’s duration is either 6 months, 8 months or 12 months. I want to emphasize that a large majority of the people who go to military service get the 6 months. Only some special areas demand the longer 8 or 12 months. Then there’s also the alternative service called ”civilian service” for conscientious objectors (like me). It’s duration is 13 months, which is considered a punishment for not doing military service, and to keep people from going to civilian service. Most people choose the (propably) 6 months military service instead of the 13 months alternative. Yet there are some thousands of people who still go to civilian service each year..

I started my civilian service some three years ago, and stopped it after 11 and a half months as a protest to the punishmental duration of civilian service, and the fact that conscientious objectors are released from the military only during peace time. I had 41 days before my service would have ended.

A long juridical process started and I eventually had my trial a couple of months ago. I was convicted quilty of ”civilian service crime”, and (as is the standard) the court ordered me to jail for half of my remaining service, which (rounded to full days) was 20 days. I complained to the upper court level, but the result didn’t change. And now I’m starting at the Kerava prison on 3th of July. It is a normal closed prison. (In Finland there are also so called ”open prisons”, where non-violent prisoners who have done less serious crimes might be able to get to.) So for the next three weeks I will not be able to code on Pihlaja and I’ll only be able to see my two year old daughter during visiting hours on the weekends. I’ll propably spend my time mostly reading books.

Since 1999 Amnesty international has considered Finnish ”total objectors” as prisoners of conscience, because of the punitive length of the civilian service. Also in the recent years many international bodies (including UN’s Human Rights Committee) have demanded Finland to take measures to improve the legislation concerning conscientious objectors. There are about 50 people going to jail each year as ”total objectors”. Some of them have to spend 6 and a half months in a prison, if they don’t even start doing any civilian service at all. More info about these issues is available here.

If you too feel like that this punishment that I’m getting is a bit over the top, then I’d like to ask you to take up a little of your time to write one letter (or even a postcard) to either

A) a random member of the Finnish parliament, who could decide to end this

Pick a random parlamentarian from this list, and send the letter to this address:

firstname lastname
Eduskunta, Parliament of Finland


B) a random member of the European parliament, who could pressure Finnish parliamentarians to act on this issue. You can find contact information from:

I don’t think it would be good that the letter’s would all be the same, so I won’t make any example texts, so you’d might have to write it yourself. But if you do take the time to write one, then me (and yearly about 50 young finnish men, who are put to jail as prisoners of conscience) would much appreciate it. Thank you!


But back to the Pihlaja release notes:

Here’s a list of issues and a guide to survival:

Installing (is that even possible?)


You can get Pihlaja binaries from the sourceforge site. I’ve put the compiling from source section to the end, as that’s kind of hard to do, really. But you can get the source from svn in


What you can do


When you start Pihlaja, you are greeted with a project chooser dialog. Pihlaja is one of those nasty programs that manage your files for you. Currently you can’t even override that. So there’s no ”save as”. There is an autosave every 5 minutes. Ignore the users section, as it doesn’t affect anything yet, and focus on the projects section. You can alternatively edit the name of the ”New untitled project” into something meaningfull, or you can just select it and click OK, in which case it will ask the name in a dialog. If Pihlaja doesn’t crash before it closes you will find your project here the next time you start Pihlaja.


Now the project window opens up. On the left you have a list of all the movies, materials and bins in your project. On the right there’s some room for the monitor. And the lower part of the window is reserved for the editing canvas. On the editing canvas you can see two rectangles right next to each other, the ”Start” and the ”End” rectangle. Below the list of the movies, materials and bins you have a big button labeled ”Import material…”. Click on that and you’re presented with a file chooser dialog letting you to choose one or more files to import. Be sure to only import files with DV content (.dv, .mov and .avi should be fine as long as their contents are DV. I haven’t tested .avi myself though. I just tested some Quicktime files, and found out that when exporting from Final Cut Pro, you’ll have to ”export using quicktime conversion” and make the sound linear PCM with little endian. The default seems to be big endian and that doesn’t seem to work with Pihlaja). You can double click on files you want to import. When you’re done, you must click the close button (this way you can import many files easily).


If you’re lucky, your files will get recognized correctly and they’ll end up in the list. Now you should drag a file (or material in Pihlaja terminology) into the editing canvas. Bing. It’s there. And it hopefully didn’t crash, as it has never crashed for me at this stage! But you never know. Drag two more files somewhere else on the canvas. The objects that you just created that look like windows of an operating system are called scenes in Pihlaja. The scenes you created only contain two tracks, one video, one audio (if all went well). The tracks contain only one edit or clip each at this stage (haven’t yet decided on that terminology, as I’m not sure what those should be called in english. Feedback is welcome). The scenes could contain more edits, but let’s forget that, as that side of Pihlaja is not really working reliably yet (what part of Pihlaja is working reliably – one might ask).


The scene has a white ruler on it’s middle, separating the video and audio tracks. You can click on the ruler to see how buggy Pihlaja is this time. If you’re really really lucky, you’ll see a monitor appear on the right (Oh, it might have appeared there before too). Press space on the keyboard to make the scene play and to pause again. You can use the arrow keys to move around. Left and right for 1 frame and up and down for 10 frames movement.


There’s two ways to edit in Pihlaja.

1. You can grab the scene ”windows” from their headers, and put them one after each other (they’ll snap, and then you just release) to form chains of scenes.

2. Or you can move your mouse a little left from the ruler of a scene, to the outside of the ”scene window”, and from there start dragging a link to another scene. This way you can connect scenes, as if they we’re nodes.


Much of this doesn’t work the way it’s supposed to yet, so you can’t really reorder them or relink them, after you’ve done it the first time. So, you can just put them together, and watch the result. Trimming the scenes doesn’t work yet. And I didn’t get the export working yet, so that put’s Pihlaja in the “not really usable for anything” -category.


A list of things not to do (feel free to do them if you want to test the limits)


  • Holding your mouse button pressed and moving it on the Ruler might sometimes result in Pihlaja crashing while it has grabbed the mouse. This will make your system look like it’s crashed, but it’s not. You should avoid dragging on the ruler to avoid this, but if you happen to come to crash while dragging, then do the following (you should write this down on a piece of paper): CTRL-ALT-F4 to create a new terminal session(?). Log in with your username. Write: ”ps -x”. This will list the running processes. Locate Pihlaja on the list and look it’s process id – it should be the first number in the front. Then write: ”kill 8712” – and replace the 8712 with the number of the Pihlaja process you just checked with ps -x. CTRL-ALT-F7 to get back to your X session. Great! Now it’s working again.

  • Don’t do anything that you’d think should work. It will propably not work, or it will crash.

  • Saving works, but loading can be a little unreliable. So don’t do any real work with this version.

  • Sometimes your monitor might disappear, because of screensaver or some window blocking it. You usually can move the pane handles(?) to resize the monitor so it will be redrawn. (This is a bug with me not getting the expose event handled correctly with the xoverlay.)

  • You should propably avoid using multiple movies, or selecting the materials. So, just use that one movie, and test editing the scenes and scenechains with that. Selecting other movies will eventually lead to crashes, and before that you’ll propably not be able to select scenes and see them in the monitor anymore. (So, sometimes the gstreamer pads don’t get connected correctly. This is propably my fault, because of not fully understanding how to do stuff correctly.)

  • Changing the scenes order doesn’t work yet.

  • Editing the edits/clips inside the scene doesn’t work that great yet, so don’t do it.

  • Trimming the edits isn’t good, so forget about that too, for now.


A huge thanks to the freenode channels #d, #d.tango and #gstreamer for much appreciated help on various issues. Pihlaja reuses some code from the Pitivi project and heavily relies on Gnonlin for it’s functionality, so a big thank you goes out to bilboed.


Compiling from source


Umm. It might be hard. But here’s a list of what you need:

Get the Pihlaja 003 alpha source package from sourceforge. It will also include my personal branch of gtkD and gstreamerD, because I didn’t have the time to merge it with the official version found from Pihlaja only works on Linux. Some other Unixes might work too. I’m currently using Ubuntu 6.10 Dapper Drake (never had the time to backup my files and update).

  • You should have the usual GCC stuff installed. You also need GStreamer (and the plugins) and Gnonlin installed.

  • Get the DMD D compiler from I’m currently using version 1.014. To be sure, get that version. Don’t get the experimental 2.0 beta version. (You might also try GDC, but it appears there’s not yet a version that matches DMD 1.014. But it might work anyway… Haven’t tested it yet.)

  • Get DSSS from Try to find some installation instructions.

  • Get the Tango library from There’s propably a way to install Tango with DSSS too, so if you find that, you can use it. It will be easier. It has something to do with dsss net install tango, but I’ve never used it yet.

  • You also need the Tangobos library. You can propably install that with dsss net install, somehow.

  • In the dir where you’ve got the patched version of gtkD and gstreamerD, run command: dsss build. If that finishes without errors, and you’ve got libraries called libSgtkD.a and libSgstreamerD.a, then you can run the command: sudo dsss install.

  • In the Pihlaja directory called pihlaja/src/ again run command: dsss build. You don’t have to run install. After you’ve made some changes to the code, you should run dsss clean and after that dsss build to build it again. Run ../pihlaja to try it out.

  • The build process will be much more simpler after I’ll find the time to merge with the official branch of gtkD, which doesn’t need Tangobos. Hopefully it will be as easy as dsss net install pihlaja.

  • To get the latest Pihlaja source after this release you can do:

    svn co

Some Pihlaja related websites (ideally there should be only one): The Pihlaja development blog is the number one source of information regarding Pihlaja development and news. This is going to be a promotional site for using Pihlaja. Currently it just links to the old sourceforge pages. The sourceforge page is currently used for binary releases, but that might change in the future. Development wiki and subversion repository. Pihlaja forums for all feedback and questions.


The plan D


Hey, you, programmer!

Pihlaja is written in the D programming language with libraries such as GStreamer for multimedia playback, and Duit (D bindings for GTK+) and Cairo for the user interface.

In 2007 I’m going to make Pihlaja actually do something usefull. I’m trying to gather a team of 4 to 6 developers who could participate in the project this spring. The timeline is set for 6 months, so we should have something working by the end of June or July. So if you would be interested in joining the project – read on:

D is a relatively new programming language (started in 1999, 1.0 released in January 2007). It produces fast native programs just like C or C++, but it’s a bit higher level language that looks a bit like Java or C#. It’s fast to develop for, and the programs run very fast too. Other languages that influenced D are Eiffel and Ruby.

The language and the reference compiler DMD, was designed by Walter Bright, whose merit is writing the first native C++ compiler Zortech C++. It could be said that D is a redesign of C++, the way it should have been written. There is also a GCC compiler version called GDC, which unifies the opensource DMD compiler frontend with the GCC compiler backend.

Here’s a timeline for the project. Containing the history since 2003, and the ambitious future plans for this spring.

2003 First version with C++, Gtkmm, timeline in OpenGL. Concepts evolving.
2004 My computer brakes. I make a rewrite of almost everything using C++, Gtkmm, timeline in libgnomecanvasmm.
2005 There is a blank space in my memory for this year.
2006 Another computer brakes. I get the C++ version working quite nicely, except that it lacks originality.
Too much is copied from existing editing applications.
summer 2006 Third computer brakes. I’ll start thinking of a rewrite in D. I write down the concept, and get some new
node-based ideas.
autumn 2006 Rewrite using D, Duit, and Cairo for the nodes/timeline.
December 2006 Start RTree; Scenes, Edits

Plans for this spring:

Time Plan Status
January 2007 Finish RTree; Scenes, Edits, Movies almost work. Done. RTree has some bugs sometimes.
February GStreamerD bindings video & sound working in a simple example app. Gnonlin testing. 16.2.2007 Bindings are working. They are not complete, but enough for most things. I’m able to play video (.dv and .mov!) and multiple simultaneous audio with GNonLin and D.
March Gnonlin somewhat working. Look at Jokoshers python code. Scenes, Edits and Movies user interface does what it should, but doesn’t necessarily work with real video or audio files yet. Wow, March went by. And a lot of stuff was made. Can’t remember what exactly.
April XML file format. Video and audio working with editing. Reorganizing. Moving to Tango. Did I start using subversion here? XML fileformat is defined, but it’s currently broken.
May Final user interface decisions. Polishing. Making everything work together. It’s almost usable.  
June More polishing. Fixing things that are still broken. Release Pihlaja 003 which can do something usefull: import a few common file formats and codecs like DV. Edit them using all the node-based, “movies are made of scenes” concepts. Export to DV files.  

So, basically I’m fed up with having a non-working video and audio editor and a bunch of supposedly original ideas that are nonexistent in other video or audio editing applications. And I’ve done so many rewrites of the system, broken too many computers, gotten on peoples nerves while always talking about my editor, that I’ve got to get this project off my system.

All those four years haven’t been so active in coding, because of my studies. But this spring might be a chance for me to work on Pihlaja almost fulltime. So I’m confident that I can do a lot of stuff. But I’m (almost) realistic, and think, that I can’t do it alone that fast.

If you’re a developer wanting to work on Pihlaja, the best node-based truly non-linear editor ever, get in contact through:

satelliittipupu at y***

All you need is some motivation, experience in C++, Java, C or other programming language. Team working skills. Willingness to learn about D, Cairo, GStreamer, Subversion, non-linear editing software development, RTrees, XML. Contact me, and I’ll send you a presentation of the new editing concepts involved.