StaticImage from pixel buffer

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

StrickenKid
Just popping in
Just popping in
Posts: 9
Joined: Wed Jun 23, 2010 05:59

StaticImage from pixel buffer

Postby StrickenKid » Mon Jul 05, 2010 04:04

Hi,

Could anyone be nice enough to give me an example of how to render an image from a pixel buffer onto a StaticImage control?

I'm making a web browser with LLMozLib, I have LLMozLib all setup, but I have no idea how to get the pixel buffer into an image.

Thanks for any help,

Ethan

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

Re: StaticImage from pixel buffer

Postby Jamarr » Tue Jul 06, 2010 16:31

You need to create a texture with the underlying renderer you are using. Once you have the texture object, then you can create a CEGUI::ImageSet based on that texture. With the ImageSet, you can define an image in the set to be the entire texture. Then assign that image in to the window via its "Image" property. Something like this:

Code: Select all

   _imageset = CEGUI::ImagesetManager::getSingleton().createImageset(setName, _texture);
   _imageset->defineImage(imageName, CEGUI::Point(0,0), CEGUI::Size(texture.w, texture.h), CEGUI::Point(0,0));
   _window->setProperty("Image", "set:" + setName + " image:" + imageName);


At least in v0.6.2. There may be an easier method in v0.7 but I am not familiar enough with that version to comment. I assume the above approach would work in v0.7 as well.
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!

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

Re: StaticImage from pixel buffer

Postby CrazyEddie » Tue Jul 06, 2010 18:26

The above approach is still valid in 0.7.x. There are other approaches too, that again involve texture backed windows (usually via the AutoRenderingSurface property). There's a post on here somewhere about rendering directly to a window using Ogre. The same technique is valid for all the renderer options.

I can't remember which approach I used for the OpenGL based browser demo I did (which is show in the videos). I think it was the imageset approach from above, I'll check over the next couple of days and either confirm that or tell what I really did :P

CE.

StrickenKid
Just popping in
Just popping in
Posts: 9
Joined: Wed Jun 23, 2010 05:59

Re: StaticImage from pixel buffer

Postby StrickenKid » Tue Jul 06, 2010 20:47

Thanks for the info!

I did go through the forum earlier and I did find a more up-to-date way to do it I think:

Code: Select all

         ImagesetManager::getSingleton().get( "InGameBrowser" ).
            getTexture()->loadFromMemory( pixels,
               Size( (float)( LLMozLib::getInstance()->getBrowserRowSpan( mBrowser->mBrowserWindowId ) /
                  LLMozLib::getInstance()->getBrowserDepth( mBrowser->mBrowserWindowId ) ),
                     (float)mBrowser->mBrowserWindowHeight ), Texture::PF_RGB );


That's the method I'm currently using, although the texture isn't rendering properly, this is what it looks like: http://ft.dtupload.com/cT1/sa-mp-081.png

I think it has to do with the buffer_size parameter, but I used the same method to get the size as in the test from LLMozLib.

What method did you use to render the browser, CE?

Thanks for your help,

StrickenKid

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

Re: StaticImage from pixel buffer

Postby CrazyEddie » Thu Jul 08, 2010 09:12

I used OpenGL calls directly, and the matching part of the code looked like this:

Code: Select all

    // grab the page
    LLMozLib::getInstance()->grabBrowserWindow( mBrowserWindowId );
    const unsigned char* pixels = LLMozLib::getInstance()->getBrowserWindowPixels( mBrowserWindowId );
    if (pixels)
    {
        // write them into the texture
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
            // because sometimes the rowspan != width * bytes per pixel (mBrowserWindowWidth)
            LLMozLib::getInstance()->getBrowserRowSpan( mBrowserWindowId ) / LLMozLib::getInstance()->getBrowserDepth( mBrowserWindowId ),
            600,
            LLMozLib::getInstance()->getBrowserDepth( mBrowserWindowId ) == 3 ? GL_BGR_EXT : GL_BGRA_EXT,
            GL_UNSIGNED_BYTE,
            pixels);
    }


Which is basically exactly the same except for the part about the pixel format, so you may want to check the depth of the image and use the 'right' format based on that because I'd say, looking at the image, the issue is one relating to the format of the pixel data.

CE.

StrickenKid
Just popping in
Just popping in
Posts: 9
Joined: Wed Jun 23, 2010 05:59

Re: StaticImage from pixel buffer

Postby StrickenKid » Thu Jul 08, 2010 23:45

Thanks for the info, but did you mean like this:

Code: Select all

         ImagesetManager::getSingleton().get( "InGameBrowser" ).
            getTexture()->loadFromMemory( pixels,
               Size( (float)( LLMozLib::getInstance()->getBrowserRowSpan( mBrowser->mBrowserWindowId ) /
                  LLMozLib::getInstance()->getBrowserDepth( mBrowser->mBrowserWindowId ) ),
                     (float)mBrowser->mBrowserWindowHeight ),
                     LLMozLib::getInstance()->getBrowserDepth( mBrowser->mBrowserWindowId ) == 3 ? Texture::PF_RGB : Texture::PF_RGBA);


Because now the texture doesn't show at all :S

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

Re: StaticImage from pixel buffer

Postby CrazyEddie » Mon Jul 12, 2010 08:50

Yes, I meant something like that.

So, what is the content of the texture after the data has been transferred? Or more to the point, is the data actually in one of the supported formats (i.e RGB / RGBA)? If not you may need to access D3D interfaces directly in order to transfer the data (kind of like what I did for OpenGL), I can't remember if I tried to use loadFromMemory myself, perhaps I did and also encountered these issues, I can't recall :oops:

CE


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 3 guests