仮想計算機構

IT業界と無縁な派遣社員のブログ

Windows で tinyrenderer を動かしてみる

はじめに


ライブラリに依存しないTiny(小さい)Rendererです。tinyrendererの存在意義としては作者の下記の言葉がすべてかと思います。

In this series of articles, I want to show the way OpenGL works by writing its clone (a much simplified one). Surprisingly enough, I often meet people who cannot overcome the initial hurdle of learning OpenGL / DirectX. Thus, I have prepared a short series of lectures, after which my students show quite good renderers.

OpenGLとかDirectXってハードル高いから、クローンを自分で書いて理解しようというコンセプトのようです。面白そうなので自分の環境で動くのかどうか試してみます。

環境

ビルド

READMEに書いてあるとおりに実行していきます。

git clone https://github.com/ssloy/tinyrenderer.git
cd tinyrenderer
mkdir build
cd build

次にcmakeを使うのですが、筆者の環境ですと下記のとおりVisual Studioに対してビルドされてしまいます。

cmake ..

-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19044.
-- The C compiler identification is MSVC 19.28.29336.0
-- The CXX compiler identification is MSVC 19.28.29336.0
(以下省略)

この場合、buildディレクトリ配下には下記のファイルが作成されます。

CMakeFiles
ALL_BUILD.vcxproj
ALL_BUILD.vcxproj.filters
CMakeCache.txt
cmake_install.cmake
tinyrenderer.sln
tinyrenderer.vcxproj
tinyrenderer.vcxproj.filters
ZERO_CHECK.vcxproj
ZERO_CHECK.vcxproj.filters

やりたいこととは違う結果になっているのでbuild配下のファイルはいったんすべて削除します。筆者の環境ではMinGWをインストール済みなので、下記の文言を加えて実行します。

cmake -G "MinGW Makefiles" ..

-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
(以下省略)

最後の仕上げです。

cmake --build . -j

[ 16%] Building CXX object CMakeFiles/tinyrenderer.dir/geometry.cpp.obj
[ 33%] Building CXX object CMakeFiles/tinyrenderer.dir/main.cpp.obj
[ 50%] Building CXX object CMakeFiles/tinyrenderer.dir/model.cpp.obj[ 66%]
Building CXX object CMakeFiles/tinyrenderer.dir/our_gl.cpp.obj
[ 83%] Building CXX object CMakeFiles/tinyrenderer.dir/tgaimage.cpp.obj
[100%] Linking CXX executable tinyrenderer.exe
[100%] Built target tinyrenderer

これで準備は整いました。最後はサンプルを動かしてみます。

./tinyrenderer ../obj/diablo3_pose/diablo3_pose.obj ../obj/floor.obj

# v# 2519 f# 5022 vt# 3263 vn# 2519
texture file ../obj/diablo3_pose/diablo3_pose_diffuse.tga loading 1024x1024/24
ok
texture file ../obj/diablo3_pose/diablo3_pose_nm_tangent.tga loading 1024x1024/24
ok
texture file ../obj/diablo3_pose/diablo3_pose_spec.tga loading 1024x1024/24
ok
# v# 4 f# 2 vt# 4 vn# 1
texture file ../obj/floor_diffuse.tga loading 600x600/32
ok
texture file ../obj/floor_nm_tangent.tga loading 512x512/24
ok
texture file ../obj/floor_spec.tga loading can't open file ../obj/floor_spec.tga
failed

最後だけfailed(失敗)と表示されています。プログラムは動いているようですが、実行結果の画像がTGA形式という珍しいデータなので開くのに失敗しているようです。筆者の環境だと LibreOffice というソフトウェアでかろうじてTGAファイルを開くことができました。githubwiki には Lesson がたくさんあるようなので、勉強にはちょうどよさそうです。