-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdl2_opengl3.nim
128 lines (110 loc) · 3.62 KB
/
sdl2_opengl3.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Compiling:
# nim c -d:SDL sdl2_opengl3
import std/[os]
import ../utils/appImGuiSdl2
when defined(windows):
include ./res/resource
const MainWinWidth = 1024
const MainWinHeight = 900
#------
# main
#------
proc main() =
var win = createImGui(MainWinWidth, MainWinHeight, title="ImGui: SDL2")
defer: destroyImGui(win)
var
showDemoWindow = true
showFirstWindow = true
fval = 0.5f
counter = 0
xQuit: bool
sBuf = newString(200)
#-------------
# Load image
#-------------
var
textureId: GLuint
textureWidth = 0
textureHeight = 0
var ImageName = os.joinPath(os.getAppDir(),"fuji-400.jpg")
loadTextureFromFile(ImageName, textureId, textureWidth,textureHeight)
defer: glDeleteTextures(1, addr textureId)
let pio = igGetIO()
#-----------
# Main loop
#-----------
while not xQuit:
var event: Event
while 0 != sdl.pollevent(addr event):
ImGui_ImplSDL2_ProcessEvent(cast[ptr SdlEvent](addr event))
if event.kind == QUIT:
xQuit = true
if event.kind == WINDOWEVENT and event.window.event ==
WINDOWEVENT_CLOSE and
event.window.windowID == sdl.getWindowID(win.handle):
xQuit = true
newFrame()
if showDemoWindow:
igShowDemoWindow(addr showDemoWindow)
#-----------------
# showFirstWindow
#-----------------
if showFirstWindow:
igBegin("Nim: Dear ImGui test with Futhark", showFirstWindow.addr, 0)
defer: igEnd()
igText((ICON_FA_COMMENT & " " & getFrontendVersionString()).cstring)
igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring)
igText("%s %s", ICON_FA_COMMENT_DOTS & " Dear ImGui", igGetVersion())
igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion)
igInputTextWithHint("InputText" ,"Input text here" ,sBuf)
igText(("Input result:" & sBuf).cstring)
igCheckbox("Demo window", addr showDemoWindow)
igSliderFloat("Float", addr fval, 0.0f, 1.5f, "%.3f", 0)
igColorEdit3("Background color", win.ini.clearColor.array3, ImGuiColorEditFlags_None.ImGuiColorEditFlags)
if igButton("Button", vec2(0.0f, 0.0f)):
inc counter
igSameLine(0.0f, -1.0f)
igText("counter = %d", counter)
igText("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / pio.Framerate.float, pio.Framerate)
#
igSeparatorText(ICON_FA_WRENCH & " Icon font test ")
igText(ICON_FA_TRASH_CAN & " Trash")
igText(ICON_FA_MAGNIFYING_GLASS_PLUS &
" " & ICON_FA_POWER_OFF &
" " & ICON_FA_MICROPHONE &
" " & ICON_FA_MICROCHIP &
" " & ICON_FA_VOLUME_HIGH &
" " & ICON_FA_SCISSORS &
" " & ICON_FA_SCREWDRIVER_WRENCH &
" " & ICON_FA_BLOG)
# Show image load window
block:
igBegin("Image load test", nil, 0)
defer: igEnd()
# Load image
let
size = vec2(textureWidth, textureHeight)
uv0 = vec2(0, 0)
uv1 = vec2(1, 1)
tint_col = vec4(1, 1, 1, 1)
border_col = vec4(0, 0, 0, 0)
var
imageBoxPosTop:ImVec2
imageBoxPosEnd:ImVec2
igGetCursorScreenPos(addr imageBoxPosTop) # Get absolute pos.
igImage(cast[ImTextureID](textureId), size, uv0, uv1, tint_col, border_col);
igGetCursorScreenPos(addr imageBoxPosEnd) # Get absolute pos.
# Magnifiying glass
if igIsItemHovered(ImGui_HoveredFlags_DelayNone.ImGuiHoveredFlags):
zoomGlass(textureId, textureWidth, imageBoxPosTop, imageBoxPosEnd)
#--------
# render
#--------
render(win)
if not showFirstWindow and not showDemoWindow :
xQuit = true
### end while
#------
# main
#------
main()