Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - iforce2d

Pages: [1]
1
Graphics / Using SFML in a resizable QT-Widget
« on: December 27, 2011, 08:24:27 pm »
Okay, I discovered something else. I can put the same code I had in the main message loop of the standalone app, into the OnUpdate() function of the widget, like this:

Code: [Select]
void MyCanvas::OnUpdate()
{
    sf::Event event;
    while ( PollEvent(event) )
    {
        if ( event.Type == sf::Event::Resized ) {
            glViewport(0, 0, event.Size.Width, event.Size.Height);
            SetView( sf::View( sf::FloatRect(0,0,m_GetWidth,m_GetHeight) ) );
        }

        // ... check mouse and keys etc
    }
}


Maybe this is bad practice, I don't know. But it works ok so far and I like it because I can use almost the exact same code when I detach this from the Qt framework.
If anybody has any reason why this may be bad please let me know  :P

2
Graphics / Using SFML in a resizable QT-Widget
« on: December 27, 2011, 05:06:48 pm »
I'm using the latest snapshot of 2.0 and can't get this to work either. In a normal standalone window in the main message loop it works great with glViewport and sf::RenderWindow::SetView, like this:
Code: [Select]
if (event.Type == sf::Event::Resized) {
    glViewport(0, 0, event.Size.Width, event.Size.Height);
    window.SetView( sf::View( sf::FloatRect(0,0,window.GetWidth(),window.GetHeight()) ) );
}

So I figured that when the resize event comes from the Qt widget, you would do the same, like this:
Code: [Select]
void QSFMLCanvas::resizeEvent( QResizeEvent * event )
{
    int newWidth = event->size().width();
    int newHeight = event->size().height();

    glViewport( 0, 0, newWidth, newHeight );
    SetView( sf::View( sf::FloatRect(0,0,newWidth, newHeight) ) );

    QWidget::resizeEvent(event);
}

But it seems that the extent of the drawn region does not change. Here is what it looks like when the application first starts:



... and this is after resizing the window a little. It looks like the RenderWindow itself is filling the widget correctly because the green background from the Clear() is there, but the stuff that I am drawing never gets out of the original region it started in.



I discovered that I can use sf::RenderWindow::SetViewport to get what I want, but this is a bit inconvenient because it seems to require the ratio to the original window dimensions. For example, if my widget's starting dimensions are 149x115, this will work ok:
Code: [Select]
   sf::View newView(sf::FloatRect(0,0,newWidth, newHeight) );
    newView.SetViewport( sf::FloatRect( 0,0, newWidth / 149.f, newHeight / 115.f ) );
    SetView( newView );


and gives me the behavior I want:



... but it seems unusually inconvenient for SFML where everything else is easy :)
Am I missing something?

3
Window / Illegal symbol index in relocs. tickStat has no section.
« on: December 20, 2011, 07:32:31 pm »
Linking the libs in the right order seemed to do the trick:

http://www.sfml-dev.org/tutorials/1.6/start-cb.php

4
Window / Illegal symbol index in relocs. tickStat has no section.
« on: December 20, 2011, 06:13:47 pm »
Allow me to bump this as well. I changed from using dynamic libs (just downloading the source and using the CMakeLists.txt file to build without altering anything) to using static libs (set BUILD_SHARED_LIBS to false and define SFML_STATIC in my source code) and now I'm getting the error below at the linking stage:

/libsfml-window-s.a(dspfs00244.o): illegal symbol index 2823 in relocs

Pages: [1]
anything