Page 1 of 1

load texture from memory problem

Posted: Sun Oct 29, 2006 02:20
by richy
im trying to load a texture from memory with the code:

from minimap class

Code: Select all

#define MAXSIZE 900
int *m_pMapBuffer[MAXSIZE];

MiniMap::MiniMap(void)
{
   for (int i = 0; i < MAXSIZE; i++)
   {
      m_pMapBuffer[i] = (int*)RGB(120,120,120);
   }
}
MiniMap* MiniMap::pGS()
{
   static MiniMap MiniMapInstance;
   return &MiniMapInstance;
}
void* MiniMap::getMiniMap()
{
   return &m_pMapBuffer;
}


from game class

Code: Select all

CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
CEGUI::StaticImage* img = (CEGUI::StaticImage*)wmgr.getWindow((CEGUI::utf8*)"MiniMap");
CEGUI::Renderer* render = mGUISystem->getRenderer();
CEGUI::Texture* text;

text = render->createTexture();
text->loadFromMemory(MiniMap::pGS()->getMiniMap(),30,30);

CEGUI::Imageset* imageSet = CEGUI::ImagesetManager::getSingleton().createImageset("MiniMap", text);
imageSet->defineImage("MiniMap", CEGUI::Point(0.0,0.0), CEGUI::Size(30,30), CEGUI::Point(0.0,0.0));
img->setImage(&imageSet->getImage((CEGUI::utf8*)"MiniMap"));
img->show();



I've tested it with an image from disk and it displays fine, just when i do loadFromMemory it displays nothing.

Please help,


thanks

Posted: Sun Oct 29, 2006 11:26
by lindquist
Textures need to be powers of two. try 32x32 instead

Posted: Sun Oct 29, 2006 15:06
by richy
I changed MAXSIZE to 1024, the temp function to devidex by 10000*16 inszted of 10000*15 and text->loadFromMemory(MiniMap::pGS()->getMiniMap(),32,32); and imageSet->defineImage("MiniMap", CEGUI::Point(0.0,0.0), CEGUI::Size(32,32), CEGUI::Point(0.0,0.0));

but it still displays black, I also tried using unsigned ints for m_pMapBuffer and still only black, it should display a grey.

Posted: Sun Oct 29, 2006 16:55
by CrazyEddie
Hi,

I think this is probably an issue with the pixel format; you need an alpha component too, I'm not sure what:

Code: Select all

RGB(120,120,120);
returns, but if it returns something that has 0 where the alpha would be, then this is why you are getting nothing.

So, my advice would be to check the format of the data you are providing to loadFromMemory.

HTH

CE.

Posted: Mon Oct 30, 2006 06:03
by richy
worked awesome, thanks guys. I used

Code: Select all

(unsigned int*)((181 <<  0) |(181 <<  8) |(181 << 16) |(255 << 24));

insted.