Page 1 of 1

StaticImage don't show a memory loaded texture!!!

Posted: Mon Jul 12, 2010 16:26
by strangedays

Code: Select all

CEGUI::Window* root = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow","root");   
    CEGUI::System::getSingleton().setGUISheet(root);

    fw = (CEGUI::FrameWindow*) CEGUI::WindowManager::getSingleton().createWindow("Vanilla/StaticImage","HelloWorlWindow");

    root->addChildWindow(fw);

    fw->setPosition( UVector2( UDim( 0.1f, 0 ), UDim( 0.1f, 0 ) ) );
    fw->setSize( UVector2( UDim( 0.5f, 0 ), UDim( 0.5f, 0 ) ) );
   
    unsigned char* texPtr = 0;
    unsigned int width2 = 0;
    unsigned int height2 = 0;

    if ( loadBMP("test.bmp", texPtr, width2, height2 ) )
    {
        bool test = 1;
    }

    CEGUI::Size sz;
    sz.d_height = height2;
    sz.d_width = width2;

     pTex = (CEGUI::Texture*)
        &CEGUI::System::getSingleton().getRenderer()->createTexture(sz);

    pTex->loadFromMemory(texPtr, sz, CEGUI::Texture::PixelFormat::PF_RGB );

    CEGUI::Imageset imgSet = CEGUI::ImagesetManager::getSingleton() .create("RTT", *pTex);

    imgSet.setAutoScalingEnabled(true);

    imgSet.defineImage("full_image",CEGUI::Point(0,0), CEGUI::Size(width2, height2), CEGUI::Point(0,0));

    fw->setProperty( "Image", CEGUI::PropertyHelper::imageToString(& imgSet.getImage("full_image")) );



This is a temporary workaround loading a texture from file ( later I will attach texture from secondary OpenGL context ). This sample code won't display texture from memory and I don't know really why. It will show instead the Vanilla scheme default StaticImage ( default grey background ).

I really dont' know what to do... any suggestion?

PS: I am not using OGRE, just plain OpenGL.. texturing is enabled ( hello world FrameWindow will display indeed )

Re: StaticImage don't show a memory loaded texture!!!

Posted: Mon Jul 12, 2010 18:01
by Jamarr
strangedays wrote:

Code: Select all

    CEGUI::Imageset imgSet = CEGUI::ImagesetManager::getSingleton() .create("RTT", *pTex);
    imgSet.setAutoScalingEnabled(true);
    imgSet.defineImage("full_image",CEGUI::Point(0,0), CEGUI::Size(width2, height2), CEGUI::Point(0,0));


ImagesetManager::create() returns a reference, but you are not assign it to a reference variable; you are assigning it to a local variable, resulting in a copy of the object. Therefore, when you set the properties on this variable they are being applied to the copy and not the original object.

At least, that is my guess. Aside from that, I cannot see anything wrong with your code. Also, for future reference, please read this thread; in particular, you should always post your log so that we know what version and environment you are using. Thanks.

Re: StaticImage don't show a memory loaded texture!!!

Posted: Tue Jul 13, 2010 14:07
by strangedays
I see. that was pretty easy thank you very much! :) I was tired and it was a bad mistake thank u so much!


I have just one more question:

following the code:

Code: Select all

int DrawGLScene(GLvoid)                           // Here's Where We Do All The Drawing
{
    bool retVal  = wglMakeCurrent(ExtraContenent, GLExtraRenderContext);
    GdiFlush();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    GenGraphics();

    pTex->loadFromMemory( pData, CEGUI::Size(320, 200), CEGUI::Texture::PixelFormat::PF_RGB );
    retVal  =  wglMakeCurrent(hDC, hRC);

    GdiFlush();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   
    glLoadIdentity(); // Reset The Current Modelview Matrix

    GenGraphics();

    CEGUI::System::getSingleton().renderGUI();

    glFlush();

    return TRUE;                              // Everything Went OK
}



This is a draw cycle for rendering. It switches two rendering contexes: one for the main window and one is a render to memory using a DIB bitmap.

pData is a pointer to a DIB section related to a secondary rendering context. Looks like I cannot live update CEGUI with raster image , since it won't update its texture. pTex is on a global scope.

Re: StaticImage don't show a memory loaded texture!!!

Posted: Tue Jul 13, 2010 15:40
by Jamarr
I am not that familiar with v0.7, but I assume that the CEGUI::Texture::loadFromMemory does not automatically invalidate windows using this texture. So, if the window is backed by texture-caching (AutoRenderingSurface property) then you need to call CEGUI::Window::invalidate so that CEGUI knows the windows needs to be redrawn/recached.

Re: StaticImage don't show a memory loaded texture!!!

Posted: Wed Jul 14, 2010 11:43
by strangedays
Looks like it works! thank u so much ;)

Re: StaticImage don't show a memory loaded texture!!!

Posted: Mon Oct 04, 2010 16:21
by strangedays
Renderer won't update rendering target associated to StaticImage:

here is a draw callback function called each rendering cycle:


Code: Select all

   CEGUI::Texture& rTex = *g_pImgSet->getTexture();

   static unsigned char* pOldData = 0;

   if( !pOldData)
       pOldData = new unsigned char[ g_sizeRTT.d_width * g_sizeRTT.d_height * 3 ];

   rTex.saveToMemory(pOldData);

   int val1 = pOldData[0];
   int val2 = pOldData[1];
   int val3 = pOldData[2];


   if( m_pTempData == 0  )
   {
      m_pTempData = new unsigned char[g_sizeRTT.d_width * g_sizeRTT.d_height * 3 ];
      memset( m_pTempData, 0x00 , g_sizeRTT.d_width * g_sizeRTT.d_height * 3 );
   }

   wglMakeCurrent(_hdc, __hrc );

   CEGUI::System::getSingleton().renderGUI();

   // Main window ( attached to parent node root )
   m_pHostWindow->setUsingAutoRenderingSurface(false);

   
   // StaticImage attached to main window
   m_pFrameTarget->setUsingAutoRenderingSurface(false);

   CEGUI::WindowManager::getSingleton().getWindow("root")->setUsingAutoRenderingSurface(false);

   rTex.loadFromMemory( (const void* ) m_pTempData, g_sizeRTT, CEGUI::Texture::PixelFormat::PF_RGB );

   memset( pOldData, 0x00 , g_sizeRTT.d_width * g_sizeRTT.d_height * 3 );
   rTex.saveToMemory(pOldData);

   ((CEGUI::Window*) m_pHostWindow )->invalidate();

   CEGUI::WindowManager::getSingleton().getWindow("root")->invalidate(true);
   

   //// (Re)Activate the appropriate CEGUI render target.
   //CEGUI::System::getSingleton().getRenderer()->getDefaultRenderingRoot().getRenderTarget().activate();

   memset( pOldData, 0x00 , g_sizeRTT.d_width * g_sizeRTT.d_height * 3 );
   rTex.saveToMemory(pOldData);



I've tried all tecniques adopted in this forum, still can't get it work done... I've run out of ideas..

Re: StaticImage don't show a memory loaded texture!!!

Posted: Wed Oct 06, 2010 09:12
by CrazyEddie
I don't understand what you're trying to do. Why are there all those calls in there to disable rendering surfaces and such?

What results are you getting and how does this differ from what you were expecting?

CE.