You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

import ctypes
import os
import sdl2
import imgui
from imgui.integrations.sdl2 import SDL2Renderer
import sdl2.ext
def main():
# Initialize SDL2
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
# Set OpenGL ES version
sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_MAJOR_VERSION, 2)
sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_MINOR_VERSION, 0)
sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_PROFILE_MASK, sdl2.SDL_GL_CONTEXT_PROFILE_ES)
# Create an SDL window
window = sdl2.SDL_CreateWindow(b"SDL2 OpenGL ES2",
sdl2.SDL_WINDOWPOS_UNDEFINED,
sdl2.SDL_WINDOWPOS_UNDEFINED,
640, 480,
sdl2.SDL_WINDOW_OPENGL | sdl2.SDL_WINDOW_SHOWN)
# Create an OpenGL context
gl_context = sdl2.SDL_GL_CreateContext(window)
# Main loop
running = True
event = sdl2.SDL_Event()
# Create an SDL2 renderer for ImGui
imgui.set_current_context(imgui.create_context())
renderer = SDL2Renderer(window)
while running:
while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
if event.type == sdl2.SDL_QUIT:
running = False
is_expand, show_custom_window = imgui.begin("Custom window", True)
if is_expand:
imgui.text("Bars")
imgui.text_colored("Eggs", 0.2, 1.0, 0.0)
imgui.end()
imgui.render()
renderer.render(imgui.get_draw_data())
sdl2.SDL_GL_SwapWindow(window)
# Cleanup
sdl2.SDL_GL_DeleteContext(gl_context)
sdl2.SDL_DestroyWindow(window)
sdl2.SDL_Quit()
if __name__ == "__main__":
main()