-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui-imgui: Add basic initialization/deinitialization and renderning
For now, draw ImGui's demo window on top of the scene to see that it works. Hook up the initialization/deinitialization to the glfw part of the code. The same is done for emscripten, except don't use the glfw emulation, as it's just one more intermediate layer. Instead, skip the platform backend for now. All that's really needed is input, and mostly mouse input. When enough of that is done, it can be made into a proper backend for ImGui. Signed-off-by: Alexander Shishkin <[email protected]>
- Loading branch information
Showing
7 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#include "common.h" | ||
#include "ui-debug.h" | ||
|
||
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS | ||
#include "cimgui.h" | ||
|
||
#ifndef __EMSCRIPTEN__ | ||
#include <GLFW/glfw3.h> | ||
#include "imgui_impl_glfw.h" | ||
#endif | ||
|
||
#include "imgui_impl_opengl3.h" | ||
|
||
static struct ImGuiContext *ctx; | ||
static struct ImGuiIO *io; | ||
|
||
void imgui_render(int width, int height) | ||
{ | ||
io->DisplaySize.x = width; | ||
io->DisplaySize.y = height; | ||
|
||
ImGui_ImplOpenGL3_NewFrame(); | ||
#ifndef __EMSCRIPTEN__ | ||
ImGui_ImplGlfw_NewFrame(); | ||
#endif | ||
igNewFrame(); | ||
|
||
// igSetNextWindowPos((struct ImVec2){0,0}, ImGuiCond_FirstUseEver,(struct ImVec2){0,0} ); | ||
// igShowDemoWindow(NULL); | ||
|
||
igRender(); | ||
ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData()); | ||
} | ||
|
||
void imgui_init(void *data, int width, int height) | ||
{ | ||
ctx = igCreateContext(NULL); | ||
io = igGetIO(); | ||
|
||
io->DisplaySize.x = width; | ||
io->DisplaySize.y = height; | ||
|
||
#ifndef __EMSCRIPTEN__ | ||
GLFWwindow *win = data; | ||
ImGui_ImplGlfw_InitForOpenGL(win, true); | ||
const char *glsl_version = "#version 410"; | ||
#else | ||
const char *glsl_version = "#version 300 es"; | ||
#endif | ||
|
||
ImGui_ImplOpenGL3_Init(glsl_version); | ||
|
||
igStyleColorsDark(NULL); | ||
} | ||
|
||
void imgui_done(void) | ||
{ | ||
ImGui_ImplOpenGL3_Shutdown(); | ||
#ifndef __EMSCRIPTEN__ | ||
ImGui_ImplGlfw_Shutdown(); | ||
#endif | ||
igDestroyContext(ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters