static Glfw.Window CreateWindow(Glfw.Monitor monitor) { int width, height; Glfw.Window window; if (monitor) { var mode = Glfw.GetVideoMode(monitor); Glfw.WindowHint(Glfw.Hint.RefreshRate, mode.RefreshRate); Glfw.WindowHint(Glfw.Hint.RedBits, mode.RedBits); Glfw.WindowHint(Glfw.Hint.GreenBits, mode.GreenBits); Glfw.WindowHint(Glfw.Hint.BlueBits, mode.BlueBits); width = mode.Width; height = mode.Height; } else { width = 640; height = 480; } window = Glfw.CreateWindow(width, height, "Iconify", monitor, Glfw.Window.None); if (!window) { Glfw.Terminate(); System.Environment.Exit(1); } Glfw.MakeContextCurrent(window); return(window); }
internal static void InitGlFwForm(GlFwForm f, int initW, int initH, string title = "") { GlfwWindowPtr glWindowPtr = Glfw.CreateWindow(initW, initH, title, new GlfwMonitorPtr(), //default monitor new GlfwWindowPtr()); //default top window Glfw.MakeContextCurrent(glWindowPtr); //*** f.SetupNativePtr(glWindowPtr, f.Width, f.Height); //------------------- //setup events for glfw window Glfw.SetWindowCloseCallback(glWindowPtr, s_windowCloseCb); Glfw.SetWindowFocusCallback(glWindowPtr, s_windowFocusCb); Glfw.SetWindowIconifyCallback(glWindowPtr, s_windowIconifyCb); Glfw.SetWindowPosCallback(glWindowPtr, s_windowPosCb); Glfw.SetWindowRefreshCallback(glWindowPtr, s_windowRefreshCb); Glfw.SetWindowSizeCallback(glWindowPtr, s_windowSizeCb); Glfw.SetCursorPosCallback(glWindowPtr, s_windowCursorPosCb); Glfw.SetCursorEnterCallback(glWindowPtr, s_windowCursorEnterCb); Glfw.SetMouseButtonCallback(glWindowPtr, s_windowMouseButtonCb); Glfw.SetScrollCallback(glWindowPtr, s_scrollCb); Glfw.SetKeyCallback(glWindowPtr, s_windowKeyCb); Glfw.SetCharCallback(glWindowPtr, s_windowCharCb); //------------------- s_existingForms.Add(glWindowPtr, f); exitingFormList.Add(f); //------------------- GLFWPlatforms.CreateGLESContext(f); }
static void Main(string[] args) { if (!Glfw.Init()) { return; } window = Glfw.CreateWindow(width, height, "", GlfwMonitorPtr.Null, GlfwWindowPtr.Null); Glfw.MakeContextCurrent(window); Glfw.SetInputMode(window, InputMode.CursorMode, CursorMode.CursorCaptured); Glfw.SetErrorCallback(OnError); Input.Init(window); Renderer.Init(); Camera.Init(new Vector3(0, 0, -5), Vector3.Zero); Terrain.Init(Terrain.GenerateHeights()); Init(); while (!Glfw.WindowShouldClose(window)) { MainLoop(); } Glfw.DestroyWindow(window); Glfw.Terminate(); Renderer.CleanUp(); }
internal void Init() { Glfw.ConfigureNativesDirectory(GlfwLibraryPath); // Check glfw init Debug.Assert(() => Glfw.Init(), "Glfw Could not be initialised", LogLayer.Application, LogState.Error, () => { Environment.Exit(-1); }, "Glfw has been Initialised"); // Create window window = Glfw.CreateWindow(Width, Height, Name); Debug.Assert(() => window, "Window could not be created", LogLayer.Application, LogState.Error, () => { Glfw.Terminate(); Environment.Exit(-1); }, $"Window has been created {Width}x{Height}"); Glfw.SwapInterval(SwapInterval); Glfw.MakeContextCurrent(window); // Set character callback Glfw.SetCharCallback(window, new Glfw.CharFunc((w, code) => { })); }
/// <summary> /// Initialize this windows instance. /// </summary> public void Initialize() { // - Reset window hints Glfw.DefaultWindowHints(); // - Let the user choose whenever show the window Glfw.WindowHint(Hint.ClientApi, 0); Glfw.WindowHint(Hint.Visible, false); // - Make the new window saving the GLFW pointer GLFWHAndle = Glfw.CreateWindow ( Size.Value.Width, Size.Value.Height, Title, Monitor.None, Window.None ); // - Manage events handlers Glfw.SetWindowSizeCallback(GLFWHAndle, pSizeCallback); // - Send initialization event Initialized?.Invoke(this, EventArgs.Empty); }
public static void CreateWindow(int width, int height, string title) { WindowSize = new Vector2(width, height); Glfw.Init(); //OpenGL 3.3 Glfw.WindowHint(Hint.ContextVersionMajor, 3); Glfw.WindowHint(Hint.ContextVersionMinor, 3); Glfw.WindowHint(Hint.OpenglProfile, Profile.Core); Glfw.WindowHint(Hint.Focused, true); Glfw.WindowHint(Hint.Resizable, false); Window = Glfw.CreateWindow(width, height, title, Monitor.None, Window.None); //Error checking if (Window == Window.None) { return; } Rectangle screen = Glfw.PrimaryMonitor.WorkArea; int x = (screen.Width) / 2; int y = (screen.Height) / 2; Glfw.MakeContextCurrent(Window); Import(Glfw.GetProcAddress); glViewport(0, 0, width, height); Glfw.SwapInterval(0); //No V-Sync }
public ChunkGenerator() { Thread generator = new Thread(p => { ThreadParams parameters = ((ThreadParams)p); BlockingCollection <Chunk> chunkList = parameters.chunkList; OpenGL gl = new OpenGL(); gl.MakeCurrent(); Glfw.MakeContextCurrent(parameters.window); while (parameters.running) { chunkList.Take().initialize(gl); } }) { IsBackground = true }; _parameters = new ThreadParams(_chunkList, Glfw.CreateWindow(1, 1, "", Monitor.None, ToolBox.window)); generator.Start(_parameters); }
public void Main(string[] args) { Init(); Glfw.Window window; if (!Glfw.Init()) { Environment.Exit(1); } window = Glfw.CreateWindow(200, 200, "Window Icon"); if (!window) { Glfw.Terminate(); Environment.Exit(1); } Glfw.MakeContextCurrent(window); Glfw.SetKeyCallback(window, KeyCallback); SetIcon(window, m_CurIconColor); while (!Glfw.WindowShouldClose(window)) { Gl.Clear(ClearBufferMask.ColorBufferBit); Glfw.SwapBuffers(window); Glfw.WaitEvents(); } Glfw.DestroyWindow(window); Glfw.Terminate(); }
static void Main(string[] args) { Init(); Glfw.Window window; if (!Glfw.Init()) { Environment.Exit(1); } window = Glfw.CreateWindow(400, 400, "English 日本語 русский язык 官話"); if (!window) { Glfw.Terminate(); Environment.Exit(1); } Glfw.MakeContextCurrent(window); Glfw.SwapInterval(1); Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback); while (!Glfw.WindowShouldClose(window)) { Gl.Clear(ClearBufferMask.ColorBufferBit); Glfw.SwapBuffers(window); Glfw.WaitEvents(); } Glfw.Terminate(); }
internal static void InitGlFwForm(GlFwForm f) { //create pointer GlfwWindowPtr glWindowPtr = Glfw.CreateWindow(f.Width, f.Height, f.Text, new GlfwMonitorPtr(), //default monitor new GlfwWindowPtr()); //default top window f.InitGlFwForm(glWindowPtr, f.Width, f.Height); //------------------- //setup events for glfw window Glfw.SetWindowCloseCallback(glWindowPtr, s_windowCloseCb); Glfw.SetWindowFocusCallback(glWindowPtr, s_windowFocusCb); Glfw.SetWindowIconifyCallback(glWindowPtr, s_windowIconifyCb); Glfw.SetWindowPosCallback(glWindowPtr, s_windowPosCb); Glfw.SetWindowRefreshCallback(glWindowPtr, s_windowRefreshCb); Glfw.SetWindowSizeCallback(glWindowPtr, s_windowSizeCb); Glfw.SetCursorPosCallback(glWindowPtr, s_windowCursorPosCb); Glfw.SetCursorEnterCallback(glWindowPtr, s_windowCursorEnterCb); Glfw.SetMouseButtonCallback(glWindowPtr, s_windowMouseButtonCb); Glfw.SetScrollCallback(glWindowPtr, s_scrollCb); Glfw.SetKeyCallback(glWindowPtr, s_windowKeyCb); Glfw.SetCharCallback(glWindowPtr, s_windowCharCb); ////------------------- existingForms.Add(glWindowPtr, f); exitingFormList.Add(f); }
public static GlFwForm CreateGlfwForm(int w, int h, string title) { GlfwWindowPtr glWindowPtr = Glfw.CreateWindow(w, h, title, new GlfwMonitorPtr(), //default monitor new GlfwWindowPtr()); //default top window GlFwForm f = new GlFwForm(); f.InitGlFwForm(glWindowPtr, w, h); f.Text = title; //------------------- //setup events for glfw window Glfw.SetWindowCloseCallback(glWindowPtr, s_windowCloseCb); Glfw.SetWindowFocusCallback(glWindowPtr, s_windowFocusCb); Glfw.SetWindowIconifyCallback(glWindowPtr, s_windowIconifyCb); Glfw.SetWindowPosCallback(glWindowPtr, s_windowPosCb); Glfw.SetWindowRefreshCallback(glWindowPtr, s_windowRefreshCb); Glfw.SetWindowSizeCallback(glWindowPtr, s_windowSizeCb); Glfw.SetCursorPosCallback(glWindowPtr, s_windowCursorPosCb); Glfw.SetCursorEnterCallback(glWindowPtr, s_windowCursorEnterCb); Glfw.SetMouseButtonCallback(glWindowPtr, s_windowMouseButtonCb); Glfw.SetScrollCallback(glWindowPtr, s_scrollCb); Glfw.SetKeyCallback(glWindowPtr, s_windowKeyCb); Glfw.SetCharCallback(glWindowPtr, s_windowCharCb); ////------------------- existingForms.Add(glWindowPtr, f); exitingFormList.Add(f); return(f); }
public void Show() { _window = Glfw.CreateWindow(Width, Height, Title); if (_window == Glfw.Window.None) { throw new Exception(); } Glfw.SetWindowSizeCallback(_window, HandleSizeCallback); Glfw.SetWindowPosCallback(_window, HandlePosCallback); Glfw.SetWindowRefreshCallback(_window, HandleRefreshCallback); Glfw.SetWindowCloseCallback(_window, HandleCloseCallback); Glfw.SetWindowFocusCallback(_window, HandleFocusCallback); Glfw.SetWindowIconifyCallback(_window, HandleIconifyCallback); Glfw.SetFramebufferSizeCallback(_window, HandleFramebufferSizeCallback); Glfw.MakeContextCurrent(_window); //_context = NVG.CreateGL3Glew(3); //_context.CreateFont("sans-bold", "Roboto-Bold.ttf"); HandleRefreshCallback(_window); }
static GlfwWindowPtr CreateNewWindow(int Width, int Height, string Title, GlfwMonitorPtr Monitor, GlfwWindowPtr OldWindow) { GlfwWindowPtr NewWindow = Glfw.CreateWindow(Width, Height, Title, Monitor, OldWindow); Glfw.DestroyWindow(OldWindow); return(NewWindow); }
static void Main(string[] args) { TimeStart = DateTime.Now; Console.WriteLine("Realtime render / Image sequence render : y / n"); while (true) { string input = Console.ReadLine(); if (input == "y") { view = true; break; } else if (input == "n") { view = false; break; } } view = true; if (!Glfw.Init()) { return; } window = Glfw.CreateWindow(width, height, "GLFW OpenGL", GlfwMonitorPtr.Null, GlfwWindowPtr.Null); Glfw.MakeContextCurrent(window); Glfw.SetErrorCallback(OnError); Input.Init(window); if (!view) { Glfw.HideWindow(window); } Init(); Update(); consoleThread = new Thread(new ThreadStart(delegate() { while (true) { string input = Console.ReadLine(); if (input == "s") { SetShouldClose(true); } } })); consoleThread.Start(); while (!Glfw.WindowShouldClose(window)) { MainLoop(); } Glfw.DestroyWindow(window); Glfw.Terminate(); consoleThread.Abort(); CleanUp(); }
public static void CreateWindow(int width, int height, string title) { Glfw.WindowHint(Hint.ClientApi, ClientApi.OpenGL); Glfw.WindowHint(Hint.ContextVersionMajor, 3); Glfw.WindowHint(Hint.ContextVersionMinor, 3); Glfw.WindowHint(Hint.OpenglProfile, Profile.Core); Glfw.WindowHint(Hint.Doublebuffer, true); Glfw.WindowHint(Hint.Decorated, true); Glfw.WindowHint(Hint.OpenglDebugContext, true); Window = Glfw.CreateWindow(width, height, title, Monitor.None, Window.None); if (Window == Window.None) { return; // window creation failed - bail } // center the window Rectangle screen = Glfw.PrimaryMonitor.WorkArea; int x = (screen.Width - width) / 2; int y = (screen.Height - height) / 2; Glfw.SetWindowPosition(Window, x, y); Glfw.MakeContextCurrent(Window); Import(Glfw.GetProcAddress); ViewportWidth = (float)width; ViewportHeight = (float)height; glViewport(0, 0, width, height); Glfw.SwapInterval(0); // vsync 0=off }
public Window(int width, int height, string title) { if (Glfw.Init() < 0) { Console.WriteLine("unable to initialize glfw"); Environment.Exit(-1); } Glfw.WindowHint((int)State.ContextVersionMajor, 3); Glfw.WindowHint((int)State.ContextVersionMinor, 3); window = Glfw.CreateWindow(width, height, title, null, null); if (window == null) { Console.WriteLine("unable to create window"); Glfw.Terminate(); Environment.Exit(-1); } Gl.Initialize(); Glfw.MakeContextCurrent(window); Glfw.SwapInterval(1); Glfw.SetWindowSizeCallback(window, delegate { UpdateViewportSize(); }); Glfw.SetKeyCallback(window, KeyPress); Glfw.SetInputMode(window, (int)State.Cursor, (int)State.CursorDisabled); Singleton = this; }
static ContextManager() { Gl.Initialize(); Glfw.Init(); Glfw.DefaultWindowHints(); Glfw.WindowHint(Glfw.ContextVersionMajor, 4); Glfw.WindowHint(Glfw.ContextVersionMinor, 1); Glfw.WindowHint(Glfw.OpenglProfile, Glfw.OpenglCoreProfile); Glfw.WindowHint(Glfw.OpenglForwardCompat, Glfw.True); Glfw.WindowHint(Glfw.Doublebuffer, Glfw.True); Glfw.WindowHint(Glfw.Visible, Glfw.False); DefaultContext = Glfw.CreateWindow(1, 1, "", IntPtr.Zero, IntPtr.Zero); if (DefaultContext == IntPtr.Zero) { throw new NullReferenceException("Default OpenGL context failed to initialize."); } SetActiveContext(DefaultContext); Glx.IsRequired = true; Gl.BindAPI(new KhronosVersion(4, 1, "gl"), new Gl.Extensions()); }
static Glfw.Window OpenWindow(int width, int height, Glfw.Monitor monitor) { double b; Glfw.Window window; b = Glfw.GetTime(); window = Glfw.CreateWindow(width, height, "Window Re-opener", monitor, Glfw.Window.None); if (!window) { return(Glfw.Window.None); } Glfw.MakeContextCurrent(window); Glfw.SwapInterval(1); Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback); Glfw.SetWindowCloseCallback(window, WindowCloseCallback); Glfw.SetKeyCallback(window, KeyCallback); if (monitor) { Log("Opening full screen window on monitor {0} took {1} seconds", Glfw.GetMonitorName(monitor), Glfw.GetTime() - b); } else { Log("Opening regular window took {0} seconds", Glfw.GetTime() - b); } return(window); }
static void Main(string[] _) { //Console.WriteLine("Hello World!"); //Glfw.Init(); Glfw.WindowHint(Hint.ClientApi, ClientApi.OpenGl); Glfw.WindowHint(Hint.ContextVersionMajor, 3); Glfw.WindowHint(Hint.ContextVersionMinor, 3); Glfw.WindowHint(Hint.OpenGlProfile, Profile.Core); Glfw.WindowHint(Hint.Doublebuffer, true); Glfw.WindowHint(Hint.Decorated, true); Glfw.WindowHint(Hint.OpenGlForwardCompat, false); using (Window window = Glfw.CreateWindow(1280, 720, "Test", null, null)) { Glfw.MakeContextCurrent(window); Glfw.SwapInterval(1); Monitor[] monitors = Monitor.Monitors; foreach (Monitor monitor in monitors) { Console.Out.WriteLine($"Monitor {monitor.Name}:"); Console.Out.WriteLine($"Current VideoMode: {monitor.CurrentMode.Width}x{monitor.CurrentMode.Height}"); foreach (VideoMode mode in monitor.VideoModes) { Console.Out.WriteLine($"\t{mode.Width}x{mode.Height}"); } } Size size = window.Size; Rectangle workArea = Monitor.PrimaryMonitor.WorkArea; int x = (workArea.Width - size.Width) / 2; int y = (workArea.Height - size.Height) / 2; window.Position = new Point(x, y); glClearColor = Glfw.GetProcAddress <glClearColorHandler>("glClearColor"); glClear = Glfw.GetProcAddress <glClearHandler>("glClear"); Glfw.OnKey += keyCallback; long tick = 0L; ChangeClearColor(); while (!Glfw.WindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT); Glfw.SwapBuffers(window); Glfw.PollEvents(); if (++tick % 60 == 0) { ChangeClearColor(); } } } //Glfw.DestroyWindow(window); Glfw.Terminate(); }
static void Main(string[] args) { Glfw.Init(); Glfw.WindowHint(Hint.ContextVersionMajor, 4); Glfw.WindowHint(Hint.ContextVersionMinor, 6); Glfw.WindowHint(Hint.OpenglProfile, Profile.Compatibility); Window window = Glfw.CreateWindow(1080, 720, "Yeet", Monitor.None, Window.None); // `Gl.Initialize()` has to be don before `Glfw.MakeContextCurrent(window)` // [How Do I Initialize OpenGL.NET with GLFW.Net?](https://stackoverflow.com/questions/61318104/how-do-i-initialize-opengl-net-with-glfw-net/61319044?noredirect=1#comment108476826_61319044) Gl.Initialize(); Glfw.MakeContextCurrent(window); var v = Gl.GetString(StringName.Version); Console.WriteLine(v); uint vao = Gl.CreateVertexArray(); Gl.BindVertexArray(vao); uint vbo = Gl.GenBuffer(); Gl.BindBuffer(BufferTarget.ArrayBuffer, vbo); var vertices = new float[] { -0.5f, -0.5f, 0.5f, -0.5f, 0.0f, 0.5f }; Gl.BufferData(BufferTarget.ArrayBuffer, (uint)(4 * vertices.Length), null, BufferUsage.StaticDraw); IntPtr unmanagedPointer = Marshal.AllocHGlobal(4 * vertices.Length); Marshal.Copy(vertices, 0, unmanagedPointer, vertices.Length); Gl.BufferSubData(BufferTarget.ArrayBuffer, new IntPtr(0), (uint)(4 * vertices.Length), unmanagedPointer); Marshal.FreeHGlobal(unmanagedPointer); //Gl.BufferSubData(BufferTarget.ArrayBuffer, new IntPtr(0), (uint)(4 * vertices.Length), vertices); Gl.VertexAttribPointer(0, 2, VertexAttribType.Float, false, 0, null); while (!Glfw.WindowShouldClose(window)) { Glfw.PollEvents(); Gl.ClearColor(0.0f, 1.0f, 1.0f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit); Gl.BindVertexArray(vao); Gl.EnableVertexAttribArray(0); Gl.DrawArrays(PrimitiveType.Triangles, 0, 3); Gl.DisableVertexAttribArray(0); Gl.BindVertexArray(0); Glfw.SwapBuffers(window); } Glfw.DestroyWindow(window); Glfw.Terminate(); }
public IWindow CreateWindow(int width, int height, string title) { this.width = width; this.height = height; this.title = title; var window = Glfw.CreateWindow(width, height, title); return(new GLWindow(window)); }
// the pragram starts here private static void AppMain() { // initialize GLFW if (!Glfw.Init()) { throw new Exception("glfwInit failed"); } // open a window with GLFW Glfw.WindowHint(WindowHint.OpenGLProfile, (int)OpenGLProfile.Core); Glfw.WindowHint(WindowHint.ContextVersionMajor, 3); Glfw.WindowHint(WindowHint.ContextVersionMinor, 2); _window = Glfw.CreateWindow(ScreenSize.X, ScreenSize.Y, "", GlfwMonitorPtr.Null, GlfwWindowPtr.Null); if (_window.Equals(GlfwWindowPtr.Null)) { throw new Exception("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?"); } Glfw.MakeContextCurrent(_window); // TODO: GLEW in C# // print out some info about the graphics drivers Console.WriteLine("OpenGL version: {0}", GL.GetString(StringName.Version)); Console.WriteLine("GLSL version: {0}", GL.GetString(StringName.ShadingLanguageVersion)); Console.WriteLine("Vendor: {0}", GL.GetString(StringName.Vendor)); Console.WriteLine("Renderer: {0}", GL.GetString(StringName.Renderer)); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Less); // load vertex and fragment shaders into opengl LoadShaders(); // load the texture LoadTexture(); // create buffer and fill it with the points of the triangle LoadCube(); double lastTime = Glfw.GetTime(); // run while window is open while (!Glfw.WindowShouldClose(_window)) { // update the scene based on the time elapsed since last update double thisTime = Glfw.GetTime(); Update(thisTime - lastTime); lastTime = thisTime; // draw one frame Render(); } // clean up and exit Glfw.Terminate(); }
private void OpenWindow(bool startInFullscreen, int width, int height) { GlfwMonitorPtr monitor = startInFullscreen ? Glfw.GetPrimaryMonitor() : GlfwMonitorPtr.Null; SetupWindow(); nativeWindow = Glfw.CreateWindow(width, height, "GLFW3", monitor, GlfwWindowPtr.Null); Glfw.MakeContextCurrent(nativeWindow); Glfw.SetWindowSizeCallback(nativeWindow, OnWindowResize); Glfw.SwapInterval(settings.UseVSync); }
public Window(int width, int height, string name) { Width = width; Height = height; rescaleDelegate = Rescale; GlfwWindow = Glfw.CreateWindow(Width, Height, name); Glfw.Vidmode vidmode = Glfw.GetVideoMode(Glfw.GetPrimaryMonitor()); Glfw.SetWindowPos(GlfwWindow, (vidmode.Width - Width) / 2, (vidmode.Height - Height) / 2); Glfw.SetWindowSizeCallback(GlfwWindow, rescaleDelegate); }
/// <summary> /// Starts this renderer. /// </summary> /// <param name="gameInstance"> /// A reference to the Junkbot game engine instance. /// </param> public void Start(JunkbotGame gameInstance) { Game = gameInstance; CurrentInputState = new InputEvents(); // Setup GLFW parameters and create window // Glfw.Init(); Glfw.SetErrorCallback(OnError); Glfw.WindowHint(WindowHint.ContextVersionMajor, 3); Glfw.WindowHint(WindowHint.ContextVersionMinor, 2); Glfw.WindowHint(WindowHint.OpenGLForwardCompat, 1); Glfw.WindowHint(WindowHint.OpenGLProfile, (int)OpenGLProfile.Core); WindowPtr = Glfw.CreateWindow(650, 420, "Junkbot (OpenGL 3.2)", GlfwMonitorPtr.Null, GlfwWindowPtr.Null); IsOpen = true; Glfw.MakeContextCurrent(WindowPtr); // Set GL pixel storage parameter // GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); // Set up VAO // GlVaoId = GL.GenVertexArray(); GL.BindVertexArray(GlVaoId); // Set up enabled features // GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // Set up viewport defaults // GL.ClearColor(0.39f, 0.58f, 0.93f, 1.0f); // Approx. cornflower blue GL.Viewport(0, 0, (int)JUNKBOT_VIEWPORT.X, (int)JUNKBOT_VIEWPORT.Y); // Set up input callbacks // Glfw.SetCharCallback(WindowPtr, OnChar); Glfw.SetCursorPosCallback(WindowPtr, OnCursorPos); Glfw.SetKeyCallback(WindowPtr, OnKey); Glfw.SetMouseButtonCallback(WindowPtr, OnMouseButton); Glfw.SetWindowSizeCallback(WindowPtr, OnWindowSize); // Now attach the game state event to update our strategies // Game.ChangeState += Game_ChangeState; }
void CheckNativeHandle() { if (_nativeGlFwWindowPtr.IsEmpty) { //create native glfw window this._nativeGlFwWindowPtr = Glfw.CreateWindow(this.Width, this.Height, this.Text, new GlfwMonitorPtr(), //default monitor new GlfwWindowPtr()); //default top window } }
public Window(int Width, int Height, string Title) { title = Title; width = Width; height = Height; WindowHint(); WindowInstance = Glfw.CreateWindow(Width, Height, Title, Monitor.None, GLFW.Window.None); if (!WindowCreationCheck()) { return; } }
private unsafe static void Main(string[] args) { glfw = Glfw.GetApi(); Console.WriteLine(glfw.GetVersionString()); glfw.SetErrorCallback(GlfwError); //SilkManager.Register<IWindowPlatform>(glfwPlatform); SilkManager.Register <GLSymbolLoader>(new Silk.NET.GLFW.GlfwLoader()); glfw.Init(); glfw.WindowHint(WindowHintInt.ContextVersionMajor, 3); glfw.WindowHint(WindowHintInt.ContextVersionMinor, 3); glfw.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core); window = glfw.CreateWindow(800, 600, "3Dtest", null, null); if (window == null) { Console.WriteLine("Window creation failed"); glfw.Terminate(); return; } glfw.MakeContextCurrent(window); glfw.SetWindowSizeCallback(window, OnResize); glfw.SetCursorPosCallback(window, MouseInput); glfw.SetScrollCallback(window, ScrollInput); glfw.SetInputMode(window, CursorStateAttribute.Cursor, CursorModeValue.CursorDisabled); //glfw.SwapInterval(1); OnLoad(); double currentFrame; while (!glfw.WindowShouldClose(window)) { currentFrame = glfw.GetTimerValue(); deltaTime = (currentFrame - lastFrame) / glfw.GetTimerFrequency(); lastFrame = currentFrame; ProcessInput(window); //Console.WriteLine($"Fps: {Math.Round(1f/deltaTime)}"); OnRender(); } glfw.Terminate(); }
public static void Main() { ToolBox.gl = new OpenGL(); Glfw.Init(); Glfw.SetErrorCallback((code, message) => Console.WriteLine($"GLFW {code}: {Marshal.PtrToStringAnsi(message)}")); Glfw.WindowHint(Hint.Resizable, false); Glfw.WindowHint(Hint.Visible, false); Glfw.WindowHint(Hint.ContextVersionMajor, 4); Glfw.WindowHint(Hint.ContextVersionMinor, 6); VideoMode mode = Glfw.GetVideoMode(Glfw.PrimaryMonitor); Window window = Glfw.CreateWindow(mode.Width, mode.Height, "Meinkraft", Glfw.PrimaryMonitor, Window.None); ToolBox.window = window; Glfw.MakeContextCurrent(window); Glfw.SetInputMode(window, InputMode.Cursor, (int)CursorMode.Disabled); ToolBox.gl.Enable(OpenGL.GL_DEPTH_TEST); ToolBox.gl.Enable(OpenGL.GL_CULL_FACE); ToolBox.gl.FrontFace(OpenGL.GL_CW); ToolBox.gl.ClearColor(0x87 / 255.0f, 0xCE / 255.0f, 0xFA / 255.0f, 0xFF / 255.0f); ToolBox.world = new World(window); while (!Glfw.WindowShouldClose(window)) { Glfw.PollEvents(); if (Glfw.GetKey(window, Keys.Escape) == InputState.Press) { Glfw.SetWindowShouldClose(window, true); } ToolBox.world.update(); ToolBox.gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); ToolBox.world.render(); Glfw.SwapBuffers(window); } ToolBox.world.Dispose(); Glfw.Terminate(); }
public void GameLoop() { // Initialize OpenGL and GLFW Gl.Initialize(); Glfw.Init(); // Set Window Hints Glfw.WindowHint(Hint.ClientApi, ClientApi.OpenGL); Glfw.WindowHint(Hint.ContextVersionMajor, 4); Glfw.WindowHint(Hint.ContextVersionMinor, 6); Glfw.WindowHint(Hint.OpenglProfile, Profile.Core); Glfw.WindowHint(Hint.Doublebuffer, true); Glfw.WindowHint(Hint.Decorated, true); Window = Glfw.CreateWindow(Width, Height, WindowTitle, Monitor.None, Window.None ); if (Window == Window.None) { Console.Error.WriteLine("Failed to create GLFW Window"); Glfw.Terminate(); Environment.Exit(1001); } Glfw.MakeContextCurrent(Window); Glfw.SwapInterval(1); Gl.Viewport(0, 0, Width, Height); Glfw.SetFramebufferSizeCallback(Window, OnResizeCallback); Init(); while (!Glfw.WindowShouldClose(Window)) { PreUpdate(); Gl.ClearColor(BackgroundColor.red, BackgroundColor.green, BackgroundColor.blue, BackgroundColor.alpha); Gl.Clear(ClearBufferMask.ColorBufferBit); Draw(); Update(); Glfw.SwapBuffers(Window); Glfw.PollEvents(); } Quit(); Glfw.Terminate(); }