Compiling GLFW as Universal under OSX

Using GLFW
gianmarco
2012-07-18
2012-11-08
  • gianmarco
    gianmarco
    2012-07-18

    Hello,
    I noticed that the latest GLFW (2.7.6) compiles correctly under OSX, but not
    if you compile with the i386 arch (at least on a x86_64 system). I was able
    to create a universal version (both i386 and x86_64 in the same binary
    library) in 2.7.5 simply by modifying the Makefile.cocoa under lib/cocoa
    (and the ones in examples and tests) and adding -arch i386 -arch x86_64 to
    both the linker and compiler flags

    #########################################################################
    # Compiler settings
    ##########################################################################
    CC     ?= cc
    CFLAGS ?= -O2 -g
    CFLAGS += -c -I. -I.. -Wall -fno-common [b]-arch i386 -arch x86_64[/b]
    ##########################################################################
    # Library builder settings
    ##########################################################################
    AR          = ar
    SED         = sed
    INSTALL     = install
    ARFLAGS     = -rcs 
    RANLIB      = ranlib
    DYLIBFLAGS  = [b]-arch i386 -arch x86_64[/b] -framework Cocoa -framework OpenGL \
                  -dynamiclib -Wl,-single_module -compatibility_version 1 \
                  -current_version 1 -install_name @executable_path/libglfw.dylib
    HEADERS     = ../../include/GL/glfw.h ../internal.h platform.h
    

    This time around, though, compiling for the i386 architecture gives a
    compilation error because _glfwPlatformSetMouseCursorPos() makes an
    implicit conversion between NSPoint and CGPoint. So to make it compile I
    simply modified the function (in cocoa_window.m, line 1122):

    void _glfwPlatformSetMouseCursorPos( int x, int y )
    {
        if( _glfwWin.fullscreen )
        {
            NSPoint globalPoint = NSMakePoint( x, y );
        [b]CGPoint globalPointCG = CGPointMake( globalPoint.x, globalPoint.y );[/b]
            CGDisplayMoveCursorToPoint( CGMainDisplayID(), [b]globalPointCG[/b] );
        }
        else
        {
            NSPoint localPoint = NSMakePoint( x, _glfwWin.height - y - 1 );
            NSPoint globalPoint = [_glfwWin.window convertBaseToScreen:localPoint];
            CGPoint mainScreenOrigin = CGDisplayBounds( CGMainDisplayID() ).origin;
            double mainScreenHeight = CGDisplayBounds( CGMainDisplayID() ).size.height;
            CGPoint targetPoint = CGPointMake( globalPoint.x - mainScreenOrigin.x,
                                              mainScreenHeight - globalPoint.y -
                                                  mainScreenOrigin.y );
            CGDisplayMoveCursorToPoint( CGMainDisplayID(), targetPoint );
        }
    }
    

    An explicit cast is probably better, but there you go. I thought I'd share
    this with everyone.

    Enjoy!
    Gian Marco

     
  • Camilla Löwy
    Camilla Löwy
    2012-07-18

    Thank you for an excellent bug report!