Hi Dirk,
Dirk Reiners schrieb:
Hi Oliver,
On Wed, 2005-08-24 at 19:42 +0200, Oliver Kutter wrote:
I've tried to set up some 16 bit float images and textures, but it is
not as easy as it seems. I tried the following (just for the test a 1x1
pixel sized image):
float array[] = {0.1f, 0.2f, 0.3f};
beginEditCP(myImage);
myImage->set(Image::OSG_RGB_PF, 1, 1, 1, 1, 1, 0, (UInt8*)array,
Image::OSG_FLOAT32_IMAGEDATA, true, 1);
endEditCP(myImage);
OK. The true and 1 are not necessary, but don't hurt.
But when I want to check the three values, like this,
cout << (float)myImage->getPixel(0) << endl;
cout << (float)myImage->getPixel(1) << endl;
cout << (float)myImage->getPixel(2) << endl;
Yeah, that doesn't work. The getPixel() will give you the nth byte, as
that is what's stored, it is not specific to the type. You need to cast
the pointer to get that:
float *fdata = (float*)myImage->getData();
cout << fdata[0] << endl;
cout << fdata[1] << endl;
cout << fdata[2] << endl;
I'm not getting the values, that I stored before. Why?
What happend to my values, when I cast my array ((UInt8*)array) to UInt8?
Nothing, you're just accessing the byte data, not the floats you expect.
OK, that worked fine, and I have created an image (.dat / and .raw
automatically) and saved it to disk. But when I want to load it again, I
get a warning. I think that could be, because it is stored in a
subfolder and I have to specify this folder in my .dat file, e.g.
ImagePtr image = Image::create();
image->read("data/raw/myImage.dat");
WARNING: Can not open myImage.raw image data
WARNING: could not read data/raw/myImage.dat
The first line of my .dat file should then look like this.
ObjectFileName: data/raw/groundheight.raw
Am I right? It works for me.
-----------------
And I habe another problem. I think I create my raw files in a false
way, because everytime I load it, I get a warning
WARNING: RAW file length to big!
but my data array from the image seemed to be to short.
Let's check out my code:
int x, z;
int size = 128;
int rgba = 4;
// just clear the data completely
float *data = new float[size*size*rgba];
for (x=0; x<size*size*rgba; x++) {
data[x] = 0.0f;
}
// fill it
for (z=0; z<size; z++) {
for (x=0; x<size; x++) {
// here I compute my data in value
float value = ...;
data[index] = value;
data[index+1] = value;
data[index+2] = value;
data[index+3] = value;
}
index += rgba;
}
ImagePtr image = Image::create();
image->set(Image::OSG_RGBA_PF, size, size, 1, 1, 1, 0,
reinterpret_cast<UInt8*>(data), Image::OSG_FLOAT32_IMAGEDATA);
image->write("data/raw/myImage.dat");
For the test I load it and want to get some values from it
ImagePtr image = Image::create();
image->read("data/raw/myImage.dat");
float* fdata = (float*)image->getData();
int x = 64, z = 64;
// This is where I get a segm.
cout << fdata[(z*size + x)*rgba] << endl;
// This output is 65536, 128
cout << image->getSize() << ", " << image->getWidth() << endl;
Is something wrong?
and tell the TextureChunk which internal format
you want (probably GL_RGB32F_ARB).
And I tried to set up the texture:
beginEditCP (_tcInPart);
_tcInPart->setImage(myImage);
_tcInPart->setInternalFormat(GL_RGB32F_ARB);
endEditCP (_tcInPart);
But the compiler don't know the GL_RGB32F_ARB. What else do I have to
include and where do I get it from? I'm using a GeForce 6.
That should come from OpenSG/OSGOGLExt.h, which is included
automatically. You just need a reasonably current version of OpenSG, 1.4
doesn't have that yet.
See attached example, which divides the texture data by a factor between
10 and 30 before using it as a color to prove it's really values > 1
that are stored in the texture.
OK, can I get somewhere a complete src package of the OpenSG 1.6
(similar to OpenSG 1.4 at opensg.org/download) or do I have to checkout
the cvs?
Bye
Oliver
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users