I am trying to work on a project in OpenGL in which I want to make an animated complex-valued function plotter. Basically, I am trying to do the animation illustrated in the topmost image of this page:


This means that I will need to tranform each vertex of my complex plane, and the way I tranform each vertex depends on the given function. Morevoer, this function is user-defined and is not known to the program.

Now, initially I had thought of passing a function pointer to the vertex shader but I just learned that it cannot be done (Till now, I had only worked in OpenGL 2.0. This is my first Advanced OpenGL project). How else can I do it?

  • \$\begingroup\$ Two possibilities come to mind: 1) generate your vertex shader as text, injecting a string representing the function you want evaluated, and then compile this dynamically generated source code. 2) CPU-side, run the custom function to generate points which you store as pixels in a texture, and then read this information in your shader as a vertex texture. Neither these techniques nor this problem are unique to games though, so you might consider asking on a general computer graphics site instead. \$\endgroup\$
    – DMGregory
    Dec 22, 2016 at 1:15
  • \$\begingroup\$ @DMGregory , thanks for the suggestions! I was working on the first possibility so far, but it's not very convenient as I lose out on the robustness of using std::complex functions. As per your suggestion, I will flag this question for a moderator to move. \$\endgroup\$ Dec 22, 2016 at 1:22


You must log in to answer this question.

Browse other questions tagged .