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.
#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.