Scientific plotting in opengl


I would like to use a high level plotting library within my opengl application. I believe this is a fairly well covered topic however I am new to opengl and did some research about it, however I could not find any “straightforward” solution. It could be because I am missing even the most basic pointers about opengl.

I am working in a framework that provides me with tabs to create custom visualizations :

While I have access to some implementation details, I would like to stick to the framework and use it as intended : Simply write my visualization code in the callback function I am supposed to modify :

void Visualization::visuCallback(inputArg info_) //inputArg contains infos like width, height and want I believe to be a void* to an opengl context
    // example code





I would typically need to plot 2d points and other classic scientific graph things.
it seems to be quite a pain to do that directly in opengl. I usually do my plots in matlab but really any c++ library would work for me, as long as it is very high level, quick and easy to use (Pyhton / matlab -like api for instance).
My main problem is to make whatever library used plot in the opengl window.

Do you have pointers about how to achieve that, or how this is typically done ?


I guess if you are stuck with those basic callbacks, you can just make a big list of your data and iterate through it while drawing whatever it is you need.

Maybe something like:

     for each triangle {
         // drawing canvas geometry

     for each line {
         // drawing grid on top of canvas geometry

     for each point {
        // drawing points on top of grid and canvas

You might need to add glEnd() at the end of each drawing, I don’t remember.


Thanks for your answer :).

We could indeed just use the opengl API directly to do all our scientific plotting, but that sounds quite cumbersome to us. And I am afraid the result wouldn’t look professional without massive amount of work.
I think we’ll try to use whatever library that can output to bitmap and display this bitmap through the opengl API. I don’t know how suitable this is for real time (roughly 2 to 10 hz) display.
And we still don’t know how we can create a more advanced, interactive GUI. I’ve seen that some GUI library can “display” in an existing opengl context, so we might investigate that.
Although I have no idea how the event handling will work. As somebody without any opengl experience, nor gui experience beside matlab and python’s matplotlib, this all very confusing :x.

Really taking any inputs that would help understand how one can build a scientific display, with some interfactive gui elements, in an existing opengl context, when one just has access to a basic render callback and the opengl context.

It sounds to me like OpenGL is not the right choice for you. It is not exactly an easy to use library, in fact, I would say it requires an advanced understanding of programming and software developement. User interfaces in particular are very difficult to do right in OpenGL without a decent library. If you really need to do something that you can not do with an off-the-shelf solution then I would suggest paying an experienced programmer to do the coding for you. Just winging it or learning it on the fly will probably give you a sub-par result which may or may not be much worse than existing solutions. It is very easy to do things wrong when working with OpenGL for the first time. Especially if this is supposed to be a professional project or some other kind of project which is supposed to be worked on by different people over a long period of time, you really want to get the basics right.

Hi Cornix, thanks for the answer.
I totally agree with you. The problem is that our context is quite constrained : we have to use the opengl render callback to do our visualisation. Getting an external isn’t really an option here either. We just don’t have so much time for this visualisation topic. But still have to make it work :wink:

This is why I am really trying to find a way to use a high level library that I can use in this opengl render callback.
If I had total freedom, doing a decent GUI in matlab or python would take something like a day to do.

My current plan is to use matlablib’s c++ binding, save the results as bmp and display it with opengl. Hopfully this can work in realtime.
Next problem is to have some elements of interactive gui. I am somehow surpised that there’s isnt much existing solution for this problem.
I am wondering if we can use thing like nanogui :

Do you have suggestion of libraries we could embed in this opengl render callback ?

But as you highlighted, it isnt easy to come up with an idea/concept to integrate an external library without a good grasp of opengl

OpenGL is not really designed for graphical user interfaces. OpenGL is a state machine and every action depends on the current state which in turn depends on all the actions that have taken place before. This is the reason why GUI’s are very complicated with OpenGL. For example: the framework you mentioned in your original post is most likely changing OpenGL state. This will certainly conflict with any state changes a GUI library needs to do. Just putting random libraries together is dangerous if you dont keep an overview of how these libraries are changing OpenGL state. Otherwise things will quickly become messy and seemingly “random” or rather “unpredictable” bugs will appear and become very difficult to debug.

I cannot recommend a C++ GUI library for OpenGL because I am personally working with Java. But the problems are the same regardless of the programming language.