add background for F3 text, fix single-channel texture display
This commit is contained in:
parent
a17a43505c
commit
a628fdb434
@ -1,7 +1,7 @@
|
||||
{
|
||||
"WindowWidth": 1600,
|
||||
"WindowHeight": 900,
|
||||
"WindowWidth": 800,
|
||||
"WindowHeight": 600,
|
||||
|
||||
"FramerateLimit": 60
|
||||
"FramerateLimit": 0
|
||||
}
|
||||
|
||||
|
@ -54,13 +54,18 @@ func (g *Game) initImgui(win *glfw.Window) {
|
||||
func (g *Game) imgui() {
|
||||
if io.ShowDebugInfo {
|
||||
imgui.SetNextWindowPosV(imgui.Vec2{}, imgui.ConditionAlways, imgui.Vec2{})
|
||||
imgui.SetNextWindowSize(imgui.Vec2{X: float32(io.DisplaySize[0]), Y: float32(io.DisplaySize[1])})
|
||||
if igwrap.Begin("F3", nil, imgui.WindowFlagsAlwaysAutoResize|imgui.WindowFlagsNoBackground|imgui.WindowFlagsNoNavFocus|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoInputs|imgui.WindowFlagsNoSavedSettings|imgui.WindowFlagsNoFocusOnAppearing) {
|
||||
igwrap.Text("Gl01(glfw%s, imgui%s) - compiled by %s[%s/%s]", glfw.GetVersionString(), imgui.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||
igwrap.Text("CgoCalls:%d (%d lastframe), Goroutines:%d", runtime.NumCgoCall(), runtime.NumCgoCall()-g.gui.lastframeCgoCalls, runtime.NumGoroutine())
|
||||
imgui.Text("")
|
||||
bg := itype.Vec4f{0, 0, 0, 0.5}
|
||||
pad := igwrap.Vec2f(imgui.CurrentStyle().ItemSpacing())
|
||||
|
||||
igwrap.TextBackground(bg, pad, "Gl01 compiled by %s/%s [%s/%s] (120AVG) %.1f FPS (%.3f frame)", runtime.Compiler, runtime.Version(), runtime.GOOS, runtime.GOARCH, imgui.CurrentIO().Framerate(), 1000/imgui.CurrentIO().Framerate())
|
||||
igwrap.TextBackground(bg, pad, "GLFW %s, Dear ImGUI %s", glfw.GetVersionString(), imgui.Version())
|
||||
igwrap.TextBackground(bg, pad, "CgoCalls:%d (%d lastframe), Goroutines:%d", runtime.NumCgoCall(), runtime.NumCgoCall()-g.gui.lastframeCgoCalls, runtime.NumGoroutine())
|
||||
imgui.Dummy(imgui.Vec2{X: 8, Y: 8})
|
||||
|
||||
pos := g.player.Position()
|
||||
igwrap.Text("Player: (%.3f, %.5f, %.3f) - (Y%.2f, Z%.2f)", pos[0], pos[1], pos[2], g.rotY.Degrees(), g.rotZ)
|
||||
igwrap.TextBackground(bg, pad, "Player: (%.3f, %.5f, %.3f) (Y%.2f, Z%.2f)", pos[0], pos[1], pos[2], g.rotY.Degrees(), g.rotZ)
|
||||
imgui.End()
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FLAG_COLORS (FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA)
|
||||
|
||||
#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)
|
||||
|
@ -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]}
|
||||
|
@ -47,6 +47,7 @@ const (
|
||||
TextureFlag_Alpha // Renders the Alpha channel.
|
||||
|
||||
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
|
||||
|
@ -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.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user