ABRG-Models / morphologica

A library of supporting code for numerical modelling (JSON config, HDF5 data, Modern OpenGL visualization)
https://abrg-models.github.io/morphologica/
Apache License 2.0
256 stars 29 forks source link

<GL3/gl3.h>in windows #44

Closed niclar closed 2 weeks ago

niclar commented 2 years ago

does not exist. Can the occurrences be replaced by i.e;

#ifndef USE_GLEW
#ifdef __OSX__
# include <OpenGL/gl3.h>
#elif _WIN32
# include <glad/glad.h>
# include <GLFW/glfw3.h>
#else
# include <GL3/gl3.h>
#endif
#endif

win32_opengl3_path.patch.txt

sebjameswml commented 2 years ago

I'm happy to make a change along these lines, but I think I should test in my Windows build first.

niclar commented 2 years ago

FYI at least the scatter visual works just fine with the proposed changes

sebjameswml commented 2 years ago

Ok, thanks for the test. The code as it stands must have worked for me on my Windows setup, but I'm not quite sure where my GL was installed or whether I had to install the library glad.

You can combine ScatterVisual and TriaxesVisual to make nice 3D scatter plots with axes. See this program for example code:

https://github.com/sebjameswml/RetinoTectal/blob/master/sim/agent/anneal1read.cpp#L236

sebjameswml commented 2 years ago

Your suggested code includes GLFW headers in a piece of code which only makes use of GL code, so it works because GLFW (or glad) brings in the GL headers, but I don't think it's the best way to solve the problem you had. GLFW is #included in VisualResources.h and Visual.h as that's where the glfw calls are made.

The way that I have a complete copy of the GL headers in the morphologica code is itself a bit strange - it would be better to have these headers installed by the operating system's package manager (so that they'd be guaranteed to match the binary implementation of GL being run on the GPU). In fact, on a Mac, we #include OpenGL/gl3.h which is installed by Apple and so it was only for Linux (and I guess Windows) that I needed the in-tree copy of the GL headers. I should take a look at some other good cross-platform GL projects to see how they deal with this.

niclar commented 2 years ago

I use vcpkg to handle all thirdparty dependencies cross platform. Made a working morphologica port (all dependecies, build and install) I can contribute.

sebjameswml commented 2 years ago

Nanogui uses a special opengl header to bring in its gl headers: https://github.com/wjakob/nanogui/blob/master/include/nanogui/opengl.h

niclar commented 2 years ago

Yeah having the include workarounds in a separate header is nicer

niclar commented 2 years ago

Thanks for the TriaxesVisual tip! I'll try it out when I get there

sebjameswml commented 2 years ago

I must make up a new ScatterVisual + TriaxesVisual example - I coded TriaxesVisual to help show the result of a simulated annealing parameter search (visualising 3 of the parameter space dimensions at a time, with scatter blob size/colour indicating the value of the objective function).

Regarding contributions - please go ahead and fork morphologica and make any pull requests you think should be included. I'm not yet sure about the GL include thing - I don't really like the idea of a separate include header for opengl, because that is yet another thing that a coder has to delve into to understand a file that it is used in.

sebjameswml commented 2 years ago

I see you suggested use of glad.h. That's a header that you kind of generate for a project and is an alternative to using GLEW, which is an option in the cmake build process for morphologica. Use of glad could be offered within the CMakeLists.txt of morphologica something like this: https://github.com/Dav1dde/glad/issues/186

sebjameswml commented 2 years ago

It's also worth noting that if you were compiling with an 'in tree' morphologica, then your compile process would have been able to find include/GL3 from the morphologica/include, but I have omitted to have the morphologica install process actually install GL3.

sebjameswml commented 2 weeks ago

I think this is stale, since I updated the way gl headers are used. It's possible to do your own thing with headers and visual.h etc will respect it. Closing this ticket.