Oct 12

Rendering Multiple OpenGL 2D Textures, Only the First One Is Rendered

Exactly a month ago I was dealing with the problem of rendering some text on the screen using the font + texture rendering method. The problem I had was only the first text block was rendered to the screen. After a little bit of digging around I found this question on StackOverflow. Although the answers there did not solve my problem, I realized that the problem was caused by having depth testing enabled while rendering the 2D blocks. All I had to do was place a call to glDisable(GL_DEPTH_TEST).

Aug 14

Linux Cheat Sheet


Today I decided to keep a Linux cheat sheet around to avoid looking up some common tasks on Google. I keep forgetting some commands and I feel like I should get them tattooed somewhere on the back of my hand so that I wouldn’t forget them. Although this list is currently very short, I will keep adding new stuff to it.

Program Specific:


Update a submodule to the latest remote commit: git submodule update --remote --merge


Start a named session: screen -S [SESSION NAME]
Rename the session currently attached to: Ctrl + A ; :sessionname [NEW SESSION NAME]
List all sessions: screen -ls
Attach to a session screen -r [SESSION NAME]
Detach from window: Ctrl + A ; D
Exit screen: Ctrl + A ; \


Unban an IP address: fail2ban-client set [JAIL NAME] unbanip [IP ADDRESS]

Script Related:

Autostart program: put the script in /etc/rc.local
Dump output to file (with stderr rerouting): [PROGRAM]  |& tee output.txt


     File and Directory Management:

Create symbolic link: ln -s [TARGET] [LINK NAME]
Change to last working directory: cd -
Copy from remote to local rsync -az --progress [USERNAME]@[REMOTE HOST]:[REMOTE PATH] [LOCAL PATH]


Find a specific file:  find [START PATH] -name [NAME OF FILE]
Find a directory:  find [START PATH] -type d -name [NAME OF DIRECTORY]
Find text if files: grep -Ril "[TEXT TO FIND]" [START PATH]

     User Management:

List the groups that a user belongs to: groups
Add user to the list of sudoers: sudo adduser [USERNAME] sudo
Run program as another user: su [USERNAME] -c "[COMMAND TO RUN]"

Jul 20

Distinguish Between Touch/Pen and Mouse Input in WinForms

In WinForms, mouse events are raised regardless of the original source of the mouse. If you click a button with the stylus for instance, you’d still get the MouseClick event. This MSDN page explains how to distinguish between the sources of the event. To make the long story short, you’d have to place an API call to the GetMessageExtraInfo() function and check the returned value. The following C# code snippet performs the checking:


Jul 07

Git: Merge Specific Commit from Another Branch to Main Branch

Let’s say that in your git repository, you have a master branch and an experimental branch. You’ve fixed a bug on file A on the experimental branch and you would like to commit that fix to the master branch. This is possible using the git cherry-pick command.

First, switch to the experimental branch and execute git log. Take note of the ID of the commit you’d like to merge into the master branch. Now switch to the master branch and use the command git cherry-pick ID where ID is the ID of the commit you noted earlier. This will merge the selected commit into the master branch.

Jun 30

3D Line Fitting in 5 Easy Steps with SVD

Least squares fit is used for 2D line fitting. In 3D space, the line is called 3D Orthogonal Distance Regression (ODR) line. The line can be easily found in 3D using SVD (singular value decomposition).

Assuming that we have a bunch of 3D points (x0, y0, z0) to (xn, yn, zn), the algorithm (in MATLAB) is as follows:


Jun 26

Intersection of a Ray and a Line Segment in 3D

This page contains methods for performing various intersection tests. Although it does not have an entry for ray vs. line segment intersection, I tried the suggested ray vs. ray intersection test (page 782 of Real-Time Rendering 3rd Edition) and it did not work in my case.

I looked around quite a bit and based on an adaptation of this answer, I finally found a method that works fine. Given a ray (with a start point, an end point and direction) and a line segment with the defined start and end points, we perform the 3D line intersection test. However, note that in various graphics APIs, there is always some error when converting screen points to lines (because there is no 1-1 mapping from screen pixels to exact 3D points in space). Therefore, when performing intersection tests, some degree of tolerance must be considered. This is especially important in the early rejection step of the intersection test algorithm. The early rejection test, checks to see whether the two 3D lines are co-planer. If they aren’t, then no intersection will be reported.

After finding the intersection point, we must check and see if this point lies between the start and end points of the line segment. This can be done by comparing the length of the line segment with the sum of distances of the intersection point from the start point and end point of the line segment respectively. If the length is “almost” equal, then it means that the original ray will intersect with the line segment.

Here is the pseudo-code of the described process (adapted from the original answer):


Jun 15

Compilation Error when Invoking “CudafyTranslator.Cudafy()”

When using CUDAfy.NET, if you encounter the “Compilation Error” when running examples, simply add “cl.exe” to your PATH! It will resolve the translator exceptions. It’s funny how I didn’t find much about it online…

May 10

Carve Error : “didn’t manage to link up hole!”

Carve is a fast and robust library for performing Constructive Solid Geometry (CSG) operations (boolean operations) on meshes.

In case the mesh is corrupted or has self-intersections, Carve will refuse to perform operations on it and will terminate with this error: “didn’t manage to link up hole!”.

To solve that, simply open the mesh in a mesh software (such as netfabb) and repair it.

May 01

C# Deserialization of a List<> Returns a List with “null” objects

In .NET, the List<> class is serializable. However, you should note that during a call to the deserialization constructor of the objects the list contains, the list will be empty. All operations on the newly deserialized objects (such as value checking and so on) need to be performed in another function marked by the [OnDeserializedAttribute] attribute. More info on this can be found here.

Apr 25

CMake Unable to Find AMD’s ACML Files Under Windows

One popular BLAS implementation under Windows is AMD’s ACML.
CMake has some modules that can find certain required dependency libraries. As far as I know, under Windows the “FindBLAS” and “FindLapack” modules are unable to locate AMD’s ACML libraries. This is because ACML > v4.0 does not include the “mv” related packages anymore.

I looked around a little bit and I found a patched version of these files here and here. However, I couldn’t get them to work. If anyone was able to get them to work, comment below.