Monday, 8 September 2008

"Cool and quiet" search box

It's cool (and a bit web2.0) to have a search box which works as soon as we cease typing, and displays new contents in the very page we're navigating.

The concept of "typing ceased" is tricky anyway; it's not cool (and not quiet!) to have the page refreshed soon after the onKeyUp event, because maybe we're still typing the whole word.

So, it takes a bit of javascripting:


function lookupStuff(flag) {
if (flag) {
do_things();
} else {
clearTimeout(timerid);
timerid = setTimeout("lookupStuff(true)", 1000);
}
}


If we bind this to the onKeyUp event of an text input form, we have do_things() called after 1 second, which is enough for typing anything; clearing the timer is useful for "jittered" key pressing.

This snippet has been tested successfully on every browser, and appears pretty usable.

Friday, 5 September 2008

Reinventing the wheel

Matrix multiplication is fundamental in computer graphics, expecially when you're dealing with shadow maps and texture projections.

Unfortunately, there are no standard functions for matrix multiplication, so it was time for DIY. Here comes my snippet:



float* matrixProduct(float* A, float* B) {

// we have to allocate space for a 4x4 floats matrix
float* pointer= (float *) calloc(sizeof(float), 16);

// in order to compute the resulting matrix, we have to use two nested fors
for (int r=0; r<4; r++) {
for (int c=0; c<4; c++) {

// actual multiplications
for (int i=0; i<4; i++) {
pointer[r*4+c] = pointer[r*4+c] + A[r*4+i]*B[c+i*4];
}
}
}

return
pointer;

}


This simple function returns a pointer to an handful 4x4 array of floats, without memory flaws. Maybe this snippet will be helpful for someone in the future.

Thursday, 4 September 2008

Reload a page with javascript

There's a lot of ways for completely reloading a web page via javascript.

Only a few permit to clean up any selection done to option forms.

Moreover, it turns out that there's only one robust way to do it, without weird confirmations popups (Internet Explorer) or strange behaviours (Firefox):

window.location.href=window.location.pathname;

Of course, works seemlessly in Chrome.

Monday, 1 September 2008

Work in progress


The answer to the previous question was: "it does work". I don't know how the framework I'm working on exactly works, but it does strange things with depth buffer.

It seems I'm at a good point. Shadow mapping consists in three steps (two, if the video cards supports the GL_ARB_shadow_ambient extension):
  1. depth buffer acquisition from light's point of view
  2. a "dim light" rendering from camera's point of view
  3. full light rendering w/ shadow map depths comparison
Screenshots prove that everything seems to works correctly.

New question is: why doesn't the shadow map show up..? ^^"
Damn!

Wednesday, 20 August 2008

Uncomfortable

Summer and CG don't meet: my warfare computer resists a couple of minutes and then hangs up.

I'm working on my trusty notebook now, but the SiS graphics card is resulting a major pain in the ass:
  • warning: OpenGL VBOs not supported
  • warning: OpenGL shading language not supported
God! Any facility that should help me out to work on shadow mapping is not present on this machine. It's like programming in late 90s. By the way, it could tactical for me: willing or not I'm forced to develop an engine whose performances could be tweaked later, by using advanced functionalities.

There's, anyway, a couple (of thousands) of opened issues to fix before "popping champagne". For instance, why the hell reading depth buffer with glReadPixels() and putting it into the frame buffer (as luminance) using glDrawPixels() does not work? I'm surely missing something... but what?!