Examples: Added a color slider for the background color + tweak first example use of button.s

This commit is contained in:
ocornut
2015-01-15 09:59:18 +00:00
parent 02f0dbca37
commit 62ecdd21a5
4 changed files with 37 additions and 31 deletions

View File

@ -169,7 +169,7 @@ void InitGL()
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL);
window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, glfw_key_callback);
glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
@ -321,6 +321,10 @@ int main(int argc, char** argv)
InitGL();
InitImGui();
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_col(0.8f, 0.6f, 0.6f, 1.0f);
while (!glfwWindowShouldClose(window))
{
ImGuiIO& io = ImGui::GetIO();
@ -329,17 +333,15 @@ int main(int argc, char** argv)
glfwPollEvents();
UpdateImGui();
static bool show_test_window = true;
static bool show_another_window = false;
// 1. Show a simple window
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
{
static float f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
show_test_window ^= ImGui::Button("Test Window");
show_another_window ^= ImGui::Button("Another Window");
ImGui::ColorEdit3("clear color", (float*)&clear_col);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
// Calculate and show frame rate
static float ms_per_frame[120] = { 0 };
@ -364,13 +366,13 @@ int main(int argc, char** argv)
// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
if (show_test_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver);
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver);
ImGui::ShowTestWindow(&show_test_window);
}
// Rendering
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(0.8f, 0.6f, 0.6f, 1.0f);
glClearColor(clear_col.x, clear_col.y, clear_col.z, clear_col.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui::Render();
glfwSwapBuffers(window);