🎉 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

@undefined Hey I was searching about nano gui on the internet and it said it only worked on glfw not glut is this true

Advertisement

Umm. Sir are you still there

Shaanveer said:

Umm. Sir are you still there

Shaanveer said:

Umm. Sir are you still there

Can you just answer this quick question

@Shaanveer Thanks in advance

Shaanveer said:

Shaanveer said:

Umm. Sir are you still there

Can you just answer this quick question

Hi Shaanveer,

I was hoping you'd figure something out after asking @dotnka (and @fleabay in the other thread you created). I get that you're looking for lots of very specific answers, and likely complete solutions. You're not accustomed to programming, and that's fine.

I also started programming at a young age. Around 8, I was fortunate enough to have a father who taught me BASIC. The “Online help” in QBASIC wasn't online, but it was good, and I messed with a ton of the example code I copied from it.

You're probably in a different situation. You have easy-to-use game engines and the world wide web. You have tonnes of resources you can sift through. Some with good examples, some with outdated, bad examples. As you've already experienced wrt. using GLUT, it can be difficult to tell whether a resource/approach is outdated or recent. You'd need to go search the web for the source (often found on github) or the official website for the library. This will help you a lot to tell whether you're dealing with some outdated library. Often, if you add the right keywords.

Now, unless I'm already completely off about this since I started my latest project, GLFW3 and GLAD are the way to go when wanting to use OpenGL today. I personally top this off with SFML and Dear ImGui to make some things a lot easier. I think you can do this too, but please don't. Please don't mess with all this stuff yet.

I don't know if you want to do something really advanced - if the goal is to do something in a complex way, but it shouldn't be at this point. Pick up Godot. Follow the tutorial.
Refer to the excellent online (and offline) resources and community. Make games.

And I promise you - it will let you drag and drop buttons just about anywhere you wish to have that bloody button.

SuperVGA said:

Shaanveer said:

Shaanveer said:

Umm. Sir are you still there

Can you just answer this quick question

Hi Shaanveer,

I was hoping you'd figure something out after asking @dotnka (and @fleabay in the other thread you created). I get that you're looking for lots of very specific answers, and likely complete solutions. You're not accustomed to programming, and that's fine.

I also started programming at a young age. Around 8, I was fortunate enough to have a father who taught me BASIC. The “Online help” in QBASIC wasn't online, but it was good, and I messed with a ton of the example code I copied from it.

You're probably in a different situation. You have easy-to-use game engines and the world wide web. You have tonnes of resources you can sift through. Some with good examples, some with outdated, bad examples. As you've already experienced wrt. using GLUT, it can be difficult to tell whether a resource/approach is outdated or recent. You'd need to go search the web for the source (often found on github) or the official website for the library. This will help you a lot to tell whether you're dealing with some outdated library. Often, if you add the right keywords.

Now, unless I'm already completely off about this since I started my latest project, GLFW3 and GLAD are the way to go when wanting to use OpenGL today. I personally top this off with SFML and Dear ImGui to make some things a lot easier. I think you can do this too, but please don't. Please don't mess with all this stuff yet.

I don't know if you want to do something really advanced - if the goal is to do something in a complex way, but it shouldn't be at this point. Pick up Godot. Follow the tutorial.
Refer to the excellent online (and offline) resources and community. Make games.

And I promise you - it will let you drag and drop buttons just about anywhere you wish to have that bloody button.

SuperVGA now I know why you have the best rating. You are one of the best programmer and teacher I have met. Thanks a lot for the websites and everything else. I will start using glfw3 and glad. I knew about them at the start, but I didn't use them as they didn't allow me to make a snake game.(thats what I thought). Thanks a lot. This topic is closed. I will not need your help on the snake game because, it is my job to figure out how to do it. I will use dear Imgui or sfml since they are better than glut. Thanks soooooooooooooooooooo much. FROM THE HEART

Sounds genuine. ?

SuperVGA said:

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;

Thanks, man!

Using this i was able to add debug output to 3D positions. I've lost this ability when switching to ImGui and never found how to do it.

But now i can do it again:

:D

I'm super happy!

Code in case someone needs that too:

static int labelID = 0;

void Vis::NewFrame ()
{
	labelID = 0;
}

void Vis::RenderLabel (sVec3 pos, float r, float g, float b, char *text, ...)
{
	pos = WorldToScreen (pos);
	if (pos[2]<0) return;
	if (pos[0]<-300) return;
	if (pos[0]>simpleVis.viewportWidth) return;
	if (pos[1]<-30) return;
	if (pos[1]>simpleVis.viewportHeight) return;

	labelID++;
	char stringID[4];
	stringID[0] = 48 + (labelID & 0x3F);
	stringID[1] = 48 + ((labelID>>6) & 0x3F);
	stringID[2] = 48 + ((labelID>>12) & 0x3F);
	stringID[3] = 0;

	ImGui::SetNextWindowPos(ImVec2(pos[0], pos[1]));
	ImGui::SetNextWindowSize(ImVec2 (100000, 100000));
	
	ImGui::Begin((char*)stringID, NULL, 
		ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | 
		ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize | 
		ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMouseInputs | 
		ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus);

	va_list args;
	va_start(args, text);
	ImGui::TextColoredV(ImVec4(r,g,b,1), text, args);
	va_end(args);

	ImGui::End();
}

Edit: Updated the code which had many issues.

Limited the size of IDs that can be created over time (ImGui tracks them and becomes very slow after some time - Make sure to reuse IDs from previous frame).
Added some frustum culling.
Added some more flags so does not conflict with other windows to remain clickable.

Seems to work pretty fine now : )

JoeJ said:

Thanks, man!

Using this i was able to add debug output to 3D positions. I've lost this ability when switching to ImGui and never found how to do it.

But now i can do it again:

:D

I'm super happy!

Code in case someone needs that too. Makung unique window name seems hacky but “##” did not work as expected.

void Vis::RenderLabel (sVec3 pos, char *text, ...)
{
	static uint64_t id[2] = {0,0};
	pos = WorldToScreen (pos);
	if (pos[2]<0) return;

	ImGui::SetNextWindowPos(ImVec2(pos[0], pos[1]));
	ImGui::SetNextWindowSize(ImVec2 (100000, 100000));
	id[0]++;
	ImGui::Begin((char*)id, NULL, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
		va_list args;
		va_start(args, text);
		ImGui::TextV(text, args);
		va_end(args);
	ImGui::End();
}

Sweet! Glad you could use and improve upon it. It looks really good and easy to follow on top of the space. What are you making?

And yeah, there was a few things I could have scraped out to make it simpler. I wonder if the ids can be omitted…

SuperVGA said:
What are you making?

I make a huge mesh that covers the entire level of a game, which i use to construct a surfel hierarchy for realtime GI.

So i need to divide into chunks to support out of core, multi threading, and regional updates on edits. But sometimes the remeshed chunks do not exactly match their neighbors, so i need to stitch and fix. And maintain data structure so i can traverse the chunks as if it would be one connected mesh. Yeah, and ofc. that's pretty error prone. Those debug labels will surely help a lot. : )

This topic is closed to new replies.

Advertisement