markaren / threepp

C++20 port of three.js (r129)
MIT License
628 stars 59 forks source link

Easiest way to compile a single example #277

Closed Choons closed 1 month ago

Choons commented 1 month ago

Hi, I just discovered threepp and am fascinated by it. I've been a three.js user for quite a while and always found mrdoob's approach intuitive, but it always kind of bugged me to be at the mercy of a browser and server to use it. I'm pretty much a noob at C++ though I took it in college pre-Y2K, long before cmake etc. My question is: what is the simplest way to just compile a single custom example? For instance, if I copy the demo example code into my own file and try some different things, I assume just using g++ and outputting to my own experiments directory is easiest? Do I need to compile against --libs or other cflags? OR is there a cmake file for that I'm just not seeing? Thanks.

markaren commented 1 month ago

The test folder contains a standalone example project (which uses CMake fetchContent to download threepp automatically from GitHub)

https://github.com/markaren/threepp/tree/master/tests/threepp_fetchcontent_test

Edit this project as you wish and build using CMake (copy out of the threepp project)

cmake . -B build -DCMAKE_BUILD_TYPE="Release"
cmake --build build

As long as #251 remains an issue, you probably need to add

set(THREEPP_USE_EXTERNAL_GLFW ON)

before FetchContent_Declare in the CMakeList on linux

asmwarrior commented 1 month ago

Maybe in the future, we can create a github action to automatically generate some demo programs(for example, if users are using Windows, I can build the whole Code::Blocks IDE under github action under msys2 shell, see here: asmwarrior/x86-codeblocks-builds: Automatically built codeblocks for both 32b and 64b Windows systems.). So, users can directly download the full binary demo package (which include all the demo exe files and dependency dll files), and run the demo code in their own PC.

Choons commented 1 month ago

OK, thanks for the replies. I did successfully build threepp and all the demos with the code Mark suggested, but isn't it a bit time-consuming to rebuild everything every time? I'd rather just compile the file I am working on. If I create myhelloworld.cpp, how can I compile only that file? I'm on Ubuntu, and a simple g++ call would be preferable, but I need to know the necessary flags, libs, etc. to compile against.

markaren commented 1 month ago

I really think the threepp_fetchcontent_test project is what you are looking for. You build threepp once (happens automatically), then after that you only build your own file. Of course, once you have built threepp statically (which should be by default, you could just link against that and pass the include folder. The only flag you need is probably c++20. If you use external glfw, you need to link that as well.

Not using CMake is inviting pain in my opinion. Again, the demo project is painless and smooth.

Choons commented 1 month ago

OK thanks. I'll look at that fetchcontent approach.

Edit: OK I got that threepp_demo working by:

cd into: threepp/tests/threepp_fetchcontent_test cmake -S . -B build -DTHREEPP_USE_EXTERNAL_GLFW=ON cmake --build build

I noticed it built the entire threepp package again in that directory, so now I have double the amount of code on disk, but I was able to modify and recompile the demo successfully.

markaren commented 1 month ago

I noticed it built the entire threepp package again in that directory, so now I have double the amount of code on disk, but I was able to modify and recompile the demo successfully.

Yes fetchcontent does a git clone of the requested library, builds it and keeps a cache in the build directory.