GLFW for Linux

Monkey Forums/Monkey Programming/GLFW for Linux

Risc(Posted 2012) [#1]
Hi,
So this finally happened:
http://imgur.com/a/BsF9p

I will post details tomorrow on how I did it. I'm too tired now and I need to be at work in a couple of hours :S

/Risc


Gerry Quinn(Posted 2012) [#2]
Well done!


Risc(Posted 2012) [#3]
Here's how I compiled trans on Ubuntu (12.04) and got the GLFW target working. This assumes you've got a Windows machine to generate main.cpp for trans (I haven't tested it on MacOS X but the process should be identical).

One thing to note, unless stated otherwise all paths originate from your Monkey root folder.

We start on Windows.
Download the latest Monkey version (61b while I'm writing this).
Edit and replace src\trans\targets\glfw.monkey with the code below. This just basically adds linux as a valid HostOS and adds an entry to MakeTarget for the linux host.



Open src\trans\trans.monkey in Ted and build it with the stdcpp target.
Download the GLFW tarball from http://www.glfw.org/download.html and extract and overwrite the files in targets\glfw\gflw.
Create a folder called 'linux' under targets\glfw
Create a new file targets\glfw\linux\makefile and copy the following to it (note that a leading TAB before g++ on both rows is required, so fix that in case copying it screws up the tabs):


Edit: Note: the makefile contains identical parts for the 'Debug' and 'Release' configuration, if some gcc-guru could come up with some optimizations and what-not that would be cool. Also, homework: create the 'Clean' configuration.

Copy the entire Monkey-folder to your Ubuntu machine.
Open a terminal and navigate to your Monkey-folder.
Navigate to src/trans/trans.build/stdcpp

Make sure g++ is installed:
sudo apt-get install g++


Issue the following command (change the path to Monkey's bin-folder):
g++ main.cpp -o /path/to/Monkey/bin/translinux


Navigate to Monkey's bin-folder and verify that translinux works, type:
./translinux


You can put Monkey's bin-folder in your path if you want to make the compilation process easier, issue the following command (correct the path first):
sudo export PATH=$PATH:/path/to/Monkey/bin


Navigate away and verify that translinux is working properly:
translinux


It should output valid targets glfw and stdcpp (you can replace config.linux.txt with config.winnt.txt if you want to build for html5 too, but mserver won't work as this has to be compiled with BlitzMax first).

Make sure libx11-dev, OpenGL, GLUT, OpenAL and Xrandr is installed, otherwise do that. Depending on your graphics card, you may want to install a specific version of GL (Nvidia's for example), otherwise you may just install the generic mesa-common-dev:
sudo apt-get install libx11-dev mesa-common-dev freeglut3 freeglut3-dev libopenal1 libopenal-dev libxrandr-dev


Now, navigate to targets/glfw/glfw. Compile GLFW:
make x11


If it spits out any errors about missing libraries, install those and try again.

Now you should have a working Monkey environment! Time to test it. Go to Monkey-folder/bananas/difference/clock

Build and run it:
translinux -run -target=glfw clock.monkey


Next time we'll cross-compile trans for Raspberri Pi's ARM platform. Stay tuned.


BlackD(Posted 2012) [#4]
Awesome, awesome work! :) Thanks for spending the time getting this working and sharing it with us!


Risc(Posted 2012) [#5]
Thanks :)
As I mentioned, the makefile needs some love. I just left it at the basics for you g++-gurus out there to improve and didn't bother with optimization-flags etc.

Btw, is it the same BlackD*** that hung around "The Hive Workshop" a few years ago?


BlackD(Posted 2012) [#6]
No. :) Sorry!


slenkar(Posted 2012) [#7]
very good. thanks

Do you own blitzmax?


Risc(Posted 2012) [#8]
Just realized that the OpenGL module (gles20) does not work with this configuration since it relies on the win32 bindings of GLEW. It probably wouldn't be too hard to make a linux version of the bindings and modify gles20.monkey if someone's up for it.

Edit: Realized I was wrong, it's working with the -DGL_GLEXT_PROTOTYPES flag. Updated the makefile above.


Risc(Posted 2012) [#9]
slenkar: Thanks but no. As I have no personal interest in building for html5 on linux, I left that task for anyone who's up for it.


fsoft(Posted 2012) [#10]
Risc: Thanks a lot. I did this before and provided a patch, but your step-by-step guide is more accurate :-)

Mark: Since Linux support is *that* easy, and considering you are putting some 'beta' code inside latest monkey release, would it be great if you could add Linux supporto by default?


dawlane(Posted 2012) [#11]
Very nice thanks. But remember kiddies if you build on a Linux 64bit you will get a 64bit monkey build.


slenkar(Posted 2012) [#12]
it says GL/gl.h is missing
it is located in /usr/X11/include

I exported this location to my PATH and LD_LIBRARY_PATH but it still cant find it


Risc(Posted 2012) [#13]
slenkar: gl.h should be part of the mesa-common-dev package, did you remember to install that? You can try referencing the path to the compiler with the -I/path/to/include/folder flag.

dawlane: you can force the compiler to output a 32-bit executable with the -m32 flag to g++


slenkar(Posted 2012) [#14]
the gl.h files are definitely there,


Risc(Posted 2012) [#15]
I read your post again. You say it's located in /usr/X11/include. Problem is it wants /usr/include/GL/gl.h. I guess you receive this error when compiling GLFW with make x11?


slenkar(Posted 2012) [#16]
yes


Risc(Posted 2012) [#17]
You first need to get the GLFW library to build before you can compile anything with Monkey (GLFW target ofc). I am by no means an expert on GNU/linux, so I my advice is somewhat limited to what I've posted. If I were you I would try to reinstall mesa-common-dev and see if it produces the OpenGL headers. Maybe your distribution stores the GL headers somewhere else. Hopefully someone else can provide a solution.

Best of luck!

/Risc


Risc(Posted 2012) [#18]
I promised at the end of the article a follow-up guide on how to build trans for Raspberry Pi. This is rather straight-forward. In fact, you can follow the above guide and it will compile fine (estimate 30min for compilation though if you don't cross-compile on a faster machine). However, running a monkey game (read: anything) on top of X11 on the Pi is pretty lame since it's so limited in memory/cpu, so I began researching on how to run it off the framebuffer device instead.

Turns out you can do this with an EGL surface on top of the framebuffer, but there's no (as far as I know) stable build of GLFW that supports EGL atm. An alternative would be to make a special target for this that don't rely on GLFW, but this is way too much work for me atm (for a too low paycheck). It would be awesome if someone with more experience of EGL would give this a shot! :)


slenkar(Posted 2012) [#19]
the -I option worked but now it says


RANS FAILED: TRANS Failed to execute 'make Release', return code=512
/usr/lib/gcc/i486-t2-linux-gnu/4.3.4/../../../../i486-t2-linux-gnu/bin/ld: cannot find -lXrandr
collect2: ld returned 1 exit status

TRANS FAILED: TRANS Failed to execute 'make Release', return code=512
/usr/lib/gcc/i486-t2-linux-gnu/4.3.4/../../../../i486-t2-linux-gnu/bin/ld: cannot find -lGL



dawlane(Posted 2012) [#20]
dawlane: you can force the compiler to output a 32-bit executable with the -m32 flag to g++
Yep already know that mate. But you have to faff about making sure you have the 32bit libs installed and a few system links to them.
I will be having a look to see if I can get it to do a multi-arch build at the week end. It's been a while since I mess with Linux.

/usr/lib/gcc/i486-t2-linux-gnu/4.3.4/../../../../i486-t2-linux-gnu/bin/ld: cannot find -lXrandr
Is the Xrandr libray installed?


slenkar(Posted 2012) [#21]
when i remove =xrandr from the compilation it says:

TRANS FAILED: TRANS Failed to execute 'make Release', return code=512
/usr/lib/gcc/i486-t2-linux-gnu/4.3.4/../../../../i486-t2-linux-gnu/bin/ld: cannot find -lGL


dawlane(Posted 2012) [#22]
@slenkar: What linux distro are you using and for what architecture?


slenkar(Posted 2012) [#23]
I have the normal x68 architecture

im using puppylinux maybe I should switch


dawlane(Posted 2012) [#24]
puppylinux
I'll download it and have a look at it in Virtual box.
I see there are two versions Slackware and Ubuntu.


slenkar(Posted 2012) [#25]
its a variant called saluki linux btw

the g++ stuff is in this file http://smokey01.com/saluki/isos/devx_luki_022.sfs which you have to rename to 023

then simply double click on it


dawlane(Posted 2012) [#26]
Talk about old school. Virtual Box doesn't like puppy much; took me 2 hours just get it installed. The Xrandr lib should be there in /usr/lib/X11 (it's a syslink) but for some reason ld isn't going down the search path but adding -L/usr/lib/X11 to the compiler options should solve this (the easy way).
Or editing LD_LIBRARY_PATH in the file .profile in /etc (the not so easy way). To permanently set the monkey bin folder so translinx will run, you can add this
PATH="$PATH:/path_to_monkey_bin"
in /etc/.profile or .bashrc (or what ever you command shell uses for configuration ) in your home folder.
And your going to have to download the OpenAl-Soft source code and use cmake to generate the make files to build it then add the libs and syslinks created to /usr/lib.

My verdict on puppy is it's not very user friendly (and some version are not stable ) and not something I would recommend to any one new to linux. Plus being root all the time can lead you in to some trouble.


slenkar(Posted 2012) [#27]
I found lxrandr in /usr/bin
I gave that folder to the compiler along with /usr/lib/x11
but it still says it cant find lxrandr

I think Im just gonna install Xubuntu, thanks for trying


dawlane(Posted 2012) [#28]
I found lxrandr in /usr/bin
I gave that folder to the compiler along with /usr/lib/x11
but it still says it cant find lxrandr


The file in the /usr/bin should be a binary. And if hope you didn't use -L/usr/lib/x11 but used -L/usr/lib/X11 as a typo can cause problems. In /usr/lib/X11 there should be a syslink called libXrandr.so

I think Im just gonna install Xubuntu
Well at least it's better supported and easier to use.


slenkar(Posted 2012) [#29]
it was actually /usr/X11/lib

I dont have any blank discs spare so I tried again :D


dawlane(Posted 2012) [#30]
it was actually /usr/X11/lib
There should have been a syslink /usr/lib for X11 if there is it may be broken.


DruggedBunny(Posted 2012) [#31]
This has been really helpful in getting trans going on the Pi again, but any idea why g++ might claim that libglfw.a doesn't exist? It's been built directly on the Pi and I believe it's in the correct place.

This screenshot shows the error in Ted (at the bottom in red) and a folder window (top left) showing libglfw.a, plus the contents of the makefile (top right) in targets/glfw/linux -- as far as I can tell, everything is correct and the relative paths point to the right place from the makefile in targets/glfw/linux, yet it still claims not to see it.


DruggedBunny(Posted 2012) [#32]
Well, after nearly a whole day, I got it building OK, but it's hard to say whether that was due to doing make x11-install (took a guess after reading through the makefiles!) or because I tried deleting the mygame.build folder, which contained a copy of the targets/glfw folder. I suspect the latter was the case.

So, I can now fire up Ted, code away and build no problem! However, the executable fails to run, stating that GLX is not supported.

I did have GLFW working on the previous distro, so I suspect something has changed in the most recent Debian (the hard-float build) -- some other posts seem to suggest this too.

I found that libglx.so was missing and reinstalled xorg-server-core (I think!), which got me that file, but still no change. After several hours reading up on xorg.conf settings, I manually enabled glx, but still to no avail.

I suspect a new distro update is what's required. Still, I know it'd run like crap until someone sorts out X drivers for it! The Monkey side of things is fine anyway...

@Risc: What Pi distro are you on? Hmm, just discovered my distro is about a month older than the latest... sigh...


Risc(Posted 2012) [#33]
Right now I'm running Raspbmc. Debian I think so the steps above should probably work with only minor changes. Make sure you have a huge cup of coffee though. It's really slow to compile on the Pi. You'd be better off building a cross-compiler for it.


Sensei(Posted 2015) [#34]
Thought I'd update this thread with a post I just put in on http://www.monkey-x.com/Community/posts.php?topic=2953#105098 to hopefully get some Linux heads to see if they could help?