[BlackPearl引擎开发记录 6] --ImGui

完整代码:https://github.com/DXT00/LearnOpenGL_study/tree/1977d59c505868f63f718cb7d8d22c3f5176cd69

ImGui selectable 菜单:
 

const char* entityItems[] = { "Empty","PointLight","SpotLight","IronMan","Cube" };
static const char* currentItem = nullptr;
if (ImGui::BeginCombo("CreateEntity", currentItem)) {

	for (int n = 0; n < IM_ARRAYSIZE(entityItems); n++)
	{

		bool is_selected = (currentItem == entityItems[n]); // You can store your selection however you want, outside or inside your objects
		if (ImGui::Selectable(entityItems[n], is_selected)) { //ImGui::Selectable()显示可选择的选项
			currentItem = entityItems[n];
			if (currentItem != nullptr) {
				std::string debug_currentItem(currentItem);
				std::cout << debug_currentItem << std::endl;
			}
		}			
	}

	ImGui::EndCombo();
}

注意:ImGui的所有用法在imgui_demo.cppimgui_draw.cpp

通过ImGui控制Object 生成:

void OnImguiRender() override {


		ImGui::Begin("Settings");
		ImGui::ColorEdit3("Suqare Color", glm::value_ptr(m_BackgroundColor));
		ImGui::End();


		if (ImGui::CollapsingHeader("Create")) {

			const char* const entityItems[] = { "Empty","PointLight","SpotLight","IronMan","Cube" };
			static int entityIdx = -1;
			if (ImGui::Combo("CreateEntity", &entityIdx, entityItems, 5))
			{
				switch (entityIdx)
				{
				case 0:
					GE_CORE_INFO("Creating Empty...");
					Layer::CreateEmpty();
					break;
				case 1:
					GE_CORE_INFO("Creating PointLight...");
					Layer::CreateLight(BlackPearl::LightType::PointLight);
					break;
				case 2:
					GE_CORE_INFO("SpotLight");
					Layer::CreateLight(BlackPearl::LightType::SpotLight);
					break;
				case 3:
					GE_CORE_INFO("IronMan");
					Layer::CreateModel();
					break;
				case 4:
					GE_CORE_INFO("Cube");
					Layer::CreateCube();
					break;
				}
			}
		}
		if (ImGui::CollapsingHeader("Scene")) {


		}


	}

 

dynamically add items with listbox 

参考:https://github.com/ocornut/imgui/issues/2259

 

ImGuiRender:获取现有的Object列表,并放到ListBox上

	void OnImguiRender() override {


		ImGui::Begin("Settings");
		ImGui::ColorEdit3("Suqare Color", glm::value_ptr(m_BackgroundColor));
		ImGui::End();


		if (ImGui::CollapsingHeader("Create")) {

			const char* const entityItems[] = { "Empty","PointLight","SpotLight","IronMan","Cube" };
			static int entityIdx = -1;
			if (ImGui::Combo("CreateEntity", &entityIdx, entityItems, 5))
			{
				switch (entityIdx)
				{
				case 0:
					GE_CORE_INFO("Creating Empty...");
					Layer::CreateEmpty();
					break;
				case 1:
					GE_CORE_INFO("Creating PointLight...");
					Layer::CreateLight(BlackPearl::LightType::PointLight);
					break;
				case 2:
					GE_CORE_INFO("Creating SpotLight ...");
					Layer::CreateLight(BlackPearl::LightType::SpotLight);
					break;
				case 3:
					GE_CORE_INFO("Creating IronMan ...");
					Layer::CreateModel();
					break;
				case 4:
					GE_CORE_INFO("Creating Cube ...");
					Layer::CreateCube();
					break;
				}
			}
		}
		if (ImGui::CollapsingHeader("Scene")) {

			std::vector<std::string> objsList = GetObjectsName();		
			ImGui::ListBoxHeader("CurrentEntities", (int)objsList.size(), 6);
			for (int n = 0; n < objsList.size(); n++)			
				ImGui::Text("%s", objsList[n].c_str());
			ImGui::ListBoxFooter();
		}


	}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值