public OpenTKDeviceSet(OpenTK.NativeWindow window) : base("OpenTK", new OpenTKKeyboard(window.InputDriver.Keyboard.Count > 0 ? window.InputDriver.Keyboard[0] : null), // TODO: Cannot be null new OpenTKMouse(window, window.InputDriver.Mouse.Count > 0 ? window.InputDriver.Mouse[0] : null), (int index) => { return(new OpenTKGamePad(index)); }) { }
public EditorRenderer(NativeWindow nw, Editor badger, Palette p = null) { _palette = p ?? Palette.Dark; Nw = nw; Badger = badger; customFont = ImGui.GetIO().FontAtlas.AddFontFromFileTTF("fonts/Hack-Regular.ttf", Fontsize); }
public IntPtr SetupWin32Window() { WindowInstance = Process.GetCurrentProcess().SafeHandle.DangerousGetHandle(); NativeWindow = new OpenTK.NativeWindow(1280, 720, Name, OpenTK.GameWindowFlags.Default, GraphicsMode.Default, OpenTK.DisplayDevice.Default); NativeWindow.X = 50; NativeWindow.Y = 50; NativeWindow.Visible = true; NativeWindow.Resize += OnNativeWindowResized; NativeWindow.MouseWheel += OnMouseWheel; NativeWindow.MouseMove += OnMouseMove; NativeWindow.MouseDown += OnMouseDown; NativeWindow.KeyDown += OnKeyDown; Window = NativeWindow.WindowInfo.Handle; return(NativeWindow.WindowInfo.Handle); }
protected override void Initialize() { base.Initialize(); #if WINDOWS try { OpenTK.NativeWindow window = typeof(OpenTKGameWindow).GetField("window", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(((OpenTKGameWindow)Window)) as OpenTK.NativeWindow; if (window != null) { window.Move += (object sender, EventArgs e) => skipNextUpdate = true; } } catch (Exception e) { Logger.Log(e); } #endif }
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); }
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 - Direct3D 9 renderer", _fullscreen ? OpenTK.GameWindowFlags.Fullscreen : OpenTK.GameWindowFlags.FixedWindow, mode, OpenTK.DisplayDevice.Default); _window.Visible = true; _window.Closed += (x, y) => _closed = true; // _window = SDL2.SDL.SDL_CreateWindow("FreeGeeKayThree - Direct3D 9 Renderer", SDL2.SDL.SDL_WINDOWPOS_CENTERED, SDL2.SDL.SDL_WINDOWPOS_CENTERED, _width, _height, _fullscreen ? SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN : 0); //Sdl.SDL_SetVideoMode(_width, _height, _depth, (_fullscreen ? Sdl.SDL_FULLSCREEN : 0)); // Sdl.SDL_WM_SetCaption("FreeGeeKayThree - Direct3D 9 Renderer", "FreeGK3"); // SDL_SysWMinfo wmInfo; // SDL_GetWMInfo(out wmInfo); _renderer = new Gk3Main.Graphics.Direct3D9.Direct3D9Renderer(this, Handle, _width, _height, false); 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"); }