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

Author Topic: Okno.Capture() - it takes too much time  (Read 1231 times)

0 Members and 1 Guest are viewing this topic.

Dawidsoni

  • Newbie
  • *
  • Posts: 6
    • View Profile
Okno.Capture() - it takes too much time
« on: January 25, 2012, 07:40:21 pm »
Hi! I did gray-scale effect in SFML 1.6, but it works too slowly (half second).
Here is the code:
Code: [Select]
void odcien::zrob_obraz(unsigned int x1,unsigned int y1,unsigned int szerokosc,unsigned int wysokosc, RenderWindow & Okno_) {
Okno = &Okno_;
czy_okno = true;
m = Okno_.Capture();
Color stary;
for(int i=y1;i<wysokosc;i++) {
for(int ii=x1;ii<szerokosc;ii++) {
stary = m.GetPixel(ii,i);
int ile = (stary.r + stary.g + stary.b)/3;
if(ile==0)
ile = 1;
m.SetPixel(ii,i,Color(ile * w_r,ile * w_g,ile * w_b));
}
}
sprajt.SetImage(m);
sprajt.SetSubRect(IntRect(x1,y1,x1 + szerokosc, y1 + wysokosc));
sprajt.SetPosition(x1,y1);
Okno_.Draw(sprajt);
Okno_.Display();
}


Problem is a function: Okno.Capture() - it takes 0.4 second!

Class RenderWindow hasn't function SetPixel(). What can I do to make this algorithm run faster?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Okno.Capture() - it takes too much time
« Reply #1 on: January 25, 2012, 11:01:37 pm »
Use a shader!
Laurent Gomila - SFML developer

Dawidsoni

  • Newbie
  • *
  • Posts: 6
    • View Profile
Okno.Capture() - it takes too much time
« Reply #2 on: January 26, 2012, 05:31:14 pm »
How to use a shader? Can you give me example?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Okno.Capture() - it takes too much time
« Reply #3 on: January 26, 2012, 05:57:57 pm »
Look at the doc and tutorials.
Laurent Gomila - SFML developer