add background for F3 text, fix single-channel texture display

This commit is contained in:
2022-02-10 21:13:55 +08:00
parent a17a43505c
commit a628fdb434
7 changed files with 44 additions and 11 deletions

View File

@ -87,7 +87,7 @@ func CreateFontsTexture() {
)
io.Fonts().SetTextureID(imgui.TextureID(tex))
igwrap.SetTextureFlag(tex, igwrap.TextureFlag_Red)
igwrap.SetTextureFlag(tex, igwrap.TextureFlag_ImGUIFont)
gl.BindTexture(gl.TEXTURE_2D, uint32(lastTexture))
}

View File

@ -6,7 +6,8 @@
#define FLAG_ALPHA (1<<3)
#define FLAG_COLORS (FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA)
#define FLAG_LINEAR (1<<4)
#define FLAG_LINEAR (1<<4)
#define FLAG_IMGUI_FONT (1<<5)
uniform sampler2D tex;
uniform int flags;
@ -19,8 +20,10 @@ out vec4 outputColor;
const float gamma = 2.2;
void main() {
if ((flags & FLAG_COLORS) == FLAG_RED) {
if ((flags & FLAG_IMGUI_FONT) != 0) {
outputColor = vec4(fragColor.rgb, fragColor.a * texture(tex, fragUV.st).r);
} else if ((flags & FLAG_COLORS) == FLAG_RED) {
outputColor = vec4(vec3(texture(tex, fragUV.st).r), 1);
} else {
vec4 color = texture(tex, fragUV.st);
if ((flags & FLAG_LINEAR) != 0)

View File

@ -15,11 +15,21 @@ func Color(r, g, b, a uint8) imgui.Vec4 {
}
}
// PackedColor converts RGBA to imgui.PackedColor.
func PackedColor(color itype.Vec4f) imgui.PackedColor {
return imgui.PackedColorFromVec4(Vec4(color))
}
// Vec2 converts itype.Vec2f to imgui.Vec2.
func Vec2(v itype.Vec2f) imgui.Vec2 {
return imgui.Vec2{X: v[0], Y: v[1]}
}
// Vec2f converts imgui.Vec2 to itype.Vec2f.
func Vec2f(v imgui.Vec2) itype.Vec2f {
return itype.Vec2f{v.X, v.Y}
}
// Vec4 converts itype.Vec4f to imgui.Vec4.
func Vec4(v itype.Vec4f) imgui.Vec4 {
return imgui.Vec4{X: v[0], Y: v[1], Z: v[2], W: v[3]}

View File

@ -46,7 +46,8 @@ const (
TextureFlag_Blue // Renders the Blue channel.
TextureFlag_Alpha // Renders the Alpha channel.
TextureFlag_Linear // Linear source data, requires gamma correction.
TextureFlag_Linear // Linear source data, requires gamma correction.
TextureFlag_ImGUIFont // This is a font texture from ImGUI, with a single red channel.
TextureFlag_RGB = TextureFlag_Red | TextureFlag_Green | TextureFlag_Blue
TextureFlag_RGBA = TextureFlag_Red | TextureFlag_Green | TextureFlag_Blue | TextureFlag_Alpha

View File

@ -21,6 +21,20 @@ func Text(format string, a ...interface{}) {
imgui.Text(fmt.Sprintf(format, a...))
}
// TextBackground wraps imgui.Text to create a
// shortcut for fmt.Sprintf.
//
// It also fills the background of the text with the given color.
func TextBackground(color itype.Vec4f, padding itype.Vec2f, format string, a ...interface{}) {
text := fmt.Sprintf(format, a...)
orig := imgui.CursorScreenPos()
size := imgui.CalcTextSize(text, false, 0)
halfpad := padding.Multiply(0.5)
imgui.BackgroundDrawList().AddRectFilledV(orig.Minus(Vec2(halfpad)), orig.Plus(size).Plus(Vec2(halfpad)), PackedColor(color), 0, 0)
imgui.Text(text)
}
// Begin wraps imgui.BeginV to create a
// easy-to-use and intuitive interface.
//