forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFontAtlas.go
56 lines (47 loc) · 1.82 KB
/
FontAtlas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package imgui
// #include "FontAtlasWrapper.h"
import "C"
import "unsafe"
// Alpha8Image represents a imgui backed 8-bit alpha value image.
type Alpha8Image struct {
Width, Height int
Pixels unsafe.Pointer
}
// FontAtlas contains runtime data for multiple fonts,
// bake multiple fonts into a single texture, TTF/OTF font loader
type FontAtlas uintptr
func (atlas FontAtlas) handle() C.IggFontAtlas {
return C.IggFontAtlas(atlas)
}
// AddFontDefault adds the default font to the atlas. This is done by default if you do not call any
// of the AddFont* methods before retrieving the texture data.
func (atlas FontAtlas) AddFontDefault() Font {
fontHandle := C.iggAddFontDefault(atlas.handle())
return Font(fontHandle)
}
// AddFontFromFileTTF attempts to load a font from given TTF file.
func (atlas FontAtlas) AddFontFromFileTTF(filename string, sizePixels float32) Font {
filenameArg, filenameFin := wrapString(filename)
defer filenameFin()
fontHandle := C.iggAddFontFromFileTTF(atlas.handle(), filenameArg, C.float(sizePixels))
return Font(fontHandle)
}
// TextureDataAlpha8 returns the image in 8-bit alpha values for the font atlas.
// The returned image is valid as long as the font atlas is.
func (atlas FontAtlas) TextureDataAlpha8() *Alpha8Image {
var pixels *C.uchar
var width C.int
var height C.int
var bytesPerPixel C.int
C.iggFontAtlasGetTexDataAsAlpha8(atlas.handle(), &pixels, &width, &height, &bytesPerPixel)
return &Alpha8Image{
Width: int(width),
Height: int(height),
Pixels: unsafe.Pointer(pixels), // nolint: gas
}
}
// SetTextureID sets user data to refer to the texture once it has been uploaded to user's graphic systems.
// It is passed back to you during rendering via the DrawCommand.
func (atlas FontAtlas) SetTextureID(id TextureID) {
C.iggFontAtlasSetTextureID(atlas.handle(), id.handle())
}