Page 1 of 1

Use external images

Posted: Fri Apr 18, 2008 13:44
by Yoha
Hi, I would like to use a CEGUI Interface with SFML (there is a version in english too). I successed to compile and use an interface. My problem is: I want to use images from files wich are not frameset and no in repertories of CEGUI in a Window of CEGUI but I don't know how do it. If someone can help me... :roll:

Posted: Sat Apr 19, 2008 08:52
by CrazyEddie
Hi, and welcome :)

I've not looked at SFML at all so what I say here is just general descriptions of how things are.

As you may know, currently all imagery used by CEGUI needs to be defined in an Imageset somehow. That somehow is important, since it does not mean you have load the Imageset from a graphic file and xml definition.

Generally the approach will be:
1) obtain the image / texture from the engine (in this case SFML)
2) use this base level imagery to create a CEGUI::Texture (the interface / renderer module will hopefully provide a means of doing that)
3) use the CEGUI::Texture to create a CEGUI::Imageset in code using the ImagesetManager
4) define images on the newly created CEGUI::Imageset
5) use the new Imageset images as normal.

HTH

CE

Posted: Sat Apr 19, 2008 10:41
by Yoha
Thanks. I think I loaded the image but I can't draw it on the screen. I tried to do it with setMouseCursor on a FrameWindow but it do nothing. The cursor is not displayed. How can I get sure the image is loaded or no ?

Edit: I didn't find CEGUI::StaticImage in the doc and the compiler refuse it. What is a StaticImage in fact ? How use it ?

Posted: Sun Apr 20, 2008 08:29
by CrazyEddie
Please post some code or whatever showing what you're doing. To be sure the image is loaded you can use ImagesetManager::isImagesetPresent and Imageset::isImageDefined

The StaticImage is actually a simple DefaultWindow - everything else is handled via a combination of the window renderer (most likely Falagard/StaticImage) and looknfeel skin.

CE.

Posted: Sun Apr 20, 2008 08:45
by Yoha
The two tests return true. My code is:

Code: Select all

sf::Image* image = new sf::Image(*GestionnaireDonnees->GetImage(7));
CEGUI::Texture* texture = mRenderer->createTexture( (image->GetWidth() > image->GetHeight() ? image->GetWidth() : image->GetHeight()) );
texture->loadFromMemory(image->GetPixelsPtr(), image->GetWidth(), image->GetHeight(), CEGUI::Texture::PF_RGBA);
CEGUI::Imageset* test = CEGUI::ImagesetManager::getSingleton().createImageset("test", texture);
test->defineImage("ImgTest", CEGUI::Rect(0, 0, 64, 64), CEGUI::Point(0, 0) );
CEGUI::Image testImg = test->getImage("ImgTest");
m_win->setMouseCursor(&testImg);

std::cout << "ImageSet: " << CEGUI::ImagesetManager::getSingleton().isImagesetPresent("test") << "\n";
std::cout << "Image: " << test->isImageDefined("ImgTest") << "\n";


Where "GestionnaireDonnees" is an image manager I created. The result on the console is:

Code: Select all

ImageSet: 1
Image: 1


Edit: The image class I use: http://www.sfml-dev.org/documentation/classsf_1_1Image.htm

Posted: Mon Apr 21, 2008 08:45
by CrazyEddie
Well it seems the thing is getting created, but the data is not getting transferred to the texture properly.

Is there some way you can dump the underlying texture content to see what is getting transferred?

Rather than setting the image as the cursor on a frame window, can you set it as the default mouse cursor (this way you know it's definitely going to get used - even if nothing eventually shows up).

Posted: Mon Apr 21, 2008 10:06
by scriptkid
Hi,

i a not sure whether the Texture dimensions should be a power of two. Maybe you can try to play with that.

HTH.

Posted: Wed Apr 23, 2008 11:17
by Yoha
scriptkid -> Normally, it is calculated automatically.

The program stop directly when I use:

Code: Select all

frame->setMouseCursor(&testImg);


Where frame is the Window returned by the loadWindowLayout method.


I don't understand the mean of "Is there some way you can dump the underlying texture content to see what is getting transferred?". If I have to test if the image is loaded well by SFML, I used it and it runs.

Posted: Thu Apr 24, 2008 18:43
by CrazyEddie
Yoha wrote:I don't understand the mean of "Is there some way you can dump the underlying texture content to see what is getting transferred?". If I have to test if the image is loaded well by SFML, I used it and it runs.


Ok. Let me try to explain. What is currently happening is this:

1) You load the image into SFML
2) You create a CEGUI texture of the required dimension.
3) You load the data from the SFML image to the CEGUI texture - this should copy the pixel data from one buffer to another.

What I meant was, is there a way to examine the underlying SFML buffer/texture created in step 2, after the data has been copied in step 3 - because it seems the data may not be getting copied correctly.

CE

Posted: Sat Apr 26, 2008 14:43
by Yoha
I found it int he CEGUI log:

Code: Select all

26/04/2008 16:36:50 (Std)    Attempting to create Imageset 'test' with texture only.


but there is also these lines after imageset delcaration:


Code: Select all

test->defineImage("ImgTest", CEGUI::Rect(0, 0, 64, 64), CEGUI::Point(0, 0) );
CEGUI::Image testImg = test->getImage("ImgTest");

Posted: Fri May 02, 2008 16:20
by Yoha
Nobidy knows how I can do it ?

Posted: Mon May 05, 2008 07:54
by CrazyEddie
To reiterate...

I think there is an issue with how the pixel data is getting transferred to the texture used for the 'test' imageset; not that the creation of the imageset or image fails, we have clearly established that is happening correctly.

What you need is to confirm that the pixel data in the texture used is what it should be (not the original version, but the copy made when the loadFromMemory call is made). One way you might do this is to to get the engine to render the entire texture to the screen.

CE.