1
0
mirror of https://github.com/Drezil/imgui.git synced 2024-12-19 06:26:35 +00:00

Examples: shallow tweaks to match upcoming other examples.

This commit is contained in:
ocornut 2015-03-09 13:02:32 +00:00
parent b227b0f8cd
commit b87ec205a9
6 changed files with 21 additions and 20 deletions

View File

@ -14,13 +14,12 @@
#include <GLFW/glfw3native.h>
#endif
// Data
static GLFWwindow* g_Window = NULL;
static double g_Time = 0.0f;
static bool g_MousePressed[3] = { false, false, false };
static float g_MouseWheel = 0.0f;
static double g_Time = 0.0f;
static bool g_FontTextureLoaded = false;
// Handles for OpenGL3 rendering
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0;
@ -146,7 +145,7 @@ void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow* window, unsigned int c)
io.AddInputCharacter((unsigned short)c);
}
void ImGui_ImplGlfwGL3_LoadFontsTexture()
void ImGui_ImplGlfwGL3_InitFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
@ -293,8 +292,7 @@ void ImGui_ImplGlfwGL3_Shutdown()
glDeleteProgram(g_ShaderHandle);
g_ShaderHandle = 0;
GLuint tex_id = (GLuint)ImGui::GetIO().Fonts->TexID;
if (tex_id)
if (GLuint tex_id = (GLuint)ImGui::GetIO().Fonts->TexID)
{
glDeleteTextures(1, &tex_id);
ImGui::GetIO().Fonts->TexID = 0;
@ -305,7 +303,7 @@ void ImGui_ImplGlfwGL3_Shutdown()
void ImGui_ImplGlfwGL3_NewFrame()
{
if (!g_FontTextureLoaded)
ImGui_ImplGlfwGL3_LoadFontsTexture();
ImGui_ImplGlfwGL3_InitFontsTexture();
ImGuiIO& io = ImGui::GetIO();

View File

@ -4,8 +4,8 @@
struct GLFWwindow;
bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks);
void ImGui_ImplGlfwGL3_InitFontsTexture();
void ImGui_ImplGlfwGL3_Shutdown();
void ImGui_ImplGlfwGL3_LoadFontsTexture();
void ImGui_ImplGlfwGL3_NewFrame();
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)

View File

@ -13,31 +13,32 @@ static void error_callback(int error, const char* description)
int main(int argc, char** argv)
{
// Setup window
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(1);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
glfwMakeContextCurrent(window);
gl3wInit();
// Setup ImGui binding
ImGui_ImplGlfwGL3_Init(window, true);
//ImGuiIO& io = ImGui::GetIO();
//ImFont* my_font1 = io.Fonts->AddFontDefault();
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
ImGui_ImplGlfwGL3_Init(window, true);
ImGui_ImplGlfwGL3_LoadFontsTexture();
ImGui_ImplGlfwGL3_InitFontsTexture();
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
// Main loop
while (!glfwWindowShouldClose(window))
{
ImGuiIO& io = ImGui::GetIO();

View File

@ -13,10 +13,11 @@
#include <GLFW/glfw3native.h>
#endif
// Data
static GLFWwindow* g_Window = NULL;
static double g_Time = 0.0f;
static bool g_MousePressed[3] = { false, false, false };
static float g_MouseWheel = 0.0f;
static double g_Time = 0.0f;
static bool g_FontTextureLoaded = false;
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
@ -124,7 +125,7 @@ void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
io.AddInputCharacter((unsigned short)c);
}
void ImGui_ImplGlfw_LoadFontsTexture()
void ImGui_ImplGlfw_InitFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
@ -188,8 +189,7 @@ bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks)
void ImGui_ImplGlfw_Shutdown()
{
GLuint tex_id = (GLuint)ImGui::GetIO().Fonts->TexID;
if (tex_id)
if (GLuint tex_id = (GLuint)ImGui::GetIO().Fonts->TexID)
{
glDeleteTextures(1, &tex_id);
ImGui::GetIO().Fonts->TexID = 0;
@ -200,7 +200,7 @@ void ImGui_ImplGlfw_Shutdown()
void ImGui_ImplGlfw_NewFrame()
{
if (!g_FontTextureLoaded)
ImGui_ImplGlfw_LoadFontsTexture();
ImGui_ImplGlfw_InitFontsTexture();
ImGuiIO& io = ImGui::GetIO();

View File

@ -4,8 +4,8 @@
struct GLFWwindow;
bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks);
void ImGui_ImplGlfw_InitFontsTexture();
void ImGui_ImplGlfw_Shutdown();
void ImGui_ImplGlfw_LoadFontsTexture();
void ImGui_ImplGlfw_NewFrame();
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)

View File

@ -12,13 +12,14 @@ static void error_callback(int error, const char* description)
int main(int argc, char** argv)
{
// Setup window
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(1);
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL);
glfwMakeContextCurrent(window);
// Setup ImGui binding
ImGui_ImplGlfw_Init(window, true);
//ImGuiIO& io = ImGui::GetIO();
//ImFont* my_font1 = io.Fonts->AddFontDefault();
@ -26,12 +27,13 @@ int main(int argc, char** argv)
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
ImGui_ImplGlfw_LoadFontsTexture();
ImGui_ImplGlfw_InitFontsTexture();
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
// Main loop
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();