Updated Quickstart (markdown)

omar 2023-06-30 18:18:30 +02:00
parent 5dfea66610
commit fda00a2c44

@ -122,7 +122,7 @@ Add to end of main loop:
// (Your code clears your framebuffer, renders your stuff etc.) // (Your code clears your framebuffer, renders your stuff etc.)
ImGui::Render(); ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
// (Your call calls glfwSwapBuffers() etc.) // (Your code calls glfwSwapBuffers() etc.)
``` ```
Add to Shutdown: Add to Shutdown:
```cpp ```cpp
@ -131,3 +131,60 @@ ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
``` ```
That should be all! That should be all!
## Example: If you are using SDL2 + OpenGL/WebGL
Full standalone example: [example_sdl2_opengl3/main.cpp](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_opengl3/main.cpp)
Add to Includes:
```cpp
#include "imgui.h"
#include "imgui_impl_sdl2.h"
#include "imgui_impl_opengl3.h"
```
Add to Initialization:
```cpp
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // IF using Docking Branch
// Setup Platform/Renderer backends
ImGui_ImplSDL2_InitForOpenGL(window, YOUR_SDL_GL_CONTEXT);
ImGui_ImplOpenGL3_Init();
```
Add to start of main loop:
```cpp
// (Where your code calls SDL_PollEvent())
ImGui_ImplSDL2_ProcessEvent(&event); // Forward your event to backend
// (After event loop)
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
ImGui::ShowDemoWindow(); // Show demo window :)
```
Add to end of main loop:
```cpp
// Rendering
// (Your code clears your framebuffer, renders your stuff etc.)
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
// (Your code calls SDL_GL_SwapWindow() etc.)
```
Add to Shutdown:
```cpp
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
```
That should be all!
## Example: If you are using another combination of backends?
The various examples above should reflect integration with a majority of backends, so you can follow the same logic.
Some backends require more information from you (e.g. in particular Vulkan and DirectX12 rendering backends). In doubt, refers to the corresponding [examples](https://github.com/ocornut/imgui/tree/master/examples) application.