Monday, March 28, 2011

Sending a gmail message from the good old command line. Part 2


  • Alpine does not save passwords by default!!. So, it's necessary to enable such functionality in the configuration step before compilation


[sourcecode language="bash"]
./configure --with-local-password-cache-method --with-passfile=.alpinepwd
[/sourcecode]

  • If you installed it before just do a "make uninstall", and then build it and install it again, you know the drill.



  • The configuration for using gmail is very straight forward:


http://lusule.wordpress.com/2008/08/16/how-to-7/

and if that doesn't work you can try also:

http://www.fettesps.com/configuring-alpine-2-0-to-access-gmail-on-ubuntu-x64/

In my case wouldn't work if I didn't include the port number.

  • In order to alpine to store your passwords you need to create a password file in your home folder:


[sourcecode language="bash"]
touch .alpinepwd
chmod 600 .alpinepwd
[/sourcecode]

again, if that doesn't work ,try:

[sourcecode language="bash"]
touch .alpine-passfile
chmod 600 .alpine-passfile
[/sourcecode]

  • You can see the syntax for sending a mail via the command line is rather complicated so I created an alias in my .bash_aliases


[sourcecode language="bash"]
alias mail='alpine -I"#,^M,^X,y"'
[/sourcecode]

the application "mail" does exist but I don't have it installed.If you wish, copy it exactly this way, if you change anything won't work, of course you can call that alias whatever you like.

  • If you send a mail for the first time, it will ask you for your credentials, after you enter them, it will ask you whether you'd like it to store them in the disk.

  • The message you send is taken from a file, you can modify the script to create the file from one argument you give it.Here's the code:


[sourcecode language="bash"]
#!/bin/bash
alpine -I"#,^M,^X,y" -subject "hello from command line" i_hate_obama@gmail.com <message
[/sourcecode]

where "message" is the file where you wrote the message. I'm not using my alias here as the script won't recognize it, I need to figure out why.

  • So now my real time application can call this script and send me an email if anything goes wrong, or maybe... just to say hello =-D.

  • Got a MB in my computer graphics project!

Saturday, March 26, 2011

Sending a gmail message from the good old command line. Part 1


  • What if you want a real time application to send you a mail if it encounters trouble?


I'll be using alpine and my gmail account for this purposes, I'm using Ubuntu Maverick. We need the alpine source code that can be downloaded here:

http://www.washington.edu/alpine/acquire/

Once downloaded and extracted we need to apply this patch

http://staff.washington.edu/chappa/alpine/info/outgoing.html

Place the patch wherever you like, open a terminal there,  and issue the following command:

patch -p1 -d "path where you extracted the alpine source code" <alpine-2.00.outgoing.patch

in my case, I used this:

patch -p1 -d /home/jocker/alpine-2.00 <alpine-2.00.outgoing.patch

and if everything goes right you'll see the following output:

[sourcecode language="diff"]

patching file alpine/alpine.c
patching file alpine/arg.c
patching file alpine/busy.c
patching file alpine/confscroll.c
patching file alpine/osdep/termin.gen.c
patching file alpine/osdep/termin.gen.h
patching file alpine/osdep/termin.unx.c
patching file alpine/osdep/termout.unx.c
patching file alpine/radio.c
patching file alpine/reply.c
patching file alpine/roleconf.c
patching file alpine/send.c
patching file alpine/status.c
patching file pico/composer.c
patching file pico/display.c
patching file pico/edef.h
patching file pico/osdep/getkey.c
patching file pico/osdep/terminal.c
patching file pico/pico.c
patching file pico/pico.h
patching file pith/send.c
patching file pith/state.c
patching file pith/state.h
patching file pith/store.c

[/sourcecode]

Or else, take a look here:

http://staff.washington.edu/chappa/alpine/faq/basic.html#apply

I followed  it to the letter but didn't work for me, it might for you.

Now we make sure we have anything we need to build it (again I'm using Ubuntu Maverick)

[sourcecode language="bash"]

sudo apt-get build-dep alpine

[/sourcecode]

Now let's compile it  and install it with the well known combination:

[sourcecode language="bash"]

./configure

make

sudo make install

[/sourcecode]

Then just type:

alpine

you should see the main menu now.

[caption id="attachment_162" align="aligncenter" width="300" caption="Alpine Main Menu"][/caption]

I'll post the next part (configuring it to use gmail) tomorrow. Or google it if you don't feel like waiting 'till tomorrow.

Cheers!

 

 

 

 

Friday, March 25, 2011

Storage and linkage specifiers - The static keyword

I'll be reviewing from now on c/c++ and linux programming topics, as I might be working in the near future in a hydrology project involving a real time application for linux that'll be crunching a big load of numbers, yay!!.

  • The static keyword defines variables that live as long the program is executing, only one copy of such variables is kept. The part that caught my attention is the case when they're declared inside of a function, they live and retain their value after the function is exited, cool! Scope rules are still applicable.


[sourcecode language="cpp"]
#include <iostream>
#include <stdlib.h>
using namespace std;
int small_val(void){
static unsigned count;
count++;
cout<<"Call to small_val number: "<<count<<endl;
return (count % 16);
}
void r_func(void){
static int depth;
depth++;
if(depth > 200){
cout<<"Excessive recursion \n"<<endl;
exit(EXIT_FAILURE);
}
else{
small_val();//cout<<"count in small_val has the value: "<<count<<endl; <-invalid
r_func();
}
depth--;
}
int main(void){
r_func();
}
[/sourcecode]

Source:

http://publications.gbdirect.co.uk/c_book/chapter4/linkage.html

Thursday, March 24, 2011

Lighting: The specular effect and textures


  • I presented my computer graphics project today for grading and to my surprise, the teacher wasn't pleased with it. That upset me a lot to say the least, because I've put a great deal of effort and a great deal of myself on it, but turns out that he was right (as teachers regularly are).

  • The specular effect wasn't working as it should be, the reason is that when using textures, opengl multiplies the primitive's lighting color components with the texture color components if we use GL_MODULATE  which is my preferred mode regarding the texture environment. The solution : to add this line of code to your lighting setup


[sourcecode language="cpp"]
glLightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);
[/sourcecode]

And that's it, the difference in lighting is dramatic:

[caption id="attachment_142" align="aligncenter" width="300" caption="proyectoGraficacion_v.0.3"][/caption]

There still some other minor details I need to take care of. It was a good idea to present my advances ahead of time.

Source for this post:

http://www.opengl.org/resources/faq/technical/texture.htm

Wednesday, March 23, 2011

"K-arian" chains


  • I don't know the translation for "K-arias", but the problem is to build all the combinations possible of length n, having the digits from 0 to k-1. Here's the code based on mr.Zaragoza's page


[sourcecode language="cpp"]
#include <iostream>
#define BINARIA 2
#define KARIA 3
using namespace std;
int A[BINARIA],B[KARIA];
void procesa_b(int* A){
for(int i=0; i<BINARIA; i++)cout<<A[i]<<" ";
cout<<endl;
}
void procesa_k(int* A){
for(int i=0; i<KARIA; i++)cout<<A[i]<<" ";
cout<<endl;
}
void binario( int m){
if(m == -1) procesa_b(A);
else{
A[m] = 0; binario(m-1);
A[m] = 1; binario(m-1);
}
}
void cadena(int m,int k){
if(m==-1)procesa_k(B);
else{
for(int j=0; j<k; j++){
B[m] = j;
cadena(m-1,k);
}
}
}
int main(){
cout<<"binario: "<<endl;
binario(BINARIA);
cout<<"cadena: "<<endl;
cadena(KARIA,KARIA);
return 0;
}

[/sourcecode]

  • The issue I'm having is that "binario" is calling "procesa" exactly twice for each chain found (and makes sense since we're making two recursive calls) when it's supposed to be calling it only once.



  • Solved:  cero based array ----> decrease m by 1 in comparisons (which I intuitively did) and when calling the recursive functions (the missing part).


[sourcecode language="cpp"]
#include <iostream>
#define BINARIA 2
#define KARIA 3
using namespace std;
int A[BINARIA],B[KARIA];
void procesa_b(int* A){
for(int i=0; i<BINARIA; i++)cout<<A[i]<<" ";
cout<<endl;
}
void procesa_k(int* A){
for(int i=0; i<KARIA; i++)cout<<A[i]<<" ";
cout<<endl;
}
void binario( int m){
if(m == -1) procesa_b(A);
else{
A[m] = 0; binario(m-1);
A[m] = 1; binario(m-1);
}
}
void cadena(int m,int k){
if(m==-1)procesa_k(B);
else{
for(int j=0; j<k; j++){
B[m] = j;
cadena(m-1,k);
}
}
}
int main(){
cout<<"binario: "<<endl;
binario(BINARIA-1);
cout<<"cadena: "<<endl;
cadena(KARIA-1,KARIA);
return 0;
}
[/sourcecode]

Some silly sign


  • It's a requirement in our project for us to demonstrate the enabling and disabling of certain openGL characteristics, and the more appropriate object to do so is a simple polygon preferably with depth. So I thought of a simple Vegas style sign with diamond shape. The outcome of the enabling and disabling the specified characteristics is pretty lame and not worth a shot.

    [caption id="attachment_130" align="aligncenter" width="300" caption="proyectoGraficacion_v.0.2.6"][/caption]

    Yes it's a watermarked picture, it sucks...but is the best I found. The fun part was mapping the texture coordinates to the triangle strip I used to build the diamond.

  • So this is it, the basic requirements are fulfilled and I'm presenting it tomorrow for grading.

  • From now on, I'm focusing on my terminal project ( the equivalent of a thesis in other universities) which is a poker video-game by the way =-D.

Tuesday, March 22, 2011

Picking and Change of Looks


  • Now I'm able to click on the fan and make it spin faster or slower, this feature is called selection and picking in openGL.

  • Using GLframe.h and picking. You should be aware that if you use the GLframe.h class provided with the superbible book to move around the scene, to get a correct mapping you need to do something like this:


************************************************************************************

glMatrixMode(GL_PROJECTION);
glPushMatrix();
//Change render mode
glRenderMode(GL_SELECT);
//Establish new clipping volume to be unit cube around mouse cursor
//point (xPos, yPos) and extending two pixels in the vertical and horizontal direction
glLoadIdentity();
gluPickMatrix(xPos, viewport[3] - yPos + viewport[1], 10,10, viewport);
GLfloat aspectRatio;
aspectRatio = (float) viewport[2] / (float) viewport[3];
gluPerspective (60.0f,aspectRatio, 50.0f,800.0f);
glMatrixMode(GL_MODELVIEW);  //<-This is the important part
glPushMatrix();
frameCamera.GetCameraMatrix(cameraM);
glLoadMatrixf(cameraM); // <- and this one
RenderScene();
glPopMatrix();

*****************************************************************

This because you change the modelview matrix each time you render the scene to move around.

And here's the new style:

[caption id="attachment_125" align="aligncenter" width="300" caption="proyectoGraficacion_v.0.2.5"][/caption]

  • You can see the z-fighting under the table, I'll get it fixed soon.

  • Just a couple of requirements are left to consider this finished. Out of my own contribution I intent to place a window for those curtains, a dealer, the walls and a big sign outdoors when all the requirements are properly taken care of.  This project was really fun. Comments are welcome.

Monday, March 21, 2011

Down with Nurbs. Evaluators and Reflections


  • I had a wonderful time trying to get my Nurbs to work, but it seems there's some kind of bug in my graphics driver, so I had to use evaluators instead. It's supposed to be some sort of curtain (yep made of wood, I'll change the texture to something more appropriate tomorrow, or I might leave it like some sort of wall).

    [caption id="attachment_119" align="aligncenter" width="300" caption="proyectograficacion_v-0-2_2.png"][/caption]

    • Another effect we can achieve using the blending feature, is reflections and transparencies. Here comes the sun, like the beatles' song.

      [caption id="attachment_120" align="aligncenter" width="300" caption="Sun reflected on the floor"][/caption]

      It's actually reflected on the carpet...another weirdness of my virtual world. =-D



Saturday, March 19, 2011

Shadows,Stencil and Blending in openGL


  • Shadows are recalculated each time the sun moves.

  • Stencil is the effect of the shadows not going further than the surface limits.

  • Blending is making those shadows transparent (the shadow color "blend" with those of the surface on which they're casted).

    [caption id="attachment_113" align="aligncenter" width="300" caption="proyectoGraficacion_v.0.1.7_1"][/caption]

    • The remaining problem is the flattening of the poker table so the shadow is perfectly mapped. Being curved its surface doesn't help. Also there's some nasty z-fighting issue I need to take care of later.

      [caption id="attachment_114" align="aligncenter" width="300" caption="proyectoGraficacion_v.0.1.7"][/caption]



Friday, March 18, 2011

Meet the poker table!


  • Being Friday, I decided to spend my time doing some openGL programming just for my own leisure. At first I got confused with so many transformations, but there it is: a poker table for my casino!

    [caption id="attachment_109" align="aligncenter" width="300" caption="proyectoGraficacion_v.0.1.5"][/caption]

    • I needed the table anyway, to project the fan shadow over it, using the stencil feature.

    • Now I need a dealer, or else , who's gonna deal those cards? I'll draw one if I get everything on schedule.

    • Here's another shot:



Specular effect in openGL


  1. I just added the specular effect to the ceiling fan, I think it provides another layer of reality to the virtual world. Applying it was really straightforward, openGL does a lot of work for us behind the scenes. I had to make the wood darker to better perceive the effect.

    [caption id="attachment_104" align="aligncenter" width="300" caption="proyectoGraficacion_v.0.1.4"][/caption]

    • The specular effect generates the sparkled areas on the edges when the light source is near the surface.



Thursday, March 17, 2011

Lighting in openGL


  1. Today was kind of slow in terms of my computer graphics project. I added a light source in the sun's position (I'm using only ambient and diffuse effects at the moment being). I had to calculate every single normal for each vertex!, that really sucks (we're not allowed to use  the auto-normal function).

  2. The weird thing is that the floor goes dim as the sun is approaching! Freaking weird.proyectoGraficacion_v.0.1.3_1

  3. It's a pitfall to set the near z in glPerspective to zero. It was the case I set it to zero and the depth testing was messing everything up, in fact I'm becoming very wary of using that number altogether.



  • Tomorrow I'll be doing shadows and adding  the speculiar effect in the ceiling fan.

Wednesday, March 16, 2011

Beauty over performance


  1. I was using some pretty basic textures for my computer graphics project to save memory and computer cycles, but then I thought: hey! who cares about performance anyway? Well, in a perfect world a fast and efficient program beats one that is only "cute", but we live in a world that is way, way, way.... far from being perfect. So there it is:



  • That ball on top is supposed to be the sun, and that thing that looks like a spider is a ceiling fan (it's actually spinning around! =-D)

  • When you bind textures for further use, I think it's better to disable temporarily the whole texture functionality and enable it when needed because that binding could mess up the proper operation of other functions ( glColorf wasn't working and the texture binding was the one to blame).

  • I enabled ambient lightning which is not very useful still, but it's a start.

  • There's such thing as automatic texture coordinates generation! This will help me to apply more and more texture like these ones.


2.  Joining and Searching. Tomorrow we'll be reviewing the joining and searching problem. The algorithm exposed in mr. Zaragoza's presentation its very simple and clever, it depends heavily in the use of pointers (mmm Java, I hate you!, well but I love you too =-D). The only shortcoming I see of the proposed implementation is that if you only need to know which elements belong to one particular set you need to traverse all the array anyway. Moreover, you need to traverse up to the root each time you need to find out to what set a node belongs to.

3. What the heck is path compression? I guess I'm gonna find out tomorrow.

4. Minimal cost spanning trees.  We'll be reviewing the Prim and Kruskal algoritms. I guess too that I'll get to know these babies better with mr.Zaragoza's help, right now they look kind of abstract to me.

5. The winner mentality is a bitch. Today while playing poker, one player which I regard as a pretty good one, lost a good deal of money consistently (fake money by the way, but not easy to come by though) just because he's used to win but the odds were against him. So I think that the "winner mentality" can be a good source of profit for people with more moderated sight.

6. I thought Facebook was a royal waste of time, and it is, but  brings us closer from each other.  Otherwise many of us spend our days alienated from other people ("many of us" might be saying much , yep I'm talking about myself =-D).

 

 

Tuesday, March 15, 2011

Managing multiple textures in openGL (again)


  1. I finally got to load and bind as required, multiple textures in openGL  (currently two: wood and grass). I would have saved me going through all this, but textures are a really important component if we aim to build realistic scenarios.

    [caption id="attachment_90" align="aligncenter" width="300" caption="Projecto Final GraficaciĆ³n v.0.1"][/caption]

    I'm using the same filters for both textures (grass for the floor and wood for the circle).The thing now is to map a rectangular texture to a circular surface, it shouldn't be that hard but the issue with that circle is that is formed of about 360 vertexes, so I'm choosing evenly four of them, and that's the crappy result I'm getting (it doesn't resemble wood at all). Maybe it has something to do with the filters I'm using, but I'll leave that for tomorrow.

  2. Austrian cinema. Little Alien is a documentary-like film I watched today in the Incalli Ixcahuicopa hall. It is about two young Arabs that travel illegally to Austria and as one could expect they  find themselves with a lot of trouble. Although moving, it was terribly boring, the part that hooked me was a debate after the projection, but I couldn't make it, I was really tired and left in the middle.

  3. I'm finally matriculated for the information management seminar next week (allegedly... it could be latter), I just can't help myself when I see the word "free".

  4. We reviewed as promised the Dijkstra algorithm at Algorithms Analysis. How cute is life when you know what the teacher is talking about (I prepared the class for the first time).

Monday, March 14, 2011

Algorithms Analysis -> Preparing the class -> The Dijsktra Algorithm

It's a habit I've been procrastinating for a while but from now on I'm reviewing the class materials in advanced as there are so many concepts that won't stick at the first try, and I'm my grades lately aren't as good as I'd like them to be.

We'll be reviewing the Dijkstra algorithm ( I studied itfor the first time a couple of years ago, so my knowledge of it is kind of rusty at the moment)

  • What is it used for? It finds the shortest path in a graph from a starting point (called source) to all other nodes.

  • What does the algorithm do?



  1. Creates a table where the distance from the source (say, node a) to any other node is set to infinity. Why? To make sure that any path found will be shorter than the initial value stored in the table.

  2. The distances are updated so  we write in the table the real distances from the source to any other node that has only one edge separating them from the source.

  3. The algorithm moves now to the node with the shortest distance from (a)  within the nodes described in step 2 (say node c).

  4. Being in that new node, we examine what nodes are the closest and calculate their distance from node (a).

  5. Compare the results in step 4 with those in step 2.

  6. When all paths starting from node c have been visited we check it so it's not visited again.


This pattern continues 'till all nodes have been visited. There's a little more to it but it's 3:00 am and I'm starting to feel sleepy and dizzy.

Sunday, March 13, 2011

Another year of existence


  1. Yesterday made another year spent on this plane of existence (well, I think this is only the only one, but it sounds cool). I don't know how to feel about it, when I was younger I didn't even hope to make it this far... yes, those were long and terrible years. I've accomplished some things, failed on others; but I'm no longer obsessed with goals, competitiveness and the like, now I'm only concerned with doing the thinks I enjoy. The future... well, I only see chaos ahead: war, economic crisis, scarcity, virus outbreaks, violence, collapse..., so I avoid thinking in the future. Gosh, how dark are my thoughts today.

  2. NURBS. I spent a lot of time learning to use evaluators in openGL to create curved surfaces, but then I found out about NURBS. The mathematical background is as obscure as it is with evaluators but in practice they provide a higher level of abstraction and the outcome: fewer lines of code.

  3. Simple solutions. Today a water pipe broke down in the roof, it was a vent which probably was bent over by one of my little neighbors. Not having a valve to shut down in that area, the leak was copious, and not being so savvy in plumbing I only could think of tearing the whole thing apart with a flame thrower. A neighbor who happened to be in the roof advised me to take the pipe away and just stick a stick into the leak, which I did and worked out. It is of course temporary, but It was a simple solution to a rather complex problem. That's one example that proves that if we listen to other people and take their advise at face value, things can turn well. Naturally you can't listen to everyone, but some modesty in weighing ideas won't hurt.

  4. I think the random algorithm used to deal cards in several online casinos could be tweaked to favor the house, so online gambling might be a false representation of the real thing. Anyway, putting ethics aside, it would be awesome to design an effective dealing algorithm which "behaves" mischievously to collect the maximum amount of money possible.

  5. Managing several textures in opengl can be challenging, using just one is really straight foward, but using more than becomes rather complex. The idea is to bind a named texture with texture target, moreover. if you use independent filters... they get even more complicated!

  6. Honest marketing sells. It can sound silly but today I went to buy something some tools to fix the pipe which I just described, and the shopkeeper explained to me that the thing I wanted to do wouldn't work. He could sell me a bunch of useless things but he didn't, he told me it was a better idea to leave the stick stuck in there or renew the whole installation. If I need anything else later there's no other option in my mind than to go buy it with him. It sounds funny, but in the meantime I'll stick to the stick.

Thursday, March 10, 2011

Picking in OpenGL

1. The process of picking an object in openGL is rather complex at first but once you grasp the idea becomes quite clear. The thing goes more or less like this:


Inside the rendering function:



  • initialize the primitive naming functionality with glInitNames()

  • load a name (an unsigned integer) or push it into the name stack

  • draw



Inside the selection processing function:





  • setup the selection buffer

  • save the current projection matrix

  • change the render mode to GL_SELECT

  • set a new clipping volume around the mouse cursor with gluPickMatrix()

  • transform this new clipping volume to the one you're using for rendering (to get a true mapping)

  • draw the scene

  • collect the generated hits

  • parse the selection buffer

  • do "the magic" you want to happen when the user selects a particular object.

  • restore the former projection matrix

  • and go back to the modelview for normal rendering





Well, second guessing, it isn't that clear, but practice makes master.


2. I talked about kindness from unexpected sources in my last post, and it happened again, someone did a nice thing to help me and I wasn't expecting it. It feels right to have a concrete prove that people like you; usually you don't help someone you don't like.
3. And even more compelling is to receive compliments from someone you admire. The neurotic issue here, is the fear of letting him down. I have confidence in such thing not happening though.
4. Today I submitted my terminal project proposal, I have confidence also that it will be accepted.
5. I started reading about web services, it looks quite interesting. It's oriented towards business to business collaboration.

Thursday, March 3, 2011

Kindness from unexpected sources


  1. Today I had a serious problem at school due to an unforgivable blunder, but thanks to the help from someone I know, but with whom I don't have a particular bond beyond acquaintance, everything turned out right. This is the kind of thing that gets to me very deeply and provides me with a great deal of relieve and hope, to be in such privileged companion.

  2. I'm learning to tell the day of the week that any date in the year belongs to, someday might come handy or just for the sake of it.

  3. Speaking my mind has always given me trouble, maybe it's time to just shut the hell up.



This was one of those days in which I'd rather have stayed in bed.