Skip to content
Snippets Groups Projects
Commit a8e88ae8 authored by Armin Co's avatar Armin Co
Browse files

Working playground with imgui.

GTK is broken at the moment.
parent f5142ff2
No related branches found
No related tags found
No related merge requests found
...@@ -7,3 +7,4 @@ ...@@ -7,3 +7,4 @@
[submodule "libs/cpp_starter_project"] [submodule "libs/cpp_starter_project"]
path = libs/cpp_starter_project path = libs/cpp_starter_project
url = https://github.com/armin-co/cpp_starter_project.git url = https://github.com/armin-co/cpp_starter_project.git
#
\ No newline at end of file
...@@ -12,13 +12,18 @@ option(release_type "Set the type of the releas (Debug/Release)." Release) ...@@ -12,13 +12,18 @@ option(release_type "Set the type of the releas (Debug/Release)." Release)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
## PkgConfig # PkgConfig
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
# On macOS some things are different ^^
if(APPLE)
link_directories(/usr/local/lib)
include_directories(/usr/local/include)
# @todo Check versions of glib etc. librarys. # This may be necessary on some systems.
# On Ubuntu 19.10 there are warnings which are not present in Ubuntu 18.04 message("ATTENTION: You probably have to export the PKG_CONFIG_PATH.")
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") message("For example: $ export PKG_CONFIG_PATH=\"/usr/local/lib:/usr/local/opt/zlib/lib/pkgconfig\"")
endif()
# Add qpong lib for core qpong functionality # Add qpong lib for core qpong functionality
......
# Specific settings for macOS
if(APPLE)
link_directories("/usr/local/lib")
message("ATTENTION: You probably have to export the PKG_CONFIG_PATH.")
message("For example: export PKG_CONFIG_PATH=\"/usr/local/lib:/usr/local/opt/zlib/lib/pkgconfig\"")
endif()
# Setup GTK configuration # Setup GTK configuration
pkg_check_modules(GTKMM gtkmm-3.0) pkg_check_modules(GTKMM gtkmm-3.0)
...@@ -15,11 +8,6 @@ link_directories(${GTKMM_LIBRARY_DIRS}) ...@@ -15,11 +8,6 @@ link_directories(${GTKMM_LIBRARY_DIRS})
include_directories(${GTKMM_INCLUDE_DIRS}) include_directories(${GTKMM_INCLUDE_DIRS})
include_directories(../qpong_core) include_directories(../qpong_core)
if(APPLE)
include_directories(/usr/local/include)
endif()
# create the application # create the application
add_executable( qpong.app add_executable( qpong.app
main.cpp main.cpp
...@@ -33,5 +21,6 @@ add_executable( qpong.app ...@@ -33,5 +21,6 @@ add_executable( qpong.app
target_link_libraries( qpong.app target_link_libraries( qpong.app
qpong_core qpong_core
${GTKMM_LIBRARIES} ${GTKMM_LIBRARIES}
fftw3
m # math m # math
) )
# Specific settings for macOS
add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_GL3W) # Define OpenGL loader for Dear ImGui
# Dear ImGui include dirs
include_directories(
../libs/imgui
../libs/imgui/examples
../libs/imgui/examples/libs/gl3w
)
# Main Dear ImGui src files.
set(
dear_im_gui_srcs
../libs/imgui/imgui.cpp
../libs/imgui/imgui_draw.cpp
../libs/imgui/imgui_widgets.cpp
)
# Impl files from Dear ImGui.
set(
dear_im_gui_impl_srcs
../libs/imgui/examples/imgui_impl_sdl.cpp
../libs/imgui/examples/imgui_impl_opengl3.cpp
)
# Dear ImGui lib
add_library(
dear_im_gui
${dear_im_gui_srcs}
${dear_im_gui_impl_srcs}
../libs/imgui/examples/libs/gl3w/GL/gl3w.c
)
# Application base on Dear ImGui
add_executable(
imgui_playground.app
imgui_playground.cpp
)
# Add all SDL2 dependencies.
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
# Link everything together
target_link_libraries(
imgui_playground.app
dear_im_gui
${SDL2_LIBRARIES}
qpong_core
)
# Include macOS specific things.
if(APPLE) if(APPLE)
link_directories("/usr/local/lib") find_library(COCOA_LIBRARY Cocoa REQUIRED)
message("ATTENTION: You probably have to export the PKG_CONFIG_PATH.") find_library(IOKIT_LIBRARY IOKit REQUIRED)
message("For example: export PKG_CONFIG_PATH=\"/usr/local/lib:/usr/local/opt/zlib/lib/pkgconfig\"") find_library(COREVID_LIBRARY CoreVideo REQUIRED)
message(${COCOA_LIBRARY})
message(${IOKIT_LIBRARY})
message(${COREVID_LIBRARY})
target_link_libraries(
imgui_playground.app
${COCOA_LIBRARY}
${IOKIT_LIBRARY}
${COREVID_LIBRARY}
)
else(APPLE)
find_package(OpenGL REQUIRED)
target_link_libraries(imgui_playground.app OpenGL::GL ${CMAKE_DL_LIBS})
endif() endif()
add_executable(imgui_playground.app
imgui_playground.cpp)
\ No newline at end of file
...@@ -3,9 +3,138 @@ ...@@ -3,9 +3,138 @@
/// @brief Working example for Dear ImGui with OpenGL3 and SDL2 /// @brief Working example for Dear ImGui with OpenGL3 and SDL2
/// ///
#include "imgui.h"
#include "imgui_impl_sdl.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <SDL.h>
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
#include <GL/gl3w.h>
#endif
int main(void) int main(void)
{ {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
{
printf("Error: %s\n", SDL_GetError());
return -1;
}
// Decide GL+GLSL versions
#if __APPLE__
// GL 3.2 Core + GLSL 150
const char* glsl_version = "#version 150";
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#else
// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif
// Create window with graphics context
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
// Initialize OpenGL loader
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
bool err = gl3wInit() != 0;
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
bool err = glewInit() != GLEW_OK;
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
bool err = gladLoadGL() == 0;
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
bool err = false;
glbinding::Binding::initialize();
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
bool err = false;
glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)SDL_GL_GetProcAddress(name); });
#else
bool err = false; // If you use IMGUI_IMPL_OPENGL_LOADER_CUSTOM, your loader is likely to requires some form of initialization.
#endif
if (err)
{
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
return 1;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
ImGui_ImplOpenGL3_Init(glsl_version);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
bool done = false;
while (!done)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_QUIT)
done = true;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
done = true;
}
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();
{
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
}
// Rendering
ImGui::Render();
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(window);
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_GL_DeleteContext(gl_context);
SDL_DestroyWindow(window);
SDL_Quit();
return 0; return 0;
} }
\ No newline at end of file
# Add macOS specific include path.
if(APPLE)
include_directories(/usr/local/include)
endif()
# Core QPong library # Core QPong library
add_library(qpong_core Particle.cpp ImageBuffer.cpp Player.cpp) add_library(
qpong_core
Particle.cpp
ImageBuffer.cpp
Player.cpp
)
find_package(Threads) find_package(Threads)
target_link_libraries( qpong_core target_link_libraries(
qpong_core
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
fftw3 fftw3
fftw3_omp fftw3_omp
m
) )
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment