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
StaticImage from pixel buffer
Moderators: CEGUI MVP, CEGUI Team
-
- Just popping in
- Posts: 9
- Joined: Wed Jun 23, 2010 05:59
Re: StaticImage from pixel buffer
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:
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.
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!
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: StaticImage from pixel buffer
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
CE.
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
CE.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
-
- Just popping in
- Posts: 9
- Joined: Wed Jun 23, 2010 05:59
Re: StaticImage from pixel buffer
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:
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
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
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: StaticImage from pixel buffer
I used OpenGL calls directly, and the matching part of the code looked like this:
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.
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.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
-
- Just popping in
- Posts: 9
- Joined: Wed Jun 23, 2010 05:59
Re: StaticImage from pixel buffer
Thanks for the info, but did you mean like this:
Because now the texture doesn't show at all :S
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
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: StaticImage from pixel buffer
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
CE
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
CE
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Return to “Modifications / Integrations / Customisations”
Who is online
Users browsing this forum: No registered users and 1 guest