ilCopyPixels? Strange values

Started by Ramon, January 31, 2007, 22:20:43

Previous topic - Next topic

Ramon

Hey,

I'm using ilCopyPixels to get all of the colors from a texture. And after puzzling a while, i found out, that ilCopyPixels gives me negative values( using IL_FLOAT). And that these negative values turned out to be the highlighted parts of the image. So 1+that_value, gives the correct value in a range of 0.0f-1.0f. I think this might be really obvious for some of you, but i don't understand why it gives me those negative values.. By the way, i used IL_FLOAT, because IL_BYTE, or IL_UNSIGNED_BYTE looked even worse  ;D. Anyway, here is most of the relevant code:
IL.ilLoadFromURL();
IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
Data=BufferUtils.createByteBuffer(512*512*4*4); //texture is 512 by 512 pixels exact. and .png but i doubt it matters?
IL.ilCopyPixels(0,0,0,512,512,1,IL.IL_RGBA,IL.IL_FLOAT,Data);
//after that, just continues to load the texture normal, so it can be displayed as well
//some where else, i try to make something of the Data
for (int i=0;i<512;i++)
{
	for (int j=0;j<512;j++)
	{
		float []c=new float[3];
		c[0]=Data.getFloat((i+j*512)*4*4);
		c[1]=Data.getFloat(((i+j*512)*4+1)*4);
		c[2]=Data.getFloat(((i+j*512)*4+2)*4);
		for (int k=0;k<3;k++)
			if (c[k]<0.0f)
				c[k]=1.0f+c[k];
		//now here I can use c[0-2] with GL11.glColor3f(); to get proper colors, like in the texture
	}
}

So what's up with the negative values? I suppose it has something to do with the way DevIL and/or OpenGL stores texture data..., but how is that?

Ramon

PS I know this is really not the best way to do this,, the loop is quite expensive ::) But it was just for seeing what the hell the DevIL gave me  ;)

Fool Running

I'm gonna guess (its really just a guess ;) ) that it has something to do with converting the image to bytes (IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE)) and then reading them out as floats (IL.ilCopyPixels(0,0,0,512,512,1,IL.IL_RGBA,IL.IL_FLOAT,Data)). But I really have no idea ;D
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D