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 - fallahn

Pages: 1 ... 29 30 [31] 32 33
451
System / Re: [2.0] Using a thread to load game resources
« on: July 02, 2013, 02:10:20 pm »
AHA. It seems that the problem occurs if I call rt->clear() *after* window.clear(). If I clear the RenderTexture first it works ok. This is only the case when rt is created in a separate thread. Create it in the main thread and it works fine whether it's cleared before or after window.

So your example:
            rt->clear(sf::Color::Yellow);
            rt->display();
            window.clear();
            window.draw(sf::Sprite(rt->getTexture()));
            window.display();
 

works fine (both creating in a separate and the main thread). On the other hand:

            window.clear();
            rt->clear(sf::Color::Yellow);
            rt->display();        
            window.draw(sf::Sprite(rt->getTexture()));
            window.display();
 

or

            window.clear();
            entity.Draw(window);
            window.display();
 

only works when the RenderTexture / entity object are created in the main thread.

452
System / Re: [2.0] Using a thread to load game resources
« on: July 02, 2013, 12:54:23 pm »
Hmm. Actually apart from changing it to

rt->getTexture()
 

(just a typo, I know) they both work for me.

453
System / Re: [2.0] Using a thread to load game resources
« on: July 02, 2013, 12:36:17 pm »
Ok, I've narrowed it down a bit. Having a RenderTexture as a member of an object created in a separate thread still has the same problem - the sprite draws green instead of yellow (it works when creating the object in the same thread):

class MyEntity
{
public:
    MyEntity()
    {
        m_renderTexture.create(40u, 40u);
        m_renderTexture.clear(sf::Color::Green);
        m_renderTexture.display();
        m_renderTexture.setActive(false); //deactivate because created in another thread
    }
    void Draw(sf::RenderTarget& rt)
    {
        m_renderTexture.clear(sf::Color::Yellow);
        m_renderTexture.display();
        rt.draw(sf::Sprite(m_renderTexture.getTexture()));
    }
private:
    sf::RenderTexture m_renderTexture;
};

//---------------------------------------------------------//

std::unique_ptr<MyEntity> ent;

bool loaded(false);
void ThreadFunc()
{
    ent = std::unique_ptr<MyEntity>(new MyEntity);
    loaded = true;
    std::cout << "Thread Quitting" << std::endl;
    glFlush();
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(800u, 600u), "rt test");

    sf::Thread thread(&ThreadFunc);
    thread.launch();

    while(window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) window.close();
        }

        if(loaded) //drawing this doesn't
        {
            window.clear();
            ent->Draw(window);
            window.display();
        }
    }
    thread.wait();
    return 0;
}
 

However, declaring a RenderTexture in the main thread and calling create() on it in a separate thread seems to work:

sf::RenderTexture rt;
bool loaded(false);
void ThreadFunc()
{
    rt.create(40u, 40u);
    rt.clear(sf::Color::Green);
    rt.display();
    rt.setActive(false);
    loaded = true;
    std::cout << "Thread Quitting" << std::endl;
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(800u, 600u), "rt test");

    sf::Thread thread(&ThreadFunc);
    thread.launch();

    while(window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) window.close();
        }

        if(loaded)
        {
            rt.clear(sf::Color::Yellow);
            rt.display();
            window.clear();
            window.draw(sf::Sprite(rt.getTexture()));
            window.display();
        }
    }
    thread.wait();
    return 0;
}
 

454
System / Re: [2.0] Using a thread to load game resources
« on: July 02, 2013, 11:25:29 am »
sorry to bump the thread but I just saw that the glFlush() fix has been included in an update on github. I've recompiled SFML with latest version for both VS11 and MinGW, but it seems it still doesn't fix the render texture problem I posted above.

455
SFML projects / Re: 'Tiled' Tile-map Loader
« on: June 26, 2013, 11:53:03 am »
No problem, hope it helps. I've updated it with quadtree partitioning for map objects



Which you can read about here  8)

456
I experienced the same thing when I was working on my Tiled map loader. I'd tried rounding the position and the half pixel trick but the only work-around I found was to load the tile set as an image, then copy each tile to a texture, pushing it onto a vector each time so that the vector indices matched the tile IDs. Oh and this was happening when drawing the tiles as sprites too.

457
General / Re: Getting started
« on: June 22, 2013, 10:11:13 am »
Isn't gcc fussy about the link order? So you would need system/window/graphics rather than graphics/window/system

458
Graphics / Re: Mouse movement
« on: June 20, 2013, 09:28:51 pm »
You don't say what you're trying to do, so I am assuming you want to get a realtime update of the mouse cursor position, in which case you should look at sf::Mouse::getPosition(). The mouseWheel event is designed to be handled while you poll for events, and contains the coordinates of the cursor when a mouse wheel event is received, ie when the wheel is scrolled or clicked.

459
General / Re: Redistributing game
« on: June 19, 2013, 01:52:26 pm »
Interesting, I didn't know that , I guess that's why they have a special redistributable package. Does that cover the SFML debug dlls too (which are what I was actually referring to)?

460
General / Re: Redistributing game
« on: June 19, 2013, 10:34:32 am »
You don't need to distribute the debug dlls with the release version (or even dlls you don't use/link such as networking), although it won't do any harm as they will just be ignored. Your friends probably need to install the VC redistributable which you can get from Microsoft, and include with your installer.

461
System / Re: [2.0] Using a thread to load game resources
« on: June 18, 2013, 01:15:57 pm »
sorry, I forgot to mention that I did, and it made no difference.

462
System / Re: [2.0] Using a thread to load game resources
« on: June 18, 2013, 12:49:29 pm »
I've been having a similar problem using sf::RenderTexture. I'm using a thread to load a map file (which works fine) then create a set of entities via an entity manager based on the loaded map data (eg spawn points etc). The entity manager loads the corresponding textures and passes references to them to the entities it creates, which actually draw fine, but entities which use a render texture internally to create their sprite texture do not draw. As far as I can see the actual render texture is not clear/draw/displaying during the entity's draw() call. For example if I add a clear() call immediately after create() with sf::color::green the entity will draw from the main thread as a green sprite... but the entity's draw function should be clearing it yellow.


#include <SFML/system.hpp>
#include <SFML/graphics.hpp>
#include <SFML/window.hpp>

#include <memory>
#include <vector>
#include <atomic>
#include <iostream>

class MyEntity
{
public:
    MyEntity()
    {
        m_renderTexture.create(40u, 40u);
        m_renderTexture.setActive(false); //deactivate because created in another thread
    }
    void Draw(sf::RenderTarget& rt)
    {
        m_renderTexture.clear(sf::Color::Yellow);
        m_renderTexture.display();
        rt.draw(sf::Sprite(m_renderTexture.getTexture()));
    }
private:
    sf::RenderTexture m_renderTexture;
};

class MyEntityManager
{
public:
    MyEntityManager(){};
    void CreateEntities()
    {
        //load resources needed for entity here
        m_entities.push_back(std::unique_ptr<MyEntity>(new MyEntity()));
    }
    void Draw(sf::RenderTarget& rt)
    {
        for(auto ent = m_entities.begin(); ent != m_entities.end(); ++ent)
        {
            MyEntity& myEnt = **ent;
            myEnt.Draw(rt);
        }
    };
private:
    std::vector< std::unique_ptr<MyEntity> > m_entities;
};

//---------------------------------------------------------//

MyEntityManager entManager;
std::atomic<bool> loaded(false);
void ThreadFunc()
{
    //load map data here first

    //create entities based on loaded map data
    entManager.CreateEntities();
    loaded = true;
    std::cout << "Thread Quitting" << std::endl;
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(800u, 600u), "rt test");
    //MyEntity ent;

    sf::Thread thread(&ThreadFunc);
    thread.launch();

    while(window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) window.close();
        }

        //draw test item - this works
        /*window.clear();
        ent.Draw(window);
        window.display();*/


        if(loaded) //drawing this doesn't
        {
          window.clear();
          entManager.Draw(window);
          window.display();
        }
    }
    thread.wait();
    return 0;
}

 

This is using the latest SFML compiled from source, and happens using gcc/mingw and VS11 compilers. I've also tested it on WinXP / nVidia GTS450, Vista64 / Radeon 7970 and Win7-64 / Radeon 7750 with latest drivers and they all exhibit the problem.

I've tried putting break points on the render texture's clear/draw call but in debug mode I get 'expression can not be evaluated' and in release mode VS tells me it can't insert a break point there as the compiler has optimised it out...

463
SFML projects / Re: 'Tiled' Tile-map Loader
« on: June 14, 2013, 10:27:18 pm »
Ok so it looks like I made the silly mistake of naming a variable 'or', and there are some missing includes presumably because of VC's precompiled headers or somesuch. If I get time this weekend I'll take a look - I've been planning an update with a quadtree anyway. For now you can try renaming the variable and including cstring (I think, you'll have to look up memcpy)

EDIT: after taking a look this morning I've managed to get this working properly with MinGW / Code::Blocks. To fix it manually simply rename the variable

or

to something else like

orientation

and add

#include <cstring>

in MapLoaderPrivate.cpp. I've also updated the download file so if in doubt just re-downloaded it from my blog post.

464
SFML projects / Re: 'Tiled' Tile-map Loader
« on: June 14, 2013, 03:38:04 pm »
Ah I forgot to mention it uses C++11 features, particularly the auto keyword. In g++ you need to add

-std=c++0x

or

-std=c++11

to the compiler options (I think - I haven't actually tried compiling with anything other than VS10  :-[)

465
SFML projects / Re: 'Tiled' Tile-map Loader
« on: June 14, 2013, 10:35:19 am »
If I were to hazard a guess its because you are using the full path to the map file when the loader expects a path relative to your executable. That being said it also looks like you are using the older version of the map loader - there is a much updated version here which allows you to construct the loader with a path to your map directory, so you only have to pass the map name to the Load function.

Pages: 1 ... 29 30 [31] 32 33