Run one imgui frame before init and another after init

This commit is contained in:
bloeys
2023-02-03 01:37:01 +04:00
parent 3b8e5c06de
commit d7cd5bfc8d

View File

@ -23,14 +23,22 @@ type Game interface {
func Run(g Game, w *Window, ui nmageimgui.ImguiInfo) {
isRunning = true
g.Init()
//Simulate an imgui frame during init so any imgui calls are allowed within init
// Simulate 2 imgui frames, one before and one after g.Init so any imgui calls are allowed within init.
// Calling before is required for things like push font.
tempWidth, tempHeight := w.SDLWin.GetSize()
tempFBWidth, tempFBHeight := w.SDLWin.GLGetDrawableSize()
ui.FrameStart(float32(tempWidth), float32(tempHeight))
ui.Render(float32(tempWidth), float32(tempHeight), tempFBWidth, tempFBHeight)
g.Init()
// Second imgui frame
tempWidth, tempHeight = w.SDLWin.GetSize()
tempFBWidth, tempFBHeight = w.SDLWin.GLGetDrawableSize()
ui.FrameStart(float32(tempWidth), float32(tempHeight))
ui.Render(float32(tempWidth), float32(tempHeight), tempFBWidth, tempFBHeight)
for isRunning {
//PERF: Cache these