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

Author Topic: Thread and RenderWindow  (Read 1712 times)

0 Members and 1 Guest are viewing this topic.

valgaba

  • Newbie
  • *
  • Posts: 1
    • View Profile
Thread and RenderWindow
« on: December 14, 2010, 09:20:35 pm »
The code works well but does not appear
image you know why?

Code: [Select]

#ifndef HILO_H_INCLUDED
#define HILO_H_INCLUDED
#include <SFML/System.hpp>
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace sf;





class Hilo: public sf::Thread
{

public :

  Hilo(sf::RenderWindow *app, sf::Image iCual);

    virtual void Run();

    private:

     RenderWindow *App;
     
sf::Sprite Sprite;

};








Code: [Select]
#include <iostream>

#include "Hilo.h"
using namespace sf;


Hilo::Hilo( sf::RenderWindow *app, sf::Image iCual ){



App =  app;



 }






  void Hilo::Run(){

    sf::Image Image;
    Image.LoadFromFile("datas/pong/fo2.jpg");


    // Create the sprite
    sf::Sprite Sprite(Image);

 Sprite.SetPosition(200.f, 100.f);



 while (App->IsOpened())
    {
            std::cout << "I'm the thread number 2" << std::endl;

     App->Clear();
     App->Draw(Sprite);
     App->Display();

    }


 }





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

#include <SFML/Graphics.hpp>
using namespace sf;

//Mutex GlobalMutex; // This mutex will be used to synchronize our threads



#include "Hilo.h"

int main()
{
    // Create the main rendering window
RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Image Image;
    if (!Image.LoadFromFile("datas/pong/fo2.jpg"))
        return EXIT_FAILURE;
   


Hilo *w_Hilo= new Hilo(&App,Image);
 w_Hilo->Launch();



    // Start game loop
    while (App.IsOpened())
    {


        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

     

    return EXIT_SUCCESS;
}



Canadadry

  • Hero Member
  • *****
  • Posts: 1081
    • View Profile
Thread and RenderWindow
« Reply #1 on: December 14, 2010, 10:31:04 pm »
You cannot split the main loop like that. Everything : drawing, event handling... must be done in the same loop.
If you wanna do that on a thread you must call RenderWindow::SetActive(bool).

 

anything