public SetVerticalSyncEnabled ( bool enable ) : void | ||
enable | bool | True to enable v-sync, false to deactivate |
return | void |
public static void Main(string[] args) { window = new RenderWindow(new VideoMode(800, 600), "SFML window"); window.SetVisible(true); window.SetVerticalSyncEnabled(true); window.Closed += OnClosed; window.MouseMoved += OnMouse; window.MouseLeft += Window_MouseLeft; window.Resized += Window_Resized; List<Button> buttons = new List<Button>(); for (int i = 0; i < 10; i++) { buttons.Add(new Button(new Vector2f(i*200, 100), new Vector2f(75, 20))); } while (window.IsOpen) { window.DispatchEvents(); window.Clear(new Color(50, 50, 50)); GUIManager.GuiManager.Update(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y); foreach (var item in buttons) { window.Draw(item); } window.Display(); } }
public static void createDisplay(bool VSync = false,int FPSCap = 60) { try { //Configure the settings of the Window ContextSettings settings = new ContextSettings(24, 8, 4, 3, 2); window = new RenderWindow(new VideoMode(Convert.ToUInt32(WIDTH), Convert.ToUInt32(HEIGHT)), "OpenGL", Styles.Default, settings); Logger.Log(window.Settings.ToString(), Logger.Symbols.Warning); if (VSync) { window.SetVerticalSyncEnabled(VSync); }else { window.SetFramerateLimit(Convert.ToUInt32(FPSCap)); } //Setup EventHandler window.Closed += new EventHandler(OnClosed); window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); window.Resized += new EventHandler<SizeEventArgs>(OnResized); //Init OpenTK Toolkit.Init(); OpenTK.Graphics.GraphicsContext context = new OpenTK.Graphics.GraphicsContext(new ContextHandle(IntPtr.Zero), null); GL.Viewport(0, 0, WIDTH, HEIGHT); } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }
public Game(uint width = 1365, uint height = 768) { if (!File.Exists(IniFileName)) { MessageBox.Show(string.Format("Brak pliku {0}!", IniFileName)); Environment.Exit(1); } ReadIniFile(IniFileName); Players = new Dictionary<int, PlayerInstance>(); Width = width; Height = height; var settings = new ContextSettings { AntialiasingLevel = 8 }; Window = new RenderWindow(new VideoMode(Width, Height), "Nano War", Styles.Close, settings); Window.Closed += (s, a) => { GameClient.GameClient.Dispose(); Window.Close(); }; Window.SetVerticalSyncEnabled(true); Window.SetKeyRepeatEnabled(false); StateMachine = new StateMachine(); AudioManager = new AudioManager(); }
//private GameWorld world; static SFML.Graphics.RenderWindow InitWindow() { SFML.Graphics.RenderWindow window = new SFML.Graphics.RenderWindow(VideoMode.DesktopMode, "Top Down", Styles.Fullscreen); window.SetVerticalSyncEnabled(true); window.SetFramerateLimit(61); return(window); }
internal static void Main(string[] args) { shapes = new List<Shape>(); window = new RenderWindow(new VideoMode(WINDOW_SIZE.X, WINDOW_SIZE.Y), "Physics Playground", Styles.Titlebar | Styles.Close); window.SetVerticalSyncEnabled(true); window.SetKeyRepeatEnabled(false); SetupEvents(); Time lastTime = clock.ElapsedTime; while(window.IsOpen) { Time now = clock.ElapsedTime; Time frame = now - lastTime; lastTime = now; lag += frame; while(lag >= dt) { window.DispatchEvents(); if(!paused) { Update(); } lag -= dt; } Draw(); } }
public static void initialise() { window = new RenderWindow(new VideoMode(RESOLUTION_X, RESOLUTION_Y), "Asialaide"); // Video settings. window.SetFramerateLimit(FRAME_LIMIT); window.SetVerticalSyncEnabled(VSYNC); }
public SfmlControl() { m_renderWindow = new RenderWindow(this.Handle); m_renderWindow.SetVerticalSyncEnabled(true); //add resize event handler this.Resize += SfmlControl_Resize; SfmlControl_Resize(this, EventArgs.Empty); }
public SfmlControl() { //dllNotFoundException? copy the csfml dlls to the output folder m_renderWindow = new RenderWindow(this.Handle); m_renderWindow.SetVerticalSyncEnabled(true); //add resize event handler this.Resize += SfmlControl_Resize; SfmlControl_Resize(this, EventArgs.Empty); }
Game() { Window = new RenderWindow(new VideoMode(1024u, 768u), "Living Space"); Window.SetVisible(true); Window.SetVerticalSyncEnabled(true); Window.SetFramerateLimit(30); Window.Closed += OnWindowClosed; }
public void Run() { TextureLoader.Init(); Window = new RenderWindow(videoMode, title, Styles.Close); States = new RenderStates(RenderStates.Default); Window.Closed += (s, e) => { Console.WriteLine("Closing..."); Window.Close(); }; Window.SetVerticalSyncEnabled(true); defaultView = Window.DefaultView; gameView = Window.DefaultView; gameView.Viewport = new FloatRect(0, 0, .85f, .85f); BackgroundColor = new Color(100, 149, 237); // dat cornflower blue Tilemap = new Tilemap(this); SelectedTileID = 1; var timer = new Stopwatch(); while (Window.IsOpen) { timer.Restart(); Window.DispatchEvents(); var mouse = Mouse.GetPosition(Window); //if (Mouse.IsButtonPressed(Mouse.Button.Right)) // gameView.Move(new Vector2f(prevMouse.X - mouse.X, prevMouse.Y - mouse.Y)); Tilemap.Update(Frametime); Window.Clear(BackgroundColor); Window.SetView(gameView); Tilemap.Draw(Window, States); Window.SetView(defaultView); Debug.Draw(Window); Window.Display(); prevMouse = mouse; timer.Stop(); Frametime = (float)timer.Elapsed.TotalMilliseconds; Window.SetTitle($"{title} ({(1d / timer.Elapsed.TotalSeconds):0}fps)"); } }
public WindowManager() { //Init main window shit window = new RenderWindow(new VideoMode(640, 480), "Super cool window title!"); window.SetVerticalSyncEnabled(true); window.SetActive(true); window.Closed += window_Closed; // Open gl Gl.glEnable(Gl.GL_TEXTURE_2D); Gl.glLoadIdentity(); Gl.glOrtho(0, 640, 480, 0, 0, 1); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glDisable(Gl.GL_DEPTH_TEST); Gl.glLoadIdentity(); Gl.glTranslatef(0.375f, 0.375f, 0); particles = new CircleShape[pcount]; for (int i = 0; i < pcount; i++) { particles[i] = new CircleShape(4f); particles[i].FillColor = Color.White; particles[i].Position = new Vector2f(0, 0); particles[i].Radius = 4; } circletest = new CircleShape(); circletest.Position = new Vector2f(100, 100); circletest.OutlineColor = Color.Red; circletest.OutlineThickness = 1; circletest.FillColor = Color.Black; circletest.Radius = 100; circletest2 = new CircleShape(); circletest2.Position = new Vector2f(200, 300); circletest2.OutlineColor = Color.Red; circletest2.OutlineThickness = 1; circletest2.FillColor = Color.Black; circletest2.Radius = 100; mytext = new Text("test", new Font("arial.ttf"), 16); mytext.Position = new Vector2f(4, 4); mytext.Color = Color.White; mytext.Style = Text.Styles.Bold; mytextShadow = new Text("test", new Font("arial.ttf"), 16); mytextShadow.Position = new Vector2f(6, 6); mytextShadow.Color = Color.Black; sim = new Simulation(); sim.InitSimulation(pcount); }
public void Run() { //var mode = new SFML.Window.VideoMode(800, 600); var window = new SFML.Graphics.RenderWindow(SFML.Window.VideoMode.FullscreenModes[0], "Repair Project", SFML.Window.Styles.Fullscreen); window.KeyPressed += Window_KeyPressed; window.MouseButtonPressed += OnMouseButtonPressed; window.MouseButtonReleased += OnMouseButtonReleased; window.MouseMoved += OnMouseMoved; //this.object2DManager.SizeScreen = window.GetView().Size; SFML.Graphics.View view = window.GetView(); this.resolutionScreen = new Vector2f(view.Size.X, view.Size.Y); view.Center = new Vector2f(0, 0); window.SetView(view); window.SetVerticalSyncEnabled(true); Clock clock = new Clock(); this.officeWorld.StartLevel(); // Start the game loop while (window.IsOpen) { Time deltaTime = clock.Restart(); // Game logic update this.officeWorld.UpdateLogic(deltaTime); window.Clear(); this.object2DManager.DrawIn(window); // Process events window.DispatchEvents(); AObject2D.UpdateZoomAnimationManager(deltaTime); // Finally, display the rendered frame on screen window.Display(); } this.object2DManager.Dispose(this.officeWorld); AObject2D.StopAnimationManager(); }
public static void Main() { #region Initialize Variables window = new RenderWindow(new VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Reflexes For Friends", Styles.Default, new ContextSettings(32, 0)); timer = new Stopwatch(); world = new GameWorld(new Texture("resources/background-grass.png")); player = new Player(new Texture("resources/player.png")); friend = new Friend(new Texture("resources/friend.png")); enemies = new List<Enemy>(); gameOver = false; #endregion #region Register Event Handlers window.Closed += new EventHandler(OnClosed); window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); window.KeyReleased += new EventHandler<KeyEventArgs>(OnKeyReleased); #endregion #region Setup Modules keyboardModule = new KeyboardModule(); #endregion RegisterKeyBindings(); GenerateEnemies(); timer.Start(); long timeSinceLastUpdate = 0; window.SetVerticalSyncEnabled(true); window.SetActive(); while (window.IsOpen()) { window.DispatchEvents(); if (!gameOver) { timeSinceLastUpdate += timer.ElapsedMilliseconds; timer.Restart(); if (timeSinceLastUpdate >= UPDATE_FREQUENCY_IN_MS) { UpdateGame(UPDATE_FREQUENCY_IN_MS); timeSinceLastUpdate -= UPDATE_FREQUENCY_IN_MS; } } DrawGame(); window.Display(); } timer.Stop(); }
public SfmlControl() { m_renderWindow = new RenderWindow(this.Handle); m_renderWindow.SetVerticalSyncEnabled(true); //add event handlers this.Resize += SfmlControl_Resize; SfmlControl_Resize(this, EventArgs.Empty); this.MouseWheel += SfmlControl_MouseWheel; this.MouseDown += SfmlControl_MouseDown; this.MouseUp += SfmlControl_MouseUp; this.MouseMove += SfmlControl_MouseMove; }
public void SetupWindow() { // create window _window = new RenderWindow (new VideoMode (1000, 800), "Equation Invasion! - Tainted Mustard", Styles.Close); _window.SetVerticalSyncEnabled (true); _window.SetFramerateLimit(60); // setup SFML event handlers _window.Closed += new EventHandler(OnClosed); _window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); _window.KeyReleased += new EventHandler<KeyEventArgs> (OnKeyReleased); _window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(OnMouseClicked); _window.TextEntered += new EventHandler<TextEventArgs>(OnTextEntered); }
public GameWindow(int mScreenWidth, int mScreenHeight, int mPixelMultiplier) { _stopwatch = new PerformanceStopwatch(); _width = mScreenWidth; _height = mScreenHeight; RenderWindow = new RenderWindow(new VideoMode((uint) _width, (uint) _height), "", Styles.Default); RenderWindow.SetVerticalSyncEnabled(false); if (Settings.Framerate.IsLimited) RenderWindow.SetFramerateLimit((uint) Settings.Framerate.Limit); RenderWindow.Position = new Vector2i(400, 80); RenderWindow.Size = new Vector2u((uint) (mScreenWidth*mPixelMultiplier), (uint) (mScreenHeight*mPixelMultiplier)); RenderWindow.GainedFocus += WindowGainedFocus; RenderWindow.LostFocus += WindowLostFocus; }
private static void InitializeWindow() { //Construct window = new RenderWindow(new VideoMode(1920, 1080), "Orbs", IsFullscreen ? Styles.Fullscreen : Styles.Default); //Set parameters window.SetVisible(true); window.SetMouseCursorVisible(false); window.SetVerticalSyncEnabled(IsVSyncEnabled); //Bind events window.Closed += (sender, i) => window.Close(); window.KeyPressed += (sender, i) => stateManager.CurrentState?.HandleKeyPressed(i); window.KeyPressed += (sender, i) => { if (i.Code == Keyboard.Key.F11) { window.Close(); IsFullscreen = !IsFullscreen; InitializeWindow(); } }; }
/// <summary> /// Initialize the game. Call once after modifying GameOptions. /// </summary> public static void Initialize() { var style = Styles.Titlebar | Styles.Close; if (GameOptions.Resizable) style |= Styles.Resize; size = new Vector2f(GameOptions.Width, GameOptions.Height); running = true; Window = new RenderWindow(new VideoMode(GameOptions.Width, GameOptions.Height), GameOptions.Caption, style); Window.SetFramerateLimit(GameOptions.Framerate); Window.SetVerticalSyncEnabled(GameOptions.Vsync); if (!string.IsNullOrWhiteSpace(GameOptions.Icon)) { var icon = Assets.LoadTexture(GameOptions.Icon); Window.SetIcon(icon.Size.X, icon.Size.Y, icon.CopyToImage().Pixels); } Framerate = GameOptions.Framerate; #region Event Wrappers Window.Closed += (sender, args) => Exit(true); Window.Resized += (sender, args) => Resize(new Vector2f(args.Width, args.Height)); Window.MouseButtonPressed += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, true, args.X, args.Y)); Window.MouseButtonReleased += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, false, args.X, args.Y)); Window.MouseWheelMoved += (sender, args) => DispatchEvent(new MouseWheelInputArgs(args.Delta, args.X, args.Y)); Window.MouseMoved += (sender, args) => DispatchEvent(new MouseMoveInputArgs(args.X, args.Y)); Window.TextEntered += (sender, args) => DispatchEvent(new TextInputArgs(args.Unicode)); Window.KeyPressed += (sender, args) => { if (args.Code == Keyboard.Key.Unknown || KeyStates[(int)args.Code]) // repeated key press return; KeyStates[(int)args.Code] = true; DispatchEvent(new KeyInputArgs(args.Code, true, args.Control, args.Shift)); }; Window.KeyReleased += (sender, args) => { if (args.Code != Keyboard.Key.Unknown) KeyStates[(int)args.Code] = false; DispatchEvent(new KeyInputArgs(args.Code, false, args.Control, args.Shift)); }; #endregion }
public static void Initialize() { var style = Styles.Titlebar | Styles.Close; if (GameOptions.Resizable) style |= Styles.Resize; size = new Vector2f(GameOptions.Width, GameOptions.Height); Window = new RenderWindow(new VideoMode(GameOptions.Width, GameOptions.Height), GameOptions.Caption, style); Window.SetFramerateLimit(GameOptions.Framerate); Window.SetVerticalSyncEnabled(GameOptions.Vsync); if (GameOptions.Icon != "") { Texture texture = Assets.LoadTexture(GameOptions.Icon); Window.SetIcon(texture.Size.X, texture.Size.Y, texture.CopyToImage().Pixels); } Window.Closed += (sender, args) => Window.Close(); Window.Resized += (sender, args) => Resize(new Vector2f(args.Width, args.Height)); Window.MouseButtonPressed += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, true, args.X, args.Y)); Window.MouseButtonReleased += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, false, args.X, args.Y)); Window.MouseWheelMoved += (sender, args) => DispatchEvent(new MouseWheelInputArgs(args.Delta, args.X, args.Y)); Window.MouseMoved += (sender, args) => DispatchEvent(new MouseMoveInputArgs(args.X, args.Y)); Window.TextEntered += (sender, args) => DispatchEvent(new TextInputArgs(args.Unicode)); Window.KeyPressed += (sender, args) => { if (args.Code == Keyboard.Key.Unknown || keyStates[(int)args.Code]) // repeated key press return; keyStates[(int)args.Code] = true; DispatchEvent(new KeyInputArgs(args.Code, true, args.Control, args.Shift)); }; Window.KeyReleased += (sender, args) => { if (args.Code != Keyboard.Key.Unknown) keyStates[(int)args.Code] = false; DispatchEvent(new KeyInputArgs(args.Code, false, args.Control, args.Shift)); }; }
public Game() { _window = new RenderWindow(new VideoMode(1280, 720), "Loderpit"); _stopwatch = new Stopwatch(); _window.Closed += new EventHandler(_window_Closed); _window.GainedFocus += new EventHandler(_window_GainedFocus); _window.LostFocus += new EventHandler(_window_LostFocus); _window.SetVerticalSyncEnabled(true); // Load content loadContent(); // Create systems SystemManager.physicsSystem = new PhysicsSystem(); SystemManager.statSystem = new StatSystem(); SystemManager.levelSystem = new LevelSystem(); SystemManager.teamSystem = new TeamSystem(); SystemManager.cameraSystem = new CameraSystem(); SystemManager.characterSystem = new CharacterSystem(); SystemManager.animationSystem = new AnimationSystem(); SystemManager.particleRenderSystem = new ParticleRenderSystem(); SystemManager.renderSystem = new RenderSystem(); SystemManager.obstacleSystem = new ObstacleSystem(); SystemManager.groupSystem = new GroupSystem(); SystemManager.skillSystem = new SkillSystem(); SystemManager.combatSystem = new CombatSystem(); SystemManager.aiSystem = new AISystem(); SystemManager.interLevelSystem = new InterLevelSystem(); SystemManager.spellSystem = new SpellSystem(); SystemManager.explosionSystem = new ExplosionSystem(); SystemManager.proxySystem = new ProxySystem(); SystemManager.battleDroneSystem = new BattleDroneSystem(); // Start the initial state startMainMenuState(); }
public void Run() { var mode = new SFML.Window.VideoMode(800, 600); //var window = new SFML.Graphics.RenderWindow(SFML.Window.VideoMode.FullscreenModes[0], "Pokemon Union", SFML.Window.Styles.Fullscreen); var window = new SFML.Graphics.RenderWindow(mode, "Pokemon Union"); window.KeyPressed += Window_KeyPressed; window.MouseButtonPressed += OnMouseButtonPressed; window.MouseButtonReleased += OnMouseButtonReleased; window.MouseMoved += OnMouseMoved; //this.object2DManager.SizeScreen = window.GetView().Size; SFML.Graphics.View view = window.GetView(); view.Size = new Vector2f(400, 300); this.resolutionScreen = new Vector2f(view.Size.X, view.Size.Y); view.Center = new Vector2f(9492, -12595); this.SetView(window, view); window.SetVerticalSyncEnabled(true); Clock clock = new Clock(); this.landWorld.OnFocusAreaChanged(view.Center / MODEL_TO_VIEW, this.resolutionScreen / MODEL_TO_VIEW); // Start the game loop while (window.IsOpen) { Time deltaTime = clock.Restart(); // Game logic update this.landWorld.UpdateLogic(null, deltaTime); // Draw window AObject2D.UpdateZoomAnimationManager(deltaTime); window.Clear(); this.landWorld2D.DrawIn(window, ref this.boundsView); // Process events window.DispatchEvents(); //// To remove after. //if (Keyboard.IsKeyPressed(Keyboard.Key.Z)) //{ // view.Center += new Vector2f(0, -2f); //} //else if(Keyboard.IsKeyPressed(Keyboard.Key.S)) //{ // view.Center += new Vector2f(0, 2f); //} //if (Keyboard.IsKeyPressed(Keyboard.Key.D)) //{ // view.Center += new Vector2f(2f, 0); //} //else if (Keyboard.IsKeyPressed(Keyboard.Key.Q)) //{ // view.Center += new Vector2f(-2f, 0); //} //// Console.WriteLine(view.Center.X + " : " + view.Center.Y); //this.landWorld.OnFocusAreaChanged(view.Center / MODEL_TO_VIEW, this.resolutionScreen / MODEL_TO_VIEW, 0); //this.SetView(window, view); // Finally, display the rendered frame on screen window.Display(); } this.landWorld2D.Dispose(this.landWorld); this.landWorld.Dispose(); AObject2D.StopAnimationManager(); }
private void Start() { //SFML неща ContextSettings cs = new ContextSettings(); cs.AntialiasingLevel = 8; window = new RenderWindow(new VideoMode(renderFrame.width, renderFrame.height), "GRAPHical Learner", Styles.Titlebar | Styles.Close, cs); window.Closed += window_Closed; window.MouseWheelMoved += window_MouseWheelMoved; window.KeyPressed += window_KeyPressed; window.MouseButtonPressed += window_MouseButtonPressed; window.MouseButtonReleased += window_MouseButtonReleased; window.SetVerticalSyncEnabled(true); //Алгоритъм за подреждане fs = new ForceSimulatorMKIIB(1.5, 0.8); fs.SetGraph(activeGraph); fs.SimulatorStopped += fs_SimulatorStopped; //Изчислява се приближението на рамката renderFrame.CalcZoom(); //Пуска се GUI-то InitializeGui(); if (connector != null) EnablePhysics(); // ако е вързан алгоритъм, графа се подрежда автоматично Loop(); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // Request a 24-bits depth buffer when creating the window ContextSettings contextSettings = new ContextSettings(); contextSettings.DepthBits = 24; // Create the main window RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML graphics with OpenGL", Styles.Default, contextSettings); window.SetVerticalSyncEnabled(true); // Initialize OpenTK Toolkit.Init(); GraphicsContext context = new GraphicsContext(new ContextHandle(IntPtr.Zero), null); // Setup event handlers window.Closed += new EventHandler(OnClosed); window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); window.Resized += new EventHandler<SizeEventArgs>(OnResized); // Create a sprite for the background Sprite background = new Sprite(new Texture("resources/background.jpg")); // Create a text to display on top of the OpenGL object Text text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf")); text.Position = new Vector2f(250, 450); text.Color = new Color(255, 255, 255, 170); // Make the window the active target for OpenGL calls window.SetActive(); // Load an OpenGL texture. // We could directly use a SFML.Graphics.Texture 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("resources/texture.jpg")) { GL.GenTextures(1, out texture); GL.BindTexture(TextureTarget.Texture2D, texture); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)image.Size.X, (int)image.Size.Y, 0, PixelFormat.Rgba, PixelType.UnsignedByte, image.Pixels); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); } // Enable Z-buffer read and write GL.Enable(EnableCap.DepthTest); GL.DepthMask(true); GL.ClearDepth(1); // Disable lighting GL.Disable(EnableCap.Lighting); // Configure the viewport (the same size as the window) GL.Viewport(0, 0, (int)window.Size.X, (int)window.Size.Y); // Setup a perspective projection GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); float ratio = (float)(window.Size.X) / window.Size.Y; GL.Frustum(-ratio, ratio, -1, 1, 1, 500); // Bind the texture GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, texture); // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices) float[] cube = new float[] { // positions // texture coordinates -20, -20, -20, 0, 0, -20, 20, -20, 1, 0, -20, -20, 20, 0, 1, -20, -20, 20, 0, 1, -20, 20, -20, 1, 0, -20, 20, 20, 1, 1, 20, -20, -20, 0, 0, 20, 20, -20, 1, 0, 20, -20, 20, 0, 1, 20, -20, 20, 0, 1, 20, 20, -20, 1, 0, 20, 20, 20, 1, 1, -20, -20, -20, 0, 0, 20, -20, -20, 1, 0, -20, -20, 20, 0, 1, -20, -20, 20, 0, 1, 20, -20, -20, 1, 0, 20, -20, 20, 1, 1, -20, 20, -20, 0, 0, 20, 20, -20, 1, 0, -20, 20, 20, 0, 1, -20, 20, 20, 0, 1, 20, 20, -20, 1, 0, 20, 20, 20, 1, 1, -20, -20, -20, 0, 0, 20, -20, -20, 1, 0, -20, 20, -20, 0, 1, -20, 20, -20, 0, 1, 20, -20, -20, 1, 0, 20, 20, -20, 1, 1, -20, -20, 20, 0, 0, 20, -20, 20, 1, 0, -20, 20, 20, 0, 1, -20, 20, 20, 0, 1, 20, -20, 20, 1, 0, 20, 20, 20, 1, 1 }; // Enable position and texture coordinates vertex components GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.VertexPointer(3, VertexPointerType.Float, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 0)); GL.TexCoordPointer(2, TexCoordPointerType.Float, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 3)); // Disable normal and color vertex components GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.ColorArray); Clock clock = new Clock(); // Start game loop while (window.IsOpen) { // Process events window.DispatchEvents(); // Clear the window GL.Clear(ClearBufferMask.DepthBufferBit); // Draw background window.PushGLStates(); window.Draw(background); window.PopGLStates(); // Clear the depth buffer GL.Clear(ClearBufferMask.DepthBufferBit); // We get the position of the mouse cursor, so that we can move the box accordingly float x = Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F; float y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F; // Apply some transformations GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.Translate(x, y, -100.0F); GL.Rotate(clock.ElapsedTime.AsSeconds() * 50, 1.0F, 0.0F, 0.0F); GL.Rotate(clock.ElapsedTime.AsSeconds() * 30, 0.0F, 1.0F, 0.0F); GL.Rotate(clock.ElapsedTime.AsSeconds() * 90, 0.0F, 0.0F, 1.0F); // Draw the cube GL.DrawArrays(OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, 0, 36); // Draw some text on top of our OpenGL object window.PushGLStates(); window.Draw(text); window.PopGLStates(); // Finally, display the rendered frame on screen window.Display(); } // Don't forget to destroy our texture GL.DeleteTextures(1, ref texture); }
/// <summary> /// The main entry point for the application. /// </summary> public static void shaderMain() { // Create the main window RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader"); window.SetVerticalSyncEnabled(true); // Setup event handlers window.Closed += new EventHandler(OnClosed); window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); // Load the application font and pass it to the Effect class Font font = new Font("resources/sansation.ttf"); Effect.SetFont(font); // Create the effects effects = new Effect[] { new Pixelate(), new WaveBlur(), new StormBlink(), new Edge() }; current = 0; // Create the messages background Texture textBackgroundTexture = new Texture("resources/text-background.png"); Sprite textBackground = new Sprite(textBackgroundTexture); textBackground.Position = new Vector2f(0, 520); textBackground.Color = new Color(255, 255, 255, 200); // Create the description text description = new Text("Current effect: " + effects[current].Name, font, 20); description.Position = new Vector2f(10, 530); description.Color = new Color(80, 80, 80); // Create the instructions text Text instructions = new Text("Press left and right arrows to change the current shader", font, 20); instructions.Position = new Vector2f(280, 555); instructions.Color = new Color(80, 80, 80); // Start the game loop int startTime = Environment.TickCount; while (window.IsOpen()) { // Process events window.DispatchEvents(); // Update the current example float time = (Environment.TickCount - startTime) / 1000.0F; float x = (float)Mouse.GetPosition(window).X / window.Size.X; float y = (float)Mouse.GetPosition(window).Y / window.Size.Y; effects[current].Update(time, x, y); // Clear the window window.Clear(new Color(255, 128, 0)); // Draw the current example window.Draw(effects[current]); // Draw the text window.Draw(textBackground); window.Draw(instructions); window.Draw(description); // Finally, display the rendered frame on screen window.Display(); } }
private void UpdateGraphicsSettings(IGraphicsSettings graphicsSettings) { m_GraphicsSettings = graphicsSettings; m_PostOffice.SendMessage(Constant.enumMessage.GET_INPUT_EVENT_HANDLERS); if (m_RenderWindow != null) { m_RenderWindow.Clear(); m_RenderWindow.Close(); } m_RenderWindow = new RenderWindow(new VideoMode((uint)m_GraphicsSettings.m_ScreenSize.x, (uint)m_GraphicsSettings.m_ScreenSize.y), m_GraphicsSettings.m_Title,m_GraphicsSettings.m_FullScreen ? Styles.Fullscreen : Styles.Default ); m_RenderWindow.SetVerticalSyncEnabled(m_GraphicsSettings.m_VSync); m_RenderWindow.Closed += new EventHandler(CloseWindow); m_RenderWindow.KeyPressed += m_KeyEventHandler; m_RenderWindow.KeyReleased += m_KeyEventHandler; m_RenderWindow.MouseButtonPressed += m_MouseButtonEventHandler; m_RenderWindow.MouseButtonReleased += m_MouseButtonEventHandler; m_RenderWindow.MouseMoved += m_MouseMoveEventHandler; m_RenderWindow.MouseWheelMoved += m_MouseWheelEventHandler; }
private void LoadWindow() { // Determine settings var vmode = new VideoMode( (uint)Settings.ReadInt("Video", "ResX", 1024), (uint)Settings.ReadInt("Video", "ResY", 600), 24); bool fscreen = Settings.ReadInt("Video", "Fullscreen", 0) == 1; bool vsync = Settings.ReadInt("Video", "VSync", 1) == 1; // Setup the new window window = new RenderWindow(vmode, "FTL: Overdrive", fscreen ? Styles.Fullscreen : Styles.Close, new ContextSettings(24, 8, 8)); window.SetVisible(true); window.SetVerticalSyncEnabled(vsync); window.MouseMoved += new EventHandler<MouseMoveEventArgs>(window_MouseMoved); window.Closed += new EventHandler(window_Closed); window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(window_MouseButtonPressed); window.MouseButtonReleased += new EventHandler<MouseButtonEventArgs>(window_MouseButtonReleased); window.KeyPressed += new EventHandler<KeyEventArgs>(window_KeyPressed); window.KeyReleased += new EventHandler<KeyEventArgs>(window_KeyReleased); window.TextEntered += new EventHandler<TextEventArgs>(window_TextEntered); // Init UI Canvas = new UI.Canvas(); var screenrect = Util.ScreenRect(window.Size.X, window.Size.Y, 1.77778f); Canvas.X = screenrect.Left; Canvas.Y = screenrect.Top; Canvas.Width = screenrect.Width; Canvas.Height = screenrect.Height; // Load icon using (var bmp = new System.Drawing.Bitmap(Resource("img/exe_icon.bmp"))) { byte[] data = new byte[bmp.Width * bmp.Height * 4]; int i = 0; for (int y = 0; y < bmp.Height; y++) for (int x = 0; x < bmp.Width; x++) { var c = bmp.GetPixel(x, y); data[i++] = c.R; data[i++] = c.G; data[i++] = c.B; data[i++] = c.A; } window.SetIcon((uint)bmp.Width, (uint)bmp.Height, data); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // Request a 32-bits depth buffer when creating the window ContextSettings contextSettings = new ContextSettings(); contextSettings.DepthBits = 32; // Create the main window RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML graphics with OpenGL", Styles.Default, contextSettings); window.SetVerticalSyncEnabled(true); // Make it the active window for OpenGL calls window.SetActive(); // Setup event handlers window.Closed += new EventHandler(OnClosed); window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); window.Resized += new EventHandler<SizeEventArgs>(OnResized); // Create a sprite for the background Sprite background = new Sprite(new Texture("resources/background.jpg")); // Create a text to display on top of the OpenGL object Text text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf")); text.Position = new Vector2f(250, 450); text.Color = new Color(255, 255, 255, 170); // Load an OpenGL texture. // We could directly use a SFML.Graphics.Texture 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("resources/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.Size.X, (int)image.Size.Y, 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); // Disable lighting Gl.glDisable(Gl.GL_LIGHTING); // Configure the viewport (the same size as the window) Gl.glViewport(0, 0, (int)window.Size.X, (int)window.Size.Y); // Setup a perspective projection Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); float ratio = (float)(window.Size.X) / window.Size.Y; Gl.glFrustum(-ratio, ratio, -1, 1, 1, 500); // Bind the texture Gl.glEnable(Gl.GL_TEXTURE_2D); Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture); // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices) float[] cube = new float[] { // positions // texture coordinates -20, -20, -20, 0, 0, -20, 20, -20, 1, 0, -20, -20, 20, 0, 1, -20, -20, 20, 0, 1, -20, 20, -20, 1, 0, -20, 20, 20, 1, 1, 20, -20, -20, 0, 0, 20, 20, -20, 1, 0, 20, -20, 20, 0, 1, 20, -20, 20, 0, 1, 20, 20, -20, 1, 0, 20, 20, 20, 1, 1, -20, -20, -20, 0, 0, 20, -20, -20, 1, 0, -20, -20, 20, 0, 1, -20, -20, 20, 0, 1, 20, -20, -20, 1, 0, 20, -20, 20, 1, 1, -20, 20, -20, 0, 0, 20, 20, -20, 1, 0, -20, 20, 20, 0, 1, -20, 20, 20, 0, 1, 20, 20, -20, 1, 0, 20, 20, 20, 1, 1, -20, -20, -20, 0, 0, 20, -20, -20, 1, 0, -20, 20, -20, 0, 1, -20, 20, -20, 0, 1, 20, -20, -20, 1, 0, 20, 20, -20, 1, 1, -20, -20, 20, 0, 0, 20, -20, 20, 1, 0, -20, 20, 20, 0, 1, -20, 20, 20, 0, 1, 20, -20, 20, 1, 0, 20, 20, 20, 1, 1 }; // Enable position and texture coordinates vertex components Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY); Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); Gl.glVertexPointer(3, Gl.GL_FLOAT, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 0)); Gl.glTexCoordPointer(2, Gl.GL_FLOAT, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 3)); // Disable normal and color vertex components Gl.glDisableClientState(Gl.GL_NORMAL_ARRAY); Gl.glDisableClientState(Gl.GL_COLOR_ARRAY); int startTime = Environment.TickCount; // Start game loop while (window.IsOpen()) { // Process events window.DispatchEvents(); // Clear the window window.Clear(); // Draw background window.PushGLStates(); window.Draw(background); window.PopGLStates(); // Clear the 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 = Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F; float y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F; // Apply some transformations float time = (Environment.TickCount - startTime) / 1000.0F; 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 the cube Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 36); // Draw some text on top of our OpenGL object window.PushGLStates(); window.Draw(text); window.PopGLStates(); // Finally, display the rendered frame on screen window.Display(); } // Don't forget to destroy our texture Gl.glDeleteTextures(1, ref texture); }
public static void Initialize() { var style = Styles.Titlebar | Styles.Close; size = new Vector2f(Configuration.Width, Configuration.Height); Window = new RenderWindow(new VideoMode(Configuration.Width, Configuration.Height), "Open Empires", style); Window.SetFramerateLimit(Configuration.Framerate); Window.SetVerticalSyncEnabled(Configuration.VSync); Window.Closed += (sender, args) => Window.Close(); Window.Resized += (sender, args) => Resize(new Vector2f(args.Width, args.Height)); /*Window.MouseButtonPressed += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, true, args.X, args.Y)); Window.MouseButtonReleased += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, false, args.X, args.Y)); Window.MouseWheelMoved += (sender, args) => DispatchEvent(new MouseWheelInputArgs(args.Delta, args.X, args.Y)); Window.MouseMoved += (sender, args) => DispatchEvent(new MouseMoveInputArgs(args.X, args.Y));*/ Window.MouseMoved += new EventHandler<MouseMoveEventArgs>(Window_MouseMoved); Window.MouseWheelMoved += (sender, args) => { /* Mouse wheel zoom implementation where the view will zoom * towards the area the cursor is pointing to */ var mousePos = Mouse.GetPosition(Window); float relX = (float) mousePos.X / Window.Size.X - 0.5f; float relY = (float) mousePos.Y / Window.Size.Y - 0.5f; GameView.Move(new Vector2f { X = relX * GameView.Size.X, Y = relY * GameView.Size.Y }); GameView.Zoom(1 - (args.Delta * 0.1f)); GameView.Move(new Vector2f { X = -relX * GameView.Size.X, Y = -relY * GameView.Size.Y }); }; Window.KeyPressed += (sender, args) => { KeyStates[(int)args.Code] = true; }; Window.KeyReleased += (sender, args) => { KeyStates[(int)args.Code] = false; }; Blendomatic.ReadBlendomatic(new System.IO.FileStream("blendomatic.dat", System.IO.FileMode.Open)); map = new Map(); GameView = new View(DefaultView); GameView.Center = new Vector2f((map.Width/2)*96, 0); var blend = Blendomatic.BlendingModes[2]; var tile = blend.Tiles[12]; var img = new Image(97, 49); for (var y = 0; y < img.Size.Y; y++) for (var x = 0; x < img.Size.X; x++) img.SetPixel((uint)x, (uint)y, new Color(255, 0, 0, 0)); var i = 0; for (var y = 0; y < img.Size.X; y++) { var bytesPerRow = y < 24 ? 1 + (4 * y) : 97 - (4 * (y - 24)); var startX = 48 - (bytesPerRow / 2); for (var x = 0; x < bytesPerRow; x++) img.SetPixel((uint)(startX + x), (uint)y, new Color(0, 0, 0, tile[i++])); } var slpFile = new SLPFile(); slpFile.LoadFile("textures/ter15002.slp"); var spritewidth = slpFile.GetFrame(0).m_Width; var spriteheight = slpFile.GetFrame(0).m_Height; var imgg = new Image((uint)spritewidth, (uint)(spriteheight ), slpFile.GetFrame(0).GetRGBAArray()); for (var y = 0; y < imgg.Size.Y; y++) for (var x = 0; x < imgg.Size.X; x++) { var col = imgg.GetPixel((uint)x, (uint)y); col.A = (byte)(Math.Min(255, (128-img.GetPixel((uint)x, (uint)y).A)*2)); if (img.GetPixel((uint)x, (uint)y).R == 255) col.A = 0; imgg.SetPixel((uint)x, (uint)y, col); } selected = new Sprite(new Texture(imgg)); /* blend sand to forest now */ var blend2 = Blendomatic.BlendingModes[2]; var tile2 = blend2.Tiles[12]; var img2 = new Image(97, 49); for (var y = 0; y < img2.Size.Y; y++) for (var x = 0; x < img2.Size.X; x++) img2.SetPixel((uint)x, (uint)y, new Color(255, 0, 0, 0)); var i2 = 0; for (var y = 0; y < img.Size.X; y++) { var bytesPerRow = y < 24 ? 1 + (4 * y) : 97 - (4 * (y - 24)); var startX = 48 - (bytesPerRow / 2); for (var x = 0; x < bytesPerRow; x++) img2.SetPixel((uint)(startX + x), (uint)y, new Color(0, 0, 0, tile[i2++])); } var slpFile2 = new SLPFile(); slpFile2.LoadFile("textures/ter15017.slp"); var spritewidth2 = slpFile2.GetFrame(0).m_Width; var spriteheight2 = slpFile2.GetFrame(0).m_Height; var imgg2 = new Image((uint)spritewidth2, (uint)(spriteheight2), slpFile2.GetFrame(0).GetRGBAArray()); for (var y = 0; y < imgg2.Size.Y; y++) for (var x = 0; x < imgg2.Size.X; x++) { var col = imgg2.GetPixel((uint)x, (uint)y); col.A = (byte)(Math.Min(255, (128 - img.GetPixel((uint)x, (uint)y).A) * 2)); if (img2.GetPixel((uint)x, (uint)y).R == 255) col.A = 0; imgg2.SetPixel((uint)x, (uint)y, col); } selected2 = new Sprite(new Texture(imgg2)); EntManager = new EntityManager(); }
/// <summary> /// Handles the <see cref="IGameContainer.RenderWindowChanged"/> event. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected virtual void OnRenderWindowChanged(RenderWindow oldValue, RenderWindow newValue) { if (newValue == null) return; newValue.SetMouseCursorVisible(ShowMouseCursor); newValue.SetVerticalSyncEnabled(UseVerticalSync); newValue.SetActive(); newValue.SetVisible(true); }
public void Run() { GameHelper.SetGame(this); Window = new RenderWindow(mode, title, Styles.Close); RStates = new RenderStates(RenderStates.Default); Window.Closed += (s, e) => { Console.WriteLine("Closing"); Window.Close(); }; Window.SetVerticalSyncEnabled(true); BackgroundColor = new Color(100, 149, 237); World = new World.World(this); World.AddObject(new Box(this, new Vector2f(50, 50), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(300, 200), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(450, 350), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(100, 250), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(200, 150), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(150, 400), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(400, 100), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(500, 250), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(600, 300), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(350, 450), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(650, 500), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(400, 100), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(250, 350), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(400, 100), new Vector2f(64, 64), Color.White)); World.AddObject(new Box(this, new Vector2f(650, 50), new Vector2f(64, 64), Color.White)); Lighting = new Lighting(this); var light = new PointLight(this, new Vector2f(100, 10), Color.Blue, 100f, 32); Lighting.AddLight(light); Stopwatch timer = new Stopwatch(); while (Window.IsOpen) { timer.Restart(); Window.DispatchEvents(); Window.Clear(BackgroundColor); World.Update(Frametime); Lighting.Update(Frametime); light.Position = new Vector2f(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y); World.Draw(Window, RStates); Lighting.Draw(Window, RStates); Debug.Draw(Window); Window.Display(); timer.Stop(); Frametime = (float)timer.Elapsed.TotalMilliseconds; Window.SetTitle($"{title} ({Math.Round(Frametime, 1):0.0}ms)"); } }
private RenderWindow CreateWindow(ApplicationSettings settings) { var windowStyle = settings.Fullscreen ? Styles.Fullscreen : Styles.Close; var window = new RenderWindow(settings.VideoMode, settings.WindowCaption, windowStyle); window.SetMouseCursorVisible(settings.MouseCursorVisible); window.SetVerticalSyncEnabled(settings.VerticalSyncEnabled); if (settings.FramerateLimit > 0) window.SetFramerateLimit(settings.FramerateLimit); return window; }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // Create main window RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL", Styles.Default, new ContextSettings(32, 0)); window.SetVerticalSyncEnabled(true); // Setup event handlers window.Closed += new EventHandler(OnClosed); window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); window.Resized += new EventHandler<SizeEventArgs>(OnResized); // Create a sprite for the background Sprite background = new Sprite(new Texture("resources/background.jpg")); // Create a text to display Text text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf")); text.Position = new Vector2f(250.0F, 450.0F); text.Color = new Color(255, 255, 255, 170); // Load an OpenGL texture. // We could directly use a sf::Texture 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("resources/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.Size.X, (int)image.Size.Y, 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); int startTime = Environment.TickCount; // Start game loop while (window.IsOpen()) { // Process events window.DispatchEvents(); // Clear the window window.Clear(); // Draw background window.PushGLStates(); window.Draw(background); window.PopGLStates(); // 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 = Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F; float y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F; // Apply some transformations float time = (Environment.TickCount - startTime) / 1000.0F; 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.PushGLStates(); window.Draw(text); window.PopGLStates(); // Finally, display the rendered frame on screen window.Display(); } // Don't forget to destroy our texture Gl.glDeleteTextures(1, ref texture); }
private void Init() { Music = new MusicPlayer(); Sounds = new SoundManager(); Assets = new Assets(); Assets.Load(); var vm = new SFML.Window.VideoMode(1000, 750, 32); var style = Styles.Close; var settings = new ContextSettings(0, 0, 8); Window = new SFML.Graphics.RenderWindow(vm, "", style, settings); Window.SetView(View); Window.SetVerticalSyncEnabled(true); Window.Closed += (sender, e) => { IsAppExited = true; }; Window.LostFocus += (sender, e) => { IsPaused = true; }; Window.GainedFocus += (sender, e) => { IsPaused = false; }; Window.SetMouseCursorVisible(true); var splash = new Space("Splash", true); var menu = new Space("Menu"); var inGame = new Space("InGame"); var gameOver = new Space("GameOver"); // ----- ----- ----- Splash ----- ----- ----- var images = new SplashImage[] { new SplashImage(Assets.Textures["sfml"], 3, 1, 1), new SplashImage(Assets.Textures["rsas"], 5, 1, 1) }; SplashImage.Prepare(images, e => { splash.IsActive = false; menu.IsActive = true; }); foreach(var image in images) splash.Add(image); // ----- ----- ----- Menu ----- ----- ----- var btnStart = new MenuButton("Play", 40, new Vector(100, 100)); var btnQuit = new MenuButton("Quit", 40, new Vector(100, 200)); var btnDiffEasy = new MenuButton("Easy", 30, new Vector(250, 100)); var btnDiffMedium = new MenuButton("Medium", 30, new Vector(250, 150)); var btnDiffHard = new MenuButton("Hard", 30, new Vector(250, 200)); var infoText = "- Instructions -\n" + "- Run, shoot and survive as long as possible.\n" + "- Collect white powersups to recover health.\n" + "- New weapons are unlocked after each 1000 kills.\n" + "\n" + "- Use WASD keys to move, and mouse to aim and shoot.\n" + "- Use the numbers keys to change weapons.\n" + "- During gameplay, press ESC to pause or F1 to give up."; var btnInfoText = new MenuButton(infoText, 20, new Vector(450, 125)); var highscoreList = new HighscoreList(new Vector2f(50, 300)); Difficulty = RSaS.Difficulty.Medium; btnDiffMedium.Text.Color = Color.Red; btnStart.Click += e => { if (IsGameOver) { IsGameOver = false; InitInGame(inGame); } Music.Play("music"); menu.IsActive = false; inGame.IsActive = true; IsOSCursorVisible = false; }; btnQuit.Click += e => { IsAppExited = true; }; btnDiffEasy.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Easy; btnDiffEasy.Text.Color = Color.Red; btnDiffMedium.Text.Color = Color.White; btnDiffHard.Text.Color = Color.White; }; btnDiffMedium.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Medium; btnDiffEasy.Text.Color = Color.White; btnDiffMedium.Text.Color = Color.Red; btnDiffHard.Text.Color = Color.White; }; btnDiffHard.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Hard; btnDiffEasy.Text.Color = Color.White; btnDiffMedium.Text.Color = Color.White; btnDiffHard.Text.Color = Color.Red; }; menu.Add(btnStart); menu.Add(btnQuit); menu.Add(btnDiffEasy); menu.Add(btnDiffMedium); menu.Add(btnDiffHard); menu.Add(btnInfoText); menu.Add(highscoreList); }