SFML community forums
Help => Window => Topic started by: sNIk on October 27, 2011, 03:45:32 pm
-
hi,
i have troubles resizing the context inside my Qt-window. at first the relevant code-snippet which does the resizing: (ignore the LOG(...) stuff, thats just for testing)
void SFMLWidget::resizeEvent(QResizeEvent *e)
{
LOG("ResizeEvent -> Qt: " << e->size().width() << "x" << e->size().height() );
SetSize(e->size().width(), e->size().height());
LOG("ResizeEvent -> SFML: " << GetWidth() << "x" << GetHeight() );
}
SetSize(...) does not have any effect. didnt try that on windows though. the only thing that works, is recreating the entire context, what is a bad idea in this case since the resizeEvent is fired all the time while resizing. native sfml-window works perfectly.
i've uploaded some images to illustrate the problem. the green corners are the window-cornerns, the black area is the window itself. changing the clear-color affects the wohle black area. thats just weird to me. :)
(http://img824.imageshack.us/img824/7435/sfmlqt0.th.png) (http://imageshack.us/photo/my-images/824/sfmlqt0.png/)
(http://img443.imageshack.us/img443/4002/sfmlqt1.th.png) (http://imageshack.us/photo/my-images/443/sfmlqt1.png/)
-
Hi,
Seems like re-creating the context/window seems to be the only solution for this. I have the same problem with running SFML-context in a wxWidget-Panel. But there seems to be a bug...
When I call upon sf::Window::Create( getSystemHandle() ) in the resizeHandler, I get this funny graphical artifact. (see attachment )
(http://i.imgur.com/HfERq.png)
...where it seems like all textures are random-memory.
Please, need help figuring out a solution for this. Do I have to reload every texture?
Btw, using SFML2.0/ArchLinux/ATI
-
Do I have to reload every texture?
No, SFML always keeps a valid context so that resources are never lost.
Unfortunately I can't test/help with wxWidgets, but it could be a viewport problem.
-
Viewport of the sf::Renderwindow?
-
Thanks,
I followed your lead about the viewport. And It is possible, atleast in wxWidget, to resize to PanelSize(wxWidget) by updating both the view and viewport, to get rid of the clipping that is restricted to initial size of widget. So there is no need to call Create() on resize-handler, which is inefficient and fails for wxWidgets. Perhaps this is also true for Qt ?
Now when I resize the window / panel, I maintain coord(0,0) in top/left corner and maintain pixelsize (no streching).
-
How do you update the viewport?
-
sf::View view = sf::View(sf::FloatRect(0,0,w,h));
float a = h/(initialHeight*2);
view.SetViewport(sf::FloatRect(0,(-a+1),w/initialWidth,h/initialHeight));
sf::RenderWindow::SetView(view);
Where initialSizes are the initial-size of the wxPanel, as specified in ctor.
Please, give feedback to this solution, since the "a" was created empirically. Works like a charm though. ;)
-
Well, it is not normal. A viewport of [0, 0, 1, 1] should always map to the entire render target :-\