/// <summary> /// The main entry point for the application. /// </summary> static void Main() { var time = new TimeMonitor(1000); // Request a 32-bits depth buffer when creating the window var contextSettings = new ContextSettings { DepthBits = 32 }; // Create the main window var window = new RenderWindow(new VideoMode(1600, 900), "TenSeconds", Styles.Close | Styles.Titlebar, contextSettings); // Make it the active window for OpenGL calls window.SetActive(); var windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(window.SystemHandle); var graphicsContext = new OpenTK.Graphics.GraphicsContext(OpenTK.Graphics.GraphicsMode.Default, windowInfo); graphicsContext.MakeCurrent(windowInfo); graphicsContext.LoadAll(); // Setup event handlers window.Closed += OnClosed; window.KeyPressed += OnKeyPressed; window.Resized += OnResized; var inputManager = new InputManager(); inputManager.Init(window); var game = new Game(); game.Init(window); while (window.IsOpen() && game.IsRunning) { time.Update(); // Process events window.DispatchEvents(); inputManager.Update(window); game.HandleInput(inputManager); game.Update(time); // Clear color and depth buffer GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); game.Draw(window); // Finally, display the rendered frame on screen window.Display(); } }
private void InitializeOgl(Control WinControl) { if (RenderingContext != null) { if (!RenderingContext.IsDisposed) { DisposeOglObjects(); } } /* private OpenTK.Platform.IWindowInfo*/ WindowsInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(WinControl.Handle); OpenTK.Graphics.GraphicsMode GraphicMode = new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(PfdColorBits), PfdDepthBits, PfdStencilBits, PfdAuxBits, new OpenTK.Graphics.ColorFormat(PfdAccumBits), PfdBuffers, PfdStereo); OpenTK.Graphics.GraphicsMode GraphicMode2 = OpenTK.Graphics.GraphicsMode.Default; RenderingContext = new OpenTK.Graphics.GraphicsContext(GraphicMode2, WindowsInfo); RenderingContext.LoadAll(); FBO.LoadMethods(); RenderingContext.SwapInterval = 1; GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.ShadeModel(ShadingModel.Smooth); GL.Enable(EnableCap.Normalize); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Lighting); ShadowMapSampler = GL.GenSampler(); // Texture.Sampler= GL.GenSampler(); ActivateShader(); Lights[0].Position = new xyzwf(3, 4, 10, 0); FieldOfView = 0; Selector.PickingShader = PickingShader; //System.Diagnostics.ConsoleTraceListener myWriter = new //System.Diagnostics.ConsoleTraceListener(); //System.Diagnostics.Debug.Listeners.Clear(); //System.Diagnostics.Debug.Listeners.Add(myWriter); CheckError(); ClockWise = true; Culling = false; SwapBuffers(); CheckError(); }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(Handle); graphicsContext = new OpenTK.Graphics.GraphicsContext(graphicsMode, windowInfo, major, minor, graphicsContextFlags); graphicsContext.MakeCurrent(windowInfo); graphicsContext.LoadAll(); graphicsContext.SwapInterval = VSync ? 1 : 0; if (platformRenderContext == null) { platformRenderContext = new Graphics.Platform.OpenGL.PlatformRenderContext(); PlatformRenderer.Initialize(platformRenderContext); } graphicsContext.MakeCurrent(null); }
public override Gk3Main.Graphics.IRenderer CreateRenderer() { if (_renderer != null) { throw new InvalidOperationException("A renderer has already been created"); } OpenTK.Graphics.GraphicsMode mode = new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(32), _depth, 0, 0); _window = new OpenTK.NativeWindow(_width, _height, "FreeGeeKayThree - OpenGL 3.3 renderer", _fullscreen ? OpenTK.GameWindowFlags.Fullscreen : OpenTK.GameWindowFlags.FixedWindow, mode, OpenTK.DisplayDevice.Default); _window.Visible = true; _window.Closed += (x, y) => _closed = true; _context = new OpenTK.Graphics.GraphicsContext(mode, _window.WindowInfo, 3, 3, OpenTK.Graphics.GraphicsContextFlags.ForwardCompatible | OpenTK.Graphics.GraphicsContextFlags.Debug); _context.MakeCurrent(_window.WindowInfo); _context.LoadAll(); _renderer = new Gk3Main.Graphics.OpenGl.OpenGLRenderer(this); return(_renderer); }
static void Main() { Console.Title = "Tetraquark Console"; Running = true; const string ConfigFile = "cfg.yaml"; if (File.Exists(ConfigFile)) { Console.WriteLine("Loading config file {0}", ConfigFile); Settings.Load(File.ReadAllText(ConfigFile)); } GameWatch = new Stopwatch(); GameWatch.Start(); PackMgr.Mount("Default.zip"); string[] Files = PackMgr.GetFiles(); for (int i = 0; i < Files.Length; i++) { if (Files[i].StartsWith("resources/fonts/")) ResourceMgr.Register<Font>(PackMgr.OpenFile(Files[i]), Path.GetFileNameWithoutExtension(Files[i])); else if (Files[i].StartsWith("resources/textures/")) ResourceMgr.Register<Texture>(PackMgr.OpenFile(Files[i]), Path.GetFileNameWithoutExtension(Files[i])); } Scales.Init(new Vector2f(ResX, ResY)); // OpenTK ToolkitOptions TOpt = ToolkitOptions.Default; TOpt.Backend = PlatformBackend.PreferNative; TOpt.EnableHighResolution = true; Toolkit.Init(TOpt); // SFML VideoMode VMode = new VideoMode((uint)Scales.XRes, (uint)Scales.YRes, (uint)BitsPerPixel); ContextSettings CSet = new ContextSettings((uint)DepthBits, (uint)StencilBits); CSet.MajorVersion = 4; CSet.MinorVersion = 2; CSet.AntialiasingLevel = (uint)Samples; Styles S = Styles.None; if (Border) S |= Styles.Titlebar | Styles.Close; RenderWindow RWind = new RenderWindow(VMode, "Tetraquark", S, CSet); RWind.Closed += (Snd, E) => Running = false; RWind.SetKeyRepeatEnabled(false); // OpenTK IWindowInfo WindInfo = Utilities.CreateWindowsWindowInfo(RWind.SystemHandle); var GfxMode = new GraphicsMode(new ColorFormat(BitsPerPixel), DepthBits, StencilBits, Samples, new ColorFormat(0)); var GfxCtx = new GraphicsContext(GfxMode, WindInfo, (int)CSet.MajorVersion, (int)CSet.MinorVersion, GfxCtxFlags.Default); GfxCtx.MakeCurrent(WindInfo); GfxCtx.LoadAll(); RWind.ResetGLStates(); //GL.Enable(EnableCap.FramebufferSrgb); Renderer.Init(RWind); Stopwatch Clock = new Stopwatch(); Clock.Start(); while (Running) { RWind.DispatchEvents(); while (Clock.ElapsedMilliseconds < 10) ; float Dt = (float)Clock.ElapsedMilliseconds / 1000; Clock.Restart(); Renderer.Update(Dt); Renderer.Draw(RWind); RWind.Display(); } RWind.Close(); RWind.Dispose(); Console.WriteLine("Flushing configs"); File.WriteAllText(ConfigFile, Settings.Save()); Environment.Exit(0); }