[iOS] load UIImage as Texture
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
[iOS] load UIImage as Texture
Is it possible to load an texture based on an UIImage Object?
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
Re: [iOS] load UIImage as Texture
Nobody knows an answer?
Last edited by IrrlichtForiOS on Mon Nov 02, 2015 6:55 am, edited 1 time in total.
Re: [iOS] load UIImage as Texture
I don't do GUII, but if you look in IGUIImage.h you will see there is a method getImage that returns ITexture*. Also, since you had to add the image anyway, you must already have it?
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
Re: [iOS] load UIImage as Texture
GUII has nothing todo with iOS's UIKit UIImage class.mongoose7 wrote:I don't do GUII, but if you look in IGUIImage.h you will see there is a method getImage that returns ITexture*. Also, since you had to add the image anyway, you must already have it?
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
Re: [iOS] load UIImage as Texture
After I've found http://irrlicht.sourcearchive.com/docum ... 41a06.html I implemented the following methods.
Retrieve an Texture...
getImageData()
loadImageForBackground
The method that fails is the CImage raw-data constructor
Retrieve an Texture...
Code: Select all
core::dimension2d<u32> retTexSize;
void* data;
core::dimension2d<u32> size;
bool success = frame->getImageData(&data, &size);
if (success) {
loadImage->loadImageForBackground(data, size, retTexSize);
}
Code: Select all
bool FAAppFrame::getImageData(void *data, core::dimension2d<u32> *size)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:"PATH"];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
if (!imageData) {
return false;
}
data = (void *)[imageData bytes];
*size = core::dimension2d<u32>(512, 512);
return true;
}
return false;
}
Code: Select all
bool E3DCLoadImage::loadImageForBackground(void* data, core::dimension2d<u32> size, core::dimension2d<u32> &retTexSize)
{
video::IImage *texImg = driver->createImageFromData(video::ECF_R8G8B8, size, data, false, true ); // fails with EXC_BAD_ACCESS
video::ITexture *tex = driver->addTexture(L"datatexture", texImg);
Code: Select all
//! Constructor from raw data
CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, void* data,
bool ownForeignMemory, bool deleteForeignMemory, bool compressed, bool mipMaps)
: Data(0), Size(size), Format(format), IsCompressed(compressed), HasMipMaps(mipMaps), DeleteMemory(deleteForeignMemory)
{
if (ownForeignMemory)
{
Data = (u8*)0xbadf00d;
initData();
Data = (u8*)data;
}
else
{
Data = 0;
initData();
memcpy(Data, data, Size.Height * Pitch); // EXC_BAD_ACCESS
}
}
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
Re: [iOS] load UIImage as Texture

Re: [iOS] load UIImage as Texture
Do you get any warnings? Look, the problem is in *your* code so you have to be prepared to debug it. For example,
but
and
In summary, the pointer defined by "void *data'" is not updated, so the SIGSEGV is expected.
Code: Select all
void* data;
bool success = frame->getImageData(&data, &size);
Code: Select all
bool FAAppFrame::getImageData(void *data, core::dimension2d<u32> *size)
Code: Select all
data = (void *)[imageData bytes];
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
Re: [iOS] load UIImage as Texture
Can you explain me why you think, data will not be updated?mongoose7 wrote:Do you get any warnings? Look, the problem is in *your* code so you have to be prepared to debug it. For example,butCode: Select all
void* data; bool success = frame->getImageData(&data, &size);
andCode: Select all
bool FAAppFrame::getImageData(void *data, core::dimension2d<u32> *size)
In summary, the pointer defined by "void *data'" is not updated, so the SIGSEGV is expected.Code: Select all
data = (void *)[imageData bytes];
EDIT: I've changed my code to:
Code: Select all
irr::u8 data;
core::dimension2d<u32> size;
bool success = frame->getCurrentFassadenBildData(&data, &size);
Code: Select all
bool FAAppFrame::getCurrentFassadenBildData(irr::u8 *data, core::dimension2d<u32> *size)
Code: Select all
data = (u8 *)[imageData bytes];
in the CImage constructor data has the following value..
Code: Select all
(void *) data = 0x000000016fdf7090
These are the iOS data size and the calculated irrlicht size
Code: Select all
15586683 (iOS)
23970816 (Irrlicht)
Re: [iOS] load UIImage as Texture
"data = <value>" only changes the local pointer. To change the pointer in the outer function you need "*data = <value>". You also need to change the function prototype.
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
Re: [iOS] load UIImage as Texture
Hi,mongoose7 wrote:"data = <value>" only changes the local pointer. To change the pointer in the outer function you need "*data = <value>". You also need to change the function prototype.
I've changed my function now to
Code: Select all
bool FAAppFrame::getCurrentFassadenBildData(void *data, core::dimension2d<u32> *size)
Code: Select all
NSUInteger len = [imageData length];
data = malloc(len);
memcpy(data, [imageData bytes], len);
Re: [iOS] load UIImage as Texture
Code: Select all
bool FAAppFrame::getCurrentFassadenBildData(void **data, core::dimension2d<u32> *size)
Code: Select all
*data = malloc(len);
memcpy(*data, [imageData bytes], len);
Code: Select all
void *getCurrentDada(int width, int height)
{
int len = width*height;
void *data = malloc(len);
memcpy(data, bytes, len);
return data;
}
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
Re: [iOS] load UIImage as Texture
Thanks for your patience to try with helping... but all these ways are not working together with iOS + Irrlicht. The CImage constructor is always crashing. This has nothing to do with that i'm not abled to code. C++ is not my mother tongue as Objective-C is.mongoose7 wrote:Code: Select all
bool FAAppFrame::getCurrentFassadenBildData(void **data, core::dimension2d<u32> *size)
I can't help you any more - you're going to have to learn to code before you can make any progress. As an old C programmer, I usually preferCode: Select all
*data = malloc(len); memcpy(*data, [imageData bytes], len);
but that's the kind of guy I am.Code: Select all
void *getCurrentDada(int width, int height) { int len = width*height; void *data = malloc(len); memcpy(data, bytes, len); return data; }
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
One step forward...
So...after some struggel with this topic i'm at the Point, where i can load an image, but the resulting image is really noisy, black and strange...
Does anybody know how to get rid of this noise?
Code: Select all
// Start loading the image
void *data = frame->getCurrentFassadenBildData(&size);
if (data != nullptr) {
loadImage->loadImageForBackground(data, size, retTexSize);
}
Code: Select all
// return image data as void *
void * FAAppFrame::getCurrentFassadenBildData(core::dimension2d<u32> *size) {
//.....
void *data = FAAppFrame::getDataByBytesAndSize((void *)[imageData bytes], (int)[imageData length]);
*size = core::dimension2d<u32>(resW, resH);
return data;
}
Code: Select all
// copy iOS-data into CPP data...
void * FAAppFrame::getDataByBytesAndSize(void *bytes, int len)
{
void *data = malloc(len);
memcpy(data, bytes, len);
return data;
}
Code: Select all
// Create image CImage from data
loadImageForBackground(void *data, core::dimension2d<u32> size, core::dimension2d<u32> &retTexSize)
{
/*!
* @link http://irrlicht.sourcearchive.com/documentation/1.7.1plus-pdfsg1-1/classirr_1_1video_1_1IVideoDriver_a425d60f2fcad42d8a79c33c587f41a06.html
*/
video::IImage *texImg = driver->createImageFromData(video::ECF_R8G8B8, size, data, false, true);
Re: [iOS] load UIImage as Texture
Do you know how big an image is? If it is R8G8B8, then the size is WxHx3, not WxH.
Do you know the format of the original data? Maybe it is not R8G8B8. Maybe it is B8G8R8 or A8R8G8B8. Maybe it is JPEG.
Do you know the format of the original data? Maybe it is not R8G8B8. Maybe it is B8G8R8 or A8R8G8B8. Maybe it is JPEG.
-
- Posts: 61
- Joined: Mon Oct 08, 2012 1:46 pm
Re: [iOS] load UIImage as Texture
Therefore i'm using NSData's 'lenght' property, which is related to these factors.mongoose7 wrote:Do you know how big an image is? If it is R8G8B8, then the size is WxHx3, not WxH.
Do you know the format of the original data? Maybe it is not R8G8B8. Maybe it is B8G8R8 or A8R8G8B8. Maybe it is JPEG.