private static void CreateWindow(ImGuiViewport *viewport) { PlatformBackend backend = GetPlatformBackend(); ViewportData * viewportData = ViewportData.Allocate(); viewport->PlatformUserData = viewportData; GLFW.WindowHint(WindowHintBool.Visible, false); GLFW.WindowHint(WindowHintBool.Focused, false); GLFW.WindowHint(WindowHintBool.FocusOnShow, false); GLFW.WindowHint(WindowHintBool.Decorated, !viewport->Flags.HasFlag(ImGuiViewportFlags.NoDecoration)); GLFW.WindowHint(WindowHintBool.Floating, viewport->Flags.HasFlag(ImGuiViewportFlags.TopMost)); *viewportData = new ViewportData() { Window = GLFW.CreateWindow((int)viewport->Size.X, (int)viewport->Size.Y, "No Title Yet", null, backend.Window), WindowOwned = true, }; viewport->PlatformHandle = viewportData->Window; if (OperatingSystem.IsWindows()) { viewport->PlatformHandleRaw = (void *)GLFW.GetWin32Window(viewportData->Window); } GLFW.SetWindowPos(viewportData->Window, (int)viewport->Pos.X, (int)viewport->Pos.Y); // Install GLFW callbacks for secondary viewports GlfwNative.glfwSetWindowFocusCallback(viewportData->Window, &WindowFocusCallback); GlfwNative.glfwSetCursorEnterCallback(viewportData->Window, &CursorEnterCallback); GlfwNative.glfwSetCursorPosCallback(viewportData->Window, &CursorPosCallback); GlfwNative.glfwSetMouseButtonCallback(viewportData->Window, &MouseButtonCallback); GlfwNative.glfwSetScrollCallback(viewportData->Window, &ScrollCallback); GlfwNative.glfwSetKeyCallback(viewportData->Window, &KeyCallback); GlfwNative.glfwSetCharCallback(viewportData->Window, &CharCallback); GlfwNative.glfwSetWindowCloseCallback(viewportData->Window, &WindowCloseCallback); GlfwNative.glfwSetWindowPosCallback(viewportData->Window, &WindowPosCallback); GlfwNative.glfwSetWindowSizeCallback(viewportData->Window, &WindowSizeCallback); GLFW.MakeContextCurrent(viewportData->Window); GLFW.SwapInterval(0); }
public static unsafe void Main() { using (new ExitHandler.LifetimeHandle()) { const int glfwTrue = 1; const int glfwFalse = 0; const int glfwContextVersionMajor = 0x00022002; const int glfwContextVersionMinor = 0x00022003; const int glfwOpenGlProfile = 0x00022008; const int glfwOpenGlCoreProfile = 0x00032001; const int glfwOpenGlForwardCompat = 0x00022006; const int glfwResizable = 0x00020003; const int glColorBufferBit = 0x00004000; const int glTriangles = 0x0004; GlfwNative.Init(); GlfwNative.WindowHint(glfwContextVersionMajor, 3); GlfwNative.WindowHint(glfwContextVersionMinor, 3); GlfwNative.WindowHint(glfwOpenGlProfile, glfwOpenGlCoreProfile); GlfwNative.WindowHint(glfwOpenGlForwardCompat, glfwTrue); GlfwNative.WindowHint(glfwResizable, glfwFalse); using (var window = new Window("Poltergeist Editor")) { using (var vertexArray = VertexArray.Create()) { vertexArray.Bind(); Span <float> vertices = stackalloc float[] { -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f }; Span <VertexBufferElement> layout = stackalloc VertexBufferElement[] { new VertexBufferElement(OpenGlType.Float, 3) }; using (VertexBuffer.Create <float>(vertices, layout)) { } while (window.IsOpen) { window.PollEvents(); OpenGl3Native.ClearColor(0.3f, 0.3f, 0.3f, 1.0f); OpenGl3Native.Clear(glColorBufferBit); OpenGl3Native.DrawArrays(glTriangles, 0, 3); window.SwapBuffers(); } vertexArray.Unbind(); } } GlfwNative.Terminate(); } } } }