A link to my new blog about programming and everything

Posted 22.09.2012 by pihlaja
Categories: Uncategorized

I’ve started a new blog sometime ago, and I thought I’d just write it all in the same place from now on. One post per year, just like before!



Just changed the address to http://sadesaapuu.wordpress.com/

Using glClipPlanes and plane equations

Posted 5.10.2010 by pihlaja
Categories: d, OpenGL, problems

Tags: , , ,

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: http://local.wasp.uwa.edu.au/~pbourke/geometry/planeeq/

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

Posted 7.10.2009 by pihlaja
Categories: d, Rae

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 http://www.dsource.org/projects/rae

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.)

GtkD now supports Mac OS X

Posted 5.02.2009 by pihlaja
Categories: gtkD

Since yesterday or so, I was happy to find out that the svn trunk version of GtkD is supporting Mac OS X. This adds the supported platforms up to three. Linux and Windows are of course the other platforms.

Currently you’ll need to use the semi-official GTK+ Framework (the native Quartz port), or then if you absolutely must use the X11 version, you’ll have to edit some paths inside GtkD.

A screenshot will follow.

GtkD running on OS X

Frequency/Bush demo is now available as a video

Posted 20.03.2008 by pihlaja
Categories: d, gstreamerD, out of topic

Frequency/Bush screenshot in Pouet.net

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.

Now the presentation video is in HD

Posted 5.01.2008 by pihlaja
Categories: 003-alpha, screencapture

You can see it here. Click the right corner to see it in fullscreen.

I’ve quit coding for a year

Posted 19.12.2007 by pihlaja
Categories: Uncategorized

Lately I’ve realized that coding takes a bit too much time from my life. I’ve admitted to myself that I’m addicted to coding, coding websites, blogs, news, IRC etc. It all started with me wanting to get Pihlaja working.

I did almost succeed in making it usable. The only thing missing is the export. And I got export “working” in a simple example program (which is in the /demos/gstreamer/encoding/ folder of the gtkD temporary git repo in repo.or.cz). Well, atleast it exported some video. Not the one that I wanted, but something similar anyway. So, I was quite pleased with how the 6 months went. I’m not disappointed at that at all.

Anyway. I’m not a coder. Coding in D is my hobby. I don’t get any income from it, and it is not my dream future profession. I have no education for it whatsoever. So, it’s a bit troublesome for me, when coding takes about 80% of my time. During the last year, I have not read any books (well, a couple in prison, when I wasn’t allowed to have a computer), I haven’t written any essays to my school. I have not seen and talked to people as often as I should have. And now that I’ve also started with a new job, the time I have for other things just isn’t enough. Not to mention having a 2 and a half year old child… 🙂

So, to put it briefly: I’m quitting coding for one year®. Let’s say that I won’t be coding until 1.1.2009 or something like that. I’ll also stop manically checking for updates to planet.gnome.org, dsource forums and osnews.com every three minutes. I’ll try to stop reading them. I’ll also stop going to IRC, as now I don’t have anything to ask there…

That means my projects: Pihlaja and gstreamerD will be put on hold. Feel free to ask me for rights to commit to the subversion of Pihlaja in DSource. You can take over for the time being. 😀 Hope I’ll get back to coding Pihlaja with a little bit more sanity in 2009.

While not coding I’m going to get finished with my school, make a shortfilm, read books, write poems, draw and be with people.

P.S: I had a little side project the other day, and wrote a demo in D/OpenGL/SDL/gstreamerD/Linux. It finished 7th in the Alternative Party 2007. Results. Get the binary and the code (which is impossible to compile and is not final). The binary is for Ubuntu Feisty, contrary to the results file. It’s not a good demo, but it’s my first, and made with D.

Just a screenshot to keep things looking like somethings happening

Posted 24.08.2007 by pihlaja
Categories: gtkD, screenshot, status, tango, user-interface


It seems I haven’t posted a screenshot in a long time. So, here goes. This one shows the “fullscreen” mode that I added this week. Nothing much there, but it’s nice to have some more room for the video monitor. Hmm. I think I need some audio monitors there too. There’s also some little polishing on the widget’s layout to get some more space for the monitor. The timecode display was moved to the bottom statusbar. Hmm. I wonder if that’s a good idea. It saves space. I’ll keep it there for a while, and see how it feels. Also the “media buttons” – play, pause, rewind etc. – moved to the center toolbar. Now you can pretty much get almost a fullscreen viewing experience when you move the panes to their maximums. Maybe I’ll put that to the next video demonstration. That’ll be out somewhere in 6 months during the next release… 🙂

Lots of functionality still missing. I should rewrite SceneChain and Track. Unify them into a class called Sequence!(T). Well, I’ll see if that’s possible.

Ok. Lots of things happened. But not that much to Pihlaja. Updated to Feisty Fawn finally. Updated to new version of Tango. Less crashes, I hope. Crashes immediately if I use console output, so that issue has reversed itself! Can’t use the newest version of gtkD. Gradually learning to use git and changing Pihlaja to use that too. Should really end Pihlaja development and start doing my “final work”. 🙂

I’m back

Posted 25.07.2007 by pihlaja
Categories: gstreamerD, me, problems, status

I was freed from prison on sunday morning. I’m happy that I’m not there anymore. Twenty days is a long time, when you’re inside.

I’ve noticed that Pihlaja stops crashing doesn’t crash as often when I use it from a console, and have most of the debug output enabled. It seems that if seeks and some other GStreamer calls happen too fast, it will crash. But when it does debug output on the console on every call, it slows it down, and the crashes disappear. Hmm. I’m not sure how to deal with this problem… How to limit the amount of gstreamer calls being made…? I can just leave the debug output on, but if the user doesn’t start Pihlaja from the console, there will be crashes, so it’s not a complete solution…

Pihlaja 003 alpha released

Posted 1.07.2007 by pihlaja
Categories: 003-alpha, d, documentation, gstreamerD, gtkD, me, problems, projectchooser, release, status, xoverlay

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 http://www.dsource.org. 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: http://www.europarl.europa.eu

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 http://www.dsource.org.


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 www.dsource.org. 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 www.digitalmars.com/d. 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 www.dsource.org. Try to find some installation instructions.

  • Get the Tango library from www.dsource.org. 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 http://svn.dsource.org/projects/pihlaja

Some Pihlaja related websites (ideally there should be only one):
http://pihlaja.wordpress.org The Pihlaja development blog is the number one source of information regarding Pihlaja development and news.
http://www.pihlaja.org This is going to be a promotional site for using Pihlaja. Currently it just links to the old sourceforge pages.
https://sourceforge.net/project/showfiles.php?group_id=85992 The sourceforge page is currently used for binary releases, but that might change in the future.
http://www.dsource.org/projects/pihlaja Development wiki and subversion repository.
http://www.dsource.org/forums/viewforum.php?f=132 Pihlaja forums for all feedback and questions.