forked from inkyblackness/imgui-go
/
main.go
102 lines (82 loc) · 2.36 KB
/
main.go
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
package main
import (
"fmt"
"runtime"
"time"
"github.com/go-gl/gl/v3.2-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/inkyblackness/imgui-go"
)
func main() {
runtime.LockOSThread()
err := glfw.Init()
if err != nil {
panic(err)
}
defer glfw.Terminate()
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 2)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
glfw.WindowHint(glfw.OpenGLForwardCompatible, 1)
window, err := glfw.CreateWindow(1280, 720, "ImGui-Go GLFW+OpenGL3 example", nil, nil)
if err != nil {
panic(err)
}
defer window.Destroy()
window.MakeContextCurrent()
glfw.SwapInterval(1)
err = gl.Init()
if err != nil {
panic(err)
}
context := imgui.CreateContext(nil)
defer context.Destroy()
/*
imgui.CurrentStyle().ScaleAllSizes(2.0)
imgui.CurrentIO().SetFontGlobalScale(2.0)
*/
impl := imguiGlfw3Init(window)
defer impl.Shutdown()
showDemoWindow := false
showAnotherWindow := false
counter := 0
var clearColor imgui.Vec4
for !window.ShouldClose() {
glfw.PollEvents()
impl.NewFrame()
// 1. Show a simple window.
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
{
imgui.Text("Hello, world!")
imgui.Checkbox("Demo Window", &showDemoWindow)
imgui.Checkbox("Another Window", &showAnotherWindow)
if imgui.Button("Button") {
counter++
}
imgui.SameLine()
imgui.Text(fmt.Sprintf("counter = %d", counter))
}
// 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows.
if showAnotherWindow {
imgui.BeginV("Another Window", &showAnotherWindow, 0)
imgui.Text("Hello from another window!")
if imgui.Button("Close Me") {
showAnotherWindow = false
}
imgui.End()
}
// 3. Show the ImGui demo window. Most of the sample code is in imgui.ShowDemoWindow().
// Read its code to learn more about Dear ImGui!
if showDemoWindow {
imgui.ShowDemoWindow(&showDemoWindow)
}
displayWidth, displayHeight := window.GetFramebufferSize()
gl.Viewport(0, 0, int32(displayWidth), int32(displayHeight))
gl.ClearColor(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W)
gl.Clear(gl.COLOR_BUFFER_BIT)
imgui.Render()
impl.Render(imgui.RenderedDrawData())
window.SwapBuffers()
<-time.After(time.Millisecond * 25)
}
}