3D Textures & DevIL

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

3D Textures & DevIL

Post by iso »

Hi, I know it was already mentioned somewhere here, but I now hope for a better answer.

I made an external utility, that generates silces (in TGA), that I'd like to use as a 3D Texture and it would be the best for me, just to define it in the material script to load.

Probably, won't be so easy. I ave no problem with conversion of the TGA's to any other format, but wich format should I use for the final 3D Texture? Here http://www.ogre3d.org/phpBB2/viewtopic. ... d+textures it's written, that DevIL supports only dss 3D textures. But in the DevIL Manual i saw that DevIL also supports raw textures, so I could just push all the data together in a raw file and then load with DevIL (I hope). Because to do it like in Volmume Texture demo is not a good alternative for me.

So, how can I load an image with DevIL routines and then use it as Ogre texture?

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Just save your 3d texture as a devil .raw file with the ilSaveImage..., then you can use it in ogre as texture. Easy as that :)

The devil raw format has one problem though: it is not endian independent. So if you make a file on a PowerPC/Mac you can't read it in Intel, and the reverse.

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

I don't care about portability :twisted:

Another way that seems even better to me is:
If I want to load a 513x513x4 texture, then I make a 1026x1026 2D texture, that I simply load with dimensions 513x513x4 with Image::loadDynamicImage(). I don't know if it will work, but I'm just about to test it.

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

513 is a very bad number, you should use a power of 2, otherwise it will be scaled up to 1024 which is true evil for volume textures (unless you have a latest generation card which has the nonpoweroftwo extension)

Also, you solution does not give the desired result. For the combined image approach to work you must make the image 513x2052 and put the slices below each other on the y axis.

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

It won't be scaled, OpenGL supports size = 2^n and size = 2^n +1 textures. And I'm using just OpenGL. Hm, well and my card also supprots GL_NON_POWER_OF_TWO textures.

Ok, I'll try it with 513x2052.
[edit]
Following problem already solved. ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
[/edit]
But I have one more problem:

When I try tio Image->load("filename","resourcegroup")

I always get the error, that such a group doesn't exist. So how can I create one? Doesn't Ogre create a new automaticly, when I use a name that isn't already used?

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

iso wrote:It won't be scaled, OpenGL supports size = 2^n and size = 2^n +1
Interesting, I never knew. Do you have an official reference on this?

To create a resource group, call the approciate method on ResourceGroupManager, and add resource paths into that group. (like the example framework does with resources.cfg)

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

:wumpus: wrote:Interesting, I never knew. Do you have an official reference on this?
http://oss.sgi.com/projects/ogl-sample/ ... of_two.txt

You'll find that at the beginning of the overview.

Somehow, it seems, that Ogre can't deal with that. When I try to create a 513x513x4 texture, it crashes. But 512x512x4 is ok. The problem is, my terrain has the size of 513x513 and so I'll probably have to cut out one collum and ane row out of it, because I need each textel to be mapped exactly to a position of a a terrain vertex.
Last edited by iso on Sat Apr 16, 2005 3:16 pm, edited 1 time in total.

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »


Conventional OpenGL texturing is limited to images with
power-of-two dimensions and an optional 1-texel border.
I already knew about the 'texture border', but isn't that always a fixed color?

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

I don't think so. I remember, I used it. Wait, I'll try :-)

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

:wumpus: wrote:I already knew about the 'texture border', but isn't that always a fixed color?
Hm, you're right it doesn't run.

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

As mentioned here: http://www.ogre3d.org/phpBB2/viewtopic.php?t=8889

I need to load a raw texture to Ogre's resource manager. Now, I'm doing it this way:

Code: Select all

...
		ILuint	ImgId;
		ilGenImages(1, &ImgId);
		ilBindImage(ImgId);
        ilLoad(IL_RAW,"Horizon.raw");
		uchar* iData = ilGetData();
		uint width = ilGetInteger(IL_IMAGE_WIDTH);
		uint height = ilGetInteger(IL_IMAGE_HEIGHT);

		Image* hImage = new Image();
		hImage->loadDynamicImage(iData,width,width,height/width,PF_BYTE_L);

		TextureManager::getSingleton().loadImage("TempHorTexture", "Terrain", *hImage, TEX_TYPE_3D, 3);

		MaterialPtr m = mSceneManager->getTerrainMaterial();
		TextureUnitState* t = m->getTechnique(0)->getPass(0)->getTextureUnitState(3);
...
But I always get an error, don't why (no description is included). Can it be caused by the loadDynamicalImage call? Because I'm calling it with PF_SHORT_L and the short type is hiding in the uchar* argument iData.
Any suggestions how to save the image at ImgId to ogre resources as a texture?

[edit]
The error is "Division by zero" and it shows up by calling the TextureManager::getSingleton().loadImage. The raw image seems to be loaded correctly (at the DevIL's ImgId )[/edit]

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

hImage->loadDynamicImage(iData,width,width,height/width,PF_BYTE_L);
What the hell are you doing here? :-)
What values are width, height, and height/width ?

And why aren't you just using Ogre itself to load the .raw image, but driving IL manually?

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

Because Ogre couldn't decode it! Instead of searching the error, I better tried this solution.

In this case, first I load the image as if it was 1024x8192 to memory and then I load it as a 3D texture 1024x1024x8. So much about width and height.

Just to be sure... the header of a DevIL raw file is:

uint width
uint height
uint depth
uchar bytes_per_pixel

is it right? May be i'm missing something, because in the DevIL manual, a 13-byte header is mentioned (but not described) and in the source code of DevIL, iCurImage->Bpc occurs and I don't know, what it could mean.

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

iread(&iCurImage->Width, sizeof(ILuint), 1);
iread(&iCurImage->Height, sizeof(ILuint), 1);
iread(&iCurImage->Depth, sizeof(ILuint), 1);
iread(&iCurImage->Bpp, sizeof(ILubyte), 1);
if (iread(&iCurImage->Bpc, sizeof(ILubyte), 1) != 1)
return IL_FALSE;
It needs bpc as well, which is bytes per component, I think.

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

I added the Bpc byte to my raw file. And changed the code to:

Code: Select all

...
		Image* mImage = new Image();
		mImage->load("Horizon.raw",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
		uchar* iData = mImage->getData();
		int width = mImage->getWidth();
		int height = mImage->getHeight();

		Image* hImage = new Image();		
		hImage->loadDynamicImage(iData,width,width,height/width,mImage->getFormat());

		TextureManager::getSingleton().loadImage("TempHorTexture", "Terrain", *hImage, TEX_TYPE_3D, 3);
...
But I still get the division by zero by TextureManager::getSingleton().loadImage. When I used tga format (wich doesn't support 16bits per channel), everything was fine.[/code]

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Can you post an exact traceback on where you get that error? There might be a bug somewhere, the 16 bit texture stuff isn't that well tested.

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

:wumpus: wrote:Can you post an exact traceback on where you get that error? There might be a bug somewhere, the 16 bit texture stuff isn't that well tested.
Of course, but how do I get the traceback? (I'm using VS7)
Hm, but for testing pourposes, I'm using only 8bits luminance texture for now... I want to make this run and then I'll switch to 16bit.

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

I brushed up the code a bit:

Code: Select all

...
		Image* mImage = new Image();
		mImage->load("Horizon2.raw",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
		TextureManager::getSingleton().loadImage("TempHorTexture", "Terrain", *mImage, TEX_TYPE_3D, 3);

		MaterialPtr m = mSceneManager->getTerrainMaterial();
		TextureUnitState* t = m->getTechnique(0)->getPass(0)->getTextureUnitState(3);

		t->setTextureName("TempHorTexture");
		t->setTextureFiltering(FO_LINEAR, FO_LINEAR, FO_LINEAR);

		delete mImage;
ogre.log shows this:

17:16:07: Texture: TempHorTexture: Loading 1 faces(PF_L8,1024x1024x8) with 3 generated mipmaps from Image. Internal format is PF_A8R8G8B8,0x0x0.

So, the question where the division by zero is, is answered. But why takes ogre for the internal format PF_A8R8G8B8 and why the dimensions become zero remains a big mystery... :(

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

That's usually the case when GL returns an error.. hmm. strange, so this doesn't only happen with PF_L16 but also PF_L8?

What card is this? Can you send me the .raw file so I can try this out too?
Last edited by :wumpus: on Sun Apr 17, 2005 4:40 pm, edited 1 time in total.

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

Yes, I don't work with 16bits when I can't get 8bit work.
And yes, I use only OpenGL rendering.

After changing

Code: Select all

TextureManager::getSingleton().loadImage("TempHorTexture", "Terrain", *mImage, TEX_TYPE_3D, 3); 
to

Code: Select all

TextureManager::getSingleton().loadImage("TempHorTexture", "Terrain", *mImage, TEX_TYPE_2D, 3); 
it correctly and without error creates a PF_L8 2D texture with size 1024x1024 (and throws the remaining 7 slices away).

Can there be a bug in loading 3D Textures with only luminance component?
Of course I don't see textures as images. Who would?

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

That's very possible, although it sounds more like a driver problem/refusal. Very strange..
As I asked above, what card (and OS) is this, and can I get the .raw file to test?

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

It's WinXP SP1, NVida GF6800 with Forceware 66.93 and Cg 1.3, usin Ogre 1.0.0.

It would be great, if you could test the raw file (may be, I my creation code is not correct). I'll put it somewhere to web...

http://leon.svf.stuba.sk/~iso/Horizon2.exe

it's a self-extracting rar archive, size ~2MB.
Of course I don't see textures as images. Who would?

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Texture: TempHorTexture: Loading 1 faces(PF_L8,1024x1024x8) with 3 generated mipmaps from Image. Internal format is PF_A8R8G8B8,0x0x0.
Zwevende-punt uitzondering

Good news: I can reproduce this (Linux, NV) Now looking into the cause.

iso
Halfling
Posts: 73
Joined: Fri Mar 18, 2005 11:43 am
Location: Slovakia

Post by iso »

Great :)
I'll try to make a test with the same image, but PF_R8G8B8...
... returning the same error.
Of course I don't see textures as images. Who would?

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

It seems 512 is the dimension of the largest 3d texture that the NVidia driver takes. That's your problem. 512x512x8 in PF_L8 works fine.

Post Reply