public GameConsole() { this.TextString = new String2D(); this.TextString.Color = Color.White; this.TextString.Size = 16; this.TextString.Position = new Vector2(10, 16 * MainGame.TileSize - 28); }
/// <summary> /// 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) { // 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); // Start the game loop while (App.IsOpened()) { // Process events App.DispatchEvents(); // Clear the window App.Clear(); // Draw the error message App.Draw(ErrorStr); // Finally, display the rendered frame on screen App.Display(); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // Create main window RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL"); App.PreserveOpenGLStates(true); // Setup event handlers App.Closed += new EventHandler(OnClosed); App.KeyPressed += new EventHandler <KeyEventArgs>(OnKeyPressed); App.Resized += new EventHandler <SizeEventArgs>(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 String2D 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 int Texture = 0; using (Image TempImage = 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.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 (App.IsOpened()) { // Process events App.DispatchEvents(); // Clear the window App.Clear(); // 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(); } // Don't forget to destroy our texture Gl.glDeleteTextures(1, ref Texture); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // Create main window RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL"); App.PreserveOpenGLStates(true); // Setup event handlers App.Closed += new EventHandler(OnClosed); App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); App.Resized += new EventHandler<SizeEventArgs>(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 String2D 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 int Texture = 0; using (Image TempImage = 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.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 (App.IsOpened()) { // Process events App.DispatchEvents(); // Clear the window App.Clear(); // 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(); } // Don't forget to destroy our texture Gl.glDeleteTextures(1, ref Texture); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // Create the main window RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net PostFX"); // Setup event handlers App.Closed += new EventHandler(OnClosed); App.KeyPressed += new EventHandler <KeyEventArgs>(OnKeyPressed); // Check that the system can use post effects if (PostFx.CanUsePostFX == false) { DisplayError(App); return; } // Load a cute background image to display :) Sprite Background = new Sprite(new Image("datas/post-fx/background.jpg")); // Load the text font 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"); // 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"); 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); // 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); // 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); // Start the game loop while (App.IsOpened()) { // Process events App.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; // 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); } // Clear the window App.Clear(); // Draw background and apply the post-fx App.Draw(Background); App.Draw(CurrentEffect.Current.Value); // Draw interface strings App.Draw(CurFXStr); App.Draw(InfoStr); // Finally, display the rendered frame on screen App.Display(); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // Create the main window RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net PostFX"); // Setup event handlers App.Closed += new EventHandler(OnClosed); App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); // Check that the system can use post effects if (PostFx.CanUsePostFX == false) { DisplayError(App); return; } // Load a cute background image to display :) Sprite Background = new Sprite(new Image("datas/post-fx/background.jpg")); // Load the text font 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"); // 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"); 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); // 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); // 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); // Start the game loop while (App.IsOpened()) { // Process events App.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; // 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); // Clear the window App.Clear(); // Draw background and apply the post-fx App.Draw(Background); App.Draw(CurrentEffect.Current.Value); // Draw interface strings App.Draw(CurFXStr); App.Draw(InfoStr); // Finally, display the rendered frame on screen App.Display(); } }
public Label(string _text, Font _font, float _x = 0, float _y = 0) { Text = new String2D(_text, _font, 14); Text.Position = new Vector2(_x, _y); }