Page 1 of 1
StaticImage from pixel buffer
Posted: Mon Jul 05, 2010 04:04
by StrickenKid
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
Re: StaticImage from pixel buffer
Posted: Tue Jul 06, 2010 16:31
by Jamarr
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.
Re: StaticImage from pixel buffer
Posted: Tue Jul 06, 2010 18:26
by CrazyEddie
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.
Re: StaticImage from pixel buffer
Posted: Tue Jul 06, 2010 20:47
by StrickenKid
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.pngI 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
Re: StaticImage from pixel buffer
Posted: Thu Jul 08, 2010 09:12
by CrazyEddie
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.
Re: StaticImage from pixel buffer
Posted: Thu Jul 08, 2010 23:45
by StrickenKid
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
Re: StaticImage from pixel buffer
Posted: Mon Jul 12, 2010 08:50
by CrazyEddie
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