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 int createSolidTexture(Vector4 color) { byte[] data; List <byte> pixels = new List <byte>(); pixels.Add((byte)color.X); pixels.Add((byte)color.Y); pixels.Add((byte)color.Z); pixels.Add((byte)color.W); data = pixels.ToArray(); var context = new OpenTK.Graphics.GraphicsContext(AlethaApplication.GraphicsMode, AlethaApplication.NativeWindowContext.WindowInfo); context.MakeCurrent(AlethaApplication.NativeWindowContext.WindowInfo); int texture = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, texture); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, 1, 1, 0, OpenTK.Graphics.OpenGL4.PixelFormat.Rgba, PixelType.UnsignedByte, data); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.BindTexture(TextureTarget.Texture2D, 0); return(texture); }
public static skybox loadFromShader(shader_p surface, shader_gl shader) { skybox sky = new skybox(); var context = new OpenTK.Graphics.GraphicsContext(AlethaApplication.GraphicsMode, AlethaApplication.NativeWindowContext.WindowInfo); context.MakeCurrent(AlethaApplication.NativeWindowContext.WindowInfo); // determine type of skybox: number of textures to load //sky.type = skybox_type.one_tex; buildSkyboxbuffers(); loadSkyTexture(shader, surface, (int texture) => { //.skymap = texture; }, (int texture) => { sky.skymap = texture; //GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap); }); return(sky); }
/// <summary> /// Initializes a new instance of the <see cref="Window"/> class with <paramref name="title"/> as the title of the Window. /// </summary> /// <param name="title">Title of the window, see Text property.</param> public Window(string title) { #if STRIDE_GRAPHICS_API_OPENGL var flags = SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL; #elif STRIDE_GRAPHICS_API_VULKAN var flags = SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN | SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN; #else var flags = SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN; #endif // Create the SDL window and then extract the native handle. SdlHandle = SDL.SDL_CreateWindow(title, SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, 640, 480, flags); if (SdlHandle == IntPtr.Zero) { throw new Exception("Cannot allocate SDL Window: " + SDL.SDL_GetError()); } else { SDL.SDL_SysWMinfo info = default(SDL.SDL_SysWMinfo); SDL.SDL_VERSION(out info.version); if (SDL.SDL_GetWindowWMInfo(SdlHandle, ref info) == SDL.SDL_bool.SDL_FALSE) { throw new Exception("Cannot get Window information: " + SDL.SDL_GetError()); } else if (Core.Platform.Type == Core.PlatformType.Windows) { Handle = info.info.win.window; } else if (Core.Platform.Type == Core.PlatformType.Linux) { Handle = info.info.x11.window; Display = info.info.x11.display; } else if (Core.Platform.Type == Core.PlatformType.macOS) { Handle = info.info.cocoa.window; } Application.RegisterWindow(this); Application.ProcessEvents(); #if STRIDE_GRAPHICS_API_OPENGL glContext = SDL.SDL_GL_CreateContext(SdlHandle); if (glContext == IntPtr.Zero) { throw new Exception("Cannot create OpenGL context: " + SDL.SDL_GetError()); } // The external context must be made current to initialize OpenGL SDL.SDL_GL_MakeCurrent(SdlHandle, glContext); // Create a dummy OpenTK context, that will be used to call some OpenGL features // we need to later create the various context in GraphicsDevice.OpenGL. DummyGLContext = new OpenTK.Graphics.GraphicsContext(new OpenTK.ContextHandle(glContext), SDL.SDL_GL_GetProcAddress, () => new OpenTK.ContextHandle(SDL.SDL_GL_GetCurrentContext())); #endif } }
public GraphicsContext( IGraphicsDevice graphicsDevice, bool isImmediate ) { GraphicsDevice = graphicsDevice; CullMode = CullMode.ClockWise; if ( isImmediate ) graphicsContext = OpenTK.Graphics.GraphicsContext.CurrentContext as OpenTK.Graphics.GraphicsContext; else graphicsContext = new OpenTK.Graphics.GraphicsContext ( new OpenTK.Graphics.GraphicsMode ( new OpenTK.Graphics.ColorFormat ( 8, 8, 8, 8 ), 24, 8 ), ( graphicsDevice.Handle as OpenTK.GameWindow ).WindowInfo ); }
/// <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(); } }
public static void CreateGLESContext() { //make open gl es current context GlfwWindowPtr currentContext = Glfw.GetCurrentContext(); _glContextHandler = new OpenTK.ContextHandle(currentContext.inner_ptr); _glfwContextForOpenTK = new GLFWContextForOpenTK(_glContextHandler); _externalContext = OpenTK.Graphics.GraphicsContext.CreateExternalContext(_glfwContextForOpenTK); //glfwContext = OpenTK.Graphics.GraphicsContext.CreateDummyContext(contextHandler); bool isCurrent = _glfwContextForOpenTK.IsCurrent; }
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(); }
private void DisposeOglObjects() { BackGroundShader.Dispose(); if (Selector.PickingShader != null) { Selector.PickingShader.Dispose(); Selector.PickingShader = null; } Selector.PickingShader = null; RenderingContext.Dispose(); RenderingContext = null; }
protected override void OnHandleDestroyed(EventArgs e) { base.OnHandleDestroyed(e); if (graphicsContext != null) { graphicsContext.Dispose(); graphicsContext = null; } if (windowInfo != null) { windowInfo.Dispose(); windowInfo = null; } }
/// <summary> /// Initialize current instance with <paramref name="title"/> as the title of the Window. /// </summary> /// <param name="title">Title of the window, see Text property.</param> public Window(string title) { #if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGL var flags = SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL; #else var flags = SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN; #endif // Create the SDL window and then extract the native handle. SdlHandle = SDL.SDL_CreateWindow(title, SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, 640, 480, flags); if (SdlHandle == IntPtr.Zero) { throw new Exception("Cannot allocate SDL Window: " + SDL.SDL_GetError()); } else { SDL.SDL_SysWMinfo info = default(SDL.SDL_SysWMinfo); SDL.SDL_VERSION(out info.version); if (SDL.SDL_GetWindowWMInfo(SdlHandle, ref info) == SDL.SDL_bool.SDL_FALSE) { throw new Exception("Cannot get Window information: " + SDL.SDL_GetError()); } else { #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP Handle = info.info.win.window; #elif SILICONSTUDIO_PLATFORM_LINUX Handle = info.info.x11.window; #endif } Application.RegisterWindow(this); Application.ProcessEvents(); #if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGL glContext = SDL.SDL_GL_CreateContext(SdlHandle); if (glContext == IntPtr.Zero) { throw new Exception("Cannot create OpenGL context: " + SDL.SDL_GetError()); } // The external context must be made current to initialize OpenGL SDL.SDL_GL_MakeCurrent(SdlHandle, glContext); // Create a dummy OpenTK context, that will be used to call some OpenGL features // we need to later create the various context in GraphicsDevice.OpenGL. DummyGLContext = new OpenTK.Graphics.GraphicsContext(new OpenTK.ContextHandle(glContext), SDL.SDL_GL_GetProcAddress, () => new OpenTK.ContextHandle(SDL.SDL_GL_GetCurrentContext())); #endif } }
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 static void LoadComplete(int index, TextureTarget target, OnTextueLoad onloadComplete) // OnSkymapLoadComplete { var context = new OpenTK.Graphics.GraphicsContext(AlethaApplication.GraphicsMode, AlethaApplication.NativeWindowContext.WindowInfo); context.MakeCurrent(AlethaApplication.NativeWindowContext.WindowInfo); int skybox = GL.GenTexture(); index = skybox; skymap = skybox; System.Drawing.Imaging.BitmapData xposd, yposd, zposd, xnegd, ynegd, znegd; //gl.enable(RenderingContext.TEXTURE_CUBE_MAP); GL.BindTexture(TextureTarget.TextureCubeMap, skybox); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); //gl.TexParameter(RenderingContext.TEXTURE_CUBE_MAP, RenderingContext.TEXTURE_WRAP_R, RenderingContext.CLAMP_TO_EDGE); int level = 0; PixelInternalFormat format = PixelInternalFormat.Rgba; PixelFormat pformat = PixelFormat.Rgba; PixelType type = PixelType.UnsignedByte; xposd = texture.UnlockBitmap(xpos); yposd = texture.UnlockBitmap(ypos); zposd = texture.UnlockBitmap(zpos); xnegd = texture.UnlockBitmap(xneg); ynegd = texture.UnlockBitmap(yneg); znegd = texture.UnlockBitmap(zneg); // gl.texImage2D(RenderingContext.TEXTURE_2D, 0, RenderingContext.RGBA, RenderingContext.RGBA, RenderingContext.UNSIGNED_BYTE, image); GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX, level, format, xpos.Width, xpos.Height, 0, pformat, type, xposd.Scan0); GL.TexImage2D(TextureTarget.TextureCubeMapNegativeX, level, format, xneg.Width, xneg.Height, 0, pformat, type, xnegd.Scan0); GL.TexImage2D(TextureTarget.TextureCubeMapPositiveY, level, format, ypos.Width, ypos.Height, 0, pformat, type, yposd.Scan0); GL.TexImage2D(TextureTarget.TextureCubeMapNegativeY, level, format, yneg.Width, yneg.Height, 0, pformat, type, ynegd.Scan0); GL.TexImage2D(TextureTarget.TextureCubeMapPositiveZ, level, format, zpos.Width, zpos.Height, 0, pformat, type, zposd.Scan0); GL.TexImage2D(TextureTarget.TextureCubeMapNegativeZ, level, format, zneg.Width, zneg.Height, 0, pformat, type, znegd.Scan0); onloadComplete(skybox); }
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); }
void TextureThread() { OpenTK.INativeWindow window = new OpenTK.NativeWindow(); OpenTK.Graphics.IGraphicsContext context = new OpenTK.Graphics.GraphicsContext(GLMode, window.WindowInfo); context.MakeCurrent(window.WindowInfo); TextureThreadContextReady.Set(); PendingTextures.Open(); Logger.DebugLog("Started Texture Thread"); while (window.Exists && TextureThreadRunning) { window.ProcessEvents(); TextureLoadItem item = null; if (!PendingTextures.Dequeue(Timeout.Infinite, ref item)) continue; // Already have this one loaded if (item.Data.TextureInfo.TexturePointer != 0) continue; byte[] imageBytes = null; if (item.TGAData != null) { imageBytes = item.TGAData; } else if (item.TextureData != null || item.LoadAssetFromCache) { if (item.LoadAssetFromCache) { item.TextureData = Client.Assets.Cache.GetCachedAssetBytes(item.Data.TextureInfo.TextureID); } ManagedImage mi; if (!OpenJPEG.DecodeToImage(item.TextureData, out mi)) continue; bool hasAlpha = false; bool fullAlpha = false; bool isMask = false; if ((mi.Channels & ManagedImage.ImageChannels.Alpha) != 0) { fullAlpha = true; isMask = true; // Do we really have alpha, is it all full alpha, or is it a mask for (int i = 0; i < mi.Alpha.Length; i++) { if (mi.Alpha[i] < 255) { hasAlpha = true; } if (mi.Alpha[i] != 0) { fullAlpha = false; } if (mi.Alpha[i] != 0 && mi.Alpha[i] != 255) { isMask = false; } } if (!hasAlpha) { mi.ConvertChannels(mi.Channels & ~ManagedImage.ImageChannels.Alpha); } } item.Data.TextureInfo.HasAlpha = hasAlpha; item.Data.TextureInfo.FullAlpha = fullAlpha; item.Data.TextureInfo.IsMask = isMask; imageBytes = mi.ExportTGA(); if (CacheDecodedTextures) { RHelp.SaveCachedImage(imageBytes, item.TeFace.TextureID, hasAlpha, fullAlpha, isMask); } } if (imageBytes != null) { Image img; using (MemoryStream byteData = new MemoryStream(imageBytes)) { img = OpenMetaverse.Imaging.LoadTGAClass.LoadTGA(byteData); } Bitmap bitmap = (Bitmap)img; bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); item.Data.TextureInfo.TexturePointer = RHelp.GLLoadImage(bitmap, item.Data.TextureInfo.HasAlpha); GL.Flush(); bitmap.Dispose(); } item.TextureData = null; item.TGAData = null; imageBytes = null; } context.MakeCurrent(window.WindowInfo); context.Dispose(); window.Dispose(); TextureThreadContextReady.Set(); Logger.DebugLog("Texture thread exited"); }
void TextureThread() { OpenTK.INativeWindow window = new OpenTK.NativeWindow(); OpenTK.Graphics.IGraphicsContext context = new OpenTK.Graphics.GraphicsContext(GLMode, window.WindowInfo); context.MakeCurrent(window.WindowInfo); TextureThreadContextReady.Set(); PendingTextures.Open(); Logger.DebugLog("Started Texture Thread"); while (window.Exists && TextureThreadRunning) { window.ProcessEvents(); TextureLoadItem item = null; if (!PendingTextures.Dequeue(Timeout.Infinite, ref item)) continue; if (LoadTexture(item.TeFace.TextureID, ref item.Data.Texture, false)) { GL.GenTextures(1, out item.Data.TexturePointer); GL.BindTexture(TextureTarget.Texture2D, item.Data.TexturePointer); Bitmap bitmap = new Bitmap(item.Data.Texture); bool hasAlpha; if (item.Data.Texture.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { hasAlpha = true; } else { hasAlpha = false; } item.Data.IsAlpha = hasAlpha; bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); Rectangle rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height); BitmapData bitmapData = bitmap.LockBits( rectangle, ImageLockMode.ReadOnly, hasAlpha ? System.Drawing.Imaging.PixelFormat.Format32bppArgb : System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.TexImage2D( TextureTarget.Texture2D, 0, hasAlpha ? PixelInternalFormat.Rgba : PixelInternalFormat.Rgb8, bitmap.Width, bitmap.Height, 0, hasAlpha ? OpenTK.Graphics.OpenGL.PixelFormat.Bgra : OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, bitmapData.Scan0); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); if (hasMipmap) { GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1); GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); } else { GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); } bitmap.UnlockBits(bitmapData); bitmap.Dispose(); GL.Flush(); SafeInvalidate(); } } Logger.DebugLog("Texture thread exited"); }
private static void processSurfacesThread() { shader_p surface; bool processSurfaces; // Any method called within this thread that accesses GL must update the context like this before GL calls can be made: var context = new OpenTK.Graphics.GraphicsContext(AlethaApplication.GraphicsMode, AlethaApplication.NativeWindowContext.WindowInfo); context.MakeCurrent(AlethaApplication.NativeWindowContext.WindowInfo); processSurfaces = true; // PROCESS SURFACE SHADERS // as they come in until there are none left while (processSurfaces) { // Sort any surfaces found in unshadedSurfaces in correct model, effect, or default bins as discovered if (unshadedSurfaces.Count == 0) { // Have we processed all surfaces? // Sort to ensure correct order of transparent objects effectSurfaces.Sort((shader_p a, shader_p b) => { int order = a.shader.sort - b.shader.sort; // TODO: Sort by state here to cut down on changes? return(order); //(order == 0 ? 1 : order); }); processSurfaces = false; } { String shader_name; shader_gl shader; if (unshadedSurfaces.Count != 0) { surface = unshadedSurfaces.Last(); unshadedSurfaces.RemoveAt(unshadedSurfaces.Count - 1); //shader_p surface = unshadedSurfaces.RemoveAt(0); // var surface = unshadedSurfaces.shift(); shader_name = surface.shaderName; //shader_name = shader_name.startsWith('"')?shader_name.substring(1):shader_name; // BUG if (q3bsp.shaders.ContainsKey(shader_name)) { shader = q3bsp.shaders[shader_name]; } else { shader = null; } //shader_gl skyshader = q3bsp.shaders['textures/atcs/skybox_s']; if (shader == null) { surface.shader = glshading.buildDefault(surface); if (surface.geomType == 3) { surface.shader.model = true; modelSurfaces.Add(surface); } else { defaultSurfaces.Add(surface); } } else { glshading.loadShaderMaps(surface, shader); surface.shader = shader; if (shader.sky == true) { skybox.skyShader = shader; // Sky does not get pushed into effectSurfaces. It's a separate pass } else { effectSurfaces.Add(surface); } } } } } Console.WriteLine("Processed surfaces"); }
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); }