glui

package module
v0.0.0-...-debada0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

Simple Image Display For Go

This package wraps the Go port of the C implementation of GLFW in some boilerplate to make displaying an image on the screen almost trivial.

The version of OpenGL used is 4.1 and the boilerplate includes the necessary shaders to perform the rendering.

See glui/cmd/image.go for a simple example of reading an image and displaying it in a window.

$ go run image.go <your image here - most image types supported>

The glui/cmd/images.go version takes multiple images on the command line and rotates through them. This example also demonstrates attaching a call back for character processing - hitting ESC will close the window.

Functions are included to allow you to create new windows with a backing image, set that image to some other image and a loop function (which actually does the rendering). The loop function can take a zero argument function that will be called once per loop iteration. In addition to handling the window rendering, the loop function also handles any call backs registered on the windows.

Finally, the events.c program provided in the C implementation of GLFW has been ported over to Go and is in glui/cmd/events.go.

$ go run events.go

This will dump out all the event types, for which call backs can be registered, to the terminal. It doesn't utilize the glui package itself.

Documentation

Overview

Package glui provides a simple way to display an image or images on a screen, each in its own window. The package makes use of the GLFW library and OpenGL v4.1

Index

Constants

This section is empty.

Variables

View Source
var WinMap = make(map[*glfw.Window]*GLWin)

WinMap provides a map of all windows to their corresponding GLWin

Functions

func Loop

func Loop(update func())

Loop is how window events get processed and the images rendered to their windows. It will run until there are no windows left to process. The update function provides a way to insert code into this loop - it should be non-blocking otherwise window updates will stall.

Types

type GLWin

type GLWin struct {
	Img *image.RGBA
	Win *glfw.Window
	// contains filtered or unexported fields
}

GLWin ties an image to a window

func NewGLWin

func NewGLWin(w, h int, title string, img image.Image, decorated bool) *GLWin

NewGLWin is used to create a new window of width w and height h. If the window is decorated then the title will appear in the window frame. Note - the window and image sizes are independent of each other. The image is scaled (not cropped) to fit the window.

func (*GLWin) SetImage

func (w *GLWin) SetImage(img image.Image)

SetImage is used to change the current image in a window. It's thread safe.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL