Advertisement

How to make buttons in ImGui in OpenGL with glfw

Started by August 01, 2020 12:16 AM
28 comments, last by Shaanveer 4 years, 3 months ago

Hey. I am new to ImGui and I wanted to know how to make a button with it. Thanks a lot.

I had it working in no time by watching this video.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Advertisement

Here is some basic code:

https://gist.github.com/sjhalayka/6cd70980ce38e2cb0aa64a46c4abc8b0

Shaanveer please drop that approach. You're clearly unable to compose something that does this with Dear ImGui, despite the example I provided last time. Use Godot.

Have you checked the links I provided last time?

I run the first ImGUI example in my life a few minutes later. Thanks to video above (The Cerno). I set up ImGUI in QtCreator IDE and MinGW 32-bit. I use QtCreater just like IDE for pure C++. I create the window using the GLFW library. I met a few simple problems but I solved them using Google very quickly. For example, I added the #define IMGUI_IMPL_OPENGL_LOADER_GLAD line in the imgui_impl_opengl3.cpp file. Now I can add GUI to my OpenGL 3 (GLFW and SDL2) projects in QtCreator. I need to try SDL2 because it has a built-in sound library that is good for simple 2D games and applications because it is easy to use and you need to add another library for sounds/music, but I think it will work too. ImGUI is cool library. I'm GUI. I'm Nigan ?

I compiled the example to Release: FirstExampleImGUI_win32.zip (490KB in archive and 1.30MB (unzipped state) with glfw3.dll)

@SuperVGA Yes. I saw the links but they didn't help to much

Advertisement

@8Observer8 How did you add the button icon it didn't say in the video. Is it in any other vid of his

Shaanveer said:

@SuperVGA Yes. I saw the links but they didn't help to much

Didn't help? Did you follow the tutorial?

Shaanveer said:
@8Observer8 How did you add the button icon it didn't say in the video. Is it in any other vid of his

I just copypasta the official “hello, world” example for GLFW: https://github.com/ocornut/imgui/blob/master/examples/example_glfw_opengl3/main.cpp

I use the QtCreator IDE and the MinGW compiler. You can create an empty C++ project in QtCreator like this: “File” > “New File or Project…” > “Other Project” > “Empty qmake Project”

Just copy the ImGUI files to your project. You can see my .pro file below. If you want that your apps and games works on laptops then add this code to the beginning of your main.cpp:

#ifdef _WIN32
#include <windows.h>
extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
#endif

HelloImGuiQtCreator.pro

INCLUDEPATH += "E:\Libs\glad-0.1.33-mingw-32bit\include"
LIBS += -L"E:\Libs\glad-0.1.33-mingw-32bit\lib"
LIBS += -lglad

INCLUDEPATH += "E:\Libs\glfw-3.3.2-mingw-32bit\include"
LIBS += -L"E:\Libs\glfw-3.3.2-mingw-32bit\lib"
LIBS += -lglfw3

LIBS += -lopengl32 -lgdi32

HEADERS += \
    imconfig.h \
    imgui.h \
    imgui_impl_glfw.h \
    imgui_impl_opengl3.h \
    imgui_internal.h \
    imstb_rectpack.h \
    imstb_textedit.h \
    imstb_truetype.h

SOURCES += \
    imgui.cpp \
    imgui_demo.cpp \
    imgui_draw.cpp \
    imgui_impl_glfw.cpp \
    imgui_impl_opengl3.cpp \
    imgui_widgets.cpp \
    main.cpp

@8Observer8 This is all great but I saw all of the chernos vids and they all showed how to make icons on the imgui window not opengl did this happen to you too?

This topic is closed to new replies.

Advertisement