Examples: Added a color slider for the background color + tweak first example use of button.s
This commit is contained in:
parent
02f0dbca37
commit
62ecdd21a5
@ -540,6 +540,10 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
|
|
||||||
InitImGui();
|
InitImGui();
|
||||||
|
|
||||||
|
bool show_test_window = true;
|
||||||
|
bool show_another_window = false;
|
||||||
|
ImVec4 clear_col(0.8f, 0.6f, 0.6f, 1.0f);
|
||||||
|
|
||||||
// Enter the message loop
|
// Enter the message loop
|
||||||
MSG msg;
|
MSG msg;
|
||||||
ZeroMemory(&msg, sizeof(msg));
|
ZeroMemory(&msg, sizeof(msg));
|
||||||
@ -551,20 +555,17 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateImGui();
|
UpdateImGui();
|
||||||
|
|
||||||
static bool show_test_window = true;
|
|
||||||
static bool show_another_window = false;
|
|
||||||
|
|
||||||
// 1. Show a simple window
|
// 1. Show a simple window
|
||||||
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
||||||
{
|
{
|
||||||
static float f;
|
static float f;
|
||||||
ImGui::Text("Hello, world!");
|
ImGui::Text("Hello, world!");
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||||
show_test_window ^= ImGui::Button("Test Window");
|
ImGui::ColorEdit3("clear color", (float*)&clear_col);
|
||||||
show_another_window ^= ImGui::Button("Another Window");
|
if (ImGui::Button("Test Window")) show_test_window ^= 1;
|
||||||
|
if (ImGui::Button("Another Window")) show_another_window ^= 1;
|
||||||
|
|
||||||
// Calculate and show frame rate
|
// Calculate and show frame rate
|
||||||
static float ms_per_frame[120] = { 0 };
|
static float ms_per_frame[120] = { 0 };
|
||||||
@ -594,8 +595,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
float clearColor[4] = { 204 / 255.f, 153 / 255.f, 153 / 255.f };
|
g_pd3dDeviceImmediateContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
|
||||||
g_pd3dDeviceImmediateContext->ClearRenderTargetView(g_mainRenderTargetView, clearColor);
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
g_pSwapChain->Present(0, 0);
|
g_pSwapChain->Present(0, 0);
|
||||||
}
|
}
|
||||||
|
@ -281,6 +281,10 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
|
|
||||||
InitImGui();
|
InitImGui();
|
||||||
|
|
||||||
|
bool show_test_window = true;
|
||||||
|
bool show_another_window = false;
|
||||||
|
ImVec4 clear_col(0.8f, 0.6f, 0.6f, 1.0f);
|
||||||
|
|
||||||
// Enter the message loop
|
// Enter the message loop
|
||||||
MSG msg;
|
MSG msg;
|
||||||
ZeroMemory(&msg, sizeof(msg));
|
ZeroMemory(&msg, sizeof(msg));
|
||||||
@ -292,20 +296,17 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateImGui();
|
UpdateImGui();
|
||||||
|
|
||||||
static bool show_test_window = true;
|
|
||||||
static bool show_another_window = false;
|
|
||||||
|
|
||||||
// 1. Show a simple window
|
// 1. Show a simple window
|
||||||
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
||||||
{
|
{
|
||||||
static float f;
|
static float f;
|
||||||
ImGui::Text("Hello, world!");
|
ImGui::Text("Hello, world!");
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||||
show_test_window ^= ImGui::Button("Test Window");
|
ImGui::ColorEdit3("clear color", (float*)&clear_col);
|
||||||
show_another_window ^= ImGui::Button("Another Window");
|
if (ImGui::Button("Test Window")) show_test_window ^= 1;
|
||||||
|
if (ImGui::Button("Another Window")) show_another_window ^= 1;
|
||||||
|
|
||||||
// Calculate and show frame rate
|
// Calculate and show frame rate
|
||||||
static float ms_per_frame[120] = { 0 };
|
static float ms_per_frame[120] = { 0 };
|
||||||
@ -330,7 +331,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
|
// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
|
||||||
if (show_test_window)
|
if (show_test_window)
|
||||||
{
|
{
|
||||||
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver);
|
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver);
|
||||||
ImGui::ShowTestWindow(&show_test_window);
|
ImGui::ShowTestWindow(&show_test_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +339,8 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
|
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
|
||||||
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
|
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
|
||||||
g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
|
g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
|
||||||
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(204, 153, 153), 1.0f, 0);
|
D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_col.x*255.0f), (int)(clear_col.y*255.0f), (int)(clear_col.z*255.0f), (int)(clear_col.w*255.0f));
|
||||||
|
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0);
|
||||||
if (g_pd3dDevice->BeginScene() >= 0)
|
if (g_pd3dDevice->BeginScene() >= 0)
|
||||||
{
|
{
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
@ -169,7 +169,7 @@ void InitGL()
|
|||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
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);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetKeyCallback(window, glfw_key_callback);
|
glfwSetKeyCallback(window, glfw_key_callback);
|
||||||
glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
|
glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
|
||||||
@ -321,6 +321,10 @@ int main(int argc, char** argv)
|
|||||||
InitGL();
|
InitGL();
|
||||||
InitImGui();
|
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))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
@ -329,17 +333,15 @@ int main(int argc, char** argv)
|
|||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
UpdateImGui();
|
UpdateImGui();
|
||||||
|
|
||||||
static bool show_test_window = true;
|
|
||||||
static bool show_another_window = false;
|
|
||||||
|
|
||||||
// 1. Show a simple window
|
// 1. Show a simple window
|
||||||
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
||||||
{
|
{
|
||||||
static float f;
|
static float f;
|
||||||
ImGui::Text("Hello, world!");
|
ImGui::Text("Hello, world!");
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||||
show_test_window ^= ImGui::Button("Test Window");
|
ImGui::ColorEdit3("clear color", (float*)&clear_col);
|
||||||
show_another_window ^= ImGui::Button("Another Window");
|
if (ImGui::Button("Test Window")) show_test_window ^= 1;
|
||||||
|
if (ImGui::Button("Another Window")) show_another_window ^= 1;
|
||||||
|
|
||||||
// Calculate and show frame rate
|
// Calculate and show frame rate
|
||||||
static float ms_per_frame[120] = { 0 };
|
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()
|
// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
|
||||||
if (show_test_window)
|
if (show_test_window)
|
||||||
{
|
{
|
||||||
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver);
|
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver);
|
||||||
ImGui::ShowTestWindow(&show_test_window);
|
ImGui::ShowTestWindow(&show_test_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
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);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
@ -143,7 +143,7 @@ void InitGL()
|
|||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL);
|
window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetKeyCallback(window, glfw_key_callback);
|
glfwSetKeyCallback(window, glfw_key_callback);
|
||||||
glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
|
glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
|
||||||
@ -255,6 +255,10 @@ int main(int argc, char** argv)
|
|||||||
InitGL();
|
InitGL();
|
||||||
InitImGui();
|
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))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
@ -262,17 +266,15 @@ int main(int argc, char** argv)
|
|||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
UpdateImGui();
|
UpdateImGui();
|
||||||
|
|
||||||
static bool show_test_window = true;
|
|
||||||
static bool show_another_window = false;
|
|
||||||
|
|
||||||
// 1. Show a simple window
|
// 1. Show a simple window
|
||||||
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
||||||
{
|
{
|
||||||
static float f;
|
static float f;
|
||||||
ImGui::Text("Hello, world!");
|
ImGui::Text("Hello, world!");
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||||
show_test_window ^= ImGui::Button("Test Window");
|
ImGui::ColorEdit3("clear color", (float*)&clear_col);
|
||||||
show_another_window ^= ImGui::Button("Another Window");
|
if (ImGui::Button("Test Window")) show_test_window ^= 1;
|
||||||
|
if (ImGui::Button("Another Window")) show_another_window ^= 1;
|
||||||
|
|
||||||
// Calculate and show frame rate
|
// Calculate and show frame rate
|
||||||
static float ms_per_frame[120] = { 0 };
|
static float ms_per_frame[120] = { 0 };
|
||||||
@ -303,7 +305,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
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);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
Loading…
Reference in New Issue
Block a user