git.haldean.org ana / e227f5b
start integrating imgui Haldean Brown 1 year, 9 months ago
3 changed file(s) with 53 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
55 find_package(SDL2 REQUIRED)
66 find_package(GLEW REQUIRED)
77
8 set(CMAKE_CXX_FLAGS "-Wall -Werror")
8 set(CMAKE_CXX_FLAGS "-Wall -Werror -DIMGUI_IMPL_OPENGL_LOADER_GLEW")
99
10 include_directories(lib)
10 include_directories(lib/imgui lib/imgui/examples SDL2::SDL2)
1111
1212 add_executable(ana
1313 src/ana.cpp
1414 src/node.cpp
1515 src/shaders.cpp
1616 src/ui.cpp
17 lib/imgui/imgui.cpp
18 lib/imgui/imgui_demo.cpp
19 lib/imgui/imgui_draw.cpp
20 lib/imgui/imgui_widgets.cpp
21 lib/imgui/examples/imgui_impl_sdl.cpp
22 lib/imgui/examples/imgui_impl_opengl3.cpp
1723 )
1824
19 target_link_libraries(ana glm SDL2 GLEW GL)
25 target_link_libraries(ana ${GLM_LIBRARIES} SDL2::SDL2 ${GLEW_LIBRARIES} GL)
0 cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
1 cmake_policy(VERSION 3.7)
2 project(ana VERSION 0.1.0 LANGUAGES CXX)
3
4 find_package(glm REQUIRED)
5 find_package(SDL2 REQUIRED)
6 find_package(GLEW REQUIRED)
7
8 set(CMAKE_CXX_FLAGS "-Wall -Werror -DIMGUI_IMPL_OPENGL_LOADER_GLEW")
9
10 include_directories(lib/imgui lib/imgui/examples SDL2::SDL2)
11
12 add_executable(ana
13 src/ana.cpp
14 src/node.cpp
15 src/shaders.cpp
16 src/ui.cpp
17 lib/imgui/imgui.cpp
18 lib/imgui/imgui_demo.cpp
19 lib/imgui/imgui_draw.cpp
20 lib/imgui/imgui_widgets.cpp
21 lib/imgui/examples/imgui_impl_sdl.cpp
22 lib/imgui/examples/imgui_impl_opengl3.cpp
23 )
24
25 target_link_libraries(ana ${GLM_LIBRARIES} SDL2::SDL2 ${GLEW_LIBRARIES} GL)
33
44 #include <GL/glew.h>
55 #include <SDL2/SDL.h>
6
7 #include "imgui.h"
8 #include "imgui_impl_opengl3.h"
9 #include "imgui_impl_sdl.h"
610
711 #include "node.hpp"
812 #include "shaders.hpp"
2226 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
2327 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
2428 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1);
25 if (SDL_GL_CreateContext(window) == NULL) {
29 SDL_GLContext context = SDL_GL_CreateContext(window);
30 if (context == NULL) {
2631 std::cerr << "[E] SDL_GL_CreateContext: " << SDL_GetError() << std::endl;
2732 return EXIT_FAILURE;
2833 }
4550
4651 ana::ui ui;
4752
53 ImGui::CreateContext();
54 ImGuiIO &io = ImGui::GetIO();
55 ImGui_ImplOpenGL3_Init("#version 420");
56 ImGui_ImplSDL2_InitForOpenGL(window, context);
57
4858 bool run = true;
4959 while (run) {
60 ImGui_ImplOpenGL3_NewFrame();
61 ImGui_ImplSDL2_NewFrame(window);
5062 SDL_Event ev;
5163 while (SDL_PollEvent(&ev)) {
64 ImGui_ImplSDL2_ProcessEvent(&ev);
5265 switch (ev.type) {
5366 case SDL_QUIT:
5467 run = false;
6275 break;
6376
6477 case SDL_MOUSEWHEEL:
65 if (ev.wheel.y != 0) {
78 if (!io.WantCaptureMouse && ev.wheel.y != 0) {
6679 ui.view_step(ev.wheel.y);
6780 }
6881 break;
6982
7083 case SDL_MOUSEMOTION:
71 if (ev.motion.state & SDL_BUTTON_MMASK) {
84 if (!io.WantCaptureMouse && ev.motion.state & SDL_BUTTON_MMASK) {
7285 ui.translate(-ev.motion.xrel, ev.motion.yrel);
7386 }
7487 break;
8396 }
8497
8598 ana::shaders::destroy();
99 ImGui_ImplOpenGL3_Shutdown();
100 ImGui_ImplSDL2_Shutdown();
86101 return EXIT_SUCCESS;
87102 }