How to use SoSFImage
The image field of the SoTexture2 sets its value in SoSFImage.
It tells how to use SoSFImage and how to store the texture-map pixels in memory.
It is an example of code:
SoTexture2 *biMap = new SoTexture2;
unsigned char bytes[] = {
255, 0, // Intensity value of the 1st pixel and the Information for the 2nd pixel
0, 255,
255, 0
};
biMap->image.setValue(SbVec2s(3, 2), 1, bytes);
SbVec2s(3, 2) means the size of the texture. This
texture has the width 3 and the height 2 (unsigned char
bytes[3*2]). Next number 1 means this texture is grey that has no
Alpha value. The Alpha value is used to model transparency. If this number is 2,
this texture is grey + Alpha value. 3 is rgb, and 4 is rgb +
Alpha value.
| value | color and transparency
------------------------------------------------------
1 | Intensity value | grey
------------------------------------------------------
2 | Intensity + Alpha value | grey and transparency
------------------------------------------------------
3 | rgb value | rgb
------------------------------------------------------
4 | rgb + Alpha value | rgb and transparency
------------------------------------------------------
Bytes has 6 (3*2) numbers. The 1st number 255 (byte 0) is the 1st pixel's
Intensity value. The next number 0 (byte1) is the information for
the pixel 2.
Here is another example of code:
SoTexture2 *sample = new SoTexture2;
unsigned char bytes[] = {
255, 0, 0, 1, // r,g,b and Alpha value of the 1st pixel
0, 255, 0, 1, // r,g,b and Alpha value of the 2nd pixel
0, 0, 255, 1, // ...
255, 0, 0, 0.5,
0, 255, 0, 0.5,
0, 0, 255, 0.5,
255, 0, 0, 0,
0, 255, 0, 0,
0, 0, 255, 0 // r,g,b and Alpha value of the 9th pixel
};
int s = pow(2,ceil(log10(3)/log10(2)));
sample->image.setValue(SbVec2s(s, s), 4, bytes);
The value of SbVec2s (image.setValue) should be 2 power
of something. In this example, to show 3 colors at each rows, the
value may be 4. In other words, the value may be the smallest
2 power of something number bigger than 3.
s1021058@u-aizu.ac.jp