aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/llgcode/draw2d/samples/helloworldgl
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-09-09 09:42:37 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-09-09 09:42:37 +0200
commit500caaeda74dd9c660279036293f4b2997cf0b03 (patch)
tree1226f60231a408b0aae67867faaa3f2cfbac8c83 /vendor/github.com/llgcode/draw2d/samples/helloworldgl
parent413560591fc2d89a73eb8a33ba28b0cc3407b1db (diff)
Add vendor
Diffstat (limited to 'vendor/github.com/llgcode/draw2d/samples/helloworldgl')
-rw-r--r--vendor/github.com/llgcode/draw2d/samples/helloworldgl/helloworldgl.go119
1 files changed, 119 insertions, 0 deletions
diff --git a/vendor/github.com/llgcode/draw2d/samples/helloworldgl/helloworldgl.go b/vendor/github.com/llgcode/draw2d/samples/helloworldgl/helloworldgl.go
new file mode 100644
index 0000000..be89db5
--- /dev/null
+++ b/vendor/github.com/llgcode/draw2d/samples/helloworldgl/helloworldgl.go
@@ -0,0 +1,119 @@
+// Open an OpenGl window and display a rectangle using a OpenGl GraphicContext
+package main
+
+import (
+ "image/color"
+ "log"
+ "runtime"
+
+ "github.com/go-gl/gl/v2.1/gl"
+ "github.com/go-gl/glfw/v3.1/glfw"
+ "github.com/llgcode/draw2d"
+ "github.com/llgcode/draw2d/draw2dgl"
+ "github.com/llgcode/draw2d/draw2dkit"
+)
+
+var (
+ // global rotation
+ rotate int
+ width, height int
+ redraw = true
+ font draw2d.FontData
+)
+
+func reshape(window *glfw.Window, w, h int) {
+ gl.ClearColor(1, 1, 1, 1)
+ /* Establish viewing area to cover entire window. */
+ gl.Viewport(0, 0, int32(w), int32(h))
+ /* PROJECTION Matrix mode. */
+ gl.MatrixMode(gl.PROJECTION)
+ /* Reset project matrix. */
+ gl.LoadIdentity()
+ /* Map abstract coords directly to window coords. */
+ gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
+ /* Invert Y axis so increasing Y goes down. */
+ gl.Scalef(1, -1, 1)
+ /* Shift origin up to upper-left corner. */
+ gl.Translatef(0, float32(-h), 0)
+ gl.Enable(gl.BLEND)
+ gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
+ gl.Disable(gl.DEPTH_TEST)
+ width, height = w, h
+ redraw = true
+}
+
+// Ask to refresh
+func invalidate() {
+ redraw = true
+}
+
+func display() {
+ gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
+
+ gl.LineWidth(1)
+ gc := draw2dgl.NewGraphicContext(width, height)
+ gc.SetFontData(draw2d.FontData{
+ Name: "luxi",
+ Family: draw2d.FontFamilyMono,
+ Style: draw2d.FontStyleBold | draw2d.FontStyleItalic})
+
+ gc.BeginPath()
+ draw2dkit.RoundedRectangle(gc, 200, 200, 600, 600, 100, 100)
+
+ gc.SetFillColor(color.RGBA{0, 0, 0, 0xff})
+ gc.Fill()
+
+ gl.Flush() /* Single buffered, so needs a flush. */
+}
+
+func init() {
+ runtime.LockOSThread()
+}
+
+func main() {
+ err := glfw.Init()
+ if err != nil {
+ panic(err)
+ }
+ defer glfw.Terminate()
+ width, height = 800, 800
+ window, err := glfw.CreateWindow(width, height, "Show RoundedRect", nil, nil)
+ if err != nil {
+ panic(err)
+ }
+
+ window.MakeContextCurrent()
+ window.SetSizeCallback(reshape)
+ window.SetKeyCallback(onKey)
+ window.SetCharCallback(onChar)
+
+ glfw.SwapInterval(1)
+
+ err = gl.Init()
+ if err != nil {
+ panic(err)
+ }
+
+ reshape(window, width, height)
+ for !window.ShouldClose() {
+ if redraw {
+ display()
+ window.SwapBuffers()
+ redraw = false
+ }
+ glfw.PollEvents()
+ // time.Sleep(2 * time.Second)
+ }
+}
+
+func onChar(w *glfw.Window, char rune) {
+ log.Println(char)
+}
+
+func onKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
+ switch {
+ case key == glfw.KeyEscape && action == glfw.Press,
+ key == glfw.KeyQ && action == glfw.Press:
+ w.SetShouldClose(true)
+ }
+}