mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Changed naming convention for local variables
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1181 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
34817446c0
commit
16275d05e8
@ -14,32 +14,32 @@ namespace sample_opengl
|
||||
static void Main()
|
||||
{
|
||||
// Create main window
|
||||
RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL");
|
||||
App.PreserveOpenGLStates(true);
|
||||
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL");
|
||||
window.PreserveOpenGLStates(true);
|
||||
|
||||
// Setup event handlers
|
||||
App.Closed += new EventHandler(OnClosed);
|
||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
App.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
||||
window.Closed += new EventHandler(OnClosed);
|
||||
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
window.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
||||
|
||||
// Create a sprite for the background
|
||||
Image BackgroundImage = new Image("datas/opengl/background.jpg");
|
||||
Sprite Background = new Sprite(BackgroundImage);
|
||||
Image backgroundImage = new Image("datas/opengl/background.jpg");
|
||||
Sprite background = new Sprite(backgroundImage);
|
||||
|
||||
// Create a text to display
|
||||
String2D Text = new String2D("SFML / OpenGL demo");
|
||||
Text.Position = new Vector2(250.0F, 450.0F);
|
||||
Text.Color = new Color(255, 255, 255, 170);
|
||||
String2D text = new String2D("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 TempImage = new Image("datas/opengl/texture.jpg"))
|
||||
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)TempImage.Width, (int)TempImage.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, TempImage.Pixels);
|
||||
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);
|
||||
}
|
||||
@ -56,84 +56,84 @@ namespace sample_opengl
|
||||
|
||||
// Bind our texture
|
||||
Gl.glEnable(Gl.GL_TEXTURE_2D);
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture);
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
|
||||
Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
float Time = 0.0F;
|
||||
float time = 0.0F;
|
||||
|
||||
// Start game loop
|
||||
while (App.IsOpened())
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
App.DispatchEvents();
|
||||
window.DispatchEvents();
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
window.Clear();
|
||||
|
||||
// Draw background
|
||||
App.Draw(Background);
|
||||
window.Draw(background);
|
||||
|
||||
// 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;
|
||||
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 += App.GetFrameTime();
|
||||
time += window.GetFrameTime();
|
||||
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
||||
Gl.glLoadIdentity();
|
||||
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);
|
||||
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;
|
||||
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, 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.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
|
||||
App.Draw(Text);
|
||||
window.Draw(text);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
|
||||
// Don't forget to destroy our texture
|
||||
Gl.glDeleteTextures(1, ref Texture);
|
||||
Gl.glDeleteTextures(1, ref texture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -8,9 +8,9 @@ namespace sample_postfx
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
private static Dictionary<string, PostFx> Effects;
|
||||
private static Dictionary<string, PostFx>.Enumerator CurrentEffect;
|
||||
private static String2D CurFXStr;
|
||||
private static Dictionary<string, PostFx> effects;
|
||||
private static Dictionary<string, PostFx>.Enumerator currentEffect;
|
||||
private static String2D curFXStr;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
@ -18,106 +18,106 @@ namespace sample_postfx
|
||||
static void Main()
|
||||
{
|
||||
// Create the main window
|
||||
RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net PostFX");
|
||||
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net PostFX");
|
||||
|
||||
// Setup event handlers
|
||||
App.Closed += new EventHandler(OnClosed);
|
||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
window.Closed += new EventHandler(OnClosed);
|
||||
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
|
||||
// Check that the system can use post effects
|
||||
if (PostFx.CanUsePostFX == false)
|
||||
{
|
||||
DisplayError(App);
|
||||
DisplayError(window);
|
||||
return;
|
||||
}
|
||||
|
||||
// Load a background image to display
|
||||
Sprite Background = new Sprite(new Image("datas/post-fx/background.jpg"));
|
||||
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"));
|
||||
Sprite entity = new Sprite(new Image("datas/post-fx/sprite.png"));
|
||||
|
||||
// Load the text font
|
||||
Font Cheeseburger = new Font("datas/post-fx/cheeseburger.ttf");
|
||||
Font cheeseburger = new Font("datas/post-fx/cheeseburger.ttf");
|
||||
|
||||
// Load the image needed for the wave effect
|
||||
Image WaveImage = new Image("datas/post-fx/wave.jpg");
|
||||
Image waveImage = new Image("datas/post-fx/wave.jpg");
|
||||
|
||||
// Load all effects
|
||||
Effects = new Dictionary<string, PostFx>();
|
||||
Effects["nothing"] = new PostFx("datas/post-fx/nothing.sfx");
|
||||
Effects["blur"] = new PostFx("datas/post-fx/blur.sfx");
|
||||
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();
|
||||
effects = new Dictionary<string, PostFx>();
|
||||
effects["nothing"] = new PostFx("datas/post-fx/nothing.sfx");
|
||||
effects["blur"] = new PostFx("datas/post-fx/blur.sfx");
|
||||
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();
|
||||
|
||||
// Do specific initializations
|
||||
Effects["nothing"].SetTexture("framebuffer", null);
|
||||
Effects["blur"].SetTexture("framebuffer", null);
|
||||
Effects["blur"].SetParameter("offset", 0.0F);
|
||||
Effects["colorize"].SetTexture("framebuffer", null);
|
||||
Effects["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
|
||||
Effects["fisheye"].SetTexture("framebuffer", null);
|
||||
Effects["wave"].SetTexture("framebuffer", null);
|
||||
Effects["wave"].SetTexture("wave", WaveImage);
|
||||
Effects["pixelate"].SetTexture("framebuffer", null);
|
||||
effects["nothing"].SetTexture("framebuffer", null);
|
||||
effects["blur"].SetTexture("framebuffer", null);
|
||||
effects["blur"].SetParameter("offset", 0.0F);
|
||||
effects["colorize"].SetTexture("framebuffer", null);
|
||||
effects["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
|
||||
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);
|
||||
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();
|
||||
InfoStr.Text = "Move your mouse to change the effect parameters\nPress numpad + to change effect\nWarning : some effects may not work\ndepending on your graphics card";
|
||||
InfoStr.Font = Cheeseburger;
|
||||
InfoStr.Position = new Vector2(20.0F, 460.0F);
|
||||
InfoStr.Color = new Color(200, 100, 150);
|
||||
String2D infoStr = new String2D();
|
||||
infoStr.Text = "Move your mouse to change the effect parameters\nPress numpad + to change effect\nWarning : some effects may not work\ndepending on your graphics card";
|
||||
infoStr.Font = cheeseburger;
|
||||
infoStr.Position = new Vector2(20.0F, 460.0F);
|
||||
infoStr.Color = new Color(200, 100, 150);
|
||||
|
||||
// Start the game loop
|
||||
float AppTime = 0.0F;
|
||||
while (App.IsOpened())
|
||||
float time = 0.0F;
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
App.DispatchEvents();
|
||||
window.DispatchEvents();
|
||||
|
||||
// Get the mouse position in the range [0, 1]
|
||||
float X = App.Input.GetMouseX() / (float)App.Width;
|
||||
float Y = App.Input.GetMouseY() / (float)App.Height;
|
||||
float x = window.Input.GetMouseX() / (float)window.Width;
|
||||
float y = window.Input.GetMouseY() / (float)window.Height;
|
||||
|
||||
// Update the current effect
|
||||
if (CurrentEffect.Current.Key == "blur") CurrentEffect.Current.Value.SetParameter("offset", X * Y * 0.1f);
|
||||
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);
|
||||
if (currentEffect.Current.Key == "blur") currentEffect.Current.Value.SetParameter("offset", x * y * 0.1f);
|
||||
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;
|
||||
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;
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
window.Clear();
|
||||
|
||||
// Draw background, the sprite and apply the post-fx
|
||||
App.Draw(Background);
|
||||
App.Draw(Entity);
|
||||
App.Draw(CurrentEffect.Current.Value);
|
||||
window.Draw(background);
|
||||
window.Draw(entity);
|
||||
window.Draw(currentEffect.Current.Value);
|
||||
|
||||
// Draw interface strings
|
||||
App.Draw(CurFXStr);
|
||||
App.Draw(InfoStr);
|
||||
window.Draw(curFXStr);
|
||||
window.Draw(infoStr);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,27 +125,27 @@ namespace sample_postfx
|
||||
/// Fonction called when the post-effects are not supported ;
|
||||
/// Display an error message and wait until the user exits
|
||||
/// </summary>
|
||||
private static void DisplayError(RenderWindow App)
|
||||
private static void DisplayError(RenderWindow window)
|
||||
{
|
||||
// Define a string for displaying the error message
|
||||
String2D ErrorStr = new String2D("Sorry, your system doesn't support post-effects");
|
||||
ErrorStr.Position = new Vector2(100.0F, 250.0F);
|
||||
ErrorStr.Color = new Color(200, 100, 150);
|
||||
String2D errorStr = new String2D("Sorry, your system doesn't support post-effects");
|
||||
errorStr.Position = new Vector2(100.0F, 250.0F);
|
||||
errorStr.Color = new Color(200, 100, 150);
|
||||
|
||||
// Start the game loop
|
||||
while (App.IsOpened())
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
App.DispatchEvents();
|
||||
window.DispatchEvents();
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
window.Clear();
|
||||
|
||||
// Draw the error message
|
||||
App.Draw(ErrorStr);
|
||||
window.Draw(errorStr);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,12 +172,12 @@ namespace sample_postfx
|
||||
else if (e.Code == KeyCode.Add)
|
||||
{
|
||||
// Advance to the next effect
|
||||
if (CurrentEffect.MoveNext() == false)
|
||||
if (currentEffect.MoveNext() == false)
|
||||
{
|
||||
CurrentEffect = Effects.GetEnumerator();
|
||||
CurrentEffect.MoveNext();
|
||||
currentEffect = effects.GetEnumerator();
|
||||
currentEffect.MoveNext();
|
||||
}
|
||||
CurFXStr.Text = "Current effect is \"" + CurrentEffect.Current.Key + "\"";
|
||||
curFXStr.Text = "Current effect is \"" + currentEffect.Current.Key + "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,24 +26,24 @@ namespace sample_sound
|
||||
private static void PlaySound()
|
||||
{
|
||||
// Load a sound buffer from a wav file
|
||||
SoundBuffer Buffer = new SoundBuffer("datas/sound/footsteps.wav");
|
||||
SoundBuffer buffer = new SoundBuffer("datas/sound/footsteps.wav");
|
||||
|
||||
// Display sound informations
|
||||
Console.WriteLine("footsteps.wav :");
|
||||
Console.WriteLine(" " + Buffer.Duration + " sec");
|
||||
Console.WriteLine(" " + Buffer.SampleRate + " samples / sec");
|
||||
Console.WriteLine(" " + Buffer.ChannelsCount + " channels");
|
||||
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();
|
||||
Sound sound = new Sound(buffer);
|
||||
sound.Play();
|
||||
|
||||
// Loop while the sound is playing
|
||||
while (Sound.Status == SoundStatus.Playing)
|
||||
while (sound.Status == SoundStatus.Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
Console.CursorLeft = 0;
|
||||
Console.Write("Playing... " + Sound.PlayingOffset + " sec ");
|
||||
Console.Write("Playing... " + sound.PlayingOffset + " sec ");
|
||||
|
||||
// Leave some CPU time for other processes
|
||||
Thread.Sleep(100);
|
||||
@ -56,23 +56,23 @@ namespace sample_sound
|
||||
private static void PlayMusic()
|
||||
{
|
||||
// Load an ogg music file
|
||||
Music Music = new Music("datas/sound/lepidoptera.ogg");
|
||||
Music music = new Music("datas/sound/lepidoptera.ogg");
|
||||
|
||||
// Display music informations
|
||||
Console.WriteLine("lepidoptera.ogg :");
|
||||
Console.WriteLine(" " + Music.Duration + " sec");
|
||||
Console.WriteLine(" " + Music.SampleRate + " samples / sec");
|
||||
Console.WriteLine(" " + Music.ChannelsCount + " channels");
|
||||
Console.WriteLine(" " + music.Duration + " sec");
|
||||
Console.WriteLine(" " + music.SampleRate + " samples / sec");
|
||||
Console.WriteLine(" " + music.ChannelsCount + " channels");
|
||||
|
||||
// Play it
|
||||
Music.Play();
|
||||
music.Play();
|
||||
|
||||
// Loop while the music is playing
|
||||
while (Music.Status == SoundStatus.Playing)
|
||||
while (music.Status == SoundStatus.Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
Console.CursorLeft = 0;
|
||||
Console.Write("Playing... " + Music.PlayingOffset + " sec ");
|
||||
Console.Write("Playing... " + music.PlayingOffset + " sec ");
|
||||
|
||||
// Leave some CPU time for other processes
|
||||
Thread.Sleep(100);
|
||||
|
@ -21,55 +21,55 @@ namespace sample_soundcapture
|
||||
|
||||
// Choose the sample rate
|
||||
Console.WriteLine("Please choose the sample rate for sound capture (44100 is CD quality) : ");
|
||||
uint SampleRate = uint.Parse(Console.ReadLine());
|
||||
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();
|
||||
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);
|
||||
recorder.Start(sampleRate);
|
||||
Console.WriteLine("Recording... press enter to stop");
|
||||
Console.ReadLine();
|
||||
Recorder.Stop();
|
||||
recorder.Stop();
|
||||
|
||||
// Get the buffer containing the captured data
|
||||
SoundBuffer Buffer = Recorder.SoundBuffer;
|
||||
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");
|
||||
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());
|
||||
char choice = char.Parse(Console.ReadLine());
|
||||
|
||||
if (Choice == 's')
|
||||
if (choice == 's')
|
||||
{
|
||||
// Choose the filename
|
||||
Console.WriteLine("Choose the file to create : ");
|
||||
string Filename = Console.ReadLine();
|
||||
string filename = Console.ReadLine();
|
||||
|
||||
// Save the buffer
|
||||
Buffer.SaveToFile(Filename);
|
||||
buffer.SaveToFile(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a sound instance and play it
|
||||
Sound Sound = new Sound(Buffer);
|
||||
Sound.Play();
|
||||
Sound sound = new Sound(buffer);
|
||||
sound.Play();
|
||||
|
||||
// Wait until finished
|
||||
while (Sound.Status == SoundStatus.Playing)
|
||||
while (sound.Status == SoundStatus.Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
Console.CursorLeft = 0;
|
||||
Console.Write("Playing... " + Sound.PlayingOffset + " sec ");
|
||||
Console.Write("Playing... " + sound.PlayingOffset + " sec ");
|
||||
|
||||
// Leave some CPU time for other threads
|
||||
Thread.Sleep(100);
|
||||
|
@ -13,12 +13,12 @@ namespace sample_window
|
||||
static void Main()
|
||||
{
|
||||
// Create the main window
|
||||
Window App = new Window(new VideoMode(640, 480, 32), "SFML.Net Window");
|
||||
Window window = new Window(new VideoMode(640, 480, 32), "SFML.Net Window");
|
||||
|
||||
// Setup event handlers
|
||||
App.Closed += new EventHandler(OnClosed);
|
||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
App.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
||||
window.Closed += new EventHandler(OnClosed);
|
||||
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
window.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
||||
|
||||
// Set the color and depth clear values
|
||||
Gl.glClearDepth(1.0F);
|
||||
@ -33,30 +33,30 @@ namespace sample_window
|
||||
Gl.glLoadIdentity();
|
||||
Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);
|
||||
|
||||
float Time = 0.0F;
|
||||
float time = 0.0F;
|
||||
|
||||
// Start the game loop
|
||||
while (App.IsOpened())
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
App.DispatchEvents();
|
||||
window.DispatchEvents();
|
||||
|
||||
// Set the active window before using OpenGL commands
|
||||
// It's useless here because the active window is always the same,
|
||||
// but don't forget it if you use multiple windows
|
||||
App.SetActive();
|
||||
window.SetActive();
|
||||
|
||||
// Clear color and depth buffer
|
||||
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Apply some transformations
|
||||
Time += App.GetFrameTime();
|
||||
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);
|
||||
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);
|
||||
@ -100,7 +100,7 @@ namespace sample_window
|
||||
Gl.glEnd();
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user