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

Author Topic: Render in one thread, load and manipulate Sprites in another, doesnt draw...  (Read 2543 times)

0 Members and 1 Guest are viewing this topic.

Alia5

  • Newbie
  • *
  • Posts: 34
    • View Profile
Hi there,

I have seperate render-class of wich one function runs in a seperate sf::Thread to draw...
In another thread i want to load my textures and sprites, and manipulate them there

So far so good.

but if i want to load a texture, i have to activate the window in the thread i want to load the texture, wich would pause rendering.

so...
Something like this works:
// create the window
//...

//set up the renderclass
Render renderer;
renderer.setwindow.....
...
//load textures and set up sprites...
//copy them into render class
window.setActive(false);
sf::Thread renderthr(&Render::renderthread, &render);   // create our renderer-thread
renderthr.launch();   //start the renderer


and something like this gives me a blank screen and doesn't draw anything
// create the window
//...
window.setActive(false);
//set up the renderclass
Render renderer;
renderer.setwindow.....
...
//load textures and set up sprites...
//copy them into render class
sf::Thread renderthr(&Render::renderthread, &render);   // create our renderer-thread
renderthr.launch();   //start the renderer

i hope this is enough code to explain my problem...
basically something like
renderer.pause(true);
window.setactive(true);
//loadmytexture and create the sprite
//copy the sprity into the rendererclass
window.setactive(false);
renderer.pause(false);
 
would work but that is suboptimal...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
You don't need to use the window's context, you can use a new one. There is the sf::Context class but you shouldn't even need it, when you load a texture SFML automatically instanciates a context if there's none in the current thread.
Laurent Gomila - SFML developer

Alia5

  • Newbie
  • *
  • Posts: 34
    • View Profile
Dang -.- ...
Had to set the same context in both threads and now it works like charm...

What you mean with "You don't need to use the window's context, you can use a new one."
If it automatically creates a new context, then it draws nothing, which was my problem.
Well, anyways you helped me out! Thank you! :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
What you mean with "You don't need to use the window's context, you can use a new one."
If it automatically creates a new context, then it draws nothing, which was my problem.
To be honest, I didn't understand what you're doing after looking at the code you've posted. So sorry if my answers are not accurate.

What I'm saying is that if you need a context to load resources, you don't need to use the window's one. You can leave your rendering thread to what it's doing and use another context in the loading thread. If you use SFML classes you don't even need to do anything because SFML takes care of that.
Laurent Gomila - SFML developer

Alia5

  • Newbie
  • *
  • Posts: 34
    • View Profile
I hoped that you understand, but well it's no problem ;)

You're right... i dunno what i had in code before but now it works.. o.O

i should sleep more

sorry for wasting time...

edit: found my already solved problem... i also have top copy the textures somewhere in the renderring-class
seems like textures aren't completely stored in sprites...
« Last Edit: July 16, 2013, 01:40:13 am by Alia5 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
seems like textures aren't completely stored in sprites...
They are not, and the doc/tutorials clearly mentions it.
Laurent Gomila - SFML developer

 

anything