FlipY texture flag, display world texture atlas

This commit is contained in:
2022-02-16 00:29:34 +08:00
parent 326253a73b
commit 565e0390f3
6 changed files with 86 additions and 17 deletions

View File

@ -8,6 +8,7 @@
#define FLAG_LINEAR (1<<4)
#define FLAG_IMGUI_FONT (1<<5)
#define FLAG_FLIP_Y (1<<6)
uniform sampler2D tex;
uniform int flags;

View File

@ -1,6 +1,17 @@
#version 330
#define FLAG_RED (1<<0)
#define FLAG_GREEN (1<<1)
#define FLAG_BLUE (1<<2)
#define FLAG_ALPHA (1<<3)
#define FLAG_COLORS (FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA)
#define FLAG_LINEAR (1<<4)
#define FLAG_IMGUI_FONT (1<<5)
#define FLAG_FLIP_Y (1<<6)
uniform mat4 projection;
uniform int flags;
in vec2 pos;
in vec2 uv;
@ -13,5 +24,8 @@ void main() {
fragUV = uv;
fragColor = color;
gl_Position = projection * vec4(pos.xy, 0, 1);
if ((flags & FLAG_FLIP_Y) != 0)
fragUV.y = 1 - fragUV.y;
}

View File

@ -38,6 +38,7 @@ func ImageV(tex uint32, size itype.Vec2f, texRange itype.Rectf, texColor itype.V
)
}
// Per-texture flags. This is passed to the shader as-is and handled only there.
type TextureFlag int
const (
@ -48,6 +49,7 @@ const (
TextureFlag_Linear // Linear source data, requires gamma correction.
TextureFlag_ImGUIFont // This is a font texture from ImGUI, with a single red channel.
TextureFlag_FlipY // The render should flip the Y axis of the texture. By default ImageXXX()s render textures with (0,0) at the bottom left, and this is for in case you want to flip them.
TextureFlag_RGB = TextureFlag_Red | TextureFlag_Green | TextureFlag_Blue
TextureFlag_RGBA = TextureFlag_Red | TextureFlag_Green | TextureFlag_Blue | TextureFlag_Alpha
@ -70,6 +72,18 @@ func SetTextureFlag(tex uint32, flags ...TextureFlag) {
texflags[tex] = f
}
// AddTextureFlag adds the given flags to the texture.
func AddTextureFlag(tex uint32, flags ...TextureFlag) {
var f TextureFlag
for _, f0 := range flags {
f |= f0
}
texflagslock.Lock()
defer texflagslock.Unlock()
texflags[tex] |= f
}
// TextureFlag returns the flags of a given texture.
func GetTextureFlag(tex uint32) TextureFlag {
texflagslock.RLock()

View File

@ -7,6 +7,10 @@ import (
"github.com/inkyblackness/imgui-go/v4"
)
const (
WindowFlagsOverlay imgui.WindowFlags = imgui.WindowFlagsAlwaysAutoResize | imgui.WindowFlagsNoBackground | imgui.WindowFlagsNoNavFocus | imgui.WindowFlagsNoNavInputs | imgui.WindowFlagsNoDecoration | imgui.WindowFlagsNoBringToFrontOnFocus | imgui.WindowFlagsNoSavedSettings | imgui.WindowFlagsNoFocusOnAppearing
)
// MenuItem wraps imgui.MenuItemV to create a
// easy-to-use and intuitive interface.
func MenuItem(name, shortcut string, selected *bool, enabled bool) {
@ -21,11 +25,18 @@ func Text(format string, a ...interface{}) {
imgui.Text(fmt.Sprintf(format, a...))
}
// TextBackground wraps imgui.Text to create a
// shortcut for fmt.Sprintf.
// TextBackground wraps imgui.Text to create a shortcut for fmt.Sprintf.
//
// It also fills the background of the text with half-transparant black, and takes care of the padding.
func TextBackground(format string, a ...interface{}) {
pad := Vec2f(imgui.CurrentStyle().ItemSpacing())
TextBackgroundV(itype.Vec4f{0, 0, 0, 0.5}, pad, format, a...)
}
// TextBackgroundV 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{}) {
func TextBackgroundV(color itype.Vec4f, padding itype.Vec2f, format string, a ...interface{}) {
text := fmt.Sprintf(format, a...)
orig := imgui.CursorScreenPos()
size := imgui.CalcTextSize(text, false, 0)
@ -35,6 +46,12 @@ func TextBackground(color itype.Vec4f, padding itype.Vec2f, format string, a ...
imgui.Text(text)
}
// TextBlank blanks a line with a nice-looking height (half the font height plus paddings).
func TextBlank() {
fontSize := imgui.FontSize()
imgui.Dummy(imgui.Vec2{X: fontSize / 2, Y: fontSize / 2})
}
// Begin wraps imgui.BeginV to create a
// easy-to-use and intuitive interface.
//