aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/gui/WindowContainer.kt
blob: 5e101b76c8356b17bab9590305fadf934702d7be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gui

import cpu.Cpu
import glm_.vec4.Vec4
import gln.checkError
import imgui.Context
import imgui.ImGui
import imgui.destroy
import imgui.impl.LwjglGL3
import org.lwjgl.opengl.GL11
import uno.glfw.GlfwWindow
import uno.glfw.glfw

class WindowContainer {

  var cpu: Cpu

  init {
    glfw.init("3.2")
    cpu = Cpu()
  }

  val window = GlfwWindow(1280, 720, "KGB - KotlinGameBoy").apply {
    init()
  }


  fun run() {

    // Enable vsync
    glfw.swapInterval = 1

    val ctx = Context()
    LwjglGL3.init(window)
    ImGui.styleColorsDark()

    window.loop(::mainLoop)

    LwjglGL3.shutdown()
    ctx.destroy()

    window.destroy()
    glfw.terminate()

  }

  private fun mainLoop() {

    LwjglGL3.newFrame()

    with(ImGui) {
      paintDebugWindow()
      paintEmulationOutputWindow()
      paintCpuRegisterWindow(cpu.registers)
    }

    gln.glViewport(window.framebufferSize)
    gln.glClearColor(Vec4(0.45f, 0.55f, 0.6f, 1f))
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT)

    ImGui.render()
    LwjglGL3.renderDrawData(ImGui.drawData!!)

    checkError("mainLoop")
  }
}