Example #1
0
def InvalidateDeviceObjects():
    global g_VaoHandle
    global g_VboHandle
    global g_ElementsHandle
    global g_ShaderHandle
    global g_VertHandle
    global g_FragHandle
    global g_FontTexture

    if (g_VaoHandle): glDeleteVertexArrays(1, g_VaoHandle)
    if (g_VboHandle): glDeleteBuffers(1, g_VboHandle)
    if (g_ElementsHandle): glDeleteBuffers(1, g_ElementsHandle)
    g_VaoHandle = g_VboHandle = g_ElementsHandle = 0

    if (g_ShaderHandle and g_VertHandle):
        glDetachShader(g_ShaderHandle, g_VertHandle)
    if (g_VertHandle): glDeleteShader(g_VertHandle)
    g_VertHandle = 0

    if (g_ShaderHandle and g_FragHandle):
        glDetachShader(g_ShaderHandle, g_FragHandle)
    if (g_FragHandle): glDeleteShader(g_FragHandle)
    g_FragHandle = 0

    if (g_ShaderHandle): glDeleteProgram(g_ShaderHandle)
    g_ShaderHandle = 0

    if (g_FontTexture):
        glDeleteTextures(1, g_FontTexture)
        imgui.GetIO().Fonts.SetTexID(0)
        g_FontTexture = 0
Example #2
0
def ProcessEvent(event):
    global g_MouseWheel
    global g_MousePressed

    io = imgui.GetIO()
    if event.type == SDL_MOUSEWHEEL:
        if (event.wheel.y > 0):
            g_MouseWheel = 1
        if (event.wheel.y < 0):
            g_MouseWheel = -1
        return True
    elif event.type == SDL_MOUSEBUTTONDOWN:
        if (event.button.button == SDL_BUTTON_LEFT): g_MousePressed[0] = True
        if (event.button.button == SDL_BUTTON_RIGHT): g_MousePressed[1] = True
        if (event.button.button == SDL_BUTTON_MIDDLE): g_MousePressed[2] = True
        return True
    elif event.type == SDL_TEXTINPUT:
        io.AddInputCharactersUTF8(event.text.text)
        return True
    elif event.type == SDL_KEYDOWN or event.type == SDL_KEYUP:
        key = event.key.keysym.sym & ~SDLK_SCANCODE_MASK
        io.SetKeysDown(key, event.type == SDL_KEYDOWN)
        io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0)
        io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0)
        io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0)
        io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0)
        return True

    return False
Example #3
0
def NewFrame(window):
    global g_MousePressed, g_MouseWheel, g_Time

    if not g_FontTexture:
        CreateDeviceObjects()

    io = imgui.GetIO()

    # Setup display size (every frame to accommodate for window resizing)
    w = ctypes.c_int()
    h = ctypes.c_int()
    SDL_GetWindowSize(window, w, h)
    display_w = ctypes.c_int()
    display_h = ctypes.c_int()
    SDL_GL_GetDrawableSize(window, display_w, display_h)
    io.DisplaySize = imgui.ImVec2(w.value, h.value)
    io.DisplayFramebufferScale = imgui.ImVec2(
        (display_w.value / float(w.value)) if w.value > 0 else 0,
        (display_h.value / float(h.value)) if h.value > 0 else 0)

    # Setup time step
    time = SDL_GetTicks()
    current_time = time / 1000.0
    io.DeltaTime = (current_time - g_Time) if g_Time > 0.0 else (1.0 / 60.0)
    g_Time = current_time

    # Setup inputs
    # (we already got mouse wheel, keyboard keys & characters from SDL_PollEvent())
    mx = ctypes.c_int()
    my = ctypes.c_int()
    mouseMask = SDL_GetMouseState(mx, my)
    if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS):
        # Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
        io.MousePos = imgui.ImVec2(mx.value, my.value)
    else:
        io.MousePos = imgui.ImVec2(-1, -1)

    # 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.
    io.SetMouseDown(
        0, g_MousePressed[0] or (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0)
    io.SetMouseDown(
        1, g_MousePressed[1]
        or (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0)
    io.SetMouseDown(
        2, g_MousePressed[2]
        or (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0)
    g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = False

    io.MouseWheel = g_MouseWheel
    g_MouseWheel = 0.0

    # Hide OS mouse cursor if ImGui is drawing it
    SDL_ShowCursor(0 if io.MouseDrawCursor else 1)

    # Start the frame
    imgui.NewFrame()
Example #4
0
def Init(window):
    io = imgui.GetIO()
    #io.SetKeyMap(imgui.ImGuiKey_Tab, SDLK_TAB);
    io.SetKeyMap(imgui.ImGuiKey_LeftArrow, SDL_SCANCODE_LEFT)
    io.SetKeyMap(imgui.ImGuiKey_RightArrow, SDL_SCANCODE_RIGHT)
    io.SetKeyMap(imgui.ImGuiKey_UpArrow, SDL_SCANCODE_UP)
    io.SetKeyMap(imgui.ImGuiKey_DownArrow, SDL_SCANCODE_DOWN)
    io.SetKeyMap(imgui.ImGuiKey_PageUp, SDL_SCANCODE_PAGEUP)
    io.SetKeyMap(imgui.ImGuiKey_PageDown, SDL_SCANCODE_PAGEDOWN)
    io.SetKeyMap(imgui.ImGuiKey_Home, SDL_SCANCODE_HOME)
    io.SetKeyMap(imgui.ImGuiKey_End, SDL_SCANCODE_END)
    io.SetKeyMap(imgui.ImGuiKey_Delete, SDLK_DELETE)
    io.SetKeyMap(imgui.ImGuiKey_Backspace, SDLK_BACKSPACE)
    io.SetKeyMap(imgui.ImGuiKey_Enter, SDLK_RETURN)
    io.SetKeyMap(imgui.ImGuiKey_Escape, SDLK_ESCAPE)
    io.SetKeyMap(imgui.ImGuiKey_A, SDLK_a)
    io.SetKeyMap(imgui.ImGuiKey_C, SDLK_c)
    io.SetKeyMap(imgui.ImGuiKey_V, SDLK_v)
    io.SetKeyMap(imgui.ImGuiKey_X, SDLK_x)
    io.SetKeyMap(imgui.ImGuiKey_Y, SDLK_y)
    io.SetKeyMap(imgui.ImGuiKey_Z, SDLK_z)

    # Alternatively you can set this to NULL and call imgui.GetDrawData() after imgui.Render() to get the same ImDrawData pointer.
    def Render(data):
        try:
            RenderDrawLists(data)
        except:
            import traceback
            traceback.print_exc()

    io.SetRenderDrawListsFn(Render)
    #io.SetClipboardTextFn = SetClipboardText;
    #io.GetClipboardTextFn = GetClipboardText;
    #io.ClipboardUserData = NULL;

    #ifdef _WIN32
    wmInfo = SDL_SysWMinfo()
    SDL_VERSION(wmInfo.version)
    SDL_GetWindowWMInfo(window, wmInfo)
    io.SetImeWindowHandle(wmInfo.info.win.window)
    #else
    #(void)window;
    #endif

    return True
Example #5
0
def CreateFontsTexture():
    # Build texture atlas
    io = imgui.GetIO()
    # Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader.
    pixels, width, height = io.Fonts.GetTexDataAsRGBA32()

    # Upload texture to graphics system
    last_texture = glGetIntegerv(GL_TEXTURE_BINDING_2D)
    g_FontTexture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, g_FontTexture)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
                 GL_UNSIGNED_BYTE, pixels)

    # Store our identifier
    io.Fonts.SetTexID(g_FontTexture)

    # Restore state
    glBindTexture(GL_TEXTURE_2D, last_texture)
Example #6
0
    def create_fonts_texture(self):
        # Build texture atlas
        io = imgui.GetIO()

        # Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
        pixels, width, height = imgui.GetTexDataAsRGBA32()

        # Upload texture to graphics system
        last_texture = glGetIntegerv(GL_TEXTURE_BINDING_2D)
        self.font_texture = glGenTextures(1)
        # numpy.uint32 to int
        glBindTexture(GL_TEXTURE_2D, self.font_texture)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
                     GL_UNSIGNED_BYTE, pixels)

        # Store our identifier
        io.SetTexID(self.font_texture)

        # Restore state
        glBindTexture(GL_TEXTURE_2D, last_texture)
Example #7
0
    def __init__(self, window):
        self.window = window
        self.font_texture = None
        self.shader_handle = None
        self.vs_handle = None
        self.fs_handle = None
        self.vbo_handle = None
        self.elements_handle = None
        self.vao_handle = None
        self.g_MousePressed = [False, False, False]
        self.g_MouseWheel = 0
        io = imgui.GetIO()
        io.SetKeyMap(imgui.ImGuiKey_Tab, SDLK_TAB)
        # Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
        io.SetKeyMap(imgui.ImGuiKey_LeftArrow, SDL_SCANCODE_LEFT)
        io.SetKeyMap(imgui.ImGuiKey_RightArrow, SDL_SCANCODE_RIGHT)
        io.SetKeyMap(imgui.ImGuiKey_UpArrow, SDL_SCANCODE_UP)
        io.SetKeyMap(imgui.ImGuiKey_DownArrow, SDL_SCANCODE_DOWN)
        io.SetKeyMap(imgui.ImGuiKey_PageUp, SDL_SCANCODE_PAGEUP)
        io.SetKeyMap(imgui.ImGuiKey_PageDown, SDL_SCANCODE_PAGEDOWN)
        io.SetKeyMap(imgui.ImGuiKey_Home, SDL_SCANCODE_HOME)
        io.SetKeyMap(imgui.ImGuiKey_End, SDL_SCANCODE_END)
        io.SetKeyMap(imgui.ImGuiKey_Delete, SDLK_DELETE)
        io.SetKeyMap(imgui.ImGuiKey_Backspace, SDLK_BACKSPACE)
        io.SetKeyMap(imgui.ImGuiKey_Enter, SDLK_RETURN)
        io.SetKeyMap(imgui.ImGuiKey_Escape, SDLK_ESCAPE)
        io.SetKeyMap(imgui.ImGuiKey_A, SDLK_a)
        io.SetKeyMap(imgui.ImGuiKey_C, SDLK_c)
        io.SetKeyMap(imgui.ImGuiKey_V, SDLK_v)
        io.SetKeyMap(imgui.ImGuiKey_X, SDLK_x)
        io.SetKeyMap(imgui.ImGuiKey_Y, SDLK_y)
        io.SetKeyMap(imgui.ImGuiKey_Z, SDLK_z)

        io.SetRenderDrawListsFn(self.render_draw_lists)

        self.f = imgui.new_floatp()
        imgui.floatp_assign(self.f, 0)
        self.clear_color = [114 / 255.0, 144 / 255.0, 154 / 255.0]
Example #8
0
def RenderDrawLists(draw_data):
    global g_ShaderHandle

    # Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
    io = imgui.GetIO()
    fb_width = int(io.DisplaySize.x * io.DisplayFramebufferScale.x)
    fb_height = int(io.DisplaySize.y * io.DisplayFramebufferScale.y)
    if fb_width == 0 or fb_height == 0:
        return
    draw_data.ScaleClipRects(io.DisplayFramebufferScale)

    # Backup GL state
    last_active_texture = glGetIntegerv(GL_ACTIVE_TEXTURE)
    glActiveTexture(GL_TEXTURE0)
    last_program = glGetIntegerv(GL_CURRENT_PROGRAM)
    last_texture = glGetIntegerv(GL_TEXTURE_BINDING_2D)
    last_array_buffer = glGetIntegerv(GL_ARRAY_BUFFER_BINDING)
    last_element_array_buffer = glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING)
    last_vertex_array = glGetIntegerv(GL_VERTEX_ARRAY_BINDING)
    last_blend_src_rgb = glGetIntegerv(GL_BLEND_SRC_RGB)
    last_blend_dst_rgb = glGetIntegerv(GL_BLEND_DST_RGB)
    last_blend_src_alpha = glGetIntegerv(GL_BLEND_SRC_ALPHA)
    last_blend_dst_alpha = glGetIntegerv(GL_BLEND_DST_ALPHA)
    last_blend_equation_rgb = glGetIntegerv(GL_BLEND_EQUATION_RGB)
    last_blend_equation_alpha = glGetIntegerv(GL_BLEND_EQUATION_ALPHA)
    last_viewport = glGetIntegerv(GL_VIEWPORT)
    last_scissor_box = glGetIntegerv(GL_SCISSOR_BOX)
    last_enable_blend = glIsEnabled(GL_BLEND)
    last_enable_cull_face = glIsEnabled(GL_CULL_FACE)
    last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST)
    last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST)

    # Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
    glEnable(GL_BLEND)
    glBlendEquation(GL_FUNC_ADD)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    glDisable(GL_CULL_FACE)
    glDisable(GL_DEPTH_TEST)
    glEnable(GL_SCISSOR_TEST)

    # Setup viewport, orthographic projection matrix
    glViewport(0, 0, fb_width, fb_height)
    ortho_projection = (ctypes.c_float * 16)(
        2.0 / io.DisplaySize.x,
        0.0,
        0.0,
        0.0,
        0.0,
        2.0 / -io.DisplaySize.y,
        0.0,
        0.0,
        0.0,
        0.0,
        -1.0,
        0.0,
        -1.0,
        1.0,
        0.0,
        1.0,
    )
    glUseProgram(g_ShaderHandle)
    glUniform1i(g_AttribLocationTex, 0)
    glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, ortho_projection)
    glBindVertexArray(g_VaoHandle)

    for n in range(draw_data.CmdListsCount):

        cmd_list = draw_data.GetCmdList(n)
        idx_buffer_offset = 0

        glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle)
        glBufferData(GL_ARRAY_BUFFER,
                     cmd_list.VtxBuffer.Size * SIZEOF_ImDrawVert,
                     cmd_list.GetVtxBufferData(), GL_STREAM_DRAW)

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle)
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                     cmd_list.IdxBuffer.Size * SIZEOF_ImDrawIdx,
                     cmd_list.GetIdxBufferData(), GL_STREAM_DRAW)

        for cmd_i in range(cmd_list.CmdBuffer.Size):

            pcmd = cmd_list.GetCmdBuffer(cmd_i)
            if pcmd.UserCallback:
                pcmd.UserCallback(cmd_list, pcmd)
            else:
                glBindTexture(GL_TEXTURE_2D, pcmd.TextureId)
                glScissor(int(pcmd.ClipRect.x),
                          int(fb_height - pcmd.ClipRect.w),
                          int(pcmd.ClipRect.z - pcmd.ClipRect.x),
                          int(pcmd.ClipRect.w - pcmd.ClipRect.y))
                glDrawElements(
                    GL_TRIANGLES, pcmd.ElemCount, GL_UNSIGNED_SHORT
                    if SIZEOF_ImDrawIdx == 2 else GL_UNSIGNED_INT,
                    ctypes.c_void_p(idx_buffer_offset))

            idx_buffer_offset += (pcmd.ElemCount * SIZEOF_ImDrawIdx)

    # Restore modified GL state
    glUseProgram(last_program)
    glBindTexture(GL_TEXTURE_2D, last_texture)
    glActiveTexture(last_active_texture)
    glBindVertexArray(last_vertex_array)
    glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer)
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer)
    glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha)
    glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb,
                        last_blend_src_alpha, last_blend_dst_alpha)
    if (last_enable_blend):
        glEnable(GL_BLEND)
    else:
        glDisable(GL_BLEND)
    if (last_enable_cull_face):
        glEnable(GL_CULL_FACE)
    else:
        glDisable(GL_CULL_FACE)
    if (last_enable_depth_test):
        glEnable(GL_DEPTH_TEST)
    else:
        glDisable(GL_DEPTH_TEST)
    if (last_enable_scissor_test):
        glEnable(GL_SCISSOR_TEST)
    else:
        glDisable(GL_SCISSOR_TEST)
    glViewport(last_viewport[0], last_viewport[1], last_viewport[2],
               last_viewport[3])
    glScissor(last_scissor_box[0], last_scissor_box[1], last_scissor_box[2],
              last_scissor_box[3])
Example #9
0
    def create_device_objects(self):
        io = imgui.GetIO()

        last_texture = glGetIntegerv(GL_TEXTURE_BINDING_2D)
        last_array_buffer = glGetIntegerv(GL_ARRAY_BUFFER_BINDING)
        last_vertex_array = glGetIntegerv(GL_VERTEX_ARRAY_BINDING)

        vertex_shader = b'''#version 330
uniform mat4 ProjMtx;
in vec2 Position;
in vec2 UV;
in vec4 Color;
out vec2 Frag_UV;
out vec4 Frag_Color;
void main()
{
	Frag_UV = UV;
	Frag_Color = Color;
	gl_Position = ProjMtx * vec4(Position.xy,0,1);
};
'''

        fragment_shader = b'''#version 330
uniform sampler2D Texture;
in vec2 Frag_UV;
in vec4 Frag_Color;
out vec4 Out_Color;
void main()
{
	Out_Color = Frag_Color * texture( Texture, Frag_UV.st);
};
'''

        self.shader_handle = glCreateProgram()
        self.vs_handle = glCreateShader(GL_VERTEX_SHADER)
        self.fs_handle = glCreateShader(GL_FRAGMENT_SHADER)
        glShaderSource(self.vs_handle, [vertex_shader])
        glShaderSource(self.fs_handle, [fragment_shader])
        glCompileShader(self.vs_handle)
        glCompileShader(self.fs_handle)
        glAttachShader(self.shader_handle, self.vs_handle)
        glAttachShader(self.shader_handle, self.fs_handle)
        glLinkProgram(self.shader_handle)

        self.g_AttribLocationTex = glGetUniformLocation(
            self.shader_handle, "Texture")
        self.g_AttribLocationProjMtx = glGetUniformLocation(
            self.shader_handle, "ProjMtx")
        self.g_AttribLocationPosition = glGetAttribLocation(
            self.shader_handle, "Position")
        self.g_AttribLocationUV = glGetAttribLocation(self.shader_handle, "UV")
        self.g_AttribLocationColor = glGetAttribLocation(
            self.shader_handle, "Color")

        self.vbo_handle = glGenBuffers(1)
        self.elements_handle = glGenBuffers(1)

        self.vao_handle = glGenVertexArrays(1)
        glBindVertexArray(self.vao_handle)
        glBindBuffer(GL_ARRAY_BUFFER, self.vbo_handle)
        glEnableVertexAttribArray(self.g_AttribLocationPosition)
        glEnableVertexAttribArray(self.g_AttribLocationUV)
        glEnableVertexAttribArray(self.g_AttribLocationColor)

        SIZE_OF_ImDrawVert = 20
        glVertexAttribPointer(self.g_AttribLocationPosition, 2, GL_FLOAT,
                              GL_FALSE, SIZE_OF_ImDrawVert, ctypes.c_void_p(0))
        glVertexAttribPointer(self.g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE,
                              SIZE_OF_ImDrawVert, ctypes.c_void_p(8))
        glVertexAttribPointer(self.g_AttribLocationColor, 4, GL_UNSIGNED_BYTE,
                              GL_TRUE, SIZE_OF_ImDrawVert, ctypes.c_void_p(16))

        self.create_fonts_texture()

        # Restore modified GL state
        glBindTexture(GL_TEXTURE_2D, last_texture)
        glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer)
        glBindVertexArray(last_vertex_array)
Example #10
0
    def new_frame(self, delta, w, h):
        if not self.font_texture:
            try:
                self.create_device_objects()
            except GLError as ex:
                print(ex)
                if ex.description:
                    print(type(ex.description))
                    print(ex.description.decode('cp932'))
                import traceback
                traceback.print_exc()
            except:
                import traceback
                traceback.print_exc()

        io = imgui.GetIO()
        io.DisplaySize = imgui.ImVec2(w, h)
        io.DisplayFramebufferScale = imgui.ImVec2(1, 1)
        io.DeltaTime = delta

        # Setup inputs
        # (we already got mouse wheel, keyboard keys & characters from SDL_PollEvent())
        mx = ctypes.c_int()
        my = ctypes.c_int()
        mouseMask = SDL_GetMouseState(mx, my)
        if (SDL_GetWindowFlags(self.window) & SDL_WINDOW_MOUSE_FOCUS) != 0:
            io.MousePos = imgui.ImVec2(mx.value, my.value)
            #  // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
        else:
            io.MousePos = imgui.ImVec2(-1, -1)

        io.SetMouseDown(
            0, self.g_MousePressed[0] != 0
            or (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0)
        # 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.
        io.SetMouseDown(
            1, self.g_MousePressed[1] != 0
            or (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0)
        io.SetMouseDown(
            2, self.g_MousePressed[2] != 0
            or (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0)
        self.g_MousePressed[0] = self.g_MousePressed[1] = self.g_MousePressed[
            2] = False

        io.MouseWheel = self.g_MouseWheel
        self.g_MouseWheel = 0.0

        # Hide OS mouse cursor if ImGui is drawing it
        SDL_ShowCursor(0 if io.MouseDrawCursor else 1)

        imgui.NewFrame()

        # 1. Show a simple window
        # Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
        imgui.Text("Hello, world!")
        imgui.SliderFloat("float", self.f, 0.0, 1.0)
        imgui.ColorEdit3("clear color", self.clear_color)
        '''
        if (imgui.Button("Test Window")):
            self.show_test_window ^= 1;
        if (imgui.Button("Another Window")):
            self.show_another_window ^= 1;
        imgui.Text("Application average %.3f ms/frame (%.1f FPS)"
                , 1000.0 / imgui.GetIO().Framerate, imgui.GetIO().Framerate);
        '''
        '''
Example #11
0
def main():

    # Setup SDL
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0):
        print("Error: %s\n", SDL_GetError())
        return -1

    # Setup window
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS,
                        SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG)
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
                        SDL_GL_CONTEXT_PROFILE_CORE)
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8)
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3)
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2)
    current = SDL_DisplayMode()
    SDL_GetCurrentDisplayMode(0, current)
    window = SDL_CreateWindow(b"ImGui SDL2+OpenGL3 example",
                              SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                              1280, 720,
                              SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE)
    glcontext = SDL_GL_CreateContext(window)
    #gl3wInit();

    # Setup ImGui binding
    ImplSdlGL3.Init(window)

    # Load Fonts
    # (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
    #ImGuiIO& io = imgui.GetIO();
    #io.Fonts->AddFontDefault();
    #io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
    #io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
    #io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
    #io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
    #io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());

    show_test_window = imgui.new_boolp()
    imgui.boolp_assign(show_test_window, True)
    show_another_window = imgui.new_boolp()
    imgui.boolp_assign(show_another_window, False)
    clear_color = [114 / 255.0, 144 / 255.0, 154 / 255.0, 0]

    # Main loop
    done = False
    while not done:

        event = SDL_Event()
        while SDL_PollEvent(event) != 0:

            ImplSdlGL3.ProcessEvent(event)
            if event.type == SDL_QUIT:
                done = True

        ImplSdlGL3.NewFrame(window)

        # 1. Show a simple window
        # Tip: if we don't call imgui.Begin()/imgui.End() the widgets appears in a window automatically called "Debug"

        f = imgui.new_floatp()
        imgui.floatp_assign(f, 0.0)
        imgui.Text("Hello, world!")
        imgui.SliderFloat("float", f, 0.0, 1.0)
        imgui.ColorEdit3("clear color", clear_color)
        if imgui.Button("Test Window"):
            imgui.boolp_assign(show_test_window,
                               not imgui.boolp_value(show_test_window))
        if imgui.Button("Another Window"):
            imgui.boolp_assign(show_another_window,
                               not imgui.boolp_value(show_another_window))
        imgui.Text("Application average %.3f ms/frame (%.1f FPS)",
                   1000.0 / imgui.GetIO().Framerate,
                   imgui.GetIO().Framerate)

        # 2. Show another simple window, this time using an explicit Begin/End pair
        if imgui.boolp_value(show_another_window):
            imgui.SetNextWindowSize(imgui.ImVec2(200, 100),
                                    imgui.ImGuiSetCond_FirstUseEver)
            imgui.Begin("Another Window", show_another_window)
            imgui.Text("Hello")
            imgui.End()

        # 3. Show the ImGui test window. Most of the sample code is in imgui.ShowTestWindow()
        if imgui.boolp_value(show_test_window):
            imgui.SetNextWindowPos(imgui.ImVec2(650, 20),
                                   imgui.ImGuiSetCond_FirstUseEver)
            imgui.ShowTestWindow(show_test_window)

        # Rendering
        glViewport(0, 0, int(imgui.GetIO().DisplaySize.x),
                   int(imgui.GetIO().DisplaySize.y))
        glClearColor(*clear_color)
        glClear(GL_COLOR_BUFFER_BIT)
        imgui.Render()
        SDL_GL_SwapWindow(window)

    # Cleanup
    ImplSdlGL3.Shutdown()
    SDL_GL_DeleteContext(glcontext)
    SDL_DestroyWindow(window)
    SDL_Quit()

    return 0