mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-12 02:00:58 +01:00
parent
22e099366f
commit
a14f6696a3
@ -31,9 +31,6 @@ static unsigned int g_VboHandle = 0, g_VaoHandle = 0;
|
||||
// - 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);
|
||||
|
@ -25,9 +25,6 @@ static GLuint g_FontTexture = 0;
|
||||
// - 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.
|
||||
|
@ -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 @@ static void ImGui_ImplSdl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_
|
||||
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 @@ static void ImGui_ImplSdl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_
|
||||
{
|
||||
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 @@ bool ImGui_ImplSdl_EventCallback(const SDL_Event& event)
|
||||
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 @@ bool ImGui_ImplSdl_CreateDeviceObjects()
|
||||
// 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 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window)
|
||||
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 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window)
|
||||
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
|
||||
|
@ -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_Shutdown();
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user