SFML community forums

Help => Graphics => Topic started by: Dawidsoni on January 25, 2012, 07:40:21 pm

Title: Okno.Capture() - it takes too much time
Post by: Dawidsoni 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?
Title: Okno.Capture() - it takes too much time
Post by: Laurent on January 25, 2012, 11:01:37 pm
Use a shader!
Title: Okno.Capture() - it takes too much time
Post by: Dawidsoni on January 26, 2012, 05:31:14 pm
How to use a shader? Can you give me example?
Title: Okno.Capture() - it takes too much time
Post by: Laurent on January 26, 2012, 05:57:57 pm
Look at the doc and tutorials.