GithubHelp home page GithubHelp logo

C code examples about imgui HOT 6 CLOSED

ocornut avatar ocornut commented on May 9, 2024
C code examples

from imgui.

Comments (6)

ocornut avatar ocornut commented on May 9, 2024

Michael,

This a mistake / misleading point, I will correct it. The current library requires a C++ compiler. It is "C friendly" in the sense that the API is rather flat and it doesn't overly use C++ features, but it does use some (namespaces, default parameters, function overload, and templates for ImVector<>).

We could possibly get rid of namespace and the template ImVector<> class, but the use of default parameters and function overload are intimately connected to making the api simple and terse, so a straight C would require more entry points.

Note that it doesn't include any C++ header and AFAIK should link without the C++ standard library but I haven't tested that.

from imgui.

pao avatar pao commented on May 9, 2024

AFAIK should link without the C++ standard library but I haven't tested that.

Not that I've managed to actually use this yet--I'm mostly confused--but I have attempted to compile imgui.cpp:

[ tup ] [0.275s] Executing Commands...                                                                              
* 1) gcc imgui.o -o test -lm                                                                                        
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
imgui.o: In function `ImGuiWindow::ImGuiWindow(char const*, ImVec2, ImVec2)':
imgui.cpp:(.text+0x2767): undefined reference to `operator new(unsigned long)'
imgui.cpp:(.text+0x2791): undefined reference to `operator delete(void*)'
imgui.o: In function `ImGuiWindow::~ImGuiWindow()':
imgui.cpp:(.text+0x2817): undefined reference to `operator delete(void*)'
imgui.o: In function `ImGui::FindWindowSettings(char const*)':
imgui.cpp:(.text+0x2c29): undefined reference to `operator new(unsigned long)'
imgui.o: In function `ImGui::LoadSettings()':
imgui.cpp:(.text+0x2db7): undefined reference to `operator new[](unsigned long)'
imgui.cpp:(.text+0x2e11): undefined reference to `operator delete[](void*)'
imgui.cpp:(.text+0x3081): undefined reference to `operator delete[](void*)'
imgui.o: In function `ImGui::NewFrame()':
imgui.cpp:(.text+0x3435): undefined reference to `operator new(unsigned long)'
imgui.cpp:(.text+0x3d90): undefined reference to `operator delete(void*)'
imgui.o: In function `ImGui::Shutdown()':
imgui.cpp:(.text+0x3dff): undefined reference to `operator delete(void*)'
imgui.cpp:(.text+0x3eae): undefined reference to `operator delete(void*)'
imgui.cpp:(.text+0x3f67): undefined reference to `operator delete(void*)'
imgui.o: In function `ImGui::Begin(char const*, bool*, ImVec2, float, unsigned int)':
imgui.cpp:(.text+0x5d6d): undefined reference to `operator new(unsigned long)'
imgui.cpp:(.text+0x5e16): undefined reference to `operator new(unsigned long)'
imgui.cpp:(.text+0x7ee0): undefined reference to `operator delete(void*)'
imgui.cpp:(.text+0x7ef6): undefined reference to `operator delete(void*)'
imgui.o: In function `ImDrawList::AddArc(ImVec2 const&, float, unsigned int, int, int, bool, ImVec2 const&)':
imgui.cpp:(.text+0x15702): undefined reference to `__cxa_guard_acquire'
imgui.cpp:(.text+0x1573f): undefined reference to `__cxa_guard_release'
imgui.o: In function `ImGui::ShowTestWindow(bool*)':
imgui.cpp:(.text+0x19193): undefined reference to `__cxa_guard_acquire'
imgui.cpp:(.text+0x191b0): undefined reference to `__cxa_guard_release'
imgui.cpp:(.text+0x19e78): undefined reference to `__cxa_guard_acquire'
imgui.cpp:(.text+0x19e95): undefined reference to `__cxa_guard_release'
imgui.cpp:(.text+0x19fa8): undefined reference to `__cxa_guard_acquire'
imgui.cpp:(.text+0x19fcb): undefined reference to `__cxa_guard_release'
imgui.cpp:(.text+0x1a15e): undefined reference to `__cxa_guard_abort'
imgui.o:(.eh_frame+0x18b): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

You need both libm and libstdc++ in the link list to get it to compile. Maybe should mention it in the README (would pull request this, but not sure where to put it.)

from imgui.

ocornut avatar ocornut commented on May 9, 2024

Thanks for trying it out. I have now removed the misleading suggestion that the lib may be suitable to raw C compilation, it isn't. What are you confused about?

from imgui.

pao avatar pao commented on May 9, 2024

Oh, basically everything 😄 There's some conceptual leaps--I haven't looked through all the immediate mode GUI references. And I'm not really interested in graphics programming, so I'm not sure what to make of the examples (is a D3D or GL context required to use this?)

But all that's not really relevant to this issue.

from imgui.

ocornut avatar ocornut commented on May 9, 2024

Can you build and run the examples?
When your application has ImGui setup you can run UI code in your application loop. Something like:

ImGui::Begin("My window"); // create window
if (ImGui::Button("Load"))
{
// call your loading code
}
ImGui::SameLine();
if (ImGui::Button("Save"))
{
// call your saving code
}
ImGui::End()

The idea is that the UI controls only "exist" when you call them. A button doesn't store any extra information, the button logic is processed immediately and ImGui output vertices so they can be rendered (later). This way of working reduce the amount of synchronisation between your data and your UI because you will always create the UI with the correct data. As opposed to a typcial retained mode UI where you have to create a control, react to event, destroy the control, and update its state if your underlynig data changed (this last step is typically causing lots of bugs).

Some references about the concept
http://www.cse.chalmers.se/edu/year/2011/course/TDA361/Advanced%20Computer%20Graphics/IMGUI.pdf
http://sol.gfxile.net/imgui/
https://mollyrocket.com/861

from imgui.

ocornut avatar ocornut commented on May 9, 2024

This is also a good read about ImGui
http://www.johno.se/book/imgui.html
I have added all those links in the README file.

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.