mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2025-07-05 12:38:47 +02:00
Add support for GLFW (#26)
Co-authored-by: Oliver Charles <ollie@ocharles.org.uk>
This commit is contained in:
60
src/DearImGui/GLFW/Vulkan.hs
Normal file
60
src/DearImGui/GLFW/Vulkan.hs
Normal file
@ -0,0 +1,60 @@
|
||||
{-# LANGUAGE BlockArguments #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE PatternSynonyms #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
{-|
|
||||
Module: DearImGui.GLFW.Vulkan
|
||||
|
||||
Initialising the Vulkan backend for Dear ImGui using GLFW3.
|
||||
-}
|
||||
|
||||
module DearImGui.GLFW.Vulkan
|
||||
( glfwInitForVulkan )
|
||||
where
|
||||
|
||||
-- base
|
||||
import Data.Bool
|
||||
( bool )
|
||||
import Foreign.C.Types
|
||||
( CBool )
|
||||
import Foreign.Ptr
|
||||
( Ptr )
|
||||
import Unsafe.Coerce
|
||||
( unsafeCoerce )
|
||||
|
||||
-- inline-c
|
||||
import qualified Language.C.Inline as C
|
||||
|
||||
-- inline-c-cpp
|
||||
import qualified Language.C.Inline.Cpp as Cpp
|
||||
|
||||
-- GLFW
|
||||
import Graphics.UI.GLFW
|
||||
( Window )
|
||||
|
||||
-- transformers
|
||||
import Control.Monad.IO.Class ( MonadIO, liftIO )
|
||||
|
||||
|
||||
C.context Cpp.cppCtx
|
||||
C.include "imgui.h"
|
||||
C.include "backends/imgui_impl_vulkan.h"
|
||||
C.include "backends/imgui_impl_glfw.h"
|
||||
C.include "GLFW/glfw3.h"
|
||||
Cpp.using "namespace ImGui"
|
||||
|
||||
|
||||
-- | Wraps @ImGui_ImplGlfw_InitForVulkan@.
|
||||
glfwInitForVulkan :: MonadIO m => Window -> Bool -> m Bool
|
||||
glfwInitForVulkan window installCallbacks = liftIO do
|
||||
( 0 /= ) <$> [C.exp| bool { ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)$(void* windowPtr), $(bool cInstallCallbacks)) } |]
|
||||
where
|
||||
windowPtr :: Ptr ()
|
||||
windowPtr = unsafeCoerce window
|
||||
|
||||
cInstallCallbacks :: CBool
|
||||
cInstallCallbacks = bool 0 1 installCallbacks
|
Reference in New Issue
Block a user