Run init within an imgui frame

This commit is contained in:
bloeys
2023-02-03 02:20:50 +04:00
parent d7cd5bfc8d
commit 70dccd757e

View File

@ -24,26 +24,25 @@ func Run(g Game, w *Window, ui nmageimgui.ImguiInfo) {
isRunning = true isRunning = true
// Simulate 2 imgui frames, one before and one after g.Init so any imgui calls are allowed within init. // Run init with an active Imgui frame to allow init full imgui access
// Calling before is required for things like push font. timing.FrameStarted()
tempWidth, tempHeight := w.SDLWin.GetSize() w.handleInputs()
tempFBWidth, tempFBHeight := w.SDLWin.GLGetDrawableSize()
ui.FrameStart(float32(tempWidth), float32(tempHeight)) width, height := w.SDLWin.GetSize()
ui.Render(float32(tempWidth), float32(tempHeight), tempFBWidth, tempFBHeight) ui.FrameStart(float32(width), float32(height))
g.Init() g.Init()
// Second imgui frame fbWidth, fbHeight := w.SDLWin.GLGetDrawableSize()
tempWidth, tempHeight = w.SDLWin.GetSize() ui.Render(float32(width), float32(height), fbWidth, fbHeight)
tempFBWidth, tempFBHeight = w.SDLWin.GLGetDrawableSize()
ui.FrameStart(float32(tempWidth), float32(tempHeight)) timing.FrameEnded()
ui.Render(float32(tempWidth), float32(tempHeight), tempFBWidth, tempFBHeight)
for isRunning { for isRunning {
//PERF: Cache these //PERF: Cache these
width, height := w.SDLWin.GetSize() width, height = w.SDLWin.GetSize()
fbWidth, fbHeight := w.SDLWin.GLGetDrawableSize() fbWidth, fbHeight = w.SDLWin.GLGetDrawableSize()
timing.FrameStarted() timing.FrameStarted()
w.handleInputs() w.handleInputs()