451
General discussions / New Shader class in SFML 2 to replace PostFx
« on: November 17, 2009, 03:41:13 am »
Got it to work by changing the RenderImage to an Image and CopyScreen() instead of the RenderImage functions.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
You do know that you are only drawing once?Yes. I don't change what the screen shows after I draw.
#include <SFML/Graphics.hpp>
int main(){
sf::RenderWindow Window;
Window.Create(sf::VideoMode(512, 512, 32), "Test");
sf::Image Background;
Background.LoadFromFile("Any512x512Image.png");
sf::Sprite BG(Background);
//sf::RenderImage Screen; // Uncomment this line and comment the definition ahead and Flush if you want to test both
if (sf::Shader::IsAvailable()){
sf::RenderImage Screen;
Screen.Draw(BG);
Screen.Display();
Window.Draw(sf::Sprite(Screen.GetImage()));
Window.Flush();
}
else
Window.Draw(BG);
Window.Display();
sf::Event Event;
while (Window.IsOpened()){
while (Window.GetEvent(Event)){
if (Event.Type == sf::Event::Closed)
Window.Close();
if (Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Escape)
Window.Close();
}
}
return EXIT_SUCCESS;
}
Moved the sf::RenderImage's Declaration to outside the if statement, in the context of the Window.Display() code. Black screen. Moved it back inside and added a Window.Flush() to the end of the if statement. Black Screen.QuoteGuess what? I just get a white screen. Why is this? When I replace the Window.Draw line with Window.Draw(BG); it works fine. When I use this code, it absolutely fails. What am I doing wrong? I'm drawing the BG to the RenderImage, Displaying the RenderImage, then drawing the RenderImage to the Screen, and I get White. :S
Your RenderImage instance gets destroyed after the call to Draw; but SFML delays the actual drawing until you call Window.Display(), and at this time the source image doesn't exist anymore.
if (sf::Shader::IsAvailable()){
Water.SetTexture("screen", sf::Shader::CurrentTexture);
Water.SetParameter("time", Clock.GetElapsedTime()*1000.f);
Blend.SetTexture("screen", sf::Shader::CurrentTexture);
Blend.SetParameter("color", 0.5, 0.0, 0.5);
Blend.SetParameter("alpha", 1.0);
sf::RenderImage Screen;
Screen.Draw(BG);
Screen.Display();
Window.Draw(sf::Sprite(Screen.GetImage()));
}
I haven't had any performance troubles on Windows 7. Have those other people updated their drivers?QuoteHmm I thought I was using SFML2.0, but I think it's 1.6 (I'm using the SVN trunk version).
Ok. This bug has been fixed in SFML 2.QuoteMy graphics card doesn't even have a name... It is an integrated one.
Ok, so the 10 FPS might just be your computer
However, one or two other users reported bad performances on Windows 7, and I still haven't found why.
Alright then. Thanks for the help! I switched to sf::Clock and it works perfect!QuoteHere's our repository: http://mke.svn.sourceforge.net/viewvc/mke/
I tried to Shader sample, and it works fine, so I dunno what's going on.
It seems like clock() has a very low resolution on Linux. Using a sf::Clock solves the problem.
Here's our repository: http://mke.svn.sourceforge.net/viewvc/mke/QuoteI updated to SFML 1268, and the glitch with the tearing and blackness is gone, but I still have the lag.
Here's the demo with SFML 1268.
http://willhostforfood.com/access.php?fileid=93440
Use run.sh to use the local .so files.
I couldn't use the local .so files (my system has a problem and needs a modified version of SFML), but I tried shaders with the latest revision:
- the Shader sample runs perfectly
- I can see the lag in your application
Can you show your source code? Did you try the Shader sample?
The sqrt returns a vec3, since the value sent to it is a vec3. vec3s cannot be assigned to floats.Quote from: "OniLink10"float edge = sqrt(hEdge.rgb * hEdge.rgb + vEdge.rgb * vEdge.rgb);
That's some good coding right there.
?
That would work, but he is not using class members, he is just defining the variables.Quote from: "OniLink10"Don't define variables in headers, it's not safe nor sane.
Class members... ?