Textures
Textures in the hlg
package can be created from images, allowing for more complex and detailed visuals. Textures are particularly useful for rendering images or sprites.
Creating a Texture from an Image
1package main
2
3import (
4 "image"
5 "net/http"
6 _ "image/jpeg"
7 "github.com/dfirebaugh/hlg"
8)
9
10func downloadImage(url string) image.Image {
11 resp, err := http.Get(url)
12 if err != nil {
13 panic(err)
14 }
15 defer resp.Body.Close()
16
17 img, _, err := image.Decode(resp.Body)
18 if err != nil {
19 panic(err)
20 }
21
22 return img
23}
24
25func main() {
26 hlg.SetWindowSize(154, 240)
27 hlg.SetTitle("hlg texture example")
28
29 t, _ := hlg.CreateTextureFromImage(downloadImage(`https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Nick_Offerman_2013_Headshot_%28cropped%29.jpg/308px-Nick_Offerman_2013_Headshot_%28cropped%29.jpg`))
30
31 hlg.Run(nil, func() {
32 t.Render()
33 })
34}
The above code should render this image.
sourced from: https://commons.wikimedia.org/w/index.php?curid=31678974
Texture Interfaces
1type Renderable interface {
2 Render()
3 Dispose()
4 Hide()
5}
6
7type Transformable interface {
8 Move(screenX, screenY float32)
9 Rotate(angle float32)
10 Scale(sx, sy float32)
11}
12
13type Texture interface {
14 Renderable
15 Transformable
16 Handle() uintptr
17 UpdateImage(img image.Image) error
18 Resize(width, height float32)
19 FlipVertical()
20 FlipHorizontal()
21 Clip(minX, minY, maxX, maxY float32)
22}