diff --git a/dotnet/examples/bin/datas/opengl/background.jpg b/dotnet/examples/bin/datas/opengl/background.jpg new file mode 100644 index 00000000..20724fa9 Binary files /dev/null and b/dotnet/examples/bin/datas/opengl/background.jpg differ diff --git a/dotnet/examples/bin/datas/opengl/texture.jpg b/dotnet/examples/bin/datas/opengl/texture.jpg new file mode 100644 index 00000000..6cf7528e Binary files /dev/null and b/dotnet/examples/bin/datas/opengl/texture.jpg differ diff --git a/dotnet/examples/bin/datas/shader/arial.ttf b/dotnet/examples/bin/datas/shader/arial.ttf new file mode 100644 index 00000000..ff0815cd Binary files /dev/null and b/dotnet/examples/bin/datas/shader/arial.ttf differ diff --git a/dotnet/examples/bin/datas/shader/background.jpg b/dotnet/examples/bin/datas/shader/background.jpg new file mode 100644 index 00000000..f37d7aed Binary files /dev/null and b/dotnet/examples/bin/datas/shader/background.jpg differ diff --git a/dotnet/examples/bin/datas/shader/blur.sfx b/dotnet/examples/bin/datas/shader/blur.sfx new file mode 100644 index 00000000..4c9f1128 --- /dev/null +++ b/dotnet/examples/bin/datas/shader/blur.sfx @@ -0,0 +1,16 @@ +uniform sampler2D texture; +uniform float offset; + +void main() +{ + vec2 offx = vec2(offset, 0.0); + vec2 offy = vec2(0.0, offset); + + vec4 c0 = texture2D(texture, gl_TexCoord[0].xy); + vec4 c1 = texture2D(texture, gl_TexCoord[0].xy - offy); + vec4 c2 = texture2D(texture, gl_TexCoord[0].xy + offy); + vec4 c3 = texture2D(texture, gl_TexCoord[0].xy - offx); + vec4 c4 = texture2D(texture, gl_TexCoord[0].xy + offx); + + gl_FragColor = gl_Color * (c0 * 0.2 + c1 * 0.2 + c2 * 0.2 + c3 * 0.2 + c4 * 0.2); +} diff --git a/dotnet/examples/bin/datas/shader/colorize.sfx b/dotnet/examples/bin/datas/shader/colorize.sfx new file mode 100644 index 00000000..eeb407c8 --- /dev/null +++ b/dotnet/examples/bin/datas/shader/colorize.sfx @@ -0,0 +1,11 @@ +uniform sampler2D texture; +uniform vec3 color; + +void main() +{ + vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * gl_Color; + float gray = pixel.r * 0.39 + pixel.g * 0.50 + pixel.b * 0.11; + + gl_FragColor = vec4(gray * color, 1.0) * 0.6 + pixel * 0.4; + gl_FragColor.a = pixel.a; +} diff --git a/dotnet/examples/bin/datas/shader/fisheye.sfx b/dotnet/examples/bin/datas/shader/fisheye.sfx new file mode 100644 index 00000000..97e3f8e4 --- /dev/null +++ b/dotnet/examples/bin/datas/shader/fisheye.sfx @@ -0,0 +1,13 @@ +uniform sampler2D texture; +uniform vec2 mouse; + +void main() +{ + float len = distance(gl_TexCoord[0].xy, mouse) * 7.0; + + vec2 coords = gl_TexCoord[0].xy; + if (len < 1.0) + coords += (gl_TexCoord[0].xy - mouse) * len; + + gl_FragColor = texture2D(texture, coords) * gl_Color; +} diff --git a/dotnet/examples/bin/datas/shader/nothing.sfx b/dotnet/examples/bin/datas/shader/nothing.sfx new file mode 100644 index 00000000..cde0473a --- /dev/null +++ b/dotnet/examples/bin/datas/shader/nothing.sfx @@ -0,0 +1,6 @@ +uniform sampler2D texture; + +void main() +{ + gl_FragColor = texture2D(texture, gl_TexCoord[0].xy) * gl_Color; +} diff --git a/dotnet/examples/bin/datas/shader/pixelate.sfx b/dotnet/examples/bin/datas/shader/pixelate.sfx new file mode 100644 index 00000000..5b82f08d --- /dev/null +++ b/dotnet/examples/bin/datas/shader/pixelate.sfx @@ -0,0 +1,10 @@ +uniform sampler2D texture; +uniform vec2 mouse; + +void main() +{ + float factor = 5 + 100 * length(mouse); + vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor; + + gl_FragColor = texture2D(texture, pos) * gl_Color; +} diff --git a/dotnet/examples/bin/datas/shader/sprite.png b/dotnet/examples/bin/datas/shader/sprite.png new file mode 100644 index 00000000..7b508f68 Binary files /dev/null and b/dotnet/examples/bin/datas/shader/sprite.png differ diff --git a/dotnet/examples/bin/datas/shader/wave.jpg b/dotnet/examples/bin/datas/shader/wave.jpg new file mode 100644 index 00000000..cd125b8c Binary files /dev/null and b/dotnet/examples/bin/datas/shader/wave.jpg differ diff --git a/dotnet/examples/bin/datas/shader/wave.sfx b/dotnet/examples/bin/datas/shader/wave.sfx new file mode 100644 index 00000000..2d04763a --- /dev/null +++ b/dotnet/examples/bin/datas/shader/wave.sfx @@ -0,0 +1,12 @@ +uniform sampler2D texture; +uniform sampler2D wave; +uniform vec2 offset; + +void main() +{ + vec2 texoffset = texture2D(wave, (gl_TexCoord[0].xy * offset).xy); + texoffset -= vec2(0.5, 0.5); + texoffset *= 0.05; + + gl_FragColor = texture2D(texture, gl_TexCoord[0].xy + texoffset) * gl_Color; +} diff --git a/dotnet/examples/bin/datas/sound/canary.wav b/dotnet/examples/bin/datas/sound/canary.wav new file mode 100644 index 00000000..a0f3aecc Binary files /dev/null and b/dotnet/examples/bin/datas/sound/canary.wav differ diff --git a/dotnet/examples/bin/datas/sound/orchestral.ogg b/dotnet/examples/bin/datas/sound/orchestral.ogg new file mode 100644 index 00000000..f764d61d Binary files /dev/null and b/dotnet/examples/bin/datas/sound/orchestral.ogg differ diff --git a/dotnet/examples/opengl/OpenGL.cs b/dotnet/examples/opengl/OpenGL.cs new file mode 100644 index 00000000..4df1c10f --- /dev/null +++ b/dotnet/examples/opengl/OpenGL.cs @@ -0,0 +1,174 @@ +using System; +using SFML; +using SFML.Graphics; +using SFML.Window; +using Tao.OpenGl; + +namespace sample_opengl +{ + static class Program + { + /// + /// The main entry point for the application. + /// + static void Main() + { + // Create main window + RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL"); + + // Setup event handlers + window.Closed += new EventHandler(OnClosed); + window.KeyPressed += new EventHandler(OnKeyPressed); + window.Resized += new EventHandler(OnResized); + + // Create a sprite for the background + Image backgroundImage = new Image("datas/opengl/background.jpg"); + Sprite background = new Sprite(backgroundImage); + + // Create a text to display + Text text = new Text("SFML / OpenGL demo"); + 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), + // but here we want more control on it (generate mipmaps, ...) so we create a new one + int texture = 0; + using (Image image = new Image("datas/opengl/texture.jpg")) + { + Gl.glGenTextures(1, out texture); + Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture); + Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, (int)image.Width, (int)image.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.Pixels); + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR); + } + + // Enable Z-buffer read and write + Gl.glEnable(Gl.GL_DEPTH_TEST); + Gl.glDepthMask(Gl.GL_TRUE); + Gl.glClearDepth(1.0F); + + // Setup a perspective projection + Gl.glMatrixMode(Gl.GL_PROJECTION); + Gl.glLoadIdentity(); + Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F); + + // Bind our texture + Gl.glEnable(Gl.GL_TEXTURE_2D); + Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture); + Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + float time = 0.0F; + + // Start game loop + while (window.IsOpened()) + { + // Process events + window.DispatchEvents(); + + // Clear the window + window.Clear(); + + // Draw background + window.SaveGLStates(); + window.Draw(background); + window.RestoreGLStates(); + + // Activate the window before using OpenGL commands. + // This is useless here because we have only one window which is + // always the active one, but don't forget it if you use multiple windows + window.SetActive(); + + // 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 x = window.Input.GetMouseX() * 200.0F / window.Width - 100.0F; + float y = -window.Input.GetMouseY() * 200.0F / window.Height + 100.0F; + + // Apply some transformations + time += window.GetFrameTime(); + Gl.glMatrixMode(Gl.GL_MODELVIEW); + Gl.glLoadIdentity(); + Gl.glTranslatef(x, y, -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(-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(-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(-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(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(-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(-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(); + + // Draw some text on top of our OpenGL object + window.SaveGLStates(); + window.Draw(text); + window.RestoreGLStates(); + + // Finally, display the rendered frame on screen + window.Display(); + } + + // Don't forget to destroy our texture + Gl.glDeleteTextures(1, ref texture); + } + + /// + /// Function called when the window is closed + /// + static void OnClosed(object sender, EventArgs e) + { + RenderWindow window = (RenderWindow)sender; + window.Close(); + } + + /// + /// Function called when a key is pressed + /// + static void OnKeyPressed(object sender, KeyEventArgs e) + { + RenderWindow window = (RenderWindow)sender; + if (e.Code == KeyCode.Escape) + window.Close(); + } + + /// + /// Function called when the window is resized + /// + static void OnResized(object sender, SizeEventArgs e) + { + Gl.glViewport(0, 0, (int)e.Width, (int)e.Height); + } + } +} diff --git a/dotnet/examples/opengl/sample-opengl.csproj b/dotnet/examples/opengl/sample-opengl.csproj new file mode 100644 index 00000000..bb79e4b6 --- /dev/null +++ b/dotnet/examples/opengl/sample-opengl.csproj @@ -0,0 +1,72 @@ + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {160AE11E-138A-4B77-9642-EA74F9A79B4D} + WinExe + Properties + sample_opengl + opengl + + + + + 2.0 + + + + + true + full + false + ..\bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\bin\ + TRACE + prompt + 4 + + + + {46786269-57B9-48E7-AA4F-8F4D84609FE6} + sfml-graphics + + + {D17DE83D-A592-461F-8AF2-53F9E22E1D0F} + sfml-window + + + + + + + + + False + ..\..\..\..\..\Bibliothèques\TaoFramework\bin\Tao.FreeGlut.dll + + + False + ..\..\..\..\..\Bibliothèques\TaoFramework\bin\Tao.OpenGl.dll + + + + + + + + \ No newline at end of file diff --git a/dotnet/examples/shader/Shader.cs b/dotnet/examples/shader/Shader.cs new file mode 100644 index 00000000..3ded018b --- /dev/null +++ b/dotnet/examples/shader/Shader.cs @@ -0,0 +1,250 @@ +using System; +using System.Collections.Generic; +using SFML; +using SFML.Graphics; +using SFML.Window; + +namespace sample_shader +{ + /// + /// A class to simplify shader selection + /// + class ShaderSelector + { + // Constructor + public ShaderSelector(Dictionary owner) + { + myOwner = owner; + myIterator = owner.GetEnumerator(); + myIterator.MoveNext(); + } + + // Select the next shader + public void GotoNext() + { + if (myIterator.MoveNext() == false) + { + myIterator = myOwner.GetEnumerator(); + myIterator.MoveNext(); + } + } + + // Update the shader parameters + public void Update(float x, float y) + { + if (myIterator.Current.Key == "blur") myIterator.Current.Value.SetParameter("offset", x * y * 0.05f); + else if (myIterator.Current.Key == "colorize") myIterator.Current.Value.SetParameter("color", 0.3f, x, y); + else if (myIterator.Current.Key == "fisheye") myIterator.Current.Value.SetParameter("mouse", x, y); + else if (myIterator.Current.Key == "wave") myIterator.Current.Value.SetParameter("offset", x, y); + else if (myIterator.Current.Key == "pixelate") myIterator.Current.Value.SetParameter("mouse", x, y); + } + + // Get the name of the current shader + public string Name + { + get {return myIterator.Current.Key;} + } + + // Get the current shader + public Shader Shader + { + get {return myIterator.Current.Value;} + } + + private Dictionary myOwner; + private Dictionary.Enumerator myIterator; + }; + + static class Program + { + private static Dictionary shaders; + private static ShaderSelector backgroundShader; + private static ShaderSelector entityShader; + private static ShaderSelector globalShader; + private static Text shaderText; + + /// + /// The main entry point for the application. + /// + static void Main() + { + // Create the main window + RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader"); + + // Setup event handlers + window.Closed += new EventHandler(OnClosed); + window.KeyPressed += new EventHandler(OnKeyPressed); + + // Check that the system can use shaders + if (Shader.IsAvailable == false) + { + DisplayError(window); + return; + } + + // Create the render image + RenderImage image = new RenderImage(window.Width, window.Height); + + // Load a background image to display + Sprite background = new Sprite(new Image("datas/shader/background.jpg")); + background.Image.Smooth = false; + + // Load a sprite which we'll move into the scene + Sprite entity = new Sprite(new Image("datas/shader/sprite.png")); + + // Load the text font + Font font = new Font("datas/shader/arial.ttf"); + + // Load the image needed for the wave effect + Image waveImage = new Image("datas/shader/wave.jpg"); + + // Load all effects + shaders = new Dictionary(); + shaders["nothing"] = new Shader("datas/shader/nothing.sfx"); + shaders["blur"] = new Shader("datas/shader/blur.sfx"); + shaders["colorize"] = new Shader("datas/shader/colorize.sfx"); + shaders["fisheye"] = new Shader("datas/shader/fisheye.sfx"); + shaders["wave"] = new Shader("datas/shader/wave.sfx"); + shaders["pixelate"] = new Shader("datas/shader/pixelate.sfx"); + backgroundShader = new ShaderSelector(shaders); + entityShader = new ShaderSelector(shaders); + globalShader = new ShaderSelector(shaders); + + // Do specific initializations + shaders["nothing"].SetTexture("texture", Shader.CurrentTexture); + shaders["blur"].SetTexture("texture", Shader.CurrentTexture); + shaders["blur"].SetParameter("offset", 0.0F); + shaders["colorize"].SetTexture("texture", Shader.CurrentTexture); + shaders["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F); + shaders["fisheye"].SetTexture("texture", Shader.CurrentTexture); + shaders["wave"].SetTexture("texture", Shader.CurrentTexture); + shaders["wave"].SetTexture("wave", waveImage); + shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture); + + // Define a string for displaying current effect description + shaderText = new Text(); + shaderText.Font = font; + shaderText.Size = 20; + shaderText.Position = new Vector2(5.0F, 0.0F); + shaderText.Color = new Color(250, 100, 30); + shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" + + "Flower shader: \"" + entityShader.Name + "\"\n" + + "Global shader: \"" + globalShader.Name + "\"\n"; + + // Define a string for displaying help + Text infoText = new Text(); + infoText.Font = font; + infoText.Size = 20; + infoText.Position = new Vector2(5.0F, 500.0F); + infoText.Color = new Color(250, 100, 30); + infoText.DisplayedString = "Move your mouse to change the shaders' parameters\n" + + "Press numpad 1 to change the background shader\n" + + "Press numpad 2 to change the flower shader\n" + + "Press numpad 3 to change the global shader"; + + // Start the game loop + float time = 0.0F; + while (window.IsOpened()) + { + // Process events + window.DispatchEvents(); + + // TOFIX -- using window.Input together with image.Draw apparently causes a memory corruption + // Get the mouse position in the range [0, 1] + //float x = window.Input.GetMouseX() / (float)window.Width; + //float y = window.Input.GetMouseY() / (float)window.Height; + float x = (float)(Math.Cos(time * 1.3) + 1) * 0.5F; + float y = (float)(Math.Sin(time * 0.8) + 1) * 0.5F; + + // Update the shaders + backgroundShader.Update(x, y); + entityShader.Update(x, y); + globalShader.Update(x, y); + + // Animate the sprite + time += window.GetFrameTime(); + float entityX = (float)(Math.Cos(time * 1.3) + 1.2) * 300; + float entityY = (float)(Math.Cos(time * 0.8) + 1.2) * 200; + entity.Position = new Vector2(entityX, entityY); + entity.Rotation = time * 100; + + // Draw the background and the moving entity to the render image + image.Draw(background, backgroundShader.Shader); + image.Draw(entity, entityShader.Shader); + image.Display(); + + // Draw the contents of the render image to the window + window.Draw(new Sprite(image.Image), globalShader.Shader); + + // Draw interface texts + window.Draw(shaderText); + window.Draw(infoText); + + // Finally, display the rendered frame on screen + window.Display(); + } + } + + /// + /// Fonction called when the post-effects are not supported ; + /// Display an error message and wait until the user exits + /// + private static void DisplayError(RenderWindow window) + { + // Define a string for displaying the error message + Text error = new Text("Sorry, your system doesn't support shaders"); + error.Position = new Vector2(100.0F, 250.0F); + error.Color = new Color(200, 100, 150); + + // Start the game loop + while (window.IsOpened()) + { + // Process events + window.DispatchEvents(); + + // Clear the window + window.Clear(); + + // Draw the error message + window.Draw(error); + + // Finally, display the rendered frame on screen + window.Display(); + } + } + + /// + /// Function called when the window is closed + /// + static void OnClosed(object sender, EventArgs e) + { + RenderWindow window = (RenderWindow)sender; + window.Close(); + } + + /// + /// Function called when a key is pressed + /// + static void OnKeyPressed(object sender, KeyEventArgs e) + { + RenderWindow window = (RenderWindow)sender; + + // Escape key : exit + if (e.Code == KeyCode.Escape) + window.Close(); + + // Numpad : switch effect + switch (e.Code) + { + case KeyCode.Numpad1 : backgroundShader.GotoNext(); break; + case KeyCode.Numpad2 : entityShader.GotoNext(); break; + case KeyCode.Numpad3 : globalShader.GotoNext(); break; + } + + // Update the text + shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" + + "Flower shader: \"" + entityShader.Name + "\"\n" + + "Global shader: \"" + globalShader.Name + "\"\n"; + } + } +} diff --git a/dotnet/examples/shader/sample-shader.csproj b/dotnet/examples/shader/sample-shader.csproj new file mode 100644 index 00000000..1992e7d6 --- /dev/null +++ b/dotnet/examples/shader/sample-shader.csproj @@ -0,0 +1,60 @@ + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {9D4738F7-34EA-433A-A765-AF85A52A174D} + WinExe + Properties + sample_shader + shader + + + 2.0 + + + sample_shader.Program + + + true + full + false + ..\bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\bin\ + TRACE + prompt + 4 + + + + {46786269-57B9-48E7-AA4F-8F4D84609FE6} + sfml-graphics + + + {D17DE83D-A592-461F-8AF2-53F9E22E1D0F} + sfml-window + + + + + + + + + + + \ No newline at end of file diff --git a/dotnet/examples/sound/Sound.cs b/dotnet/examples/sound/Sound.cs new file mode 100644 index 00000000..ee82b967 --- /dev/null +++ b/dotnet/examples/sound/Sound.cs @@ -0,0 +1,82 @@ +using System; +using System.Threading; +using SFML; +using SFML.Audio; + +namespace sample_sound +{ + static class Program + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Play a sound + PlaySound(); + Console.Clear(); + + // Play a music + PlayMusic(); + } + + /// + /// Play a sound + /// + private static void PlaySound() + { + // Load a sound buffer from a wav file + SoundBuffer buffer = new SoundBuffer("datas/sound/canary.wav"); + + // Display sound informations + Console.WriteLine("canary.wav :"); + Console.WriteLine(" " + buffer.Duration + " sec"); + Console.WriteLine(" " + buffer.SampleRate + " samples / sec"); + Console.WriteLine(" " + buffer.ChannelsCount + " channels"); + + // Create a sound instance and play it + Sound sound = new Sound(buffer); + sound.Play(); + + // Loop while the sound is playing + while (sound.Status == SoundStatus.Playing) + { + // Display the playing position + Console.CursorLeft = 0; + Console.Write("Playing... " + sound.PlayingOffset + " sec "); + + // Leave some CPU time for other processes + Thread.Sleep(100); + } + } + + /// + /// Play a music + /// + private static void PlayMusic() + { + // Load an ogg music file + Music music = new Music("datas/sound/orchestral.ogg"); + + // Display music informations + Console.WriteLine("orchestral.ogg :"); + Console.WriteLine(" " + music.Duration + " sec"); + Console.WriteLine(" " + music.SampleRate + " samples / sec"); + Console.WriteLine(" " + music.ChannelsCount + " channels"); + + // Play it + music.Play(); + + // Loop while the music is playing + while (music.Status == SoundStatus.Playing) + { + // Display the playing position + Console.CursorLeft = 0; + Console.Write("Playing... " + music.PlayingOffset + " sec "); + + // Leave some CPU time for other processes + Thread.Sleep(100); + } + } + } +} diff --git a/dotnet/examples/sound/sample-sound.csproj b/dotnet/examples/sound/sample-sound.csproj new file mode 100644 index 00000000..465b0fef --- /dev/null +++ b/dotnet/examples/sound/sample-sound.csproj @@ -0,0 +1,61 @@ + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {16E177F3-A0FF-4091-8521-562E0EBAA3AB} + Exe + Properties + sample_sound + sound + + + + + 2.0 + + + + + true + full + false + ..\bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\bin\ + TRACE + prompt + 4 + + + + {0B202C4D-A457-47FE-84A3-031DD878C6BE} + sfml-audio + + + {D17DE83D-A592-461F-8AF2-53F9E22E1D0F} + sfml-window + + + + + + + + + + + \ No newline at end of file diff --git a/dotnet/examples/sound_capture/SoundCapture.cs b/dotnet/examples/sound_capture/SoundCapture.cs new file mode 100644 index 00000000..e6a08095 --- /dev/null +++ b/dotnet/examples/sound_capture/SoundCapture.cs @@ -0,0 +1,83 @@ +using System; +using System.Threading; +using SFML; +using SFML.Audio; + +namespace sample_soundcapture +{ + static class Program + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Check that the device can capture audio + if (SoundRecorder.IsAvailable == false) + { + Console.WriteLine("Sorry, audio capture is not supported by your system"); + return; + } + + // Choose the sample rate + Console.WriteLine("Please choose the sample rate for sound capture (44100 is CD quality) : "); + uint sampleRate = uint.Parse(Console.ReadLine()); + + // Wait for user input... + Console.WriteLine("Press enter to start recording audio"); + Console.ReadLine(); + + // Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer + SoundBufferRecorder recorder = new SoundBufferRecorder(); + + // Audio capture is done in a separate thread, so we can block the main thread while it is capturing + recorder.Start(sampleRate); + Console.WriteLine("Recording... press enter to stop"); + Console.ReadLine(); + recorder.Stop(); + + // Get the buffer containing the captured data + SoundBuffer buffer = recorder.SoundBuffer; + + // Display captured sound informations + Console.WriteLine("Sound information :"); + Console.WriteLine(" " + buffer.Duration + " seconds"); + Console.WriteLine(" " + buffer.SampleRate + " samples / seconds"); + Console.WriteLine(" " + buffer.ChannelsCount + " channels"); + + // Choose what to do with the recorded sound data + Console.WriteLine("What do you want to do with captured sound (p = play, s = save) ? "); + char choice = char.Parse(Console.ReadLine()); + + if (choice == 's') + { + // Choose the filename + Console.WriteLine("Choose the file to create : "); + string filename = Console.ReadLine(); + + // Save the buffer + buffer.SaveToFile(filename); + } + else + { + // Create a sound instance and play it + Sound sound = new Sound(buffer); + sound.Play(); + + // Wait until finished + while (sound.Status == SoundStatus.Playing) + { + // Display the playing position + Console.CursorLeft = 0; + Console.Write("Playing... " + sound.PlayingOffset + " sec "); + + // Leave some CPU time for other threads + Thread.Sleep(100); + } + } + + // Finished ! + Console.WriteLine("\nDone !"); + } + } +} diff --git a/dotnet/examples/sound_capture/sample-soundcapture.csproj b/dotnet/examples/sound_capture/sample-soundcapture.csproj new file mode 100644 index 00000000..3ce78e72 --- /dev/null +++ b/dotnet/examples/sound_capture/sample-soundcapture.csproj @@ -0,0 +1,61 @@ + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {F2F48990-F81E-41BA-AD01-168F6178C807} + Exe + Properties + sample_soundcapture + sound-capture + + + + + 2.0 + + + + + true + full + false + ..\bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\bin\ + TRACE + prompt + 4 + + + + {0B202C4D-A457-47FE-84A3-031DD878C6BE} + sfml-audio + + + {D17DE83D-A592-461F-8AF2-53F9E22E1D0F} + sfml-window + + + + + + + + + + + \ No newline at end of file diff --git a/dotnet/examples/visualbasic/My Project/Application.Designer.vb b/dotnet/examples/visualbasic/My Project/Application.Designer.vb new file mode 100644 index 00000000..d73a4d86 --- /dev/null +++ b/dotnet/examples/visualbasic/My Project/Application.Designer.vb @@ -0,0 +1,13 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:2.0.50727.3053 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + diff --git a/dotnet/examples/visualbasic/My Project/Application.myapp b/dotnet/examples/visualbasic/My Project/Application.myapp new file mode 100644 index 00000000..23b627fb --- /dev/null +++ b/dotnet/examples/visualbasic/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + false + false + 0 + true + 0 + 2 + true + diff --git a/dotnet/examples/visualbasic/My Project/AssemblyInfo.vb b/dotnet/examples/visualbasic/My Project/AssemblyInfo.vb new file mode 100644 index 00000000..ee7d3d64 --- /dev/null +++ b/dotnet/examples/visualbasic/My Project/AssemblyInfo.vb @@ -0,0 +1,35 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + +' General Information about an assembly is controlled through the following +' set of attributes. Change these attribute values to modify the information +' associated with an assembly. + +' Review the values of the assembly attributes + + + + + + + + + + +'The following GUID is for the ID of the typelib if this project is exposed to COM + + +' Version information for an assembly consists of the following four values: +' +' Major Version +' Minor Version +' Build Number +' Revision +' +' You can specify all the values or you can default the Build and Revision Numbers +' by using the '*' as shown below: +' + + + diff --git a/dotnet/examples/visualbasic/My Project/Resources.Designer.vb b/dotnet/examples/visualbasic/My Project/Resources.Designer.vb new file mode 100644 index 00000000..4c1f1ee6 --- /dev/null +++ b/dotnet/examples/visualbasic/My Project/Resources.Designer.vb @@ -0,0 +1,63 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:2.0.50727.3053 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Imports System + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("visualbasic.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/dotnet/examples/visualbasic/My Project/Resources.resx b/dotnet/examples/visualbasic/My Project/Resources.resx new file mode 100644 index 00000000..ffecec85 --- /dev/null +++ b/dotnet/examples/visualbasic/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/dotnet/examples/visualbasic/My Project/Settings.Designer.vb b/dotnet/examples/visualbasic/My Project/Settings.Designer.vb new file mode 100644 index 00000000..b6a816e3 --- /dev/null +++ b/dotnet/examples/visualbasic/My Project/Settings.Designer.vb @@ -0,0 +1,73 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:2.0.50727.3053 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings),MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.visualbasic.My.MySettings + Get + Return Global.visualbasic.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/dotnet/examples/visualbasic/My Project/Settings.settings b/dotnet/examples/visualbasic/My Project/Settings.settings new file mode 100644 index 00000000..377f56d6 --- /dev/null +++ b/dotnet/examples/visualbasic/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/dotnet/examples/visualbasic/OpenGL.vb b/dotnet/examples/visualbasic/OpenGL.vb new file mode 100644 index 00000000..55b45672 --- /dev/null +++ b/dotnet/examples/visualbasic/OpenGL.vb @@ -0,0 +1,177 @@ +Imports SFML +Imports SFML.Window +Imports SFML.Graphics +Imports Tao.OpenGl +Imports Tao.FreeGlut + + +Module OpenGL + + Dim WithEvents App As RenderWindow + + ''' + ''' Entry point of application + ''' + Sub Main() + + ' Create main window + App = New RenderWindow(New VideoMode(800, 600), "SFML.Net OpenGL (Visual Basic)") + App.PreserveOpenGLStates(True) + + ' Create a sprite for the background + Dim BackgroundImage = New Image("datas/opengl/background.jpg") + Dim Background = New Sprite(BackgroundImage) + + ' Create a text to display + Dim Text = New String2D("This is a rotating cube") + Text.Position = New Vector2(250.0F, 300.0F) + Text.Color = New Color(128, 0, 128) + + ' 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 + Dim Texture = 0 + Using TempImage = New Image("datas/opengl/texture.jpg") + Gl.glGenTextures(1, Texture) + Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture) + Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, TempImage.Width, TempImage.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, TempImage.Pixels) + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR) + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR) + End Using + + ' Enable Z-buffer read and write + Gl.glEnable(Gl.GL_DEPTH_TEST) + Gl.glDepthMask(Gl.GL_TRUE) + Gl.glClearDepth(1.0F) + + ' Setup a perspective projection + Gl.glMatrixMode(Gl.GL_PROJECTION) + Gl.glLoadIdentity() + Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F) + + ' Bind our texture + Gl.glEnable(Gl.GL_TEXTURE_2D) + Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture) + Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F) + + Dim Time = 0.0F + + ' Start game loop + While (App.IsOpened()) + + ' Process events + App.DispatchEvents() + + ' Draw background + App.Draw(Background) + + ' Clear depth buffer + Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT) + + ' Apply some transformations + Time += App.GetFrameTime() + Gl.glMatrixMode(Gl.GL_MODELVIEW) + Gl.glLoadIdentity() + Gl.glTranslatef(0.0F, 0.0F, -200.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 + 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(-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(-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(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, 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(-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.glEnd() + + ' Draw some text on top of our OpenGL object + App.Draw(Text) + + ' Finally, display the rendered frame on screen + App.Display() + + End While + + ' Don't forget to destroy our texture + Gl.glDeleteTextures(1, Texture) + + End Sub + + ''' + ''' Function called when the window is closed + ''' + Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles App.Closed + Dim window = CType(sender, RenderWindow) + window.Close() + End Sub + + ''' + ''' Function called when a key is pressed + ''' + Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles App.KeyPressed + Dim window = CType(sender, RenderWindow) + If e.Code = KeyCode.Escape Then + window.Close() + End If + End Sub + + ''' + ''' Function called when the window is resized + ''' + Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles App.Resized + Gl.glViewport(0, 0, e.Width, e.Height) + End Sub + +End Module diff --git a/dotnet/examples/visualbasic/visualbasic.sln b/dotnet/examples/visualbasic/visualbasic.sln new file mode 100644 index 00000000..099bf8ba --- /dev/null +++ b/dotnet/examples/visualbasic/visualbasic.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Basic Express 2008 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "visualbasic", "visualbasic.vbproj", "{98552080-F688-46B4-A2FF-1AC7C50ECBE8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {98552080-F688-46B4-A2FF-1AC7C50ECBE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98552080-F688-46B4-A2FF-1AC7C50ECBE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98552080-F688-46B4-A2FF-1AC7C50ECBE8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98552080-F688-46B4-A2FF-1AC7C50ECBE8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/dotnet/examples/visualbasic/visualbasic.vbproj b/dotnet/examples/visualbasic/visualbasic.vbproj new file mode 100644 index 00000000..e657c3fa --- /dev/null +++ b/dotnet/examples/visualbasic/visualbasic.vbproj @@ -0,0 +1,121 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {98552080-F688-46B4-A2FF-1AC7C50ECBE8} + WinExe + visualbasic.OpenGL + visualbasic + visualbasic + 512 + WindowsFormsWithCustomSubMain + v3.5 + On + Binary + Off + On + + + true + full + true + true + bin\Debug\ + visualbasic.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + pdbonly + false + true + true + bin\Release\ + visualbasic.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + + False + ..\..\lib\sfmlnet-graphics.dll + + + False + ..\..\lib\sfmlnet-window.dll + + + + + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + \ No newline at end of file diff --git a/dotnet/examples/window/Window.cs b/dotnet/examples/window/Window.cs new file mode 100644 index 00000000..56121bb1 --- /dev/null +++ b/dotnet/examples/window/Window.cs @@ -0,0 +1,134 @@ +using System; +using SFML; +using SFML.Window; +using Tao.OpenGl; + +namespace sample_window +{ + static class Program + { + /// + /// The main entry point for the application. + /// + static void Main() + { + // Create the main window + Window window = new Window(new VideoMode(640, 480, 32), "SFML.Net Window"); + + // Setup event handlers + window.Closed += new EventHandler(OnClosed); + window.KeyPressed += new EventHandler(OnKeyPressed); + window.Resized += new EventHandler(OnResized); + + // Set the color and depth clear values + Gl.glClearDepth(1.0F); + Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F); + + // Enable Z-buffer read and write + Gl.glEnable(Gl.GL_DEPTH_TEST); + Gl.glDepthMask(Gl.GL_TRUE); + + // Setup a perspective projection + Gl.glMatrixMode(Gl.GL_PROJECTION); + Gl.glLoadIdentity(); + Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F); + + float time = 0.0F; + + // Start the game loop + while (window.IsOpened()) + { + // Process events + window.DispatchEvents(); + + // Activate the window before using OpenGL commands. + // This is useless here because we have only one window which is + // always the active one, but don't forget it if you use multiple windows + window.SetActive(); + + // Clear color and depth buffer + Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); + + // Apply some transformations + time += window.GetFrameTime(); + Gl.glMatrixMode(Gl.GL_MODELVIEW); + Gl.glLoadIdentity(); + Gl.glTranslatef(0.0F, 0.0F, -200.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 + Gl.glBegin(Gl.GL_QUADS); + + Gl.glColor3f(1.0F, 0.0F, 0.0F); + Gl.glVertex3f(-50.0F, -50.0F, -50.0F); + Gl.glVertex3f(-50.0F, 50.0F, -50.0F); + Gl.glVertex3f( 50.0F, 50.0F, -50.0F); + Gl.glVertex3f( 50.0F, -50.0F, -50.0F); + + Gl.glColor3f(1.0F, 0.0F, 0.0F); + Gl.glVertex3f(-50.0F, -50.0F, 50.0F); + Gl.glVertex3f(-50.0F, 50.0F, 50.0F); + Gl.glVertex3f( 50.0F, 50.0F, 50.0F); + Gl.glVertex3f( 50.0F, -50.0F, 50.0F); + + Gl.glColor3f(0.0F, 1.0F, 0.0F); + Gl.glVertex3f(-50.0F, -50.0F, -50.0F); + Gl.glVertex3f(-50.0F, 50.0F, -50.0F); + Gl.glVertex3f(-50.0F, 50.0F, 50.0F); + Gl.glVertex3f(-50.0F, -50.0F, 50.0F); + + Gl.glColor3f(0.0F, 1.0F, 0.0F); + Gl.glVertex3f(50.0F, -50.0F, -50.0F); + Gl.glVertex3f(50.0F, 50.0F, -50.0F); + Gl.glVertex3f(50.0F, 50.0F, 50.0F); + Gl.glVertex3f(50.0F, -50.0F, 50.0F); + + Gl.glColor3f(0.0F, 0.0F, 1.0F); + Gl.glVertex3f(-50.0F, -50.0F, 50.0F); + Gl.glVertex3f(-50.0F, -50.0F, -50.0F); + Gl.glVertex3f( 50.0F, -50.0F, -50.0F); + Gl.glVertex3f( 50.0F, -50.0F, 50.0F); + + Gl.glColor3f(0.0F, 0.0F, 1.0F); + Gl.glVertex3f(-50.0F, 50.0F, 50.0F); + Gl.glVertex3f(-50.0F, 50.0F, -50.0F); + Gl.glVertex3f( 50.0F, 50.0F, -50.0F); + Gl.glVertex3f( 50.0F, 50.0F, 50.0F); + + Gl.glEnd(); + + // Finally, display the rendered frame on screen + window.Display(); + } + } + + /// + /// Function called when the window is closed + /// + static void OnClosed(object sender, EventArgs e) + { + Window window = (Window)sender; + window.Close(); + } + + /// + /// Function called when a key is pressed + /// + static void OnKeyPressed(object sender, KeyEventArgs e) + { + Window window = (Window)sender; + if (e.Code == KeyCode.Escape) + window.Close(); + } + + /// + /// Function called when the window is resized + /// + static void OnResized(object sender, SizeEventArgs e) + { + Gl.glViewport(0, 0, (int)e.Width, (int)e.Height); + } + } +} diff --git a/dotnet/examples/window/sample-window.csproj b/dotnet/examples/window/sample-window.csproj new file mode 100644 index 00000000..9eb0b895 --- /dev/null +++ b/dotnet/examples/window/sample-window.csproj @@ -0,0 +1,66 @@ + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF} + WinExe + Properties + sample_window + window + + + 2.0 + + + + + true + full + false + ..\bin\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\bin\ + TRACE + prompt + 4 + + + + {D17DE83D-A592-461F-8AF2-53F9E22E1D0F} + sfml-window + + + + + + + + False + ..\..\..\..\..\Bibliothèques\TaoFramework\bin\Tao.FreeGlut.dll + + + False + ..\..\..\..\..\Bibliothèques\TaoFramework\bin\Tao.OpenGl.dll + + + + + + + + \ No newline at end of file