using MathGL with TclTk

25 views
Skip to first unread message

Denis Laroche

unread,
Nov 14, 2025, 4:17:10 AMNov 14
to MathGL
Hi,

has anyone ever tried to plot with MathGL inside a Tk window? I've not been successful so far.

I started with the example described here; the code of the example can be found here.

Thanks in advance for any suggestion.

--
DL

Denis Laroche

unread,
Nov 14, 2025, 8:13:34 AMNov 14
to MathGL
the example does not contain calls to the MathGL API, it just shows how to draw in a Tk window with OpenGL; this example works well

I started with the code of the example and added code to plot a sine wave but nothing shows up
I create a plot with constructor mglGraph (1) which the documentation should use an existing OpenGL rendering context

mathgl....@gmail.com

unread,
Nov 15, 2025, 5:00:55 AMNov 15
to mat...@googlegroups.com
Dear Denis,

The initial question, which you ask, is rather complicated. The right way is to prepare the tcl/tk interface for all of MathGL functions using SWIG, for example, and call them from TCL/TK code directly. This will take some time, mostly for testing results, because I'm not familiar with the TCL/TK language. If you agree to be a tester, then I can do it shortly (during a few days or week for Linux-based builds).

In your case, the combination of C/C++ code and TCL/TK one solves this problem rather easily. You just need to use OpenGL interface for MathGL library (see https://mathgl.sourceforge.net/doc_en/OpenGL-output.html ) and put it in proper functions: initialization into SetRenderWindow(), viewport functions in Resize(), and drawing ones in Loop(). For example. yours sample project can be rewritten as one in the attached files.



пт, 14 нояб. 2025 г. в 16:13, Denis Laroche <ngc...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mathgl/285414ef-77ec-4e77-b734-406dd70862e1n%40googlegroups.com.


--
Kind regards,
Alexey Balakin
gui.tcl
Makefile
main.cpp

Denis Laroche

unread,
Nov 15, 2025, 6:53:07 AMNov 15
to MathGL
Thanks for the reply Alexey.

I got it to work; the Google AI engine is very helpful. I attached the two source files, sinewave.cc and sinewave.tcl. I used FreeBSD to build with command

c++ -g -I/usr/local/include -I/usr/local/include/tcl8.6 -I/usr/local/include/tk8.6 -L/usr/local/lib -lGL -ltcl86 -ltk86 -lmgl2 sinewave.cc -o sinewave

You can click on the Demo 1 button to show the plot; I attached the resulting window. The display was sent to a 13,3 in MacBook with a 2560x1600 resolution.

Would you have a suggestion how I can improve the quality of the text in the plot?

Thanks again,

--
DL
sinewave.tcl
Capture d’écran, le 2025-11-15 à 06.44.25.png
sinewave.cc
Reply all
Reply to author
Forward
0 new messages