The values as you say are mapped to an unsigned byte.
When retreiving the normal map the values 0->255, conceptually produce values 0.0 to 1.0 in OpenGL internally, and these get mapped back to -1.0 to 1.0 on the way into the combiner unit.
There are modes on the way into texture combiners that can implement the required half bias and scale by two required for this type of operation. Specifically the token to look for that sets this up in your example code is GL_EXPAND_NORMAL_NV.
These and other similar operations are useful for this type of thing and other stuff like extended range rendering.
[This message has been edited by dorbie (edited 11-24-2002).]
Originally posted by lucidmm:
[b]glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, w, h, level, GL_BGRA_EXT, GL_UNSIGNED_BYTE, &nmap->nz);
My question is how exactly does &nmap->nz retrieve all the normal map information?[/b]
“&nmap->nz” is like passing in “the address of the the first component of the first element of ‘nmap’”. In other words, I’m pretty sure passing in “nmap”, “bnmap[/b]”, or “bnmap[/b]” would accomplish the exact same thing as “&nmap->nz”.
All components are packed into the same structure. In the array of normal objects each object has all the components in memory. The array will have the whole image with all the components interleaved in memory. The pointer to the first ->nz field merely addresses the first byte in memory of the packed array. The nx and ny members in that packed array are filled in the loop. It’s not pretty but it will work.
[This message has been edited by dorbie (edited 11-24-2002).]