mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 14:16:36 +00: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)
|
// - 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)
|
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
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
|
||||||
GLint last_program, last_texture;
|
GLint last_program, last_texture;
|
||||||
glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
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)
|
// - 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)
|
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!
|
// 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.
|
// 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.
|
// 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.h>
|
||||||
#include <SDL_syswm.h>
|
#include <SDL_syswm.h>
|
||||||
#include <SDL_OpenGL.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)));
|
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, col)));
|
||||||
|
|
||||||
int vtx_offset = 0;
|
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];
|
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
|
||||||
if (pcmd->user_callback)
|
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);
|
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));
|
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;
|
vtx_offset += pcmd->vtx_count;
|
||||||
}
|
}
|
||||||
@ -117,7 +120,7 @@ bool ImGui_ImplSdl_EventCallback(const SDL_Event& event)
|
|||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
unsigned int c = event.text.text[0];
|
unsigned int c = event.text.text[0];
|
||||||
if (c > 0 && c < 0x10000)
|
if (c > 0 && c < 0x10000)
|
||||||
io.AddInputCharacter((unsigned short)c);
|
io.AddInputCharacter((unsigned short)event.text.text[0]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
@ -153,6 +156,7 @@ bool ImGui_ImplSdl_CreateDeviceObjects()
|
|||||||
// Store our identifier
|
// Store our identifier
|
||||||
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
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->ClearInputData();
|
||||||
io.Fonts->ClearTexData();
|
io.Fonts->ClearTexData();
|
||||||
|
|
||||||
@ -224,18 +228,16 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window)
|
|||||||
SDL_GetWindowSize(window, &w, &h);
|
SDL_GetWindowSize(window, &w, &h);
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||||
|
|
||||||
// Time
|
// Setup time step
|
||||||
Uint32 time = SDL_GetTicks();
|
Uint32 time = SDL_GetTicks();
|
||||||
double current_time = time / 1000.0;
|
double current_time = time / 1000.0;
|
||||||
|
|
||||||
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
|
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
|
||||||
g_Time = current_time;
|
g_Time = current_time;
|
||||||
|
|
||||||
int mx, my;
|
|
||||||
Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
|
|
||||||
|
|
||||||
// Setup inputs
|
// Setup inputs
|
||||||
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
|
// (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)
|
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.)
|
io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
else
|
else
|
||||||
@ -249,7 +251,7 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window)
|
|||||||
io.MouseWheel = g_MouseWheel;
|
io.MouseWheel = g_MouseWheel;
|
||||||
g_MouseWheel = 0.0f;
|
g_MouseWheel = 0.0f;
|
||||||
|
|
||||||
// Hide/show hardware mouse cursor
|
// Hide OS mouse cursor if ImGui is drawing it
|
||||||
SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1);
|
SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1);
|
||||||
|
|
||||||
// Start the frame
|
// Start the frame
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// ImGui SDL2 binding with OpenGL
|
||||||
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
typedef union SDL_Event SDL_Event;
|
typedef union SDL_Event SDL_Event;
|
||||||
|
|
||||||
@ -6,5 +9,6 @@ void ImGui_ImplSdl_Shutdown();
|
|||||||
void ImGui_ImplSdl_NewFrame(SDL_Window *window);
|
void ImGui_ImplSdl_NewFrame(SDL_Window *window);
|
||||||
bool ImGui_ImplSdl_EventCallback(const SDL_Event& event);
|
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();
|
void ImGui_ImplSdl_InvalidateDeviceObjects();
|
||||||
bool ImGui_ImplSdl_CreateDeviceObjects();
|
bool ImGui_ImplSdl_CreateDeviceObjects();
|
||||||
|
Loading…
Reference in New Issue
Block a user