🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to make a text box or button in OpenGL window in c++

Started by
39 comments, last by JoeJ 3 years, 11 months ago

Hey. I need help on how to make a button in OpenGL c++.

Advertisement

There are GLUI and Dear Imgui.

@taby I know about them, but there is one problem. Both of them don't allow me to place buttons on x and y positions

Shaanveer said:

@taby I know about them, but there is one problem. Both of them don't allow me to place buttons on x and y positions

This is incorrect. Could you show us what you have currently set up, then we'll be able to tell you what you could do differently, to accomplish placing a button.

Do you just want a button rendered o top of whatever you were rendering before? (no panels etc.)

@SuperVGA I am currently trying to find an external gui library that lets me make buttons in x and y positions. I do not know how to make buttons from scratch. A video will be helpful.

@Shaanveer no panels yet

Shaanveer said:

@SuperVGA I am currently trying to find an external gui library that lets me make buttons in x and y positions. I do not know how to make buttons from scratch. A video will be helpful.

Dear ImGui does that. Have you tried playing around with the examples included with ImGui, or looked for resources? It's very easy to find help online, although I haven't found (or searched thoroughly) videos describing just that. Here's a little snipped of ImGui that renders a button over whatever you drew before:

ImGui::SetNextWindowPos(ImVec2(8, 8), ImGuiCond_FirstUseEver);
const bool did_show = ImGui::Begin("Invisible window##InvisibleWindow", NULL, ImVec2(160, 160), 1.0f, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::Button("Hello!");
ImGui::End();
return did_show;

@SuperVGA Thanks soo much. But does Dear Imgui work with glut. If yes wonderful. And does Dear Imgui or glui allow me to place buttons in x and y positions. Thanks

Shaanveer said:

@SuperVGA Thanks soo much. But does Dear Imgui work with glut. If yes wonderful. And does Dear Imgui or glui allow me to place buttons in x and y positions. Thanks

I don't know if it works with glut. I changed from freeglut to glfw3 before adopting ImGui, but I do acknowledge that many resources still involve glut. I think you should take the above example and tinker with it a bit. From the looks of it, button does not take an offset in its ctor, but it's easy to place the button at an offset anyways, wrapping it in the right parent element. Just by looking at my example, don't you see an obvious way you could offset the button?

@SuperVGA No really dont. And I know glui works with glut, but the problem is that I dont know if it allows me to place buttons in x and y pos

This topic is closed to new replies.

Advertisement