Skip to content
anbcodes edited this page Apr 4, 2018 · 13 revisions

Welcome to the goguigl wiki!

Getting Started

First you need to get the package. Use go get github.com/anbcodes/goguigl it should give you no output.

Then make a directory and unzip this in it.

Then you need to make a file and put the following code into it.

package main

import (
	"runtime"

	"github.com/anbcodes/goguigl/gui"
	"github.com/go-gl/gl/v4.1-core/gl"
	"github.com/go-gl/glfw/v3.2/glfw"
)

func windowSizeCallback(w *glfw.Window, wd, ht int) {
	fwidth, fheight := gui.FramebufferSize(w)
	gl.Viewport(0, 0, int32(fwidth), int32(fheight))
}

func main() {
	runtime.LockOSThread()
	w := gui.InitGlfw()
	gui.InitOpenGL()
	w.SetSizeCallback(windowSizeCallback)
	screen := gui.NewScreen(w)
	screen.InitGui("font/font.png", "font/font.json", "button.png", "")
	guimousebuttoncallback := screen.MouseButtonCallback()
	guicursorposcallback := screen.CursorPosCallback()
	w.SetMouseButtonCallback(guimousebuttoncallback)
	w.SetCursorPosCallback(guicursorposcallback)
	for {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		screen.Update()
		glfw.PollEvents()
		w.SwapBuffers()
	}
}

So what this does is it makes a GLFW window and puts a button on it.


import (
	"runtime"

	"github.com/anbcodes/goguigl/gui"
	"github.com/go-gl/gl/v4.1-core/gl"
	"github.com/go-gl/glfw/v3.2/glfw"
)

This imports the package and OpenGL and GLFW.


func windowSizeCallback(w *glfw.Window, wd, ht int) {
	fwidth, fheight := gui.FramebufferSize(w)
	gl.Viewport(0, 0, int32(fwidth), int32(fheight))
}

This lets the window change size.


func main() {
	runtime.LockOSThread()
	w := gui.InitGlfw()
	gui.InitOpenGL()
	w.SetSizeCallback(windowSizeCallback)
	screen := gui.NewScreen(w)
	screen.InitGui("font/font.png", "font/font.json", "button.png", "")
	guimousebuttoncallback := screen.MouseButtonCallback()
	guicursorposcallback := screen.CursorPosCallback()
	w.SetMouseButtonCallback(guimousebuttoncallback)
	w.SetCursorPosCallback(guicursorposcallback)
	for {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		screen.Update()
		glfw.PollEvents()
		w.SwapBuffers()
	}
}

This is the main function where you set up OpenGL, GLFW and goguigl. First you set your runtime with

runtime.LockOSThread()

I really don't know why you need this but it does not work without it. Goguigl has some functions to help with setting up openGL and GLFW. You don't have to do this if you already are doing something like it but these will help.

w := gui.InitGlfw()
gui.InitOpenGL()
w.SetSizeCallback(windowSizeCallback)

w is the window which you will use for creating your screen struct like this.

screen := gui.NewScreen(w)

This make a screen struct then you need to init goguigl.

screen.InitGui("extras/font/font.png", "extras/font/font.json", "extras/button.png", "entrypath (entry is not done yet")

This gives tells the gui what to use for the font and button. These will work because you downloaded and unzipped the file but you can also make your own.


guimousebuttoncallback := screen.MouseButtonCallback()
guicursorposcallback := screen.CursorPosCallback()
w.SetMouseButtonCallback(guimousebuttoncallback)
w.SetCursorPosCallback(guicursorposcallback)

This sets the callbacks if you want to do your own stuff with the callbacks go here.


for {
  gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
  screen.Update()
  glfw.PollEvents()
  w.SwapBuffers()
	}

This is your loop that calls screen.update() and the other openGL and GLFW things and now go into the directory and run go run filename.go in the terminal and your done.

Clone this wiki locally