header image
Detach a command from a terminal
January 10th, 2011 under Linux. [ Comments: none ]

When you run an application from a terminal and you close the terminal then the application terminates. This is also the case when you run the application in the background (

at the end).

To detach a application entirely from a terminal and therefore daemonized it, we can use the

command.

1
nohup cmd &
nohup cmd &


glTexImage2D doesn’t load sequential RGB data correctly
January 7th, 2011 under OpenGL. [ Comments: none ]

I wanted to render the image I had in memory with OpenGL. The image data are stored as

1
unsigned byte
unsigned byte
data without padding. The colors are represented by RGB (in this order). When I loaded the texture data with

1
2
3
4
5
6
7
8
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
             width, height, 0, 
             GL_RGB,  GL_UNSIGNED_BYTE, 
             imageData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
             width, height, 0, 
             GL_RGB,  GL_UNSIGNED_BYTE, 
             imageData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

the rendered image showed only a black and with image which was line-wise distorted. The reason for the distortion was that by image data was not correctly aligned. The

1
GL_UNPACK_ALIGNMENT
GL_UNPACK_ALIGNMENT
defines the alignment when uploading data. So, setting
1
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
solved my problem.


echo removes \n from commands
January 4th, 2011 under Linux. [ Comments: none ]

I wanted to send an email containing a folder listing. I noticed that when I do

1
2
text=`ls -lh $folder`<br />
echo $text
text=`ls -lh $folder`<br />
echo $text

the newlines in the variables are gone. Also when I force to interpret the with the option

To get the newline back the variable has to expanded within quotes.

1
echo -e "$text"
echo -e "$text"

for more info see here