Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUIで動かしたい #2

Closed
guri3 opened this issue Jul 10, 2021 · 7 comments · Fixed by #7
Closed

GUIで動かしたい #2

guri3 opened this issue Jul 10, 2021 · 7 comments · Fixed by #7

Comments

@guri3
Copy link
Owner

guri3 commented Jul 10, 2021

No description provided.

@guri3
Copy link
Owner Author

guri3 commented Jul 31, 2021

https://github.com/oprypin/crystal-imgui を試してみる

crystal-imgui-sfml のインストール手順に従うのが良さそう

https://github.com/oprypin/crystal-imgui-sfml のサンプルが動いた

スクリーンショット 2021-07-31 23 27 29

@guri3 guri3 mentioned this issue May 2, 2022
@guri3
Copy link
Owner Author

guri3 commented May 3, 2022

以前と同様に crystal-imgui-sfml を動かそうとするとエラーが発生した

❯❯❯ ./simple
Failed to open X11 display; make sure the DISPLAY environment variable is set correctly
zsh: abort      ./simple

Windows 側でソフトのインストールが必要
https://dev.classmethod.jp/articles/wsl-x-window/

上記記事のとおりにソフトをインストール・設定することで WSL から Windows で GUI を表示することができるようになった

@guri3
Copy link
Owner Author

guri3 commented May 3, 2022

nes.cr を以下のように書き換えて動作確認を行ったところエラーになった

require "./nes/emu"
require "crsfml"
require "imgui"
require "imgui-sfml"

# nes_file = File.new("roms/hello.nes")
# buf = Bytes.new(nes_file.size)
# nes_file.read(buf)
# emu = Emu.new(buf)
# emu.run

エラー内容

❯❯❯ make run
crystal run src/nes.cr
/usr/bin/ld: cannot find -lcimgui (this usually means you need to install the development package for libcimgui)
collect2: error: ld returned 1 exit status

lib/imgui-sfml 内に libcimgui.so があるかつ LD_LIBRARY_PATH を設定していてもエラーとなってしまう

@guri3
Copy link
Owner Author

guri3 commented May 3, 2022

require を一つずつ確認していくと、require "imgui" でエラーが発生していることが分かった

https://github.com/oprypin/crystal-imgui の通りにコンパイル・環境変数の設定を行ったところエラーが発生しなくなった

@guri3
Copy link
Owner Author

guri3 commented May 3, 2022

サンプルを参考に、以下のコードを実装して make run した

require "./nes/emu"
require "crsfml"
require "imgui"
require "imgui-sfml"

window = SF::RenderWindow.new(SF::VideoMode.new(256, 240), "nes.cr")
window.framerate_limit = 60
ImGui::SFML.init(window)

すると、以下のようなエラーが発生した

symbol lookup error: /home/daiki/.cache/crystal/crystal-run-nes.tmp: undefined symbol: ImGui_SFML_InitW

雑にググったところこちらのスレッドが見つかった
https://www.reddit.com/r/crystal_programming/comments/j0v2s1/crystal_bindings_to_dear_imgui_an_immediatemode/

imgui-sfml の方が意図したライブラリを参照できていないっぽい
なので、環境変数の方に imgui-sfml の方で作られた libcimgui.so も含まれるようにした

export LD_LIBRARY_PATH="$(pwd)/lib/imgui-sfml;$(pwd)/lib/imgui/cimgui"

すると、make run すると一瞬ウィンドウが表示されて消えるような動作をするようになった
ターミナルの出力は以下

❯❯❯ make run
crystal run src/nes.cr
NVD3D10: CPU cyclestats are disabled on client virtualization
NVD3D10: CPU cyclestats are disabled on client virtualization
Failed to get GLXFBConfig which corresponds to the window's visual
Failed to get GLXFBConfig which corresponds to the window's visual
Setting vertical sync not supported

@guri3
Copy link
Owner Author

guri3 commented May 3, 2022

このサンプル丸パクリで実行してみたら Window が表示された
https://github.com/oprypin/crystal-imgui-sfml/blob/master/examples/simple.cr

なので、後はライブラリのAPIの使い方を読みつつ実装していけばよさそう

@guri3
Copy link
Owner Author

guri3 commented May 5, 2022

というか、ドットを表示するだけならとりあえず crsfml だけ入れればよかった

@guri3 guri3 closed this as completed in #7 May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant