mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Update imgui
This commit is contained in:
@ -107,9 +107,9 @@ func (w *Window) handleInputs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
|
// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
|
||||||
imIo.SetMouseButtonDown(imgui.MouseButtonLeft, isSdlButtonLeftDown)
|
imIo.SetMouseButtonDown(int(imgui.MouseButtonLeft), isSdlButtonLeftDown)
|
||||||
imIo.SetMouseButtonDown(imgui.MouseButtonRight, isSdlButtonRightDown)
|
imIo.SetMouseButtonDown(int(imgui.MouseButtonRight), isSdlButtonRightDown)
|
||||||
imIo.SetMouseButtonDown(imgui.MouseButtonMiddle, isSdlButtonMiddleDown)
|
imIo.SetMouseButtonDown(int(imgui.MouseButtonMiddle), isSdlButtonMiddleDown)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) handleWindowResize() {
|
func (w *Window) handleWindowResize() {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -12,7 +12,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2
|
github.com/AllenDang/cimgui-go v0.0.0-20240912193335-545751598105
|
||||||
github.com/mandykoh/prism v0.35.1
|
github.com/mandykoh/prism v0.35.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
2
go.sum
2
go.sum
@ -1,5 +1,7 @@
|
|||||||
github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2 h1:3HA/5qD8Rimxz/y1sLyVaM7ws1dzjXzMt4hOBiwHggo=
|
github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2 h1:3HA/5qD8Rimxz/y1sLyVaM7ws1dzjXzMt4hOBiwHggo=
|
||||||
github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2/go.mod h1:iNfbIyOBN8k3XScMxULbrwYbPsXEAUD0Jb6UwrspQb8=
|
github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2/go.mod h1:iNfbIyOBN8k3XScMxULbrwYbPsXEAUD0Jb6UwrspQb8=
|
||||||
|
github.com/AllenDang/cimgui-go v0.0.0-20240912193335-545751598105 h1:bhXqv2EG5YCLdgkLSFCpqeVz4cCoNbi4RDFrHrwxQ1o=
|
||||||
|
github.com/AllenDang/cimgui-go v0.0.0-20240912193335-545751598105/go.mod h1:CYfBRenCaNtSvKVzChYh6gswUSo6c5IUcYeV6eCCRw0=
|
||||||
github.com/bloeys/assimp-go v0.4.4 h1:Yn5e/RpE0Oes0YMBy8O7KkwAO4R/RpgrZPJCt08dVIU=
|
github.com/bloeys/assimp-go v0.4.4 h1:Yn5e/RpE0Oes0YMBy8O7KkwAO4R/RpgrZPJCt08dVIU=
|
||||||
github.com/bloeys/assimp-go v0.4.4/go.mod h1:my3yRxT7CfOztmvi+0svmwbaqw0KFrxaHxncoyaEIP0=
|
github.com/bloeys/assimp-go v0.4.4/go.mod h1:my3yRxT7CfOztmvi+0svmwbaqw0KFrxaHxncoyaEIP0=
|
||||||
github.com/bloeys/gglm v0.50.0 h1:DlGLp9z8KMNx+hNR6PjnPmC0HjDRC19QwAKL1iwhOxs=
|
github.com/bloeys/gglm v0.50.0 h1:DlGLp9z8KMNx+hNR6PjnPmC0HjDRC19QwAKL1iwhOxs=
|
||||||
|
|||||||
2
main.go
2
main.go
@ -908,7 +908,7 @@ func (g *Game) showDebugWindow() {
|
|||||||
|
|
||||||
imgui.Begin("Debug controls")
|
imgui.Begin("Debug controls")
|
||||||
|
|
||||||
imgui.PushStyleColorVec4(imgui.ColText, imgui.NewColor(1, 1, 0, 1).Value)
|
imgui.PushStyleColorVec4(imgui.ColText, imgui.NewColor(1, 1, 0, 1).FieldValue)
|
||||||
imgui.LabelText("FPS", fmt.Sprint(timing.GetAvgFPS()))
|
imgui.LabelText("FPS", fmt.Sprint(timing.GetAvgFPS()))
|
||||||
imgui.PopStyleColor()
|
imgui.PopStyleColor()
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,17 @@
|
|||||||
package nmageimgui
|
package nmageimgui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
// The following is included just so we can get
|
||||||
|
// the c imports and cgo configs defined here: https://github.com/AllenDang/cimgui-go/blob/main/sdlbackend/sdl_backend.go
|
||||||
|
//
|
||||||
|
// This is needed because AllenDang/cimgui-go links sdl2 statically, which requires us
|
||||||
|
// to explicitly define all the libs it needs, which isn't normally needed if we were dynamically linking.
|
||||||
|
//
|
||||||
|
// Without this, we get compilation errors as sdl2 can't find libs it relies on.
|
||||||
|
_ "github.com/AllenDang/cimgui-go/sdlbackend"
|
||||||
|
|
||||||
imgui "github.com/AllenDang/cimgui-go"
|
imgui "github.com/AllenDang/cimgui-go"
|
||||||
"github.com/bloeys/gglm/gglm"
|
"github.com/bloeys/gglm/gglm"
|
||||||
"github.com/bloeys/nmage/materials"
|
"github.com/bloeys/nmage/materials"
|
||||||
@ -129,7 +140,7 @@ func (i *ImguiInfo) AddFontTTF(fontPath string, fontSize float32, fontConfig *im
|
|||||||
|
|
||||||
fontConfigToUse := imgui.NewFontConfig()
|
fontConfigToUse := imgui.NewFontConfig()
|
||||||
if fontConfig != nil {
|
if fontConfig != nil {
|
||||||
fontConfigToUse = *fontConfig
|
fontConfigToUse = fontConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
glyphRangesToUse := imgui.NewGlyphRange()
|
glyphRangesToUse := imgui.NewGlyphRange()
|
||||||
@ -141,13 +152,13 @@ func (i *ImguiInfo) AddFontTTF(fontPath string, fontSize float32, fontConfig *im
|
|||||||
|
|
||||||
a := imIO.Fonts()
|
a := imIO.Fonts()
|
||||||
f := a.AddFontFromFileTTFV(fontPath, fontSize, fontConfigToUse, glyphRangesToUse.Data())
|
f := a.AddFontFromFileTTFV(fontPath, fontSize, fontConfigToUse, glyphRangesToUse.Data())
|
||||||
pixels, width, height, _ := a.GetTextureDataAsAlpha8()
|
pixels, width, height, _ := a.TextureDataAsAlpha8()
|
||||||
|
|
||||||
gl.ActiveTexture(gl.TEXTURE0)
|
gl.ActiveTexture(gl.TEXTURE0)
|
||||||
gl.BindTexture(gl.TEXTURE_2D, *i.TexID)
|
gl.BindTexture(gl.TEXTURE_2D, *i.TexID)
|
||||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(width), int32(height), 0, gl.RED, gl.UNSIGNED_BYTE, pixels)
|
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(width), int32(height), 0, gl.RED, gl.UNSIGNED_BYTE, pixels)
|
||||||
|
|
||||||
return f
|
return *f
|
||||||
}
|
}
|
||||||
|
|
||||||
const DefaultImguiShader = `
|
const DefaultImguiShader = `
|
||||||
@ -212,7 +223,7 @@ func NewImGui(shaderPath string) ImguiInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
imguiInfo := ImguiInfo{
|
imguiInfo := ImguiInfo{
|
||||||
ImCtx: imgui.CreateContext(),
|
ImCtx: *imgui.CreateContext(),
|
||||||
Mat: imguiMat,
|
Mat: imguiMat,
|
||||||
TexID: new(uint32),
|
TexID: new(uint32),
|
||||||
}
|
}
|
||||||
@ -233,11 +244,12 @@ func NewImGui(shaderPath string) ImguiInfo {
|
|||||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
|
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
|
||||||
gl.PixelStorei(gl.UNPACK_ROW_LENGTH, 0)
|
gl.PixelStorei(gl.UNPACK_ROW_LENGTH, 0)
|
||||||
|
|
||||||
pixels, width, height, _ := io.Fonts().GetTextureDataAsAlpha8()
|
pixels, width, height, _ := io.Fonts().TextureDataAsAlpha8()
|
||||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(width), int32(height), 0, gl.RED, gl.UNSIGNED_BYTE, pixels)
|
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(width), int32(height), 0, gl.RED, gl.UNSIGNED_BYTE, pixels)
|
||||||
|
|
||||||
// Store our identifier
|
// Store our identifier
|
||||||
io.Fonts().SetTexID(imgui.TextureID(imguiInfo.TexID))
|
|
||||||
|
io.Fonts().SetTexID(imgui.TextureID{Data: uintptr(unsafe.Pointer(imguiInfo.TexID))})
|
||||||
|
|
||||||
//Shader attributes
|
//Shader attributes
|
||||||
imguiInfo.Mat.Bind()
|
imguiInfo.Mat.Bind()
|
||||||
|
|||||||
Reference in New Issue
Block a user