public MakeCurrent ( IWindowInfo window ) : void | ||
window | IWindowInfo | A valid |
리턴 | void |
private GLVersion GetMaximumSupportedProfile() { var window = ((AndroidWindow)this.WindowInfo); using (var context = new OpenTK.Graphics.GraphicsContext(GraphicsMode.Default, window, (int)GLVersion.ES2, 0, GraphicsContextFlags.Embedded)) { context.MakeCurrent(window); PlatformConfigurations.RendererName = GL.GetString(StringName.Renderer); int version; if (!OpenGLUtils.GetCurrentGLVersion(out version)) { version = 200; } context.MakeCurrent(null); window.DestroySurface(); if (version >= 300) { return(GLVersion.ES3); } return(GLVersion.ES2); } }
protected virtual void OnWidgetShuttingDown(object sender, System.EventArgs e) { GL.Finish(); OpenTK.Graphics.GraphicsContext current = (OpenTK.Graphics.GraphicsContext)OpenTK.Graphics.GraphicsContext.CurrentContext; current.MakeCurrent(null); current.Dispose(); }
public void Run() { GraphicsMode gmode = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, GraphicsMode.Default.Stencil, 0); DisplayDevice dd = DisplayDevice.Default; NativeWindow nw = new NativeWindow(Width, Height, "Test", GameWindowFlags.Default, gmode, dd); GraphicsContext glContext = new GraphicsContext(gmode, nw.WindowInfo, 3, 0, GraphicsContextFlags.Default); glContext.LoadAll(); glContext.MakeCurrent(nw.WindowInfo); if (Load()) { nw.Visible = true; while (nw.Visible) { Frame(); glContext.SwapBuffers(); Thread.Sleep(1000 / 60); //"60" fps (not really...) nw.ProcessEvents(); } nw.Visible = false; } Unload(); }
public static IGraphicsContext CreateGraphicsContext(GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags) { GraphicsContext graphicsContext = new GraphicsContext(mode, window, major, minor, flags); graphicsContext.MakeCurrent(window); graphicsContext.LoadAll(); return (IGraphicsContext) graphicsContext; }
public OpenGLGraphics(Form form) { this.form = form; var windowInfo = Utilities.CreateWindowsWindowInfo(form.Handle); context = new GraphicsContext(GraphicsMode.Default, windowInfo); context.MakeCurrent(windowInfo); context.LoadAll(); GL.Enable(EnableCap.DepthTest); GL.ShadeModel(ShadingModel.Smooth); GL.Enable(EnableCap.Lighting); GL.Light(LightName.Light0, LightParameter.Ambient, new[] {.2f, .2f, .2f, 1.0f}); GL.Light(LightName.Light0, LightParameter.Diffuse, new[] {1, 1, 1, 1.0f}); GL.Light(LightName.Light0, LightParameter.Position, new[] {Common.LightX, Common.LightY, Common.LightZ}); GL.Enable(EnableCap.Light0); GL.MatrixMode(MatrixMode.Projection); Matrix4 prespective = Matrix4.CreatePerspectiveFieldOfView(Common.FieldOfView, (float)form.ClientSize.Width / (float)form.ClientSize.Height, Common.NearPlane, Common.FarPlane); GL.LoadMatrix(ref prespective); GL.MatrixMode(MatrixMode.Modelview); Matrix4 view = Matrix4.CreateTranslation(Common.CameraX, Common.CameraY, Common.CameraZ) * Matrix4.CreateRotationY(Common.CameraRotationY); GL.LoadMatrix(ref view); }
public unsafe SampleWindow() { int desiredWidth = 960, desiredHeight = 540; _nativeWindow = new NativeWindow(desiredWidth, desiredHeight, "ImGui.NET", GameWindowFlags.Default, OpenTK.Graphics.GraphicsMode.Default, DisplayDevice.Default); _scaleFactor = _nativeWindow.Width / desiredWidth; GraphicsContextFlags flags = GraphicsContextFlags.Default; _graphicsContext = new GraphicsContext(GraphicsMode.Default, _nativeWindow.WindowInfo, 3, 0, flags); _graphicsContext.MakeCurrent(_nativeWindow.WindowInfo); ((IGraphicsContextInternal)_graphicsContext).LoadAll(); // wtf is this? GL.ClearColor(Color.Black); _nativeWindow.Visible = true; _nativeWindow.X = _nativeWindow.X; // Work around OpenTK bug (?) on Ubuntu. _nativeWindow.KeyDown += OnKeyDown; _nativeWindow.KeyUp += OnKeyUp; _nativeWindow.KeyPress += OnKeyPress; ImGui.GetIO().FontAtlas.AddDefaultFont(); SetOpenTKKeyMappings(); _textInputBufferLength = 1024; _textInputBuffer = Marshal.AllocHGlobal(_textInputBufferLength); long* ptr = (long*)_textInputBuffer.ToPointer(); for (int i = 0; i < 1024 / sizeof(long); i++) { ptr[i] = 0; } CreateDeviceObjects(); }
private void Form1_Load(object sender, EventArgs e) { Closing += Form1_Closing; WindowInfo = Utilities.CreateWindowsWindowInfo(panel1.Handle); var WindowMode = new GraphicsMode(32, 24, 0, 0, 0, 2); WindowContext = new GraphicsContext(WindowMode, WindowInfo, 2, 0, GraphicsContextFlags.Debug); WindowContext.MakeCurrent(WindowInfo); WindowContext.LoadAll(); // as IGraphicsContextInternal) WindowContext.SwapInterval = 1; GL.Viewport(0, 0, panel1.Width, panel1.Height); GL.Enable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); GL.ClearColor(Color.DarkBlue); try { state.LoadCLRPackage(); state.DoString(@" import ('LUA', 'LUA') "); } catch (LuaException ex) { MessageBox.Show(ex.Message, "LUA Package Exception", MessageBoxButtons.OK); } state["x"] = 0.0; state["y"] = 1.0; state["fn"] = 0; script = textBox1.Text; timer1.Enabled = true; }
public RayTracerWindow(int width, int height) { _nativeWindow = new NativeWindow(width, height, "", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default); GraphicsContextFlags flags = GraphicsContextFlags.Default; #if DEBUG //flags |= GraphicsContextFlags.Debug; #endif _graphicsContext = new GraphicsContext(GraphicsMode.Default, _nativeWindow.WindowInfo, 3, 0, flags); _graphicsContext.MakeCurrent(_nativeWindow.WindowInfo); ((IGraphicsContextInternal)_graphicsContext).LoadAll(); // wtf is this? SetInitialStates(); SetViewport(); _nativeWindow.Resize += OnGameWindowResized; _nativeWindow.Closing += OnWindowClosing; _nativeWindow.KeyDown += OnKeyDown; _scene = Scene.TwoPlanes; _scene.Camera.ReflectionDepth = DefaultReflectionDepth; SetTitle(); _renderTexture = new RenderTexture(_nativeWindow.Width, _nativeWindow.Height); _scenes = typeof(Scene).GetProperties() .Where(pi => pi.PropertyType == typeof(Scene)) .Select(pi => pi.GetValue(null)) .Cast<Scene>().ToList(); }
private void InitGL() { windowInfo = Utilities.CreateWindowsWindowInfo(window.Handle); context = new GraphicsContext(GraphicsMode.Default, windowInfo); context.MakeCurrent(windowInfo); context.LoadAll(); }
private void CreateContext(Form form) { var windowInfo = Utilities.CreateWindowsWindowInfo(form.Handle); context = new GraphicsContext(GraphicsMode.Default, windowInfo); context.MakeCurrent(windowInfo); context.LoadAll(); GL.Enable(EnableCap.DepthTest); }
public OpenGLGraphics(Form form, Common common) { this.form = form; this.common = common; var windowInfo = Utilities.CreateWindowsWindowInfo(form.Handle); context = new GraphicsContext(GraphicsMode.Default, windowInfo); context.MakeCurrent(windowInfo); context.LoadAll(); }
/// <summary> /// Creates an IGraphicsContext instance for the specified window. /// </summary> /// <param name="mode">The GraphicsMode for the GraphicsContext.</param> /// <param name="window">An IWindowInfo instance describing the parent window for this IGraphicsContext.</param> /// <param name="major">The major OpenGL version number for this IGraphicsContext.</param> /// <param name="minor">The minor OpenGL version number for this IGraphicsContext.</param> /// <param name="flags">A bitwise collection of GraphicsContextFlags with specific options for this IGraphicsContext.</param> /// <returns>A new IGraphicsContext instance.</returns> public static IGraphicsContext CreateGraphicsContext( GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags) { GraphicsContext context = new GraphicsContext(mode, window, major, minor, flags); context.MakeCurrent(window); (context as IGraphicsContextInternal).LoadAll(); return context; }
public RenderWindow(int width, int height, DisplayDevice device) : base(width, height, "RenderOutput", GameWindowFlags.Default, GraphicsMode.Default, device == null ? DisplayDevice.AvailableDisplays.FirstOrDefault(row => row.IsPrimary) : device) { try { glContext = new GraphicsContext(GraphicsMode.Default, WindowInfo, 2, 0, GraphicsContextFlags.Default); glContext.MakeCurrent(WindowInfo); (glContext as IGraphicsContextInternal).LoadAll(); //glWindow.WindowInfoChanged += delegate(object sender, EventArgs e) { OnWindowInfoChangedInternal(e); }; } catch (Exception e) { base.Dispose(); throw; } }
static void Main(string[] args) { ContextSettings contextSettings = new ContextSettings(24, 0, 0); var window = new RenderWindow(new SFML.Window.VideoMode(640, 480), "ImGui + SFML + .Net = <3", Styles.Default, contextSettings); OpenTK.Graphics.GraphicsMode graphicsMode = new OpenTK.Graphics.GraphicsMode(32, (int)contextSettings.DepthBits, (int)contextSettings.StencilBits, (int)contextSettings.AntialiasingLevel); OpenTK.Platform.IWindowInfo windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(window.SystemHandle); OpenTK.Graphics.GraphicsContext context = new OpenTK.Graphics.GraphicsContext(graphicsMode, windowInfo); context.MakeCurrent(windowInfo); context.LoadAll(); window.SetFramerateLimit(60); ImGuiSfml.Init(window); window.Closed += (s, e) => window.Close(); CircleShape shape = new CircleShape(100); shape.FillColor = Color.Green; Clock deltaClock = new Clock(); while (window.IsOpen) { window.DispatchEvents(); ImGuiSfml.Update(window, deltaClock.Restart()); ImGui.ShowDemoWindow(); //ImGui.ShowTestWindow(); /* * ImGui.Begin("Hello, world!"); * ImGui.Button("Look at this pretty button"); * ImGui.End(); */ window.Clear(); window.Draw(shape); ImGuiSfml.Render(window); window.Display(); } }
private bool CreateMesaContext() { try { _ctx = GraphicsContext.CreateMesaContext(); long ctxPtr = long.Parse(_ctx.ToString()); // cannot access private .Context if (ctxPtr != 0) { _ctx.MakeCurrent(new BitmapWindowInfo(_surface.BitmapData)); if (!_ctx.IsCurrent) { Logger.Warn("Could not make context current"); throw new InvalidOperationException("Mesa context could not be made current"); } } Logger.Info("Successfully acquired Mesa context"); return true; } catch { Logger.Warn("Mesa context could not be created"); return false; } }
public unsafe SimpleGLWindow(string title, int desiredWidth, int desiredHeight) { _nativeWindow = new NativeWindow(desiredWidth, desiredHeight, title, GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default); _scaleFactor = NativeWindow.Width / desiredWidth; GraphicsContextFlags flags = GraphicsContextFlags.Default; _graphicsContext = new GraphicsContext(GraphicsMode.Default, NativeWindow.WindowInfo, 3, 0, flags); _graphicsContext.MakeCurrent(NativeWindow.WindowInfo); ((IGraphicsContextInternal)_graphicsContext).LoadAll(); // wtf is this? GL.ClearColor(Color.Black); NativeWindow.Closing += OnWindowClosing; NativeWindow.KeyDown += OnKeyDown; NativeWindow.KeyUp += OnKeyUp; NativeWindow.KeyPress += OnKeyPress; ImGui.LoadDefaultFont(); SetOpenTKKeyMappings(); CreateDeviceObjects(); }
private void CreateContext () { AssertNotDisposed (); Layer.DrawableProperties = NSDictionary.FromObjectsAndKeys ( new NSObject [] { NSNumber.FromBoolean (true), EAGLColorFormat.RGBA8 }, new NSObject [] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat }); Layer.ContentsScale = Window.Screen.Scale; //var strVersion = OpenTK.Graphics.ES11.GL.GetString (OpenTK.Graphics.ES11.All.Version); //strVersion = OpenTK.Graphics.ES20.GL.GetString (OpenTK.Graphics.ES20.All.Version); //var version = Version.Parse (strVersion); try { __renderbuffergraphicsContext = new GraphicsContext (null, null, 2, 0, GraphicsContextFlags.Embedded); _glapi = new Gles20Api (); } catch { __renderbuffergraphicsContext = new GraphicsContext (null, null, 1, 1, GraphicsContextFlags.Embedded); _glapi = new Gles11Api (); } __renderbuffergraphicsContext.MakeCurrent (null); }
/// <summary> /// Enter the gameloop. /// </summary> void EnterGameloop() { // Create graphics context this.Log ("Creating graphics context"); context = new GraphicsContext ( mode: graphicsMode, window: window.WindowInfo, major: 4, minor: 0, flags: GraphicsContextFlags.ForwardCompatible ); // Make the created context the current context context.MakeCurrent (window.WindowInfo); // Throw if context is not available GraphicsContext.Assert (); // Set vsync mode SetupVsync (); // Load OpenGL entry points this.Log ("Loading OpenGL entry points"); context.LoadAll (); // Initialize the sprite batch SpriteBatch = new SpriteBatch (this); // Bind the UI UI.Bind (this); // Initialize the game this.Log ("Initializing game"); PreInitialize (); Initialize (); // Set target framerate // Use 60hz if framerate is not set var framerate = Configuration.TargetFramerate > 0 ? Configuration.TargetFramerate : 60; // Prepare timing variables PrepareTiming (framerate); // Present the window to the user window.Visible = true; // Wait till the window is visible while (!windowVisible && !window.Focused && !window.Visible) { } // Enter the actual game loop while (!exit) { // Set updating to true updating = true; // Invoke waiting actions for (var i = 0; i < ContextActions.Count; i++) { Action action; if (ContextActions.TryDequeue (out action)) { try { action (); } catch (Exception e) { this.Throw (e.Message); } } } // Set the paused variable to true // if the game should be paused and continue if (pause) { paused = true; continue; } // Set the paused variable to false paused = false; // Break out of the loop if the context is not available. if (context.IsDisposed) { this.Log ("Context not available"); this.Log ("Leaving gameloop"); break; } // Update current time currentTime = DateTime.UtcNow; // Update InternalUpdate (currentTime); // Draw Draw (gameTime); // Set updating to false updating = false; } }
private void CreateContext () { AssertNotDisposed (); // RetainedBacking controls if the content of the colorbuffer should be preserved after being displayed // This is the XNA equivalent to set PreserveContent when initializing the GraphicsDevice // (should be false by default for better performance) Layer.DrawableProperties = NSDictionary.FromObjectsAndKeys ( new NSObject [] { NSNumber.FromBoolean (false), EAGLColorFormat.RGBA8 }, new NSObject [] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat }); Layer.ContentsScale = Window.Screen.Scale; //var strVersion = OpenTK.Graphics.ES11.GL.GetString (OpenTK.Graphics.ES11.All.Version); //strVersion = OpenTK.Graphics.ES20.GL.GetString (OpenTK.Graphics.ES20.All.Version); //var version = Version.Parse (strVersion); try { __renderbuffergraphicsContext = new GraphicsContext (null, null, 2, 0, GraphicsContextFlags.Embedded); _glapi = new Gles20Api (); } catch { __renderbuffergraphicsContext = new GraphicsContext (null, null, 1, 1, GraphicsContextFlags.Embedded); _glapi = new Gles11Api (); } __renderbuffergraphicsContext.MakeCurrent (null); }
private void CreateContext () { AssertNotDisposed (); Layer.DrawableProperties = NSDictionary.FromObjectsAndKeys ( new NSObject [] { NSNumber.FromBoolean (true), EAGLColorFormat.RGBA8 }, new NSObject [] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat }); Layer.ContentsScale = Window.Screen.Scale; //var strVersion = OpenTK.Graphics.ES11.GL.GetString (OpenTK.Graphics.ES11.All.Version); //strVersion = OpenTK.Graphics.ES20.GL.GetString (OpenTK.Graphics.ES20.All.Version); //var version = Version.Parse (strVersion); EAGLRenderingAPI eaglRenderingAPI; try { _graphicsContext = new GraphicsContext (null, null, 2, 0, GraphicsContextFlags.Embedded); eaglRenderingAPI = EAGLRenderingAPI.OpenGLES2; _glapi = new Gles20Api (); } catch { _graphicsContext = new GraphicsContext (null, null, 1, 1, GraphicsContextFlags.Embedded); eaglRenderingAPI = EAGLRenderingAPI.OpenGLES1; _glapi = new Gles11Api (); } _graphicsContext.MakeCurrent (null); _graphicsContext.LoadAll (); // FIXME: These static methods on GraphicsDevice need // to go away someday. GraphicsDevice.OpenGLESVersion = eaglRenderingAPI; }
void IXwtRender.CreateForWidgetContext(IRenderer renderer, IRenderOwner rendererimpl, Canvas widget) { var wBackend = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget) as Xwt.Backends.ICanvasBackend; var gtkwidget = wBackend.GetType().GetPropertyValue(wBackend, "Widget"); gtkwidget.GetType().SetPropertyValue(gtkwidget, "DoubleBuffered", false); // var widget = wBackend.GetType().GetPropertyValue(wBackend, "Widget"); // widget.GetType().SetPropertyValue(widget, "DoubleBuffered", false); // var gdkwin = widget.GetType().GetPropertyValue(widget, "GdkWindow"); var h = GetHandle(wBackend); // (IntPtr)gdkwin.GetType().GetPropertyValue(gdkwin, "Handle"); IntPtr windowHandle = gdk_x11_drawable_get_xid(h); // wBackend.Widget.Handle IntPtr display2 = gdk_drawable_get_display(h); IntPtr display = gdk_x11_drawable_get_xdisplay(h); IntPtr screen = gdk_display_get_default_screen(display2); int screenn = gdk_screen_get_number(screen); IntPtr rootWindow = gdk_screen_get_root_window(screen); IntPtr visualInfo = IntPtr.Zero; XVisualInfo info = new XVisualInfo(); info.VisualID = IntPtr.Zero; int dummy; visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy); // } /* else * { * visualInfo = GetVisualInfo(display); * }*/ var wBackendMain = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget.ParentWindow) as Xwt.Backends.IWindowFrameBackend; var winmain = wBackendMain.GetType().GetPropertyValue(wBackendMain, "Window"); var gdkwinmain = winmain.GetType().GetPropertyValue(winmain, "GdkWindow"); var hmain = (IntPtr)gdkwinmain.GetType().GetPropertyValue(gdkwinmain, "Handle"); Canvas view = null; EventHandler sizefunc = null; if (h == hmain) { view = new global::Xwt.Canvas() { ExpandHorizontal = true, ExpandVertical = true, HorizontalPlacement = WidgetPlacement.Fill, VerticalPlacement = WidgetPlacement.Fill, MinWidth = 1, MinHeight = 1, BackgroundColor = Xwt.Drawing.Colors.Black }; widget.AddChild(view); var viewbackend = Xwt.Toolkit.CurrentEngine.GetSafeBackend(view) as Xwt.Backends.ICanvasBackend; var gtkview = viewbackend.GetType().GetPropertyValue(viewbackend, "Widget"); gtkview.GetType().SetPropertyValue(gtkview, "DoubleBuffered", false); var hwnd = GetHandle(viewbackend); Debug.Assert(hwnd != hmain); sizefunc = new EventHandler((s, a) => widget.SetChildBounds(view, new Rectangle(Point.Zero, widget.Size))); widget.BoundsChanged += sizefunc; sizefunc(null, EventArgs.Empty); windowHandle = gdk_x11_drawable_get_xid(hwnd); } var WindowInfo = Utilities.CreateX11WindowInfo(display, screenn, windowHandle, rootWindow, visualInfo); XFree(visualInfo); var gfxcontext = new OpenTK.Graphics.GraphicsContext(new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8), WindowInfo, 3, 3, GraphicsContextFlags.Default); views[widget] = new viewinfo(WindowInfo, gfxcontext, (gfxcontext as IGraphicsContextInternal).Context) { view = view, sizefunc = sizefunc }; gfxcontext.MakeCurrent(WindowInfo); gfxcontext.LoadAll(); int major, minor; GL.GetInteger(GetPName.MajorVersion, out major); GL.GetInteger(GetPName.MinorVersion, out minor); Console.WriteLine("OpenGL {0}.{1}", major, minor); gfxcontext.MakeCurrent(null); }
private GLVersion GetMaximumSupportedProfile() { var window = ((AndroidWindow)this.WindowInfo); using (var context = new OpenTK.Graphics.GraphicsContext(GraphicsMode.Default, window, (int)GLVersion.ES2, 0, GraphicsContextFlags.Embedded)) { context.MakeCurrent(window); PlatformConfigurations.RendererName = GL.GetString(StringName.Renderer); int version; if (!OpenGLUtils.GetCurrentGLVersion(out version)) { version = 200; } context.MakeCurrent(null); window.DestroySurface(); if (version >= 300) { return GLVersion.ES3; } return GLVersion.ES2; } }
private void StartJobThread() { Context.MakeCurrent(null); var contextReady = new AutoResetEvent(false); var thread = new Thread(() => { var window = new NativeWindow(); var context = new GraphicsContext(Context.GraphicsMode, window.WindowInfo); context.MakeCurrent(window.WindowInfo); contextReady.Set(); while (true) { var action = JobDispatcher.Instance.Dequeue(); action(); } }); thread.IsBackground = true; thread.Start(); contextReady.WaitOne(); MakeCurrent(); }
public static void InitSDLVideo() { var video_flags = SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS | SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS; if(Global.ScreenInfo.FSflag) { video_flags |= SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; } else { video_flags |= SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_SHOWN; } // TODO: is it really neede for correct work? if(SDL_GL_LoadLibrary(null) < 0) { Sys.Error("Could not init OpenGL driver"); } if(Renderer.Settings.UseGL3) { // Request opengl 3.2 context SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, (int) SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ACCELERATED_VISUAL, 1); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 2); } // Create temporary SDL window and GL context for checking capabilities. sdl_window = SDL_CreateWindow(null, Global.ScreenInfo.X, Global.ScreenInfo.Y, Global.ScreenInfo.W, Global.ScreenInfo.H, SDL_WindowFlags.SDL_WINDOW_OPENGL/* | SDL_WindowFlags.SDL_WINDOW_HIDDEN*/); sdl_gl_context = SDL_GL_CreateContext(sdl_window); if(sdl_gl_context == IntPtr.Zero) Sys.Error("Can't create OpenGL context - shutting down. Try to disable use_gl3 option in config."); Assert(sdl_gl_context != IntPtr.Zero); SDL_GL_MakeCurrent(sdl_window, sdl_gl_context); // Check for correct number of antialias samples. if(Renderer.Settings.Antialias) { var maxSamples = 0; GL.GetInteger(GetPName.MaxSamples, out maxSamples); maxSamples = maxSamples > 16 ? 16 : maxSamples; // Fix for faulty GL max. sample number if(Renderer.Settings.AntialiasSamples > maxSamples) { if(maxSamples == 0) { Renderer.Settings.Antialias = false; Renderer.Settings.AntialiasSamples = 0; Sys.DebugLog(LOG_FILENAME, "InitSDLVideo: can't use antialiasing"); } else { Renderer.Settings.AntialiasSamples = maxSamples; // Limit to max. Sys.DebugLog(LOG_FILENAME, "InitSDLVideo: wrong AA sample number, using {0}", maxSamples); } } SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_MULTISAMPLEBUFFERS, Renderer.Settings.Antialias ? 1 : 0); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_MULTISAMPLESAMPLES, Renderer.Settings.AntialiasSamples); } else { SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_MULTISAMPLEBUFFERS, 0); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_MULTISAMPLESAMPLES, 0); } // Remove temporary GL context and SDL window. SDL_GL_DeleteContext(sdl_gl_context); SDL_DestroyWindow(sdl_window); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DEPTH_SIZE, Renderer.Settings.Zdepth); if (STENCIL_FRUSTUM) { SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_STENCIL_SIZE, 8); } sdl_window = SDL_CreateWindow("FreeRaider", Global.ScreenInfo.X, Global.ScreenInfo.Y, Global.ScreenInfo.W, Global.ScreenInfo.H, video_flags); sdl_renderer = SDL_CreateRenderer(sdl_window, -1, SDL_RendererFlags.SDL_RENDERER_ACCELERATED); sdl_gl_context = SDL_GL_CreateContext(sdl_window); SDL_GL_MakeCurrent(sdl_window, sdl_gl_context); TKWindow = Utilities.CreateSdl2WindowInfo(sdl_window); GLContext = new GraphicsContext(new ContextHandle(sdl_gl_context), SDL_GL_GetProcAddress, // implement GetAddress via SDL () => new ContextHandle(SDL_GL_GetCurrentContext())); GLContext.MakeCurrent(TKWindow); if (SDL_GL_SetSwapInterval(Global.ScreenInfo.Vsync ? 1 : 0) != 0) Sys.DebugLog(LOG_FILENAME, "Cannot set VSYNC: {0}\n", SDL_GetError()); ConsoleInfo.Instance.AddLine(GL.GetString(StringName.Vendor), FontStyle.ConsoleInfo); ConsoleInfo.Instance.AddLine(GL.GetString(StringName.Renderer), FontStyle.ConsoleInfo); ConsoleInfo.Instance.AddLine("OpenGL version " + GL.GetString(StringName.Version), FontStyle.ConsoleInfo); ConsoleInfo.Instance.AddLine(GL.GetString(StringName.ShadingLanguageVersion), FontStyle.ConsoleInfo); }