MCPcopy Create free account
hub / github.com/dfranx/ImFileDialog / main

Function main

example.cpp:24–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22#undef main
23
24int main(int argc, char* argv[])
25{
26 bool run = true;
27 srand(time(NULL));
28
29 // init sdl2
30 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0) {
31 printf("Failed to initialize SDL2\n");
32 return 0;
33 }
34
35 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
36 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
37 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
38 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
39 Uint32 windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
40
41 // create the window
42 int wndWidth = 1200, wndHeight = 800;
43 SDL_Window* wnd = SDL_CreateWindow("File Dialog", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, wndWidth, wndHeight, windowFlags);
44
45 // create the GL context
46 SDL_GLContext glContext = SDL_GL_CreateContext(wnd);
47 SDL_GL_MakeCurrent(wnd, glContext);
48 glEnable(GL_DEPTH_TEST);
49 glEnable(GL_STENCIL_TEST);
50
51 // init glew
52 glewExperimental = true;
53 if (glewInit() != GLEW_OK) {
54 printf("Failed to initialize GLEW\n");
55 return 0;
56 }
57
58 // imgui
59 ImGui::CreateContext();
60 ImGuiIO& io = ImGui::GetIO(); (void)io;
61 ImGui::StyleColorsLight();
62
63 ImGui_ImplSDL2_InitForOpenGL(wnd, glContext);
64 ImGui_ImplOpenGL3_Init();
65
66 // ImFileDialog requires you to set the CreateTexture and DeleteTexture
67 ifd::FileDialog::Instance().CreateTexture = [](uint8_t* data, int w, int h, char fmt) -> void* {
68 GLuint tex;
69
70 glGenTextures(1, &tex);
71 glBindTexture(GL_TEXTURE_2D, tex);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
75 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
76 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, (fmt == 0) ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, data);
77 glGenerateMipmap(GL_TEXTURE_2D);
78 glBindTexture(GL_TEXTURE_2D, 0);
79
80 return (void*)tex;
81 };

Callers

nothing calls this directly

Calls 5

OpenMethod · 0.80
SaveMethod · 0.80
IsDoneMethod · 0.80
HasResultMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected