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

Author Topic: Alternative to window.Capture()  (Read 4585 times)

0 Members and 1 Guest are viewing this topic.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Alternative to window.Capture()
« on: March 05, 2012, 03:39:20 pm »
I need a good alternative to window.Capture(). This function take 0.5s to take image, i need a faster function to do the same!
I read a topic where laurent said "shader" can do this!
But i can't find a good tutorial or topic that explain how put in image/texture/sprite what i see in window!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Alternative to window.Capture()
« Reply #1 on: March 05, 2012, 03:58:43 pm »
Instead of drawing to the window and then capturing its contents to a texture, draw to a texture directly (sf::RenderTexture).

Shaders can change what's being drawn, they can't help reading what's already drawn.
Laurent Gomila - SFML developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Alternative to window.Capture()
« Reply #2 on: March 05, 2012, 04:36:02 pm »
Is it normal render texture takes 832 ms to create itself?
I use
Code: [Select]
sf::RenderTexture render;
Clock.Restart();
render.Create(1024,768);
std::cout << gameClock.GetElapsedTime().AsMilliseconds() <<std::endl;

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Alternative to window.Capture()
« Reply #3 on: March 05, 2012, 10:30:00 pm »
Try creating it once, then just printing on it at each frame.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Alternative to window.Capture()
« Reply #4 on: March 05, 2012, 10:42:41 pm »
Quote from: "Tex Killer"
Try creating it once, then just printing on it at each frame.

It's what i do! I've a class and i create that RenderTexture into the class costructor (called 1 time of course), but when i switch window (menu->game f.e.) it take a bit more than if i render with normal RenderWindow. Maybe i write a bad code, but it's my first full project that i want ot complete, bad-written or not :lol:

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Alternative to window.Capture()
« Reply #5 on: March 05, 2012, 11:36:54 pm »
Check if you are re-constructing your object, thus re-creating the RenderTexture.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Alternative to window.Capture()
« Reply #6 on: March 06, 2012, 12:07:21 am »
Quote from: "Tex Killer"
Check if you are re-constructing your object, thus re-creating the RenderTexture.

Code: [Select]

int main(){
sf::RenderWindow App(sf::VideoMode(1024,768,32),"SFML Project",sf::Style::Close);
App.ShowMouseCursor(false);
Game myGame;
myGame.Run(App);
return 0;
}

I'm sure i 'm not re-costructing my Game object

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Alternative to window.Capture()
« Reply #7 on: March 06, 2012, 12:15:19 am »
It's hard to know what is the issue without knowing how your Game class works.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Alternative to window.Capture()
« Reply #8 on: March 06, 2012, 12:47:36 pm »
Try a minimal example involving only a RenderTexture instance, no Game or whatever. Will be much faster to test than your big project ;)
Laurent Gomila - SFML developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Alternative to window.Capture()
« Reply #9 on: March 09, 2012, 12:06:36 am »
I found that in Release mode capture() is really fast, a lot faster than debug :) So i don't need anymore to use RenderTexture :)

 

anything