place blocks

This commit is contained in:
2022-02-24 20:20:33 +08:00
parent 9195dd7c3f
commit 32b06810e2
17 changed files with 309 additions and 55 deletions

View File

@ -24,8 +24,5 @@ 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

@ -13,11 +13,13 @@ import (
// size is in pixels. texRange is in [0, 1].
func Image(tex uint32, size itype.Vec2f, texRange itype.Rectf) {
min, max := texRange.MinPoint(), texRange.MaxPoint()
if GetTextureFlag(tex)&TextureFlag_FlipY == 0 {
min[1], max[1] = max[1], min[1] // swap minY/maxY
}
imgui.ImageV(
imgui.TextureID(tex),
Vec2(size),
imgui.Vec2{X: min[0], Y: max[1]},
imgui.Vec2{X: max[0], Y: min[1]},
Vec2(min), Vec2(max),
Color(255, 255, 255, 255),
imgui.Vec4{},
)
@ -28,17 +30,52 @@ func Image(tex uint32, size itype.Vec2f, texRange itype.Rectf) {
//
// size is in pixels. texRange is in [0, 1].
func ImageV(tex uint32, size itype.Vec2f, texRange itype.Rectf, texColor itype.Vec4f, borderColor itype.Vec4f) {
min, max := texRange.MinPoint(), texRange.MaxPoint()
if GetTextureFlag(tex)&TextureFlag_FlipY == 0 {
min[1], max[1] = max[1], min[1] // swap minY/maxY
}
imgui.ImageV(
imgui.TextureID(tex),
Vec2(size),
Vec2(texRange.MinPoint()),
Vec2(texRange.MaxPoint()),
Vec2(min), Vec2(max),
Vec4(texColor),
Vec4(borderColor),
)
}
// Per-texture flags. This is passed to the shader as-is and handled only there.
func ImageButton(tex uint32, size itype.Vec2f, texRange itype.Rectf) bool {
min, max := texRange.MinPoint(), texRange.MaxPoint()
if GetTextureFlag(tex)&TextureFlag_FlipY == 0 {
min[1], max[1] = max[1], min[1] // swap minY/maxY
}
return imgui.ImageButtonV(
imgui.TextureID(tex),
Vec2(size),
Vec2(min), Vec2(max),
-1,
imgui.Vec4{},
imgui.Vec4{1, 1, 1, 1},
)
}
func ImageButtonV(tex uint32, size itype.Vec2f, texRange itype.Rectf, padding int, bgCol, tintCol itype.Vec4f) bool {
min, max := texRange.MinPoint(), texRange.MaxPoint()
if GetTextureFlag(tex)&TextureFlag_FlipY == 0 {
min[1], max[1] = max[1], min[1] // swap minY/maxY
}
return imgui.ImageButtonV(
imgui.TextureID(tex),
Vec2(size),
Vec2(min), Vec2(max),
padding,
Vec4(bgCol),
Vec4(tintCol),
)
}
// Per-texture flags. This is passed to the shader as-is.
//
// FilpY is handled by the ImageXXX() call.
type TextureFlag int
const (