mirror of
https://github.com/ocornut/imgui.git
synced 2025-09-26 13:18:30 +00:00
Examples: made examples's main.cpp consistent with returning 1 on error.
This commit is contained in:
@@ -67,6 +67,7 @@ Other Changes:
|
|||||||
- Examples: SDL2+DirectX11: Try WARP software driver if hardware driver is
|
- Examples: SDL2+DirectX11: Try WARP software driver if hardware driver is
|
||||||
not available. (#5924, #5562)
|
not available. (#5924, #5562)
|
||||||
- Examples: SDL3+DirectX11: Added SDL3+DirectX11 example. (#8956, #8957) [@tomaz82]
|
- Examples: SDL3+DirectX11: Added SDL3+DirectX11 example. (#8956, #8957) [@tomaz82]
|
||||||
|
- Examples: made examples's main.cpp consistent with returning 1 on error.
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
|
@@ -39,7 +39,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
// From 2.0.18: Enable native IME.
|
||||||
@@ -54,7 +54,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SysWMinfo wmInfo;
|
SDL_SysWMinfo wmInfo;
|
||||||
|
@@ -51,7 +51,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail.
|
// Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail.
|
||||||
|
@@ -31,7 +31,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
// From 2.0.18: Enable native IME.
|
||||||
@@ -51,7 +51,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
|
@@ -36,7 +36,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decide GL+GLSL versions
|
// Decide GL+GLSL versions
|
||||||
@@ -85,14 +85,14 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
if (gl_context == nullptr)
|
if (gl_context == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
|
@@ -33,7 +33,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
// From 2.0.18: Enable native IME.
|
||||||
@@ -48,13 +48,13 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||||
if (renderer == nullptr)
|
if (renderer == nullptr)
|
||||||
{
|
{
|
||||||
SDL_Log("Error creating SDL_Renderer!");
|
SDL_Log("Error creating SDL_Renderer!");
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
//SDL_RendererInfo info;
|
//SDL_RendererInfo info;
|
||||||
//SDL_GetRendererInfo(renderer, &info);
|
//SDL_GetRendererInfo(renderer, &info);
|
||||||
|
@@ -349,7 +349,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
// From 2.0.18: Enable native IME.
|
||||||
@@ -364,7 +364,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVector<const char*> extensions;
|
ImVector<const char*> extensions;
|
||||||
|
@@ -34,7 +34,7 @@ int main(int, char**)
|
|||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
||||||
{
|
{
|
||||||
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup window
|
// Setup window
|
||||||
@@ -44,7 +44,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_PropertiesID props = SDL_GetWindowProperties(window);
|
SDL_PropertiesID props = SDL_GetWindowProperties(window);
|
||||||
@@ -54,7 +54,7 @@ int main(int, char**)
|
|||||||
if (!CreateDeviceD3D(hwnd))
|
if (!CreateDeviceD3D(hwnd))
|
||||||
{
|
{
|
||||||
CleanupDeviceD3D();
|
CleanupDeviceD3D();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
|
@@ -24,7 +24,7 @@ int main(int, char**)
|
|||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
||||||
{
|
{
|
||||||
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create SDL window graphics context
|
// Create SDL window graphics context
|
||||||
@@ -34,19 +34,19 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
SDL_ShowWindow(window);
|
SDL_ShowWindow(window);
|
||||||
|
|
||||||
// Create Metal device _before_ creating the view/layer
|
// Create Metal device _before_ creating the view/layer
|
||||||
id<MTLDevice> metalDevice = MTLCreateSystemDefaultDevice();
|
id<MTLDevice> metalDevice = MTLCreateSystemDefaultDevice();
|
||||||
if (!metalDevice)
|
if (!metalDevice)
|
||||||
{
|
{
|
||||||
printf("Error: failed to create Metal device.\n");
|
printf("Error: failed to create Metal device.\n");
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_MetalView view = SDL_Metal_CreateView(window);
|
SDL_MetalView view = SDL_Metal_CreateView(window);
|
||||||
CAMetalLayer* layer = (__bridge CAMetalLayer*)SDL_Metal_GetLayer(view);
|
CAMetalLayer* layer = (__bridge CAMetalLayer*)SDL_Metal_GetLayer(view);
|
||||||
@@ -128,7 +128,7 @@ int main(int, char**)
|
|||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
SDL_GetWindowSizeInPixels(window, &width, &height);
|
SDL_GetWindowSizeInPixels(window, &width, &height);
|
||||||
|
|
||||||
layer.drawableSize = CGSizeMake(width, height);
|
layer.drawableSize = CGSizeMake(width, height);
|
||||||
id<CAMetalDrawable> drawable = [layer nextDrawable];
|
id<CAMetalDrawable> drawable = [layer nextDrawable];
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ int main(int, char**)
|
|||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
||||||
{
|
{
|
||||||
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decide GL+GLSL versions
|
// Decide GL+GLSL versions
|
||||||
@@ -74,13 +74,13 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
if (gl_context == nullptr)
|
if (gl_context == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
|
@@ -31,7 +31,7 @@ int main(int, char**)
|
|||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
||||||
{
|
{
|
||||||
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create SDL window graphics context
|
// Create SDL window graphics context
|
||||||
@@ -41,7 +41,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
SDL_ShowWindow(window);
|
SDL_ShowWindow(window);
|
||||||
@@ -51,14 +51,14 @@ int main(int, char**)
|
|||||||
if (gpu_device == nullptr)
|
if (gpu_device == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateGPUDevice(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateGPUDevice(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Claim window for GPU Device
|
// Claim window for GPU Device
|
||||||
if (!SDL_ClaimWindowForGPUDevice(gpu_device, window))
|
if (!SDL_ClaimWindowForGPUDevice(gpu_device, window))
|
||||||
{
|
{
|
||||||
printf("Error: SDL_ClaimWindowForGPUDevice(): %s\n", SDL_GetError());
|
printf("Error: SDL_ClaimWindowForGPUDevice(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_SetGPUSwapchainParameters(gpu_device, window, SDL_GPU_SWAPCHAINCOMPOSITION_SDR, SDL_GPU_PRESENTMODE_VSYNC);
|
SDL_SetGPUSwapchainParameters(gpu_device, window, SDL_GPU_SWAPCHAINCOMPOSITION_SDR, SDL_GPU_PRESENTMODE_VSYNC);
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ int main(int, char**)
|
|||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
||||||
{
|
{
|
||||||
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create window with SDL_Renderer graphics context
|
// Create window with SDL_Renderer graphics context
|
||||||
@@ -38,14 +38,14 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr);
|
SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr);
|
||||||
SDL_SetRenderVSync(renderer, 1);
|
SDL_SetRenderVSync(renderer, 1);
|
||||||
if (renderer == nullptr)
|
if (renderer == nullptr)
|
||||||
{
|
{
|
||||||
SDL_Log("Error: SDL_CreateRenderer(): %s\n", SDL_GetError());
|
SDL_Log("Error: SDL_CreateRenderer(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
SDL_ShowWindow(window);
|
SDL_ShowWindow(window);
|
||||||
|
@@ -349,7 +349,7 @@ int main(int, char**)
|
|||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
|
||||||
{
|
{
|
||||||
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create window with Vulkan graphics context
|
// Create window with Vulkan graphics context
|
||||||
@@ -359,7 +359,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVector<const char*> extensions;
|
ImVector<const char*> extensions;
|
||||||
|
Reference in New Issue
Block a user