mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2024-11-22 00:47:00 +00:00
Wrap the OpenGL 3 backend (#20)
This commit is contained in:
parent
ac74572121
commit
f9412effde
10
Main.hs
10
Main.hs
@ -8,7 +8,7 @@ module Main (main) where
|
||||
import Control.Monad
|
||||
import Data.IORef
|
||||
import DearImGui
|
||||
import DearImGui.OpenGL
|
||||
import DearImGui.OpenGL3
|
||||
import DearImGui.SDL
|
||||
import DearImGui.SDL.OpenGL
|
||||
import Control.Exception
|
||||
@ -23,7 +23,7 @@ main = do
|
||||
bracket (glCreateContext w) glDeleteContext \glContext ->
|
||||
bracket createContext destroyContext \_imguiContext ->
|
||||
bracket_ (sdl2InitForOpenGL w glContext) sdl2Shutdown $
|
||||
bracket_ openGL2Init openGL2Shutdown do
|
||||
bracket_ openGL3Init openGL3Shutdown do
|
||||
checkVersion
|
||||
styleColorsLight
|
||||
|
||||
@ -38,7 +38,7 @@ main = do
|
||||
tab2 <- newIORef True
|
||||
loop w checked color slider r pos size' selected tab1 tab2
|
||||
|
||||
openGL2Shutdown
|
||||
openGL3Shutdown
|
||||
|
||||
|
||||
loop
|
||||
@ -56,7 +56,7 @@ loop
|
||||
loop w checked color slider r pos size' selected tab1Ref tab2Ref = do
|
||||
quit <- pollEvents
|
||||
|
||||
openGL2NewFrame
|
||||
openGL3NewFrame
|
||||
sdl2NewFrame w
|
||||
newFrame
|
||||
|
||||
@ -162,7 +162,7 @@ loop w checked color slider r pos size' selected tab1Ref tab2Ref = do
|
||||
render
|
||||
|
||||
glClear GL_COLOR_BUFFER_BIT
|
||||
openGL2RenderDrawData =<< getDrawData
|
||||
openGL3RenderDrawData =<< getDrawData
|
||||
|
||||
glSwapWindow w
|
||||
|
||||
|
@ -41,7 +41,7 @@ import Control.Exception
|
||||
import Control.Monad.IO.Class
|
||||
import Control.Monad.Managed
|
||||
import DearImGui
|
||||
import DearImGui.OpenGL
|
||||
import DearImGui.OpenGL2
|
||||
import DearImGui.SDL
|
||||
import DearImGui.SDL.OpenGL
|
||||
import Graphics.GL
|
||||
|
@ -1,3 +1,3 @@
|
||||
packages: *.cabal
|
||||
package dear-imgui
|
||||
flags: +sdl2 +glfw +opengl +vulkan
|
||||
flags: +sdl2 +glfw +opengl2 +opengl3 +vulkan
|
||||
|
@ -5,9 +5,17 @@ build-type: Simple
|
||||
data-files:
|
||||
imgui/imgui.h
|
||||
|
||||
flag opengl
|
||||
flag opengl2
|
||||
description:
|
||||
Enable OpenGL backend.
|
||||
Enable OpenGL 2 backend.
|
||||
default:
|
||||
False
|
||||
manual:
|
||||
False
|
||||
|
||||
flag opengl3
|
||||
description:
|
||||
Enable OpenGL 3 backend.
|
||||
default:
|
||||
True
|
||||
manual:
|
||||
@ -76,21 +84,29 @@ library
|
||||
, inline-c-cpp
|
||||
, StateVar
|
||||
|
||||
if flag(opengl)
|
||||
if flag(opengl2)
|
||||
exposed-modules:
|
||||
DearImGui.OpenGL
|
||||
DearImGui.OpenGL2
|
||||
cxx-sources:
|
||||
imgui/backends/imgui_impl_opengl2.cpp
|
||||
build-depends:
|
||||
gl
|
||||
|
||||
if flag(opengl3)
|
||||
exposed-modules:
|
||||
DearImGui.OpenGL3
|
||||
cxx-sources:
|
||||
imgui/backends/imgui_impl_opengl3.cpp
|
||||
if os(windows)
|
||||
extra-libraries:
|
||||
opengl32
|
||||
buildable:
|
||||
False
|
||||
else
|
||||
if os(darwin)
|
||||
frameworks:
|
||||
OpenGL
|
||||
buildable:
|
||||
False
|
||||
else
|
||||
extra-libraries:
|
||||
GL
|
||||
pkgconfig-depends:
|
||||
glew
|
||||
|
||||
if flag(vulkan)
|
||||
exposed-modules:
|
||||
@ -128,7 +144,7 @@ library
|
||||
pkgconfig-depends:
|
||||
sdl2
|
||||
|
||||
if flag(opengl)
|
||||
if flag(opengl2) || flag(opengl3)
|
||||
exposed-modules:
|
||||
DearImGui.SDL.OpenGL
|
||||
|
||||
@ -148,7 +164,7 @@ library
|
||||
pkgconfig-depends:
|
||||
glfw3
|
||||
|
||||
if flag(opengl)
|
||||
if flag(opengl2) || flag(opengl3)
|
||||
exposed-modules:
|
||||
DearImGui.GLFW.OpenGL
|
||||
|
||||
|
@ -11,7 +11,7 @@ import Control.Exception
|
||||
import Control.Monad.IO.Class
|
||||
import Control.Monad.Managed
|
||||
import DearImGui
|
||||
import DearImGui.OpenGL
|
||||
import DearImGui.OpenGL2
|
||||
import DearImGui.SDL
|
||||
import DearImGui.SDL.OpenGL
|
||||
import Graphics.GL
|
||||
|
@ -9,7 +9,7 @@ import Control.Monad
|
||||
import Control.Monad.IO.Class
|
||||
import Control.Monad.Managed
|
||||
import DearImGui
|
||||
import DearImGui.OpenGL
|
||||
import DearImGui.OpenGL2
|
||||
import DearImGui.GLFW
|
||||
import DearImGui.GLFW.OpenGL
|
||||
import Graphics.GL
|
||||
@ -79,4 +79,4 @@ mainLoop win = do
|
||||
|
||||
GLFW.swapBuffers win
|
||||
|
||||
mainLoop win
|
||||
mainLoop win
|
||||
|
@ -9,10 +9,10 @@
|
||||
{-|
|
||||
Module: DearImGui.OpenGL
|
||||
|
||||
OpenGL backend for Dear ImGui.
|
||||
OpenGL 2 backend for Dear ImGui.
|
||||
-}
|
||||
|
||||
module DearImGui.OpenGL
|
||||
module DearImGui.OpenGL2
|
||||
( openGL2Init
|
||||
, openGL2Shutdown
|
||||
, openGL2NewFrame
|
69
src/DearImGui/OpenGL3.hs
Normal file
69
src/DearImGui/OpenGL3.hs
Normal file
@ -0,0 +1,69 @@
|
||||
{-# LANGUAGE BlockArguments #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE PatternSynonyms #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
{-|
|
||||
Module: DearImGui.OpenGL
|
||||
|
||||
OpenGL 3 backend for Dear ImGui.
|
||||
-}
|
||||
|
||||
module DearImGui.OpenGL3
|
||||
( openGL3Init
|
||||
, openGL3Shutdown
|
||||
, openGL3NewFrame
|
||||
, openGL3RenderDrawData
|
||||
)
|
||||
where
|
||||
|
||||
-- inline-c
|
||||
import qualified Language.C.Inline as C
|
||||
|
||||
-- inline-c-cpp
|
||||
import qualified Language.C.Inline.Cpp as Cpp
|
||||
|
||||
-- transformers
|
||||
import Control.Monad.IO.Class
|
||||
( MonadIO, liftIO )
|
||||
|
||||
-- DearImGui
|
||||
import DearImGui
|
||||
( DrawData(..) )
|
||||
|
||||
|
||||
C.context (Cpp.cppCtx <> C.bsCtx)
|
||||
C.include "imgui.h"
|
||||
C.include "GL/glew.h"
|
||||
C.include "backends/imgui_impl_opengl3.h"
|
||||
Cpp.using "namespace ImGui"
|
||||
|
||||
|
||||
-- | Wraps @ImGui_ImplOpenGL3_Init@.
|
||||
openGL3Init :: MonadIO m => m Bool
|
||||
openGL3Init = liftIO $
|
||||
( 0 /= ) <$> [C.block| bool {
|
||||
glewInit();
|
||||
return ImGui_ImplOpenGL3_Init();
|
||||
} |]
|
||||
|
||||
|
||||
-- | Wraps @ImGui_ImplOpenGL3_Shutdown@.
|
||||
openGL3Shutdown :: MonadIO m => m ()
|
||||
openGL3Shutdown = liftIO do
|
||||
[C.exp| void { ImGui_ImplOpenGL3_Shutdown(); } |]
|
||||
|
||||
|
||||
-- | Wraps @ImGui_ImplOpenGL3_NewFrame@.
|
||||
openGL3NewFrame :: MonadIO m => m ()
|
||||
openGL3NewFrame = liftIO do
|
||||
[C.exp| void { ImGui_ImplOpenGL3_NewFrame(); } |]
|
||||
|
||||
|
||||
-- | Wraps @ImGui_ImplOpenGL3_RenderDrawData@.
|
||||
openGL3RenderDrawData :: MonadIO m => DrawData -> m ()
|
||||
openGL3RenderDrawData (DrawData ptr) = liftIO do
|
||||
[C.exp| void { ImGui_ImplOpenGL3_RenderDrawData((ImDrawData*) $( void* ptr )) } |]
|
Loading…
Reference in New Issue
Block a user