Examples: SDL/OpenGL: Tabs to spaces

This commit is contained in:
ocornut
2016-02-15 10:56:37 +01:00
parent 87a6110994
commit 9e86d0e225
4 changed files with 286 additions and 286 deletions
File diff suppressed because it is too large Load Diff
+14 -14
View File
@@ -10,24 +10,24 @@
int main(int, char**) int main(int, char**)
{ {
// Setup SDL // Setup SDL
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{ {
printf("Error: %s\n", SDL_GetError()); printf("Error: %s\n", SDL_GetError());
return -1; return -1;
} }
// Setup window // Setup window
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_DisplayMode current; SDL_DisplayMode current;
SDL_GetCurrentDisplayMode(0, &current); SDL_GetCurrentDisplayMode(0, &current);
SDL_Window *window = SDL_CreateWindow("ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); SDL_Window *window = SDL_CreateWindow("ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
SDL_GLContext glcontext = SDL_GL_CreateContext(window); SDL_GLContext glcontext = SDL_GL_CreateContext(window);
gl3wInit(); gl3wInit();
// Setup ImGui binding // Setup ImGui binding
@@ -48,7 +48,7 @@ int main(int, char**)
ImVec4 clear_color = ImColor(114, 144, 154); ImVec4 clear_color = ImColor(114, 144, 154);
// Main loop // Main loop
bool done = false; bool done = false;
while (!done) while (!done)
{ {
SDL_Event event; SDL_Event event;
@@ -99,8 +99,8 @@ int main(int, char**)
// Cleanup // Cleanup
ImGui_ImplSdlGL3_Shutdown(); ImGui_ImplSdlGL3_Shutdown();
SDL_GL_DeleteContext(glcontext); SDL_GL_DeleteContext(glcontext);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }
+14 -14
View File
@@ -97,7 +97,7 @@ void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
static const char* ImGui_ImplSdl_GetClipboardText() static const char* ImGui_ImplSdl_GetClipboardText()
{ {
return SDL_GetClipboardText(); return SDL_GetClipboardText();
} }
static void ImGui_ImplSdl_SetClipboardText(const char* text) static void ImGui_ImplSdl_SetClipboardText(const char* text)
@@ -203,15 +203,15 @@ bool ImGui_ImplSdl_Init(SDL_Window *window)
io.KeyMap[ImGuiKey_X] = SDLK_x; io.KeyMap[ImGuiKey_X] = SDLK_x;
io.KeyMap[ImGuiKey_Y] = SDLK_y; io.KeyMap[ImGuiKey_Y] = SDLK_y;
io.KeyMap[ImGuiKey_Z] = SDLK_z; io.KeyMap[ImGuiKey_Z] = SDLK_z;
io.RenderDrawListsFn = ImGui_ImplSdl_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. io.RenderDrawListsFn = ImGui_ImplSdl_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
io.SetClipboardTextFn = ImGui_ImplSdl_SetClipboardText; io.SetClipboardTextFn = ImGui_ImplSdl_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplSdl_GetClipboardText; io.GetClipboardTextFn = ImGui_ImplSdl_GetClipboardText;
#ifdef _WIN32 #ifdef _WIN32
SDL_SysWMinfo wmInfo; SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version); SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo); SDL_GetWindowWMInfo(window, &wmInfo);
io.ImeWindowHandle = wmInfo.info.win.window; io.ImeWindowHandle = wmInfo.info.win.window;
#endif #endif
@@ -233,12 +233,12 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window)
// Setup display size (every frame to accommodate for window resizing) // Setup display size (every frame to accommodate for window resizing)
int w, h; int w, h;
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window, &w, &h);
io.DisplaySize = ImVec2((float)w, (float)h); io.DisplaySize = ImVec2((float)w, (float)h);
// Setup time step // 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;
@@ -247,13 +247,13 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window)
int mx, my; int mx, my;
Uint32 mouseMask = SDL_GetMouseState(&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
io.MousePos = ImVec2(-1,-1); io.MousePos = ImVec2(-1,-1);
io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0; io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0; io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false; g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
io.MouseWheel = g_MouseWheel; io.MouseWheel = g_MouseWheel;
+15 -15
View File
@@ -10,22 +10,22 @@
int main(int, char**) int main(int, char**)
{ {
// Setup SDL // Setup SDL
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{ {
printf("Error: %s\n", SDL_GetError()); printf("Error: %s\n", SDL_GetError());
return -1; return -1;
} }
// Setup window // Setup window
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_DisplayMode current; SDL_DisplayMode current;
SDL_GetCurrentDisplayMode(0, &current); SDL_GetCurrentDisplayMode(0, &current);
SDL_Window *window = SDL_CreateWindow("ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); SDL_Window *window = SDL_CreateWindow("ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
SDL_GLContext glcontext = SDL_GL_CreateContext(window); SDL_GLContext glcontext = SDL_GL_CreateContext(window);
// Setup ImGui binding // Setup ImGui binding
ImGui_ImplSdl_Init(window); ImGui_ImplSdl_Init(window);
@@ -45,7 +45,7 @@ int main(int, char**)
ImVec4 clear_color = ImColor(114, 144, 154); ImVec4 clear_color = ImColor(114, 144, 154);
// Main loop // Main loop
bool done = false; bool done = false;
while (!done) while (!done)
{ {
SDL_Event event; SDL_Event event;
@@ -96,8 +96,8 @@ int main(int, char**)
// Cleanup // Cleanup
ImGui_ImplSdl_Shutdown(); ImGui_ImplSdl_Shutdown();
SDL_GL_DeleteContext(glcontext); SDL_GL_DeleteContext(glcontext);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }