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

Author Topic: Thread Background Display  (Read 3313 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Thread Background Display
« on: September 09, 2010, 04:32:44 am »
I've been trying to get a background picture to display inside my secondary window in my secondary thread. It won't display anything when I move the file loading into main(), but if I put the file loading into my thread I get the void conversion error. I've tried changing the void to an int, but it won't accept that.

Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>

using std::string;
using std::ios;
using std::ofstream;
using std::ifstream;

using std::cin;
using std::cout;
using std::endl;

void extraWindow(void *UserData)
{
    sf::Image BackImage2;
    if (!BackImage2.LoadFromFile("Images/Fire.bmp"))
        return EXIT_FAILURE;
    sf::Sprite BackG2(BackImage2);

    sf::RenderWindow App2(sf::VideoMode(1280, 720, 32), "Laz's Interactive Map :: The Wrath... :: PvP Created");

    sf::Vector2f CenterBack(960, 540);
    sf::Vector2f HalfBack(480, 270);
    sf::View BackgroundTh(CenterBack, HalfBack);
    BackgroundTh.Zoom(0.5f);

    while (App2.IsOpened())
    {
        sf::Event ThreadEvent;
        while (App2.GetEvent(ThreadEvent))
        {
            // Close window : exit
            if (ThreadEvent.Type == sf::Event::Closed)
                App2.Close();

            // Press escape : exit
            if ((ThreadEvent.Type == sf::Event::KeyPressed) && (ThreadEvent.Key.Code == sf::Key::Escape))
                App2.Close();
        }

        App2.SetView(BackgroundTh);
            App2.Draw(BackG2);

    }
}



int main()
{
    sf::RenderWindow App(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");

    //Thread Stuff
    bool thread = false;
    sf::Thread Window(extraWindow);

    // Main loop
    while (App.IsOpened())
    {
        // Event loop
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F2)) {
                thread = true;
                Window.Launch();
            }

            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Press escape : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();

        }
    }

            App.Display();

    return 0;
}


This code is very watered down from my original. It recreates the same problem though.
-Wander

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Thread Background Display
« Reply #1 on: September 09, 2010, 08:41:18 am »
I have never used SFML's threading, but from what I can see from the docs, don't you need to call Thread.Launch() to actually start the thread?

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Re: Thread Background Display
« Reply #2 on: September 09, 2010, 09:06:01 am »
The
Code: [Select]
thread = true;
Window.Launch();
is doing it ;)

I think maybe you can use a App2.Display(), no ?
Mindiell
----

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Thread Background Display
« Reply #3 on: September 09, 2010, 02:56:35 pm »
WOW! How could I forget the App2.Display(). I feel like a total moron.

But I don't how this messes it up:
Code: [Select]
thread = true;
Window.Launch();
-Wander

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Thread Background Display
« Reply #4 on: September 10, 2010, 08:43:32 am »
I was just answering to Spodi, who was asking to launch the Thread ;)
Mindiell
----

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Thread Background Display
« Reply #5 on: September 10, 2010, 09:18:10 am »
What can I say, I suck at reading code that isn't color-coded. IDEs have spoiled me. :P