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.


Topics - nelsk

Pages: [1]
1
Hi,

I'm working on integrating SFML 2.3.1 (release .so libs) into a wxWidgets 3.0 app, which I've successfully done. Now I'm trying to resize the RenderWindow-based wxControl on AppFrame resize events so that I can maintain a margin around my SFML canvas. I almost have it working, but I'm having some minor issues. I've boiled it down to a demo, here's the full source:

https://gist.github.com/eriknelson/e4ccf32534eb3d25a1ea

First, when the app first launches, it looks like the RenderWindow doesn't quite fill it's wxWindow, seen here:

http://i.imgur.com/ovCt6l4h.png

Secondly, sometimes when resizing the AppFrame, again, the RenderWindow appears not to fill the full window:

http://i.imgur.com/8qYvWLVh.png

Of particular interest is Canvas::onResize at line 87. I had originally tried simply setting the inherited RenderWindow size with
this->setSize(...)
, but that didn't work at all. Then I tried recreating the RenderWindow, which is where I'm at now. I'm almost positive what I'm doing is not advised since it's recreating the RenderWindow *on each resize event*. That seems terribly inefficient to me, and obviously does not perform well.

A couple specific questions:
- What is the right way to resize the RenderWindow on a wxWindow resize event? Should its size be changed, or does it, in fact, need to be recreated?
- If I'm on the right track, why the strange behavior seen in the screenshots?

I'm also open to any general critique of my code, I'd like to set a solid foundation and do this the right way.

Additional info:
OS: Arch Linux
Compiler: clang++ 3.6.2
Build tool: cmake 3.2.3

2
General / Texture.loadFromFile crashing due to access violation?
« on: March 17, 2013, 04:14:45 am »
Hi folks,

Just fired up SFML2 again and I'm suddenly getting a hard crash when trying to load a texture from a file?

        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window");

        sf::Texture t;
        if(!t.loadFromFile("Sheet.png")) // Access violation - CRASH!
                return EXIT_FAILURE;

Am I missing something here? Wondering if it has something to do with the libs.
I'm on Windows 7 64bit with VS2010 running in Debug. I'm using the pre-built SFML2 RC off the download page, linking against sfml-*.lib and setting my working dir to ../SFML2/bin.

Anything obvious I'm missing?

Edit: I've also noticed the title of my RenderWindow is junk - not what I've set it too. Is it not initializing correctly for some reason?

3
General / My scrolling appears quite jerky..
« on: August 05, 2012, 03:01:12 am »
Hi all,

I've implemented a demo project to scroll across a Tiled map editor level (using a loader by a fellow on the forums named Quinn. Thanks!).

It's loading the tiles fine, but while scrolling, it seems quite jerky. I'm really looking for a bit of a sanity check to make sure I'm using some of the SFML features with best practices in mind:

Main loop:
#include <SFML/Graphics.hpp>
#include "level.h"

sf::Rect<float> GetViewportRect(sf::View& v)
{
        return sf::Rect<float>(
                v.getCenter().x - (v.getSize().x / 2),
                v.getCenter().y - (v.getSize().y / 2),
                v.getSize().x,
                v.getSize().y);
}

int main()
{
        sf::RenderWindow window(sf::VideoMode(1280,640), "Sandbox!", sf::Style::Fullscreen);
        window.setFramerateLimit(30);

        nelsk::Level _level;
        _level.LoadFromFile("Level1.tmx");

        sf::Rect<float> r(500,640,1280,640);
        sf::View v(r);
        _level.SetDrawingBounds(r);
        window.setView(v);
        sf::Vector2f moveVec;

        sf::Clock _clock;
        float _deltaT;
        float fps;

        while(window.isOpen())
        {
                _deltaT = _clock.restart().asSeconds();
                fps = 1.f / _deltaT;

                sf::Event event;

                while(window.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed ||
                                sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                                window.close();
                }
               
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        moveVec.x = 400 * _deltaT;
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        moveVec.x = -400 * _deltaT;

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                        moveVec.y = 400 * _deltaT;
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                        moveVec.y = -400 *_deltaT;

                v.move(moveVec);               
                window.setView(v);

                _level.SetDrawingBounds(GetViewportRect(v));
                window.clear();
                _level.Draw(window);
               
                // Draw sprites to render frame
                window.display();
                moveVec.x = 0; moveVec.y = 0;
        }
        return EXIT_SUCCESS;
}
 

Relevent from Level.cpp

struct Layer{
                int opacity;
                std::vector <sf::Sprite> tiles;
        };

void Level::SetDrawingBounds(sf::Rect<float> bounds)
{
    drawingBounds = bounds;

    //Adjust the rect so that tiles are drawn just off screen, so you don't see them disappearing.
    drawingBounds.top -= tileHeight;
    drawingBounds.left -= tileWidth;
        drawingBounds.width += tileWidth;
        drawingBounds.height += tileHeight;
}

void Level::Draw(sf::RenderWindow &window)
{
    for (int layer = 0; layer < layers.size(); layer++)
    {
        for (int tile = 0; tile < layers[layer].tiles.size(); tile++)
        {
            if (drawingBounds.contains(layers[layer].tiles[tile].getPosition().x, layers[layer].tiles[tile].getPosition().y))
            {
                window.draw(layers[layer].tiles[tile]);
            }
        }
    }
}

Is there anything obviously wrong with this approach?
Side question: Perhaps this is a misunderstanding on my part (likely), but why does a RenderWindow not hold a reference to a view, rather than setting the view each loop through?

My fps is reporting very close to 30 and is pretty consistent, but every so often it will drop to around 19 for a couple loops. (I'm only running VStudio 2010 and my app on a pretty powerful rig)

Where should I start to smooth out this scrolling? (I've also got some pretty terrible tearing issues).

Pages: [1]
anything