3d texture problem with (unsigned) short data type

dear friends,
i have this small problem when creating and generating 3d texture.

first i have an array for my data:
static unsigned short array[24][24][24][3];

then i fill it with some random numbers as colors:
for(int x=0; x<24; x++)
				for(int y=0; y<24; y++)
					for(int z=0;z<24;z++)
					{
						array[x][y][z][0] = rand()255;
						array[x][y][z][1] = rand()255;
						array[x][y][z][2] = rand()255;
						
					}
then i generate it & bind it, set neccessary
parameters, i am not writing it here, cause i think thats not the point of my problem.

after that i use 
glTexImage3D for creating it:
glTexImage3D(GL_TEXTURE_3D, 0,GL_RGB8 , 24,24,24,
						0,GL_RGB , GL_UNSIGNED_SHORT, &array);

and finnaly map it on to a quad (i mean a rectangle although it is a 3d texture :)

so the problem is:
when i use GL_UNSIGNED_BYTE as a parameter it is ok.
i can see nice blue,red and so on rectangle.
but when i use GL_UNSIGNED_SHORT i can see only a black screen = nothing :frowning:

CAN anybody tells me where is the problem? what is wrong? should any parameter should be changed?

thanks in advance.

joe :slight_smile:

try random #s up to 65535 instead of 255?

24x24x24 ? The texture size must be a power of two, as it says the glTexImage3D specification.

Try a 16x16x16 or a 32x32x32 size.

Is very strange that this works with GL_UNSIGNED_BYTE, Do you really see something with this internal format?

Originally posted by API:
24x24x24 ? The texture size must be a power of two, as it says the glTexImage3D specification.

If ARB_texture_non_power_of_two extension or OpenGL 2.0 is supported, the power of two limitation does not apply to any texture target.

The ushort values are converted into (0.0-1.0) float range by division by (2^16 − 1) so value of 255 will be stored inside the texture as 0 or 1 from the 0-255 scale.

If ARB_texture_non_power_of_two extension or OpenGL 2.0 is supported, the power of two limitation does not apply to any texture target.
You are right, but as he doesn’t say if this extension is supported I just wondering his problem :slight_smile: ( and is common to me to not suppose this extension, as my card doesn’t support it directly :frowning: )

Well, jozko_sk, at this moment I(we) don’t know what is your problem, can you give us more information?:

  • More code
  • Card
  • Drivers
  • Extensions used

Originally posted by API:
[quote] If ARB_texture_non_power_of_two extension or OpenGL 2.0 is supported, the power of two limitation does not apply to any texture target.
You are right, but as he doesn’t say if this extension is supported I just wondering his problem :slight_smile: ( and is common to me to not suppose this extension, as my card doesn’t support it directly :frowning: )
[/QUOTE]He said the texture worked when he used GL_UNSIGNED_BYTE.

Anyway, the problem is most likely what 3B and Komat said; the range of unsigned short values is [0, 65535], not [0, 255].

hi guys,
its me, jozko.
thanks a lot for all your information.
the problem was in generation of colors, which should be 65535 and not 255.
and with texture array, you are right it should be power of 2 so not 24, but a really can see an image , i can send it to you :slight_smile: .
but i think it is because my card support non power of two.

but another question:
i have an array for example 64x64x64 for my 3d texture in unsigned short.
then i put some data into the array >

unsigned short array (64x64x64); //simplified :)
for (int i=0; i<64; i++)
{
   //but my temp data is only 4096 , 12bit
   array = tempdata;
   array += 64x64 ;
}

then i use the array as a data for 3d texture, but i am using the unsigned_short parameter.
i cannot see anything again.
i think i must stretch the array , so it is not from 0 to 4096 but to 65535.
any ideas?

thanks a lot.

Simplify, before showing a random texture make three experiments, try to show a red, green and blue texture. This will show you what range do you really need.