dearimgui / dear_bindings

C header (and language binding metadata) generator for Dear ImGui
MIT License
221 stars 12 forks source link

add Win32 DX11 C example #54

Closed shawnhatori closed 5 months ago

ocornut commented 8 months ago

I am not sure what Ben's stance would be on this, but some opinions:

ShironekoBen commented 8 months ago

@shawnhatori Thanks for the PR! Getting some functional example code in there definitely would improve usability for new users significantly, I think.

I've got a very hacky C test app here that I use to check things aren't utterly broken but it's a mess of stuff from all over the place and utterly unsuitable as an example - this code is far better!

@ocornut Yeah, that all sounds very sensible to me.

If we can align this with the C++ versions then indeed that would be ideal as that makes them both easier to maintain and more comprehensible to users who may be familiar with the C++ code already. And given that the C++ examples are not particular C++-ish (in terms of making extensive use of non-C language features) it doesn't feel like they would need to diverge very much.

Personally speaking I'm happy to go either way on this - if a bit of tidying would get this code into a place where it's closer to the C++ version then that's great, if not then I could look at porting the C++ example over.

shawnhatori commented 6 months ago

Sorry for the late reply here. I'm biased obviously, but I have always preferred the clarity of "flat" code examples. They read easily top-to-bottom and focus exactly on the minimal number of necessary function calls, so for the purpose of an example, they clearly show you what needs to happen step-by-step. No forward declarations, no error checking, no cleanup. I find that examples with helper functions (or much worse, OOP structures) jump around the file and force the writer's abstraction on the reader (see vulkan-tutorial.com for a particularly egregious example).

Thankfully, ImGui's C++ examples are, as you said, very C-like, quite clear on their own, and perfectly suitable. And I completely understand wanting to keep the two examples in parity for maintenance. If so, feel free to close this PR. This code sample was just a stripped down version of my local dear_bindings tests.

ocornut commented 5 months ago

Any reason for closing this?

ShironekoBen commented 5 months ago

FWIW I've got one of the ImGui C++ samples "ported" into C and working, and am currently looking at which others to do, so I'm currently leaning towards just using those as they line up with the main ImGui codebase, but I'm more than happy to consider pulling this in as well if there's a feeling that having this in as a sample too would be beneficial.

shawnhatori commented 5 months ago

Sorry, I should have included a comment. Based on the above discussion, I closed it in favor of the goal to line the examples up with the C++ ones for easier maintainability across repos. I think that's perfectly reasonable. For that, a better starting point is probably just taking the existing file and tweaking it to compile in C.