KJ7LNW / xnec2c

Xnec2c is a high-performance multi-threaded electromagnetic simulation package to model antenna near- and far-field radiation patterns for Linux and UNIX operating systems.
https://www.xnec2c.org/
GNU General Public License v3.0
78 stars 17 forks source link

OpenGL Support #23

Open KJ7LNW opened 1 year ago

KJ7LNW commented 1 year ago

HELP WANTED

Would you like to volunteer to help with OpenGL support to xnec2c? Read on:

This first-pass implementation partially renders antenna patterns in OpenGL. Hurray! While the OpenGL work has been started, it needs some polish (ahem, quite a bit of polish)...plus, this is a feature that the original xnec2c author, Neoklis 5B4AZ, has always wanted.

-Eric, KJ7LNW

GOALS!

Getting Started

git clone https://github.com/KJ7LNW/xnec2c.git
cd xnec2c
git checkout opengl
./autogen.sh
./configure
make
./src/xnec2c -j4 examples/airplane.nec

Once it loads:

Development Considerations

There is a work-in-progress branch for OpenGL support using CGLM which you can see in this commit comparison: https://github.com/KJ7LNW/xnec2c/compare/master...opengl . The branch is here: https://github.com/KJ7LNW/xnec2c/tree/opengl

If you would prefer to start fresh then I'm okay with that, the opengl branch is here as a reference in case it is useful. Ultimately your new branch would replace this current opengl branch and ultimately get merged into master.

  1. A new opengl.c and .h file should be created to store code for:
    • camera
    • arcball
    • vertex generation from NEC2 structures (from rad_pattern, see how rdpat_points or point_3d is created for colorization in Draw_Radiation_Pattern, but do it in a more "opengl-friendly way").
    • GTK UI hooks for pan/scale/rotate
    • other GL stuff
  2. A function from opengl.c for generating radition pattern vertexes should be hooked into src/draw_radiation.c:Draw_Radiation_Pattern().
    • Currently that logic is hard-coded into Draw_Radiation_Pattern() but that was just a convenient place to put it while testing. See the commits to understand what changed.
    • Right now the OpenGL data vertex structure is updated every time it is redrawn. This is unnecessary for OpenGL because the video card will handle it. The structure should be regenerated only when the frequency data is recalculated (like when the select frequency is changed).
  3. The current triangle creation logic isn't quite right and the radiation pattern isn't so clean. Note that theta is the azimuth and theta=0 is pointing in the direction of Z+! This is just how NEC2 was designed back in 1981...
  4. The configure.ac file should detect OpenGL libraries and link them as necessary. Some of this has been done already.
  5. CGLM should be a git submodule if it is not already
    • If you prefer a different vector/matrix math library vs CGLM then I'm open to it; it looked like CGLM was a good place to start since xnec2c is written in C, not in C++.
  6. Maintain shader version 1.20 support for older distributions, right now we don't need anything fancy.
  7. To the extent possible, widgets should be maintained as GTK Builder objects and expressed as XML in resources/xnec2c.glade. However, it might be easier to open-code as a first pass with gtk API calls and refactor into XML later.
  8. Rebase on the master branch
  9. Try to follow Linux Kernel commit practices and coding style for new code.

References

jerryd commented 1 year ago

I was thinking about doing some work to convert to GTK4. Has anyone considered doing this? KF7RCC

KJ7LNW commented 1 year ago

Generally speaking, we want to support deployment on any system that is still supported under long-term support by the distribution vendor. For example Oracle Linux 8 is supported until 2029, and it runs GTK 3. That means we cannot cut over to GTK 4 without backwards compatibility support.

If there are GTK4 features that would be nice to add, then that would be great, however they need to be detected by Autoconf in configure.ac and appropriate #ifdef checks need to be placed in the code so that it will still compile on older distributions.