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()
|
static void Main()
|
||||||
{
|
{
|
||||||
// Create main window
|
// Create main window
|
||||||
RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL");
|
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL");
|
||||||
App.PreserveOpenGLStates(true);
|
window.PreserveOpenGLStates(true);
|
||||||
|
|
||||||
// Setup event handlers
|
// Setup event handlers
|
||||||
App.Closed += new EventHandler(OnClosed);
|
window.Closed += new EventHandler(OnClosed);
|
||||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||||
App.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
window.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
||||||
|
|
||||||
// Create a sprite for the background
|
// Create a sprite for the background
|
||||||
Image BackgroundImage = new Image("datas/opengl/background.jpg");
|
Image backgroundImage = new Image("datas/opengl/background.jpg");
|
||||||
Sprite Background = new Sprite(BackgroundImage);
|
Sprite background = new Sprite(backgroundImage);
|
||||||
|
|
||||||
// Create a text to display
|
// Create a text to display
|
||||||
String2D Text = new String2D("SFML / OpenGL demo");
|
String2D text = new String2D("SFML / OpenGL demo");
|
||||||
Text.Position = new Vector2(250.0F, 450.0F);
|
text.Position = new Vector2(250.0F, 450.0F);
|
||||||
Text.Color = new Color(255, 255, 255, 170);
|
text.Color = new Color(255, 255, 255, 170);
|
||||||
|
|
||||||
// Load an OpenGL texture.
|
// Load an OpenGL texture.
|
||||||
// We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
|
// 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
|
||||||
int Texture = 0;
|
int texture = 0;
|
||||||
using (Image TempImage = new Image("datas/opengl/texture.jpg"))
|
using (Image image = new Image("datas/opengl/texture.jpg"))
|
||||||
{
|
{
|
||||||
Gl.glGenTextures(1, out Texture);
|
Gl.glGenTextures(1, out texture);
|
||||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, 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);
|
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_MAG_FILTER, Gl.GL_LINEAR);
|
||||||
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_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
|
// Bind our texture
|
||||||
Gl.glEnable(Gl.GL_TEXTURE_2D);
|
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);
|
Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
|
||||||
float Time = 0.0F;
|
float time = 0.0F;
|
||||||
|
|
||||||
// Start game loop
|
// Start game loop
|
||||||
while (App.IsOpened())
|
while (window.IsOpened())
|
||||||
{
|
{
|
||||||
// Process events
|
// Process events
|
||||||
App.DispatchEvents();
|
window.DispatchEvents();
|
||||||
|
|
||||||
// Clear the window
|
// Clear the window
|
||||||
App.Clear();
|
window.Clear();
|
||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
App.Draw(Background);
|
window.Draw(background);
|
||||||
|
|
||||||
// Clear depth buffer
|
// Clear depth buffer
|
||||||
Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);
|
Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// We get the position of the mouse cursor, so that we can move the box accordingly
|
// 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 x = window.Input.GetMouseX() * 200.0F / window.Width - 100.0F;
|
||||||
float CursorY = -App.Input.GetMouseY() * 200.0F / App.Height + 100.0F;
|
float y = -window.Input.GetMouseY() * 200.0F / window.Height + 100.0F;
|
||||||
|
|
||||||
// Apply some transformations
|
// Apply some transformations
|
||||||
Time += App.GetFrameTime();
|
time += window.GetFrameTime();
|
||||||
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
||||||
Gl.glLoadIdentity();
|
Gl.glLoadIdentity();
|
||||||
Gl.glTranslatef(CursorX, CursorY, -100.0F);
|
Gl.glTranslatef(x, y, -100.0F);
|
||||||
Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F);
|
Gl.glRotatef(time * 50, 1.0F, 0.0F, 0.0F);
|
||||||
Gl.glRotatef(Time * 30, 0.0F, 1.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 * 90, 0.0F, 0.0F, 1.0F);
|
||||||
|
|
||||||
// Draw a cube
|
// Draw a cube
|
||||||
float Size = 20.0F;
|
float size = 20.0F;
|
||||||
Gl.glBegin(Gl.GL_QUADS);
|
Gl.glBegin(Gl.GL_QUADS);
|
||||||
|
|
||||||
Gl.glTexCoord2f(0, 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(0, 1); Gl.glVertex3f(-size, size, -size);
|
||||||
Gl.glTexCoord2f(1, 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(1, 0); Gl.glVertex3f( size, -size, -size);
|
||||||
|
|
||||||
Gl.glTexCoord2f(0, 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(0, 1); Gl.glVertex3f(-size, size, size);
|
||||||
Gl.glTexCoord2f(1, 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(1, 0); Gl.glVertex3f( size, -size, size);
|
||||||
|
|
||||||
Gl.glTexCoord2f(0, 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(0, 1); Gl.glVertex3f(-size, size, -size);
|
||||||
Gl.glTexCoord2f(1, 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(1, 0); Gl.glVertex3f(-size, -size, size);
|
||||||
|
|
||||||
Gl.glTexCoord2f(0, 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(0, 1); Gl.glVertex3f(size, size, -size);
|
||||||
Gl.glTexCoord2f(1, 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(1, 0); Gl.glVertex3f(size, -size, size);
|
||||||
|
|
||||||
Gl.glTexCoord2f(0, 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(0, 0); Gl.glVertex3f(-size, -size, -size);
|
||||||
Gl.glTexCoord2f(1, 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(1, 1); Gl.glVertex3f( size, -size, size);
|
||||||
|
|
||||||
Gl.glTexCoord2f(0, 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(0, 0); Gl.glVertex3f(-size, size, -size);
|
||||||
Gl.glTexCoord2f(1, 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(1, 1); Gl.glVertex3f( size, size, size);
|
||||||
|
|
||||||
Gl.glEnd();
|
Gl.glEnd();
|
||||||
|
|
||||||
// Draw some text on top of our OpenGL object
|
// Draw some text on top of our OpenGL object
|
||||||
App.Draw(Text);
|
window.Draw(text);
|
||||||
|
|
||||||
// Finally, display the rendered frame on screen
|
// Finally, display the rendered frame on screen
|
||||||
App.Display();
|
window.Display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't forget to destroy our texture
|
// Don't forget to destroy our texture
|
||||||
Gl.glDeleteTextures(1, ref Texture);
|
Gl.glDeleteTextures(1, ref texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -8,9 +8,9 @@ namespace sample_postfx
|
|||||||
{
|
{
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
private static Dictionary<string, PostFx> Effects;
|
private static Dictionary<string, PostFx> effects;
|
||||||
private static Dictionary<string, PostFx>.Enumerator CurrentEffect;
|
private static Dictionary<string, PostFx>.Enumerator currentEffect;
|
||||||
private static String2D CurFXStr;
|
private static String2D curFXStr;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
@ -18,106 +18,106 @@ namespace sample_postfx
|
|||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// Create the main window
|
// 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
|
// Setup event handlers
|
||||||
App.Closed += new EventHandler(OnClosed);
|
window.Closed += new EventHandler(OnClosed);
|
||||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||||
|
|
||||||
// Check that the system can use post effects
|
// Check that the system can use post effects
|
||||||
if (PostFx.CanUsePostFX == false)
|
if (PostFx.CanUsePostFX == false)
|
||||||
{
|
{
|
||||||
DisplayError(App);
|
DisplayError(window);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a background image to display
|
// 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
|
// 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
|
// 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
|
// 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
|
// Load all effects
|
||||||
Effects = new Dictionary<string, PostFx>();
|
effects = new Dictionary<string, PostFx>();
|
||||||
Effects["nothing"] = new PostFx("datas/post-fx/nothing.sfx");
|
effects["nothing"] = new PostFx("datas/post-fx/nothing.sfx");
|
||||||
Effects["blur"] = new PostFx("datas/post-fx/blur.sfx");
|
effects["blur"] = new PostFx("datas/post-fx/blur.sfx");
|
||||||
Effects["colorize"] = new PostFx("datas/post-fx/colorize.sfx");
|
effects["colorize"] = new PostFx("datas/post-fx/colorize.sfx");
|
||||||
Effects["fisheye"] = new PostFx("datas/post-fx/fisheye.sfx");
|
effects["fisheye"] = new PostFx("datas/post-fx/fisheye.sfx");
|
||||||
Effects["wave"] = new PostFx("datas/post-fx/wave.sfx");
|
effects["wave"] = new PostFx("datas/post-fx/wave.sfx");
|
||||||
Effects["pixelate"] = new PostFx("datas/post-fx/pixelate.sfx");
|
effects["pixelate"] = new PostFx("datas/post-fx/pixelate.sfx");
|
||||||
CurrentEffect = Effects.GetEnumerator();
|
currentEffect = effects.GetEnumerator();
|
||||||
CurrentEffect.MoveNext();
|
currentEffect.MoveNext();
|
||||||
|
|
||||||
// Do specific initializations
|
// Do specific initializations
|
||||||
Effects["nothing"].SetTexture("framebuffer", null);
|
effects["nothing"].SetTexture("framebuffer", null);
|
||||||
Effects["blur"].SetTexture("framebuffer", null);
|
effects["blur"].SetTexture("framebuffer", null);
|
||||||
Effects["blur"].SetParameter("offset", 0.0F);
|
effects["blur"].SetParameter("offset", 0.0F);
|
||||||
Effects["colorize"].SetTexture("framebuffer", null);
|
effects["colorize"].SetTexture("framebuffer", null);
|
||||||
Effects["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
|
effects["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
|
||||||
Effects["fisheye"].SetTexture("framebuffer", null);
|
effects["fisheye"].SetTexture("framebuffer", null);
|
||||||
Effects["wave"].SetTexture("framebuffer", null);
|
effects["wave"].SetTexture("framebuffer", null);
|
||||||
Effects["wave"].SetTexture("wave", WaveImage);
|
effects["wave"].SetTexture("wave", waveImage);
|
||||||
Effects["pixelate"].SetTexture("framebuffer", null);
|
effects["pixelate"].SetTexture("framebuffer", null);
|
||||||
|
|
||||||
// Define a string for displaying current effect description
|
// Define a string for displaying current effect description
|
||||||
CurFXStr = new String2D();
|
curFXStr = new String2D();
|
||||||
CurFXStr.Text = "Current effect is \"" + CurrentEffect.Current.Key + "\"";
|
curFXStr.Text = "Current effect is \"" + currentEffect.Current.Key + "\"";
|
||||||
CurFXStr.Font = Cheeseburger;
|
curFXStr.Font = cheeseburger;
|
||||||
CurFXStr.Position = new Vector2(20.0F, 0.0F);
|
curFXStr.Position = new Vector2(20.0F, 0.0F);
|
||||||
CurFXStr.Color = new Color(150, 70, 110);
|
curFXStr.Color = new Color(150, 70, 110);
|
||||||
|
|
||||||
// Define a string for displaying help
|
// Define a string for displaying help
|
||||||
String2D InfoStr = new String2D();
|
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.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.Font = cheeseburger;
|
||||||
InfoStr.Position = new Vector2(20.0F, 460.0F);
|
infoStr.Position = new Vector2(20.0F, 460.0F);
|
||||||
InfoStr.Color = new Color(200, 100, 150);
|
infoStr.Color = new Color(200, 100, 150);
|
||||||
|
|
||||||
// Start the game loop
|
// Start the game loop
|
||||||
float AppTime = 0.0F;
|
float time = 0.0F;
|
||||||
while (App.IsOpened())
|
while (window.IsOpened())
|
||||||
{
|
{
|
||||||
// Process events
|
// Process events
|
||||||
App.DispatchEvents();
|
window.DispatchEvents();
|
||||||
|
|
||||||
// Get the mouse position in the range [0, 1]
|
// Get the mouse position in the range [0, 1]
|
||||||
float X = App.Input.GetMouseX() / (float)App.Width;
|
float x = window.Input.GetMouseX() / (float)window.Width;
|
||||||
float Y = App.Input.GetMouseY() / (float)App.Height;
|
float y = window.Input.GetMouseY() / (float)window.Height;
|
||||||
|
|
||||||
// Update the current effect
|
// Update the current effect
|
||||||
if (CurrentEffect.Current.Key == "blur") CurrentEffect.Current.Value.SetParameter("offset", X * Y * 0.1f);
|
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 == "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 == "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 == "wave") currentEffect.Current.Value.SetParameter("offset", x, y);
|
||||||
else if (CurrentEffect.Current.Key == "pixelate") CurrentEffect.Current.Value.SetParameter("mouse", X, Y);
|
else if (currentEffect.Current.Key == "pixelate") currentEffect.Current.Value.SetParameter("mouse", x, y);
|
||||||
|
|
||||||
// Animate the sprite
|
// Animate the sprite
|
||||||
AppTime += App.GetFrameTime();
|
time += window.GetFrameTime();
|
||||||
float EntityX = (float)(Math.Cos(AppTime * 1.3) + 1.2) * 300;
|
float entityX = (float)(Math.Cos(time * 1.3) + 1.2) * 300;
|
||||||
float EntityY = (float)(Math.Cos(AppTime * 0.8) + 1.2) * 200;
|
float entityY = (float)(Math.Cos(time * 0.8) + 1.2) * 200;
|
||||||
Entity.Position = new Vector2(EntityX, EntityY);
|
entity.Position = new Vector2(entityX, entityY);
|
||||||
Entity.Rotation = AppTime * 100;
|
entity.Rotation = time * 100;
|
||||||
|
|
||||||
// Clear the window
|
// Clear the window
|
||||||
App.Clear();
|
window.Clear();
|
||||||
|
|
||||||
// Draw background, the sprite and apply the post-fx
|
// Draw background, the sprite and apply the post-fx
|
||||||
App.Draw(Background);
|
window.Draw(background);
|
||||||
App.Draw(Entity);
|
window.Draw(entity);
|
||||||
App.Draw(CurrentEffect.Current.Value);
|
window.Draw(currentEffect.Current.Value);
|
||||||
|
|
||||||
// Draw interface strings
|
// Draw interface strings
|
||||||
App.Draw(CurFXStr);
|
window.Draw(curFXStr);
|
||||||
App.Draw(InfoStr);
|
window.Draw(infoStr);
|
||||||
|
|
||||||
// Finally, display the rendered frame on screen
|
// 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 ;
|
/// Fonction called when the post-effects are not supported ;
|
||||||
/// Display an error message and wait until the user exits
|
/// Display an error message and wait until the user exits
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void DisplayError(RenderWindow App)
|
private static void DisplayError(RenderWindow window)
|
||||||
{
|
{
|
||||||
// Define a string for displaying the error message
|
// Define a string for displaying the error message
|
||||||
String2D ErrorStr = new String2D("Sorry, your system doesn't support post-effects");
|
String2D errorStr = new String2D("Sorry, your system doesn't support post-effects");
|
||||||
ErrorStr.Position = new Vector2(100.0F, 250.0F);
|
errorStr.Position = new Vector2(100.0F, 250.0F);
|
||||||
ErrorStr.Color = new Color(200, 100, 150);
|
errorStr.Color = new Color(200, 100, 150);
|
||||||
|
|
||||||
// Start the game loop
|
// Start the game loop
|
||||||
while (App.IsOpened())
|
while (window.IsOpened())
|
||||||
{
|
{
|
||||||
// Process events
|
// Process events
|
||||||
App.DispatchEvents();
|
window.DispatchEvents();
|
||||||
|
|
||||||
// Clear the window
|
// Clear the window
|
||||||
App.Clear();
|
window.Clear();
|
||||||
|
|
||||||
// Draw the error message
|
// Draw the error message
|
||||||
App.Draw(ErrorStr);
|
window.Draw(errorStr);
|
||||||
|
|
||||||
// Finally, display the rendered frame on screen
|
// Finally, display the rendered frame on screen
|
||||||
App.Display();
|
window.Display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,12 +172,12 @@ namespace sample_postfx
|
|||||||
else if (e.Code == KeyCode.Add)
|
else if (e.Code == KeyCode.Add)
|
||||||
{
|
{
|
||||||
// Advance to the next effect
|
// Advance to the next effect
|
||||||
if (CurrentEffect.MoveNext() == false)
|
if (currentEffect.MoveNext() == false)
|
||||||
{
|
{
|
||||||
CurrentEffect = Effects.GetEnumerator();
|
currentEffect = effects.GetEnumerator();
|
||||||
CurrentEffect.MoveNext();
|
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()
|
private static void PlaySound()
|
||||||
{
|
{
|
||||||
// Load a sound buffer from a wav file
|
// 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
|
// Display sound informations
|
||||||
Console.WriteLine("footsteps.wav :");
|
Console.WriteLine("footsteps.wav :");
|
||||||
Console.WriteLine(" " + Buffer.Duration + " sec");
|
Console.WriteLine(" " + buffer.Duration + " sec");
|
||||||
Console.WriteLine(" " + Buffer.SampleRate + " samples / sec");
|
Console.WriteLine(" " + buffer.SampleRate + " samples / sec");
|
||||||
Console.WriteLine(" " + Buffer.ChannelsCount + " channels");
|
Console.WriteLine(" " + buffer.ChannelsCount + " channels");
|
||||||
|
|
||||||
// Create a sound instance and play it
|
// Create a sound instance and play it
|
||||||
Sound Sound = new Sound(Buffer);
|
Sound sound = new Sound(buffer);
|
||||||
Sound.Play();
|
sound.Play();
|
||||||
|
|
||||||
// Loop while the sound is playing
|
// Loop while the sound is playing
|
||||||
while (Sound.Status == SoundStatus.Playing)
|
while (sound.Status == SoundStatus.Playing)
|
||||||
{
|
{
|
||||||
// Display the playing position
|
// Display the playing position
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
Console.Write("Playing... " + Sound.PlayingOffset + " sec ");
|
Console.Write("Playing... " + sound.PlayingOffset + " sec ");
|
||||||
|
|
||||||
// Leave some CPU time for other processes
|
// Leave some CPU time for other processes
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
@ -56,23 +56,23 @@ namespace sample_sound
|
|||||||
private static void PlayMusic()
|
private static void PlayMusic()
|
||||||
{
|
{
|
||||||
// Load an ogg music file
|
// Load an ogg music file
|
||||||
Music Music = new Music("datas/sound/lepidoptera.ogg");
|
Music music = new Music("datas/sound/lepidoptera.ogg");
|
||||||
|
|
||||||
// Display music informations
|
// Display music informations
|
||||||
Console.WriteLine("lepidoptera.ogg :");
|
Console.WriteLine("lepidoptera.ogg :");
|
||||||
Console.WriteLine(" " + Music.Duration + " sec");
|
Console.WriteLine(" " + music.Duration + " sec");
|
||||||
Console.WriteLine(" " + Music.SampleRate + " samples / sec");
|
Console.WriteLine(" " + music.SampleRate + " samples / sec");
|
||||||
Console.WriteLine(" " + Music.ChannelsCount + " channels");
|
Console.WriteLine(" " + music.ChannelsCount + " channels");
|
||||||
|
|
||||||
// Play it
|
// Play it
|
||||||
Music.Play();
|
music.Play();
|
||||||
|
|
||||||
// Loop while the music is playing
|
// Loop while the music is playing
|
||||||
while (Music.Status == SoundStatus.Playing)
|
while (music.Status == SoundStatus.Playing)
|
||||||
{
|
{
|
||||||
// Display the playing position
|
// Display the playing position
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
Console.Write("Playing... " + Music.PlayingOffset + " sec ");
|
Console.Write("Playing... " + music.PlayingOffset + " sec ");
|
||||||
|
|
||||||
// Leave some CPU time for other processes
|
// Leave some CPU time for other processes
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
@ -21,55 +21,55 @@ namespace sample_soundcapture
|
|||||||
|
|
||||||
// Choose the sample rate
|
// Choose the sample rate
|
||||||
Console.WriteLine("Please choose the sample rate for sound capture (44100 is CD quality) : ");
|
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...
|
// Wait for user input...
|
||||||
Console.WriteLine("Press enter to start recording audio");
|
Console.WriteLine("Press enter to start recording audio");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
||||||
// Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer
|
// 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
|
// 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.WriteLine("Recording... press enter to stop");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
Recorder.Stop();
|
recorder.Stop();
|
||||||
|
|
||||||
// Get the buffer containing the captured data
|
// Get the buffer containing the captured data
|
||||||
SoundBuffer Buffer = Recorder.SoundBuffer;
|
SoundBuffer buffer = recorder.SoundBuffer;
|
||||||
|
|
||||||
// Display captured sound informations
|
// Display captured sound informations
|
||||||
Console.WriteLine("Sound information :");
|
Console.WriteLine("Sound information :");
|
||||||
Console.WriteLine(" " + Buffer.Duration + " seconds");
|
Console.WriteLine(" " + buffer.Duration + " seconds");
|
||||||
Console.WriteLine(" " + Buffer.SampleRate + " samples / seconds");
|
Console.WriteLine(" " + buffer.SampleRate + " samples / seconds");
|
||||||
Console.WriteLine(" " + Buffer.ChannelsCount + " channels");
|
Console.WriteLine(" " + buffer.ChannelsCount + " channels");
|
||||||
|
|
||||||
// Choose what to do with the recorded sound data
|
// Choose what to do with the recorded sound data
|
||||||
Console.WriteLine("What do you want to do with captured sound (p = play, s = save) ? ");
|
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
|
// Choose the filename
|
||||||
Console.WriteLine("Choose the file to create : ");
|
Console.WriteLine("Choose the file to create : ");
|
||||||
string Filename = Console.ReadLine();
|
string filename = Console.ReadLine();
|
||||||
|
|
||||||
// Save the buffer
|
// Save the buffer
|
||||||
Buffer.SaveToFile(Filename);
|
buffer.SaveToFile(filename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Create a sound instance and play it
|
// Create a sound instance and play it
|
||||||
Sound Sound = new Sound(Buffer);
|
Sound sound = new Sound(buffer);
|
||||||
Sound.Play();
|
sound.Play();
|
||||||
|
|
||||||
// Wait until finished
|
// Wait until finished
|
||||||
while (Sound.Status == SoundStatus.Playing)
|
while (sound.Status == SoundStatus.Playing)
|
||||||
{
|
{
|
||||||
// Display the playing position
|
// Display the playing position
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
Console.Write("Playing... " + Sound.PlayingOffset + " sec ");
|
Console.Write("Playing... " + sound.PlayingOffset + " sec ");
|
||||||
|
|
||||||
// Leave some CPU time for other threads
|
// Leave some CPU time for other threads
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
@ -13,12 +13,12 @@ namespace sample_window
|
|||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// Create the main window
|
// 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
|
// Setup event handlers
|
||||||
App.Closed += new EventHandler(OnClosed);
|
window.Closed += new EventHandler(OnClosed);
|
||||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||||
App.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
window.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
||||||
|
|
||||||
// Set the color and depth clear values
|
// Set the color and depth clear values
|
||||||
Gl.glClearDepth(1.0F);
|
Gl.glClearDepth(1.0F);
|
||||||
@ -33,30 +33,30 @@ namespace sample_window
|
|||||||
Gl.glLoadIdentity();
|
Gl.glLoadIdentity();
|
||||||
Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);
|
Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);
|
||||||
|
|
||||||
float Time = 0.0F;
|
float time = 0.0F;
|
||||||
|
|
||||||
// Start the game loop
|
// Start the game loop
|
||||||
while (App.IsOpened())
|
while (window.IsOpened())
|
||||||
{
|
{
|
||||||
// Process events
|
// Process events
|
||||||
App.DispatchEvents();
|
window.DispatchEvents();
|
||||||
|
|
||||||
// Set the active window before using OpenGL commands
|
// Set the active window before using OpenGL commands
|
||||||
// It's useless here because the active window is always the same,
|
// It's useless here because the active window is always the same,
|
||||||
// but don't forget it if you use multiple windows
|
// but don't forget it if you use multiple windows
|
||||||
App.SetActive();
|
window.SetActive();
|
||||||
|
|
||||||
// Clear color and depth buffer
|
// Clear color and depth buffer
|
||||||
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
|
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Apply some transformations
|
// Apply some transformations
|
||||||
Time += App.GetFrameTime();
|
time += window.GetFrameTime();
|
||||||
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
||||||
Gl.glLoadIdentity();
|
Gl.glLoadIdentity();
|
||||||
Gl.glTranslatef(0.0F, 0.0F, -200.0F);
|
Gl.glTranslatef(0.0F, 0.0F, -200.0F);
|
||||||
Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F);
|
Gl.glRotatef(time * 50, 1.0F, 0.0F, 0.0F);
|
||||||
Gl.glRotatef(Time * 30, 0.0F, 1.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 * 90, 0.0F, 0.0F, 1.0F);
|
||||||
|
|
||||||
// Draw a cube
|
// Draw a cube
|
||||||
Gl.glBegin(Gl.GL_QUADS);
|
Gl.glBegin(Gl.GL_QUADS);
|
||||||
@ -100,7 +100,7 @@ namespace sample_window
|
|||||||
Gl.glEnd();
|
Gl.glEnd();
|
||||||
|
|
||||||
// Finally, display the rendered frame on screen
|
// Finally, display the rendered frame on screen
|
||||||
App.Display();
|
window.Display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user