LoginSignup
6
5

More than 5 years have passed since last update.

imguiのサンプルを動かす

Last updated at Posted at 2016-09-29

imgui
alt

環境

Windows7
Visual Studio 2012
imgui 1.50
GLFW 3.2.1
CMake 3.6.2

準備

release から該当のバージョンをダウンロード

動かしてみる

opengl2_example を動かしてみる。
opengl3_example を動かそうとしたらダメそうだったのでやめた。

自分でプロジェクトを用意

下記のように配置。
imgui以下がimguiの本体でそれ以外はサンプルの実装ファイル。

.
├─libs
│  │  glfw3.lib                        # GLFW-3.2.1.bin.WIN32/lib-vc2012から
│  │
│  └─include                           # imgui/examples/libs/以下から適切に配置
│      ├─GL
│      │      gl3w.c
│      │      gl3w.h
│      │      glcorearb.h
│      │
│      └─GLFW
│              glfw3.h
│              glfw3native.h
│
└─src                                  # imgui/examples/opengl2_exapmplesから適切に配置
    │  imgui_impl_glfw.cpp
    │  imgui_impl_glfw.h
    │  main.cpp
    │
    └─imgui
            imconfig.h
            imgui.cpp
            imgui.h
            imgui_demo.cpp
            imgui_draw.cpp
            imgui_internal.h
            stb_rect_pack.h
            stb_textedit.h
            stb_truetype.h

サンプルの通りにVisualStudioの設定を変更。

  • プロジェクトのプロパティ > 構成プロパティ > C/C++
    • 追加のインクルードディレクトリ
      src;src/imgui;libs/include;
  • プロジェクトのプロパティ > 構成プロパティ > リンカー
    • 追加のライブラリディレクトリ
      libs;
    • 入力
      • 追加の依存ファイル
        opengl32.lib;glfw3.lib;
      • 特定の規定のライブラリの無視
        MSVCRT.lib;

ビルド

ビルドしてみたら失敗する。

1>glfw3.lib(monitor.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(vulkan.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(wgl_context.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(egl_context.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(win32_init.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(win32_monitor.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(window.c.obj) : error LNK2019: 未解決の外部シンボル __imp__calloc が関数 _glfwCreateWindow で参照されました。
1>glfw3.lib(input.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(win32_window.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(win32_joystick.c.obj) : error LNK2001: 外部シンボル "__imp__calloc" は未解決です。
1>glfw3.lib(win32_window.c.obj) : error LNK2019: 未解決の外部シンボル __imp___strdup が関数 __glfwPlatformGetRequiredInstanceExtensions で参照されました。
1>glfw3.lib(win32_joystick.c.obj) : error LNK2001: 外部シンボル "__imp___strdup" は未解決です。
1>glfw3.lib(monitor.c.obj) : error LNK2001: 外部シンボル "__imp___strdup" は未解決です。
1>glfw3.lib(win32_monitor.c.obj) : error LNK2019: 未解決の外部シンボル __imp__realloc が関数 __glfwPlatformGetMonitors で参照されました。

検索したら、どうも設定がよくないらしい。
http://stackoverflow.com/questions/29556290/random-unresolved-external-symbols-that-shouldnt-be-there

GLFWのビルド済みのバイナリ(glfw3.lib)はデフォルトでは「マルチスレッドDLL(/MD)」になっているらしく、
opengl2_exampleの設定も同様になっていた。
プロジェクトの設定を以下のように変更。

  • プロジェクトのプロパティ > 構成プロパティ > C/C++ > コード生成 > ランタイムライブラリ
    マルチスレッド DLL(/MD)

ビルドできた。

マルチスレッド(/MT)でGLFWを使用したい場合

GLFWをマルチスレッド設定でビルドする。

こんな感じに配置

glfw-3.2.1                # ダウンロードしたGLFWのソースコード
├─.github
├─CMake
├─cmake-3.6.2-win32-x86   # ダウンロードしたcmakeのバイナリをそのまま配置
├─deps
├─docs
├─examples
├─include
├─src
└─tests

cmakeを実行するとソリューションファイルが作成される。

glfw-3.2.1>cmake-3.6.2-win32-x86\bin\cmake.exe CMakeLists.txt

ソリューションファイルを開いて、GLFWプロジェクトの設定を以下のように変更。

  • プロジェクトのプロパティ > 構成プロパティ > C/C++ > コード生成 > ランタイムライブラリ
    マルチスレッド(/MT)

ビルドしてできた glfw3.lib をimguiのサンプルでリンクするように変更。(libs/glfw3.libを上書きするだけ)

実行

imgui.png

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5