GLFW2 to GLFW3 - help please!

Monkey Targets Forums/Desktop/GLFW2 to GLFW3 - help please!

TVCruelty(Posted 2017) [#1]
Hi,

I've written a game that runs under GLFW2 well but I'd like to move to GLFW3. I have a few reasons for this:

I'd like to use a later version of Monkey. I'm currently using v82b. If I upgrade, I find that the GLFW2 target isn't available in the Jungle IDE. (Maybe I could add it but, when I tried, it didn't work. Can't remember the error.)
I have one user who reports that the game runs very slowly on his machine. This might, of course, be a fault at his end but I'd like to be running the latest Monkey, just to rule out things like joystick port scanning.
From what I've read, GLFW3 runs a bit quicker.

If I simply try to run my app against the GLFW 3 target, I get this error:

Identifier 'GlfwGame' not found.

The code it's complaining about contains this:

	For mode = EachIn GlfwGame.GetGlfwGame().GetGlfwVideoModes()
			
                //Collect possible resolutions

        Next


I've looked at some posts on the subject of GLFW3 and can see that GetDisplayModes() is something I should be able to use but couldn't work out how.

As a little more info, I also import glfw.cpp, which looks like this:

class external
{
	public:
	
	static void setGraphics(int w, int h)
	{
		glfwSetWindowSize(w, h);
		GLFWvidmode desktopMode;
		glfwGetDesktopMode( &desktopMode );
		glfwSetWindowPos( (desktopMode.Width-w)/2,(desktopMode.Height-h)/2 );
	}
};


Thanks!


Ferdi(Posted 2017) [#2]
I think the code example that you want is in the bananas/mak/bouncyaliens/bouncyaliens.monkey. Then look at the OnCreate method:

		Print "Display modes:"
		For Local mode:=Eachin DisplayModes()
			Print mode.Width+","+mode.Height
		Next


Then use SetDeviceWindow to set the Window size. Look at method ToggleFullscreen in the bouncy aliens banana.

Hope it helps!


TVCruelty(Posted 2017) [#3]
Cool - thanks. I'll have a look.


TVCruelty(Posted 2017) [#4]
Right, that got me a bit further. :)

Do I need to be using a different version of MinGW? :(


TVCruelty(Posted 2017) [#5]
Getting this error:

TRANS FAILED: Error executing 'mingw32-make CCOPTS=" -m32 -O0" LDOPTS=" -m32 " OUT="Debug32/MonkeyGame"', return code=2

Thanks


Ferdi(Posted 2017) [#6]
Can you compile bouncy aliens example using your current Monkey setup? If you can then chances is your code, if you can't then chances is your setup.

Just to be exact, I am using Monkey from the latest github commit (04cb269). I think the latest stable 86e should be fine.

And for MinGW I am using tdm-gcc-5.1.0-3.exe (from: http://tdm-gcc.tdragon.net/download). If you need to download that you may need to change your MINGW_PATH in config.winnt.txt in your bin folder.

UPDATE: forgot to mention it must be the 32-bit MinGW according to the config.winnt.txt file.


TVCruelty(Posted 2017) [#7]
To be honest, bouncy aliens does work OK - but I have no idea what it is in my code that causes the issue...


Ferdi(Posted 2017) [#8]
Can you post the "full compile log"? So we can see where the compile is failing in your code.


TVCruelty(Posted 2017) [#9]
Thanks - here it is:

TRANS monkey compiler V1.87
Parsing...
Semanting...
Translating...
Building...
g++  -m32  -O0 -Wno-free-nonheap-object -I../glfw3/include -I../glfw3/src -I../openal/include -I../stb -I../zlib-1.2.8 -I../lpng1610 -c -o build/Debug32/main.o ../main.cpp
../main.cpp: In function 'float diddy_mouseZ()':
../main.cpp:4544:32: error: 'glfwGetMouseWheel' was not declared in this scope
  float ret = glfwGetMouseWheel() - diddy_mouseWheel;
                                ^
../main.cpp: In static member function 'static String diddy::openfilename()':
../main.cpp:4556:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   char *filter = "All Files (*.*)\0*.*\0";
                  ^
../main.cpp: In static member function 'static String diddy::savefilename()':
../main.cpp:4584:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   char *filter = "All Files (*.*)\0*.*\0";
                  ^
../main.cpp: In static member function 'static void diddy::setGraphics(int, int)':
../main.cpp:4629:25: error: invalid conversion from 'int' to 'GLFWwindow*' [-fpermissive]
   glfwSetWindowSize(w, h);
                         ^
../main.cpp:4629:25: error: too few arguments to function 'void glfwSetWindowSize(GLFWwindow*, int, int)'
In file included from ../main.h:39:0,
                 from ../main.cpp:2:
../glfw3/include/GLFW/glfw3.h:1859:14: note: declared here
 GLFWAPI void glfwSetWindowSize(GLFWwindow* window, int width, int height);
              ^
../main.cpp:4631:36: error: 'glfwGetDesktopMode' was not declared in this scope
   glfwGetDesktopMode( &desktopMode );
                                    ^
../main.cpp:4632:34: error: 'GLFWvidmode {aka struct GLFWvidmode}' has no member named 'Width'
   glfwSetWindowPos( (desktopMode.Width-w)/2,(desktopMode.Height-h)/2 );
                                  ^
../main.cpp:4632:58: error: 'GLFWvidmode {aka struct GLFWvidmode}' has no member named 'Height'
   glfwSetWindowPos( (desktopMode.Width-w)/2,(desktopMode.Height-h)/2 );
                                                          ^
../main.cpp: In static member function 'static void diddy::setMouse(int, int)':
../main.cpp:4637:23: error: 'glfwSetMousePos' was not declared in this scope
   glfwSetMousePos(x, y);
                       ^
Makefile:55: recipe for target 'build/Debug32/main.o' failed
mingw32-make: *** [build/Debug32/main.o] Error 1
TRANS FAILED: Error executing 'mingw32-make CCOPTS=" -m32  -O0" LDOPTS=" -m32 " OUT="Debug32/MonkeyGame"', return code=2
Abnormal program termination.
 Exit code: -1


Some warnings there about GFLW in main.cpp - what's that all about?


Ferdi(Posted 2017) [#10]
I think you are using a very old Diddy that has not been updated to GLFW3.

Download the latest Diddy from: https://github.com/swoolcock/diddy. I am one off the latest commit, and GLFW3 + Diddy is working ok for me.

If you open the file modules/diddy/native/diddy.glfw.cpp, find the function "diddy_mouseZ". You should see the following:

float diddy_mouseZ() {
	float ret = 0.0f;
#ifdef _glfw3_h_
	ret = diddy_mouseWheel;
	diddy_mouseWheel = 0;
#else
	ret = glfwGetMouseWheel() - diddy_mouseWheel;
	diddy_mouseWheel = glfwGetMouseWheel();
#endif
	return ret;
}


If you don't see "#ifdef _glfw3_h_" that means your Diddy module does not have the GLFW3 update.


TVCruelty(Posted 2017) [#11]
Whoo! Yessss, that works. Brilliant - thank you.

Only one little hitch - MouseZ() not working under GLFW3.

My code does this:

Local mz:Float = MouseZ()

If mz <> 0 And surface > - 1
	If mz > 0
		startingLine[surface] -= mz
...


It still works under GLFW2.


Ferdi(Posted 2017) [#12]
You may not like this solution, kinda workaround. Try caching the mouseZ value, instead of using it right away.

Something like this:

Field mz:Float = 0.0

Method FuncThatUseMouseZ:Void()
   mz += MouseZ()
   If mz <> 0 Then
      Print "mz = " + mz
      mz = 0
   Endif
End



TVCruelty(Posted 2017) [#13]
Ah, OK - I might try that.

I did find this

https://github.com/ImmutableOctet/scrollwheel

Half works atm - once it scrolls it won't stop, though, but I can fix that... probably...


TVCruelty(Posted 2017) [#14]
Still haven't fixed the ImmutableOctet code...

And adding MouseZ() to mz no good because MouseZ() always returns 0.

*sigh*


TVCruelty(Posted 2017) [#15]
All working now :)
The scrollwheel code is fine as long as you reset the return value to zero each frame.
Many, many thanks for your help Ferdi - couldn't have done it with out you!