diff --git a/CSFML/src/SFML/Internal.h b/CSFML/src/SFML/Internal.h index e7c966312..7817aa87d 100644 --- a/CSFML/src/SFML/Internal.h +++ b/CSFML/src/SFML/Internal.h @@ -95,10 +95,10 @@ #define CSFML_CALL_PTR(Object, Function) (Object->This->Function); - #define CSFML_CHECK_RETURN(Object, Default) + #define CSFML_CHECK_RETURN(Object, Default) (void)Default; - #define CSFML_CALL_RETURN(Object, Function, Default) return (Object->This.Function); + #define CSFML_CALL_RETURN(Object, Function, Default) (void)Default; return (Object->This.Function); - #define CSFML_CALL_PTR_RETURN(Object, Function, Default) return (Object->This->Function); + #define CSFML_CALL_PTR_RETURN(Object, Function, Default) (void)Default; return (Object->This->Function); #endif diff --git a/dotnet/samples/bin/datas/opengl/background.jpg b/dotnet/samples/bin/datas/opengl/background.jpg index 5b2247d4e..20724fa92 100644 Binary files a/dotnet/samples/bin/datas/opengl/background.jpg and b/dotnet/samples/bin/datas/opengl/background.jpg differ diff --git a/dotnet/samples/bin/datas/opengl/texture.jpg b/dotnet/samples/bin/datas/opengl/texture.jpg index 455a99fb1..6cf7528eb 100644 Binary files a/dotnet/samples/bin/datas/opengl/texture.jpg and b/dotnet/samples/bin/datas/opengl/texture.jpg differ diff --git a/dotnet/samples/bin/datas/post-fx/background.jpg b/dotnet/samples/bin/datas/post-fx/background.jpg index c778e86bd..f37d7aed0 100644 Binary files a/dotnet/samples/bin/datas/post-fx/background.jpg and b/dotnet/samples/bin/datas/post-fx/background.jpg differ diff --git a/dotnet/samples/bin/datas/post-fx/pixelate.sfx b/dotnet/samples/bin/datas/post-fx/pixelate.sfx new file mode 100644 index 000000000..a1ea9e0d1 --- /dev/null +++ b/dotnet/samples/bin/datas/post-fx/pixelate.sfx @@ -0,0 +1,11 @@ +texture framebuffer +vec2 mouse + +effect +{ + float factor = 5 + 100 * length(mouse); + + vec2 pos = floor(_in * factor) / factor; + + _out = framebuffer(pos); +} diff --git a/dotnet/samples/bin/datas/post-fx/sprite.png b/dotnet/samples/bin/datas/post-fx/sprite.png new file mode 100644 index 000000000..7b508f681 Binary files /dev/null and b/dotnet/samples/bin/datas/post-fx/sprite.png differ diff --git a/dotnet/samples/opengl/OpenGL.cs b/dotnet/samples/opengl/OpenGL.cs index 48b5ab0ab..33a246105 100644 --- a/dotnet/samples/opengl/OpenGL.cs +++ b/dotnet/samples/opengl/OpenGL.cs @@ -28,8 +28,8 @@ namespace sample_opengl // Create a text to display String2D Text = new String2D("This is a rotating cube"); - Text.Position = new Vector2(250.0F, 300.0F); - Text.Color = new Color(128, 0, 128); + Text.Position = new Vector2(250.0F, 450.0F); + Text.Color = new Color(255, 255, 255, 170); // Load an OpenGL texture. // We could directly use a sf::Image as an OpenGL texture (with its Bind() member function), @@ -76,47 +76,52 @@ namespace sample_opengl // Clear depth buffer Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT); + // We get the position of the mouse cursor, so that we can move the box accordingly + float CursorX = App.Input.GetMouseX() * 200.0F / App.Width - 100.0F; + float CursorY = -App.Input.GetMouseY() * 200.0F / App.Height + 100.0F; + // Apply some transformations Time += App.GetFrameTime(); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); - Gl.glTranslatef(0.0F, 0.0F, -200.0F); + Gl.glTranslatef(CursorX, CursorY, -100.0F); Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F); Gl.glRotatef(Time * 30, 0.0F, 1.0F, 0.0F); Gl.glRotatef(Time * 90, 0.0F, 0.0F, 1.0F); // Draw a cube + float Size = 20.0F; Gl.glBegin(Gl.GL_QUADS); - Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F); - Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, -50.0F); - Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F, 50.0F, -50.0F); - Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, -50.0F, -50.0F); + Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-Size, -Size, -Size); + Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-Size, Size, -Size); + Gl.glTexCoord2f(1, 1); Gl.glVertex3f( Size, Size, -Size); + Gl.glTexCoord2f(1, 0); Gl.glVertex3f( Size, -Size, -Size); - Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, 50.0F); - Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F); - Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F, 50.0F, 50.0F); - Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, -50.0F, 50.0F); + Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-Size, -Size, Size); + Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-Size, Size, Size); + Gl.glTexCoord2f(1, 1); Gl.glVertex3f( Size, Size, Size); + Gl.glTexCoord2f(1, 0); Gl.glVertex3f( Size, -Size, Size); - Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F); - Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, -50.0F); - Gl.glTexCoord2f(1, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F); - Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-50.0F, -50.0F, 50.0F); + Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-Size, -Size, -Size); + Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-Size, Size, -Size); + Gl.glTexCoord2f(1, 1); Gl.glVertex3f(-Size, Size, Size); + Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-Size, -Size, Size); - Gl.glTexCoord2f(0, 0); Gl.glVertex3f(50.0F, -50.0F, -50.0F); - Gl.glTexCoord2f(0, 1); Gl.glVertex3f(50.0F, 50.0F, -50.0F); - Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F, 50.0F, 50.0F); - Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, -50.0F, 50.0F); + Gl.glTexCoord2f(0, 0); Gl.glVertex3f(Size, -Size, -Size); + Gl.glTexCoord2f(0, 1); Gl.glVertex3f(Size, Size, -Size); + Gl.glTexCoord2f(1, 1); Gl.glVertex3f(Size, Size, Size); + Gl.glTexCoord2f(1, 0); Gl.glVertex3f(Size, -Size, Size); - Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, -50.0F, 50.0F); - Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F); - Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, -50.0F, -50.0F); - Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F, -50.0F, 50.0F); + Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-Size, -Size, Size); + Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-Size, -Size, -Size); + Gl.glTexCoord2f(1, 0); Gl.glVertex3f( Size, -Size, -Size); + Gl.glTexCoord2f(1, 1); Gl.glVertex3f( Size, -Size, Size); - Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F); - Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, 50.0F, -50.0F); - Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, 50.0F, -50.0F); - Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F, 50.0F, 50.0F); + Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-Size, Size, Size); + Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-Size, Size, -Size); + Gl.glTexCoord2f(1, 0); Gl.glVertex3f( Size, Size, -Size); + Gl.glTexCoord2f(1, 1); Gl.glVertex3f( Size, Size, Size); Gl.glEnd(); diff --git a/dotnet/samples/post-fx/PostFx.cs b/dotnet/samples/post-fx/PostFx.cs index 3a93932e1..b196102df 100644 --- a/dotnet/samples/post-fx/PostFx.cs +++ b/dotnet/samples/post-fx/PostFx.cs @@ -31,9 +31,12 @@ namespace sample_postfx return; } - // Load a cute background image to display :) + // Load a background image to display Sprite Background = new Sprite(new Image("datas/post-fx/background.jpg")); + // Load a sprite which we'll move into the scene + Sprite Entity = new Sprite(new Image("datas/post-fx/sprite.png")); + // Load the text font Font Cheeseburger = new Font("datas/post-fx/cheeseburger.ttf"); @@ -47,6 +50,7 @@ namespace sample_postfx Effects["colorize"] = new PostFx("datas/post-fx/colorize.sfx"); Effects["fisheye"] = new PostFx("datas/post-fx/fisheye.sfx"); Effects["wave"] = new PostFx("datas/post-fx/wave.sfx"); + Effects["pixelate"] = new PostFx("datas/post-fx/pixelate.sfx"); CurrentEffect = Effects.GetEnumerator(); CurrentEffect.MoveNext(); @@ -59,12 +63,14 @@ namespace sample_postfx Effects["fisheye"].SetTexture("framebuffer", null); Effects["wave"].SetTexture("framebuffer", null); Effects["wave"].SetTexture("wave", WaveImage); + Effects["pixelate"].SetTexture("framebuffer", null); // Define a string for displaying current effect description CurFXStr = new String2D(); CurFXStr.Text = "Current effect is \"" + CurrentEffect.Current.Key + "\""; CurFXStr.Font = Cheeseburger; CurFXStr.Position = new Vector2(20.0F, 0.0F); + CurFXStr.Color = new Color(150, 70, 110); // Define a string for displaying help String2D InfoStr = new String2D(); @@ -74,6 +80,7 @@ namespace sample_postfx InfoStr.Color = new Color(200, 100, 150); // Start the game loop + float AppTime = 0.0F; while (App.IsOpened()) { // Process events @@ -88,12 +95,21 @@ namespace sample_postfx else if (CurrentEffect.Current.Key == "colorize") CurrentEffect.Current.Value.SetParameter("color", 0.3f, X, Y); else if (CurrentEffect.Current.Key == "fisheye") CurrentEffect.Current.Value.SetParameter("mouse", X, 1.0F - Y); else if (CurrentEffect.Current.Key == "wave") CurrentEffect.Current.Value.SetParameter("offset", X, Y); + else if (CurrentEffect.Current.Key == "pixelate") CurrentEffect.Current.Value.SetParameter("mouse", X, Y); + + // Animate the sprite + AppTime += App.GetFrameTime(); + float EntityX = (float)(Math.Cos(AppTime * 1.3) + 1.2) * 300; + float EntityY = (float)(Math.Cos(AppTime * 0.8) + 1.2) * 200; + Entity.Position = new Vector2(EntityX, EntityY); + Entity.Rotation = AppTime * 100; // Clear the window App.Clear(); - // Draw background and apply the post-fx + // Draw background, the sprite and apply the post-fx App.Draw(Background); + App.Draw(Entity); App.Draw(CurrentEffect.Current.Value); // Draw interface strings diff --git a/samples/bin/datas/opengl/background.jpg b/samples/bin/datas/opengl/background.jpg index 5b2247d4e..20724fa92 100644 Binary files a/samples/bin/datas/opengl/background.jpg and b/samples/bin/datas/opengl/background.jpg differ diff --git a/samples/bin/datas/opengl/texture.jpg b/samples/bin/datas/opengl/texture.jpg index 455a99fb1..6cf7528eb 100644 Binary files a/samples/bin/datas/opengl/texture.jpg and b/samples/bin/datas/opengl/texture.jpg differ diff --git a/samples/bin/datas/post-fx/background.jpg b/samples/bin/datas/post-fx/background.jpg index c778e86bd..f37d7aed0 100644 Binary files a/samples/bin/datas/post-fx/background.jpg and b/samples/bin/datas/post-fx/background.jpg differ diff --git a/samples/bin/datas/post-fx/pixelate.sfx b/samples/bin/datas/post-fx/pixelate.sfx new file mode 100644 index 000000000..a1ea9e0d1 --- /dev/null +++ b/samples/bin/datas/post-fx/pixelate.sfx @@ -0,0 +1,11 @@ +texture framebuffer +vec2 mouse + +effect +{ + float factor = 5 + 100 * length(mouse); + + vec2 pos = floor(_in * factor) / factor; + + _out = framebuffer(pos); +} diff --git a/samples/bin/datas/post-fx/sprite.png b/samples/bin/datas/post-fx/sprite.png new file mode 100644 index 000000000..7b508f681 Binary files /dev/null and b/samples/bin/datas/post-fx/sprite.png differ diff --git a/samples/opengl/OpenGL.cpp b/samples/opengl/OpenGL.cpp index b08a549a6..098043d3a 100644 --- a/samples/opengl/OpenGL.cpp +++ b/samples/opengl/OpenGL.cpp @@ -26,7 +26,7 @@ int main() // Load an OpenGL texture. // We could directly use a sf::Image as an OpenGL texture (with its Bind() member function), - // but here we want more control on it (generate mipmaps, ...) so we create a new one + // but here we want more control on it (generate mipmaps, ...) so we create a new one from the image pixels GLuint Texture = 0; { sf::Image Image; @@ -83,53 +83,58 @@ int main() // Clear depth buffer glClear(GL_DEPTH_BUFFER_BIT); + // We get the position of the mouse cursor, so that we can move the box accordingly + float CursorX = App.GetInput().GetMouseX() * 200.f / App.GetWidth() - 100.f; + float CursorY = -App.GetInput().GetMouseY() * 200.f / App.GetHeight() + 100.f; + // Apply some transformations glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0.f, 0.f, -200.f); + glTranslatef(CursorX, CursorY, -100.f); glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f); glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f); glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f); // Draw a cube + float Size = 20.f; glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f); - glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f, -50.f); - glTexCoord2f(1, 1); glVertex3f( 50.f, 50.f, -50.f); - glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, -50.f); + glTexCoord2f(0, 0); glVertex3f(-Size, -Size, -Size); + glTexCoord2f(0, 1); glVertex3f(-Size, Size, -Size); + glTexCoord2f(1, 1); glVertex3f( Size, Size, -Size); + glTexCoord2f(1, 0); glVertex3f( Size, -Size, -Size); - glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, 50.f); - glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f, 50.f); - glTexCoord2f(1, 1); glVertex3f( 50.f, 50.f, 50.f); - glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, 50.f); + glTexCoord2f(0, 0); glVertex3f(-Size, -Size, Size); + glTexCoord2f(0, 1); glVertex3f(-Size, Size, Size); + glTexCoord2f(1, 1); glVertex3f( Size, Size, Size); + glTexCoord2f(1, 0); glVertex3f( Size, -Size, Size); - glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f); - glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f, -50.f); - glTexCoord2f(1, 1); glVertex3f(-50.f, 50.f, 50.f); - glTexCoord2f(1, 0); glVertex3f(-50.f, -50.f, 50.f); + glTexCoord2f(0, 0); glVertex3f(-Size, -Size, -Size); + glTexCoord2f(0, 1); glVertex3f(-Size, Size, -Size); + glTexCoord2f(1, 1); glVertex3f(-Size, Size, Size); + glTexCoord2f(1, 0); glVertex3f(-Size, -Size, Size); - glTexCoord2f(0, 0); glVertex3f(50.f, -50.f, -50.f); - glTexCoord2f(0, 1); glVertex3f(50.f, 50.f, -50.f); - glTexCoord2f(1, 1); glVertex3f(50.f, 50.f, 50.f); - glTexCoord2f(1, 0); glVertex3f(50.f, -50.f, 50.f); + glTexCoord2f(0, 0); glVertex3f(Size, -Size, -Size); + glTexCoord2f(0, 1); glVertex3f(Size, Size, -Size); + glTexCoord2f(1, 1); glVertex3f(Size, Size, Size); + glTexCoord2f(1, 0); glVertex3f(Size, -Size, Size); - glTexCoord2f(0, 1); glVertex3f(-50.f, -50.f, 50.f); - glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f); - glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, -50.f); - glTexCoord2f(1, 1); glVertex3f( 50.f, -50.f, 50.f); + glTexCoord2f(0, 1); glVertex3f(-Size, -Size, Size); + glTexCoord2f(0, 0); glVertex3f(-Size, -Size, -Size); + glTexCoord2f(1, 0); glVertex3f( Size, -Size, -Size); + glTexCoord2f(1, 1); glVertex3f( Size, -Size, Size); - glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f, 50.f); - glTexCoord2f(0, 0); glVertex3f(-50.f, 50.f, -50.f); - glTexCoord2f(1, 0); glVertex3f( 50.f, 50.f, -50.f); - glTexCoord2f(1, 1); glVertex3f( 50.f, 50.f, 50.f); + glTexCoord2f(0, 1); glVertex3f(-Size, Size, Size); + glTexCoord2f(0, 0); glVertex3f(-Size, Size, -Size); + glTexCoord2f(1, 0); glVertex3f( Size, Size, -Size); + glTexCoord2f(1, 1); glVertex3f( Size, Size, Size); glEnd(); // Draw some text on top of our OpenGL object - sf::String Text("This is a rotating cube"); - Text.SetPosition(250.f, 300.f); - Text.SetColor(sf::Color(128, 0, 128)); + sf::String Text("SFML / OpenGL demo"); + Text.SetPosition(250.f, 450.f); + Text.SetColor(sf::Color(255, 255, 255, 170)); App.Draw(Text); // Finally, display the rendered frame on screen diff --git a/samples/post-fx/PostFX.cpp b/samples/post-fx/PostFX.cpp index 8a3e4bc03..6229a3c5d 100644 --- a/samples/post-fx/PostFX.cpp +++ b/samples/post-fx/PostFX.cpp @@ -4,6 +4,7 @@ //////////////////////////////////////////////////////////// #include #include +#include void DisplayError(); @@ -26,12 +27,18 @@ int main() // Create the main window sf::RenderWindow App(sf::VideoMode(800, 600), "SFML PostFX"); - // Load a cute background image to display :) + // Load a background image to display sf::Image BackgroundImage; if (!BackgroundImage.LoadFromFile("datas/post-fx/background.jpg")) return EXIT_FAILURE; sf::Sprite Background(BackgroundImage); + // Load a sprite which we'll move into the scene + sf::Image EntityImage; + if (!EntityImage.LoadFromFile("datas/post-fx/sprite.png")) + return EXIT_FAILURE; + sf::Sprite Entity(EntityImage); + // Load the text font sf::Font Cheeseburger; if (!Cheeseburger.LoadFromFile("datas/post-fx/cheeseburger.ttf")) @@ -49,6 +56,7 @@ int main() if (!Effects["colorize"].LoadFromFile("datas/post-fx/colorize.sfx")) return EXIT_FAILURE; if (!Effects["fisheye"].LoadFromFile("datas/post-fx/fisheye.sfx")) return EXIT_FAILURE; if (!Effects["wave"].LoadFromFile("datas/post-fx/wave.sfx")) return EXIT_FAILURE; + if (!Effects["pixelate"].LoadFromFile("datas/post-fx/pixelate.sfx")) return EXIT_FAILURE; std::map::iterator CurrentEffect = Effects.find("nothing"); // Do specific initializations @@ -60,12 +68,14 @@ int main() Effects["fisheye"].SetTexture("framebuffer", NULL); Effects["wave"].SetTexture("framebuffer", NULL); Effects["wave"].SetTexture("wave", &WaveImage); + Effects["pixelate"].SetTexture("framebuffer", NULL); // Define a string for displaying current effect description sf::String CurFXStr; CurFXStr.SetText("Current effect is \"" + CurrentEffect->first + "\""); CurFXStr.SetFont(Cheeseburger); CurFXStr.SetPosition(20.f, 0.f); + CurFXStr.SetColor(sf::Color(150, 70, 110)); // Define a string for displaying help sf::String InfoStr; @@ -74,6 +84,9 @@ int main() InfoStr.SetPosition(20.f, 460.f); InfoStr.SetColor(sf::Color(200, 100, 150)); + // Create a clock to measure the total time elapsed + sf::Clock Clock; + // Start the game loop while (App.IsOpened()) { @@ -116,16 +129,24 @@ int main() float Y = App.GetInput().GetMouseY() / static_cast(App.GetHeight()); // Update the current effect - if (CurrentEffect->first == "blur") CurrentEffect->second.SetParameter("offset", X * Y * 0.1f); + if (CurrentEffect->first == "blur") CurrentEffect->second.SetParameter("offset", X * Y * 0.05f); else if (CurrentEffect->first == "colorize") CurrentEffect->second.SetParameter("color", 0.3f, X, Y); else if (CurrentEffect->first == "fisheye") CurrentEffect->second.SetParameter("mouse", X, 1.f - Y); else if (CurrentEffect->first == "wave") CurrentEffect->second.SetParameter("offset", X, Y); + else if (CurrentEffect->first == "pixelate") CurrentEffect->second.SetParameter("mouse", X, Y); + + // Animate the sprite + float EntityX = (cos(Clock.GetElapsedTime() * 1.3f) + 1.2f) * 300; + float EntityY = (cos(Clock.GetElapsedTime() * 0.8f) + 1.2f) * 200; + Entity.SetPosition(EntityX, EntityY); + Entity.Rotate(App.GetFrameTime() * 100); // Clear the window App.Clear(); - // Draw background and apply the post-fx + // Draw background, sprite and apply the post-fx App.Draw(Background); + App.Draw(Entity); App.Draw(CurrentEffect->second); // Draw interface strings