An ImGui wrapper for modern GameMaker

The itch.io page has pre-built Windows packages for GameMaker
- Import build of ImGui_GM locally or download it from the itch.io page
- Create a persistent object and call the following functions in their respective events:
ImGui.__Initialize()in the create eventImGui.__Update()in any updating event (suggested: Begin Step)ImGui.__Render()in any rendering event (suggested: Draw GUI)
- Create an instance of the object at the start of your game, then call
ImGui.BeginandImGui.Endin the step event to draw. Below is example GML for how to use the library.
ImGui.ShowAboutWindow();
if (ImGui.Begin("Test Window")) {
ImGui.Text("Hello World :3");
str = ImGui.InputText("An Input", str);
if (ImGui.Button("Press Me")) {
show_message(string("your input was: {0}", str));
}
ImGui.End();
}- See Coverage heading below or the ImGui script in project for ImGui -> GML wrappers
Not a fan of the namespace-esque functions? Add snake_case.gml to your project! This script is automatically generated at build and includes snake case function definitions for ImGui_GM
Pretty much everything is covered! Check out COVERAGE.MD to see a list of wrapped functions along with non-standard ImGui_GM-only functions! The wiki also includes some info on some differences and how to use various ImGui features in GML.
- dll/
main.cppfor DLL initialization & game loop hook-insimgui_gm.hfor some configuration likeIMGUIGM_NATIVEimgui_*_gm.cppfor wrapped ImGui->GM definitionsimgui_impl_gm.cppfor GM backend, includes (currently unusued) GML rendering logic
- scripts/
ImGui/ImGui.gmlfor ImGui static functions, enum definitions, rendering, and internal IO/eventsImGui_Misc/ImGui_Misc.gmlfor input mapping & helper classes
- shaders/
shdImGui/shdImGui.fshfor clip-rect shader used by GML renderer
- tools/
brief/Program.jsfor ImGui to GM binding generation
Using premake5 5.0.0-beta2, Windows SDK v10.0, Node.js v16.18.0, built with Visual Studio Community 2022
- Use Premake5 to generate project files (
vs2022tested and working, others unknown) - Run
copy_dependencies.batto copy required.cppand.hfiles fromthirdparty/*intodll/ - Open
dll.slnin Visual Studio (support for versions older than 2022 is unknown) - Build for x64, resulting
imgui_gm.dllfile should be automatically copied to../extensions/ImGui_GM/imgui_gm.dlland wrapped functions should be generated bybrief/main.jsinImGui_GM.yyp - Open
ImGui_GM.yypand create a local package containingImGui_GM(extension),ImGui(script), andImGui_Misc(script) - Import local package into your game and create a controller object that calls
ImGui.__Initialize()once,ImGui.__Update()every frame, andImGui.__Render()in a draw event
I'm not sure if toolchain is the correct term here, but it sounds cool so I'll run with it. Here are some extra words on how the extension building works.
- Upon building inside of Visual Studio, the
tools/brief/main.jsscript will be called. This scripts readsimgui.hto collect IMGUI_API forward declarations forCOVERAGE.MDand enums for GML, it also collects any.cppfiles ending in "_gm.cpp" (Any uses ofGMFUNCoutside of files ending in_gm.cppwill not be read) and parses out functions defined using theGMFUNCmacro. These parsed functions are then added to theextensions/ImGui_GM/ImGui_GM.yyfile and static methods are created in the@section Bindssection of thescripts/ImGui/ImGui.gmlfile automatically. Enums from ImGui are also defined in the@section Enumssection. You can use the various preprocessor definition to hint attributes for wrapped functions and their arguments. Seebrief/Wrapper.js'smodifiermethod for how various attributes are handled.
ImGui_GM implements a platform-agnostic renderer via GML, which allows for ImGui_GM to hypothetically work on any platform you can compile libraries for. Development and testing has been carried out on Windows, but you could use premake to generate makefiles for other platforms (note: compiling for Linux via WSL seems to maybe possibly work, but needs more testing.)
This extension makes extensive use of the changed static behavior in beta runtime v2023.100.0.264 and onward. Be sure to use a runtime that has these changes in them, otherwise usage may not work as expected. If you're unsure about if your runtime supports these new behaviours or not, check if the static_get function exists; if so, you're good! Otherwise, you'll likely need to upgrade (or switch to the beta). As a good rule of thumb, it's best to assume this project will be using the latest beta release of GameMaker. You can also check the .yyp file's metadata for an IDE version.
At the time of writing, the aforementioned changes to static are only avaliable on the beta branch of GameMaker; using stable builds currently unsupported
Last Updated: 1/29/2023
-
Functions like
ImGui.Beginmay not return what you expect, see "ImGuiReturnMask Usage" for more info -
Functions that accept an array of items as an argument (such as
ImGui.DragInt3,ImGui.SliderFloat2, etc) will directly modify the given array. Keep this in mind when using them. Analogous functions that accept single elements (such asImGui.DrawInt,ImGui.SliderFloat) will not make any changes directly to the value, and the return value should be used. -
Like the above,
ColorEdit4andColorPicker4take the GML classImColor(or any struct) and mutates it directly; this is worth mentioning asColorEdit3returns a BGR colour -
Honestly, I dunno the difference between a "wrapper" and a "bind", so you'll probably see the two terms are used interchangably
- Omar Cornut for creating Dear ImGui
- rousr for creating ImGuiGML which inspired development of this
- @nkrapivin for providing general assistance with
YYRunnerInterfacemagic - @kraifpatrik's GMD3D11 for serving as reference on how to retrieve textures from GameMaker