SDL example: more cleanup to match other examples (#233 #226)
diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp
index 2328a08..fb3286d 100644
--- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp
+++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp
@@ -31,9 +31,6 @@
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{
- if (cmd_lists_count == 0)
- return;
-
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
GLint last_program, last_texture;
glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
diff --git a/examples/opengl_example/imgui_impl_glfw.cpp b/examples/opengl_example/imgui_impl_glfw.cpp
index 4756947..d289a7a 100644
--- a/examples/opengl_example/imgui_impl_glfw.cpp
+++ b/examples/opengl_example/imgui_impl_glfw.cpp
@@ -25,9 +25,6 @@
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
static void ImGui_ImplGlfw_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{
- if (cmd_lists_count == 0)
- return;
-
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
// A probable faster way to render would be to collate all vertices from all cmd_lists into a single vertex buffer.
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.cpp b/examples/sdl_opengl_example/imgui_impl_sdl.cpp
index b22250b..139a5db 100644
--- a/examples/sdl_opengl_example/imgui_impl_sdl.cpp
+++ b/examples/sdl_opengl_example/imgui_impl_sdl.cpp
@@ -1,3 +1,6 @@
+// ImGui SDL2 binding with OpenGL
+// https://github.com/ocornut/imgui
+
#include <SDL.h>
#include <SDL_syswm.h>
#include <SDL_OpenGL.h>
@@ -52,7 +55,7 @@
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, col)));
int vtx_offset = 0;
- for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
+ for (int cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
if (pcmd->user_callback)
@@ -63,7 +66,7 @@
{
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id);
glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
- glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
+ glDrawArrays(GL_TRIANGLES, vtx_offset, (GLsizei)pcmd->vtx_count);
}
vtx_offset += pcmd->vtx_count;
}
@@ -117,7 +120,7 @@
ImGuiIO& io = ImGui::GetIO();
unsigned int c = event.text.text[0];
if (c > 0 && c < 0x10000)
- io.AddInputCharacter((unsigned short)c);
+ io.AddInputCharacter((unsigned short)event.text.text[0]);
return true;
}
case SDL_KEYDOWN:
@@ -153,6 +156,7 @@
// Store our identifier
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
+ // Cleanup (don't clear the input data if you want to append new fonts later)
io.Fonts->ClearInputData();
io.Fonts->ClearTexData();
@@ -224,18 +228,16 @@
SDL_GetWindowSize(window, &w, &h);
io.DisplaySize = ImVec2((float)w, (float)h);
- // Time
+ // Setup time step
Uint32 time = SDL_GetTicks();
double current_time = time / 1000.0;
-
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
g_Time = current_time;
- int mx, my;
- Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
-
// Setup inputs
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
+ int mx, my;
+ Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS)
io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
else
@@ -249,7 +251,7 @@
io.MouseWheel = g_MouseWheel;
g_MouseWheel = 0.0f;
- // Hide/show hardware mouse cursor
+ // Hide OS mouse cursor if ImGui is drawing it
SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1);
// Start the frame
diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.h b/examples/sdl_opengl_example/imgui_impl_sdl.h
index 6d56b2e..1e8d91c 100644
--- a/examples/sdl_opengl_example/imgui_impl_sdl.h
+++ b/examples/sdl_opengl_example/imgui_impl_sdl.h
@@ -1,3 +1,6 @@
+// ImGui SDL2 binding with OpenGL
+// https://github.com/ocornut/imgui
+
struct SDL_Window;
typedef union SDL_Event SDL_Event;
@@ -6,5 +9,6 @@
void ImGui_ImplSdl_NewFrame(SDL_Window *window);
bool ImGui_ImplSdl_EventCallback(const SDL_Event& event);
+// Use if you want to reset your rendering device without losing ImGui state.
void ImGui_ImplSdl_InvalidateDeviceObjects();
bool ImGui_ImplSdl_CreateDeviceObjects();