Aidan63 / linc_imgui

Haxe/hxcpp @:native bindings for Dear ImGui
MIT License
44 stars 7 forks source link

Trying to get this working with HaxeFlixel #1

Closed 01010111 closed 6 years ago

01010111 commented 6 years ago

Hello! First off, thanks for your work on this! I'm super excited to play with imgui in haxe :D

I tried to get the haxeflixel demo to work, and it came back with a couple of errors:

source/FlxImGui.hx:174: characters 16-38 : cpp.Reference<imgui.draw.ImDrawData> has no field CmdListsCount (Suggestion: cmdListsCount)
source/FlxImGui.hx:177: characters 35-52 : cpp.Reference<imgui.draw.ImDrawData> has no field CmdLists (Suggestion: cmdLists)

I went with those suggestions and now I'm getting:

source/FlxImGui.hx:178: characters 19-37 : cpp.Reference<imgui.draw.ImDrawList> has no field getCmdData
source/FlxImGui.hx:179: characters 19-37 : cpp.Reference<imgui.draw.ImDrawList> has no field getVtxData
source/FlxImGui.hx:180: characters 19-37 : cpp.Reference<imgui.draw.ImDrawList> has no field getIdxData
source/FlxImGui.hx:182: characters 17-37 : cpp.Reference<imgui.draw.ImDrawList> has no field getCmdLength

I tried to dive into the framework and figure it out, but I can't find those get_____() functions anywhere.

Aidan63 commented 6 years ago

Thanks for pointing this out, seems like I forgot to update the haxeflixel demo when I merged the ImVector changes.

I've just pushed a commit which fixes the haxeflixel implementation on my end, hopefully it will work for you as well.

01010111 commented 6 years ago

It's working ok now! A few things though:

package;

import flixel.FlxState;
import imgui.ImGui;

class PlayState extends FlxState
{

    var buf:Array<cpp.Char> = [];

    override public function create():Void
    {
        super.create();
        FlxImGui.init();
    }

    override public function update(elapsed:Float):Void
    {
        super.update(elapsed);

        FlxImGui.newFrame();

        ImGui.begin('hello');
        ImGui.inputText('text input', buf);
        ImGui.end();

        FlxImGui.render();
    }
}

thanks for the help!

Aidan63 commented 6 years ago

Thats strange that the float define would freeze the game. I've tested haxeflixel, luxe, and CLI on windows and linux and never experienced anything like that. If you create a simple haxe program (no haxeflixel or linc_imgui) and just try to do something like add two floats with that define will it work? (anything in linc_imgui involving floats will need that define to work for now)

For the input text not working you can pre-allocate the array size. So doing this.

var buf : Array<cpp.Char> = [ for (i in 0...16) 0x0 ];

Will create an array of 16 UTF8 null characters which will give that input box a max of 16 chars. Internally inputText function will read the length of the array so you can push and pop values to change the max length or add new characters and the textbox will recognize that.

01010111 commented 6 years ago

I didn't have any trouble tracing the result of adding two floats with that define. I'll try on my windows machine later and let you know! I'm currently using OSX Sierra.

Thanks for the help! Populating the array worked perfectly :) I'm having a similar issue with ImGui.colorEdit3(), I'm able to pass values from an array with three floats, but it doesn't seem to write to them when I try to change the color, and it snaps back to the original value. This could be tied to the HXCPP_FLOAT32 issue, but I figured I'd ask anyway.

package;

import imgui.ImGui;
import flixel.FlxState;

class PipeGen extends FlxState
{

    var col:Array<Float> = [0, 1, 0];

    override public function create():Void
    {
        super.create();
        FlxImGui.init();
    }

    override public function update(elapsed:Float):Void
    {
        super.update(elapsed);

        FlxImGui.newFrame();

        ImGui.begin('PipeGen');
        ImGui.colorEdit3('color', col);
        ImGui.end();

        FlxImGui.render();
    }

}
Aidan63 commented 6 years ago

Yeah, that's probably tied to the float issue. I just tried it on windows and it worked fine. I also booted up my high-sierra VM to check if OSX is working and everything seemed to work fine for me. The basic demo and stuff involving float worked fine.

I think I've found a way around needing the float define without having to make loads of double -> float wrapper functions so I'll have to give that a go when I get back home this evening.

screen shot 2018-03-21 at 07 37 12

Aidan63 commented 6 years ago

I've just pushed a commit which should remove the need for the FLAOT32 define. When passing floats into ImGui functions which directly modifies the value of the variable you pass that variable needs to be explicitly defined as a cpp.Float32. So your colour edit sample would need to be changed to.

var col:Array<cpp.Float32> = [0, 1, 0];

When creating objects such as Vec2, Vec4, etc you can pass default haxe floats as they do not permanently modify the float variables passed.

01010111 commented 6 years ago

awesome! I haven't had a chance to test anything out since yesterday, but I was able to make a nice little tool that I've been meaning on making in about an hour - this is already super awesome :) thanks!

screen shot 2018-03-21 at 1 14 59 pm

Just tested out colorEdit3() and it's working well!

Thanks again!

Aidan63 commented 6 years ago

No problem, I'm glad the issue was solved and that people other than myself are finding a use for the bindings!

Since things seem to be working I'll close the issue.