3D Textures & DevIL
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
3D Textures & DevIL
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?
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?
- :wumpus:
- OGRE Retired Team Member
- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
- :wumpus:
- OGRE Retired Team Member
- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
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.
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.
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
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?
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?
- :wumpus:
- OGRE Retired Team Member
- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
Interesting, I never knew. Do you have an official reference on this?iso wrote:It won't be scaled, OpenGL supports size = 2^n and size = 2^n +1
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)
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
http://oss.sgi.com/projects/ogl-sample/ ... of_two.txt:wumpus: wrote:Interesting, I never knew. Do you have an official reference on this?
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.
- :wumpus:
- OGRE Retired Team Member
- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
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:
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]
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);
...
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]
- :wumpus:
- OGRE Retired Team Member
- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
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.
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.
- :wumpus:
- OGRE Retired Team Member
- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
It needs bpc as well, which is bytes per component, I think.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;
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
I added the Bpc byte to my raw file. And changed the code to:
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]
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);
...
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
Of course, but how do I get the traceback? (I'm using VS7):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.
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.
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
I brushed up the code a bit:
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...
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;
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...
- :wumpus:
- OGRE Retired Team Member
- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
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?
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.
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
Yes, I don't work with 16bits when I can't get 8bit work.
And yes, I use only OpenGL rendering.
After changing
to
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?
And yes, I use only OpenGL rendering.
After changing
Code: Select all
TextureManager::getSingleton().loadImage("TempHorTexture", "Terrain", *mImage, TEX_TYPE_3D, 3);
Code: Select all
TextureManager::getSingleton().loadImage("TempHorTexture", "Terrain", *mImage, TEX_TYPE_2D, 3);
Can there be a bug in loading 3D Textures with only luminance component?
Of course I don't see textures as images. Who would?
-
- Halfling
- Posts: 73
- Joined: Fri Mar 18, 2005 11:43 am
- Location: Slovakia
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.
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?
- :wumpus:
- OGRE Retired Team Member
- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1