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

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

strangedays
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Fri Jun 06, 2008 15:25

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

Postby strangedays » Mon Jul 12, 2010 16:26

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 )

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

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

Postby Jamarr » Mon Jul 12, 2010 18:01

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.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

strangedays
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Fri Jun 06, 2008 15:25

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

Postby strangedays » Tue Jul 13, 2010 14:07

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.

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

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

Postby Jamarr » Tue Jul 13, 2010 15:40

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.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

strangedays
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Fri Jun 06, 2008 15:25

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

Postby strangedays » Wed Jul 14, 2010 11:43

Looks like it works! thank u so much ;)

strangedays
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Fri Jun 06, 2008 15:25

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

Postby strangedays » Mon Oct 04, 2010 16:21

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..

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

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

Postby CrazyEddie » Wed Oct 06, 2010 09:12

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.


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 10 guests