GLSL

17 views
Skip to first unread message

holm.h...@gmail.com

unread,
Aug 28, 2022, 3:32:49 AM8/28/22
to fltk.general

Hello,

Do anyone have a demo/test-code for using GLSL (shaders) in fltk ?

Best regards
Håvard

holm.h...@gmail.com

unread,
Aug 28, 2022, 5:29:31 AM8/28/22
to fltk.general
Hi,
Seems like there is a example already under examples/OpenGL3test

I however have problems linking the code under linux:
*** Compile OpenGL3test.cxx...
g++ -I.. -I.. -I/usr/local/include -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -Wall -I. -c OpenGL3test.cxx -o OpenGL3test.o
*** Linking OpenGL3test...
g++ OpenGL3test.o ../lib/libfltk.a -lXrender -lXcursor -lXfixes -lXft -lfontconfig -lXinerama -pthread -lpthread -ldl -lm -lX11 ../lib/libfltk_images.a -ljpeg -lpng -lz ../lib/libfltk.a -lXrender -lXcursor -lXfixes -lXft -lfontconfig -lXinerama -pthread -lpthread -ldl -lm -lX11 -o OpenGL3test
OpenGL3test.o: In function `Fl_Gl_Window::mode(int)':
OpenGL3test.cxx:(.text._ZN12Fl_Gl_Window4modeEi[_ZN12Fl_Gl_Window4modeEi]+0x21): undefined reference to `Fl_Gl_Window::mode(int, int const*)'
OpenGL3test.o: In function `Fl_Gl_Window::pixel_w()':
OpenGL3test.cxx:(.text._ZN12Fl_Gl_Window7pixel_wEv[_ZN12Fl_Gl_Window7pixel_wEv]+0x14): undefined reference to `Fl_Gl_Window::pixels_per_unit()'
OpenGL3test.o: In function `Fl_Gl_Window::pixel_h()':

Any hints ?

Best regards
Håvard

Albrecht Schlosser

unread,
Aug 28, 2022, 6:42:51 AM8/28/22
to fltkg...@googlegroups.com
On 8/28/22 11:29 holm.h...@gmail.com wrote:
> Hi,
> Seems like there is a example already under examples/OpenGL3test
>
> I however have problems linking the code under linux:
> *** Compile OpenGL3test.cxx...
> g++ -I.. -I.. -I/usr/local/include -I/usr/include/freetype2
> -I/usr/include/libpng16 -I/usr/include/freetype2
> -I/usr/include/libpng16 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
> -D_THREAD_SAFE -D_REENTRANT -Wall -I. -c OpenGL3test.cxx -o OpenGL3test.o
> *** Linking OpenGL3test...
> g++ OpenGL3test.o ../lib/libfltk.a -lXrender -lXcursor -lXfixes -lXft
> -lfontconfig -lXinerama -pthread -lpthread -ldl -lm -lX11
> ../lib/libfltk_images.a -ljpeg -lpng -lz ../lib/libfltk.a -lXrender
> -lXcursor -lXfixes -lXft -lfontconfig -lXinerama -pthread -lpthread
> -ldl -lm -lX11 -o OpenGL3test
> OpenGL3test.o: In function `Fl_Gl_Window::mode(int)':
> OpenGL3test.cxx:(.text._ZN12Fl_Gl_Window4modeEi[_ZN12Fl_Gl_Window4modeEi]+0x21):
> undefined reference to `Fl_Gl_Window::mode(int, int const*)'
> OpenGL3test.o: In function `Fl_Gl_Window::pixel_w()':
> OpenGL3test.cxx:(.text._ZN12Fl_Gl_Window7pixel_wEv[_ZN12Fl_Gl_Window7pixel_wEv]+0x14):
> undefined reference to `Fl_Gl_Window::pixels_per_unit()'
> OpenGL3test.o: In function `Fl_Gl_Window::pixel_h()':
>
> Any hints ?


Yes, please don't top-post in this group, it's hard to keep the context.
https://en.wikipedia.org/wiki/Posting_style#Top-posting

That aside, how did you compile/build? You are posting the error
message(s) but not your command which would have been really helpful.

AFAICT the OpenGL3 demos are not included in configure/make builds.
examples/Makefile
However, if you build with CMake you get them "for free" (set
FLTK_BUILD_EXAMPLES:BOOL=ON).

Finally: try to add "-lGLU -lGL -lGLEW" to your linker command. I tried
the following (you may do this as well in your environment, don't forget
"--use-gl"):

$ ../fltk-config --use-gl --compile OpenGL3test.cxx
g++ -I.. -I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
-I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
-I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
-I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
-I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -o
'OpenGL3test' 'OpenGL3test.cxx' ../lib/libfltk_gl.a -lGLU -lGL
../lib/libfltk.a -lXrender -lXcursor -lXfixes -lXft -lfontconfig
-lXinerama -pthread -lpthread -ldl -lm -lX11

[error messages removed]

Now copy the commandline and add -lGLEW:

$ g++ -I.. -I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
-I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
-I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
-I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
-I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -o
'OpenGL3test' 'OpenGL3test.cxx' ../lib/libfltk_gl.a -lGLU -lGL
../lib/libfltk.a -lXrender -lXcursor -lXfixes -lXft -lfontconfig
-lXinerama -pthread -lpthread -ldl -lm -lX11 -lGLEW
$

This worked for me. YMMV.

Note: my build includes Cairo and more, your command may be much shorter.

Albrecht Schlosser

unread,
Aug 28, 2022, 6:53:11 AM8/28/22
to fltkg...@googlegroups.com
On 8/28/22 12:42 Albrecht Schlosser wrote:
>
> You are posting the error message(s) but not your command which would
> have been really helpful.

Sorry, that statement was not correct (you posted the commands). What I
meant was that you didn't tell how you constructed these commands.

The best way is to use fltk-config but in this case it doesn't help
because fltk-config doesn't "know" the GLEW lib. Sorry for the confusion.

So, if you used fltk-config you should have used it like this to get the
required command switches:

$ fltk-config --use-gl --cxxflags
$ fltk-config --use-gl --ldflags

Then, add -lGLEW to the linker flags, and build your command line.

Here's a short and working form which you could simply copy:

$ g++ -o OpenGL3test `fltk-config --use-gl --cxxflags` OpenGL3test.cxx
`fltk-config --use-gl --ldflags` -lGLEW

holm.h...@gmail.com

unread,
Aug 28, 2022, 8:49:59 AM8/28/22
to fltk.general

Thanks Albrecht

Your recipe works fine.

Best regards
Håvard

imm

unread,
Aug 28, 2022, 12:40:05 PM8/28/22
to General FLTK
On Sun, 28 Aug 2022, 13:50 holm.haavard wrote:

Thanks Albrecht

Your recipe works fine.

Just for the benefit of anyone else following this;  note that you probably will have to install GLEW, and it's dev package, under Linux or WIN32, to make this work. Some Linux distros may have it installed by default but I think most do not, and WIN32 basically never does.

Without GLEW (or an equivalent GL extension manager) it is "difficult" to access any GL API beyond 2.1 on these hosts.

Note that macOS is a special case here, as "recent" macOS versions expose higher GL APIs "by default" and GLEW is generally not needed there at all. (Indeed, doesn't even work...)

--
Ian
From my Fairphone FP3

Manolo

unread,
Aug 28, 2022, 12:59:12 PM8/28/22
to fltk.general
Reply all
Reply to author
Forward
0 new messages