backend

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CExposerError error = errors.New("CreateBackend was unable to extract C API Exposer from your backend. This is an error if you want to use C-related backend.")

Functions

func AfterCreateContext

func AfterCreateContext() unsafe.Pointer

func AfterRender

func AfterRender() unsafe.Pointer

func BeforeDestroyContext

func BeforeDestroyContext() unsafe.Pointer

func BeforeRender

func BeforeRender() unsafe.Pointer

func ImageToRgba

func ImageToRgba(img image.Image) *image.RGBA

ImageToRgba converts image.Image to *image.RGBA.

func LoadImage

func LoadImage(imgPath string) (*image.RGBA, error)

LoadImage loads image from file and returns *image.RGBA.

func LoopCallback

func LoopCallback() unsafe.Pointer

Types

type Backend

type Backend[BackendFlagsT ~int] interface {
	SetAfterCreateContextHook(func())
	SetBeforeDestroyContextHook(func())
	SetBeforeRenderHook(func())
	SetAfterRenderHook(func())

	SetBgColor(color imgui.Vec4)
	Run(func())
	Refresh()

	SetWindowPos(x, y int)
	GetWindowPos() (x, y int32)
	SetWindowSize(width, height int)
	SetWindowSizeLimits(minWidth, minHeight, maxWidth, maxHeight int)
	SetWindowTitle(title string)
	DisplaySize() (width, height int32)
	SetShouldClose(bool)
	ContentScale() (xScale, yScale float32)

	SetTargetFPS(fps uint)

	SetDropCallback(DropCallback)
	SetCloseCallback(WindowCloseCallback[BackendFlagsT])
	SetKeyCallback(KeyCallback)
	SetSizeChangeCallback(SizeChangeCallback)
	// SetWindowFlags selected hint to specified value.
	// ATTENTION: This method is able to set only one flag per call.
	SetWindowFlags(flag BackendFlagsT, value int)
	SetIcons(icons ...image.Image)
	SetSwapInterval(interval BackendFlagsT) error
	SetCursorPos(x, y float64)
	SetInputMode(mode BackendFlagsT, value BackendFlagsT)

	CreateWindow(title string, width, height int)

	TextureManager
}

Backend is a special interface that implements all methods required to render imgui application.

func CreateBackend

func CreateBackend[BackendFlagsT ~int](backend Backend[BackendFlagsT]) (sameBackend Backend[BackendFlagsT], err error)

CreateBackend should to be called before using any cimgui methods. This enables the following features:

  • C-related callbacks: if your backend implements C functions, this will export some methods from your backend to C.
  • Advanced Texture Loading stuff. GL texture loading is a little complex. texture.go has some high-level logic.

Error:

  • Error could be CExposerError when your backend does not support C. THIS MAY STILL WORK CORRECTLY. Specificly, this may happen if you use some backend that is not part of cimgui-go. In such a case just ignore the error.

type DropCallback

type DropCallback func([]string)

type KeyCallback

type KeyCallback func(key, scanCode, action, mods int)

type SizeChangeCallback

type SizeChangeCallback func(w, h int)

type Texture

type Texture struct {
	ID     imgui.TextureID
	Width  int
	Height int
}

Texture implements a simple texture loader. It wraps backend's methods to allow creating textures easily. IMPORTANT: as the texture is mainly handled by C OpenGL, it is not covered by Garbae Collector (GC).

Remember to call (*Texture).Release when you no longer need it.

func NewTextureFromRgba

func NewTextureFromRgba(rgba *image.RGBA) *Texture

func (*Texture) Release added in v1.0.3

func (t *Texture) Release()

Release tells OpenGL that this texture is no longer needed. ATTENTION: This will not be automatically handled by GC so remember to do it manually if you have many textures!

type TextureManager

type TextureManager interface {
	CreateTexture(pixels unsafe.Pointer, width, Height int) imgui.TextureID
	CreateTextureRgba(img *image.RGBA, width, height int) imgui.TextureID
	DeleteTexture(id imgui.TextureID)
}

TextureManager is a part of Backend.

Why I separate it? Current impl of local texture.go needs to store this somewhere, and I don't want to make Texture relate on BackendFlagsT.

type WindowCloseCallback

type WindowCloseCallback[BackendFlagsT ~int] func(b Backend[BackendFlagsT])

Directories

Path Synopsis
Package ebitenbackend contains a renderer of ImGui for Ebitengine along with cimgui.Backend implementation.
Package ebitenbackend contains a renderer of ImGui for Ebitengine along with cimgui.Backend implementation.

Jump to

Keyboard shortcuts

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