ruby-glfw 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -0
- data/README.API +73 -0
- data/Rakefile +120 -0
- data/examples/boing.rb +519 -0
- data/examples/gears.rb +327 -0
- data/examples/keytest.rb +117 -0
- data/examples/listmodes.rb +20 -0
- data/examples/mipmaps.rb +104 -0
- data/examples/mipmaps.tga +0 -0
- data/examples/particles.rb +837 -0
- data/examples/pong3d.rb +741 -0
- data/examples/pong3d_field.tga +0 -0
- data/examples/pong3d_instr.tga +0 -0
- data/examples/pong3d_menu.tga +0 -0
- data/examples/pong3d_title.tga +0 -0
- data/examples/pong3d_winner1.tga +0 -0
- data/examples/pong3d_winner2.tga +0 -0
- data/examples/splitview.rb +432 -0
- data/examples/triangle.rb +89 -0
- data/examples/wave.rb +294 -0
- data/ext/glfw/glfw.c +1094 -0
- data/ext/glfw/mkrf_conf.rb +70 -0
- data/glfw-src/Makefile +220 -0
- data/glfw-src/compile.ami +61 -0
- data/glfw-src/compile.bat +217 -0
- data/glfw-src/compile.sh +607 -0
- data/glfw-src/docs/Makefile +57 -0
- data/glfw-src/docs/Reference.pdf +0 -0
- data/glfw-src/docs/UsersGuide.pdf +0 -0
- data/glfw-src/docs/cleanup.bat +22 -0
- data/glfw-src/docs/glfwdoc.sty +80 -0
- data/glfw-src/docs/glfwrm.tex +3034 -0
- data/glfw-src/docs/glfwug.tex +2024 -0
- data/glfw-src/docs/readme.txt +80 -0
- data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
- data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
- data/glfw-src/examples/Makefile.dos.djgpp +71 -0
- data/glfw-src/examples/Makefile.macosx.gcc +96 -0
- data/glfw-src/examples/Makefile.win32.bcc +75 -0
- data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
- data/glfw-src/examples/Makefile.win32.cygwin +79 -0
- data/glfw-src/examples/Makefile.win32.lcc +74 -0
- data/glfw-src/examples/Makefile.win32.mgw +75 -0
- data/glfw-src/examples/Makefile.win32.msvc +74 -0
- data/glfw-src/examples/Makefile.win32.ow +74 -0
- data/glfw-src/examples/Makefile.win32.pellesc +74 -0
- data/glfw-src/examples/Makefile.x11.in +54 -0
- data/glfw-src/examples/boing.c +606 -0
- data/glfw-src/examples/bundle.sh +46 -0
- data/glfw-src/examples/gears.c +382 -0
- data/glfw-src/examples/keytest.c +264 -0
- data/glfw-src/examples/listmodes.c +48 -0
- data/glfw-src/examples/mipmaps.c +126 -0
- data/glfw-src/examples/mipmaps.tga +0 -0
- data/glfw-src/examples/mtbench.c +301 -0
- data/glfw-src/examples/mthello.c +48 -0
- data/glfw-src/examples/particles.c +1148 -0
- data/glfw-src/examples/pong3d.c +839 -0
- data/glfw-src/examples/pong3d_field.tga +0 -0
- data/glfw-src/examples/pong3d_instr.tga +0 -0
- data/glfw-src/examples/pong3d_menu.tga +0 -0
- data/glfw-src/examples/pong3d_title.tga +0 -0
- data/glfw-src/examples/pong3d_winner1.tga +0 -0
- data/glfw-src/examples/pong3d_winner2.tga +0 -0
- data/glfw-src/examples/splitview.c +506 -0
- data/glfw-src/examples/triangle.c +108 -0
- data/glfw-src/examples/wave.c +397 -0
- data/glfw-src/images/opengl.gif +0 -0
- data/glfw-src/images/osicert.gif +0 -0
- data/glfw-src/include/GL/glfw.h +486 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
- data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
- data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
- data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
- data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
- data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
- data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
- data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
- data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
- data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
- data/glfw-src/lib/amigaos/platform.h +337 -0
- data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
- data/glfw-src/lib/dos/dos_enable.c +51 -0
- data/glfw-src/lib/dos/dos_events.c +173 -0
- data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
- data/glfw-src/lib/dos/dos_glext.c +59 -0
- data/glfw-src/lib/dos/dos_init.c +105 -0
- data/glfw-src/lib/dos/dos_irq.s +246 -0
- data/glfw-src/lib/dos/dos_joystick.c +94 -0
- data/glfw-src/lib/dos/dos_keyboard.c +694 -0
- data/glfw-src/lib/dos/dos_mouse.c +337 -0
- data/glfw-src/lib/dos/dos_thread.c +267 -0
- data/glfw-src/lib/dos/dos_time.c +309 -0
- data/glfw-src/lib/dos/dos_window.c +563 -0
- data/glfw-src/lib/dos/platform.h +341 -0
- data/glfw-src/lib/enable.c +295 -0
- data/glfw-src/lib/fullscreen.c +95 -0
- data/glfw-src/lib/glext.c +201 -0
- data/glfw-src/lib/image.c +629 -0
- data/glfw-src/lib/init.c +108 -0
- data/glfw-src/lib/input.c +280 -0
- data/glfw-src/lib/internal.h +210 -0
- data/glfw-src/lib/joystick.c +101 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
- data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
- data/glfw-src/lib/macosx/macosx_enable.c +42 -0
- data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
- data/glfw-src/lib/macosx/macosx_glext.c +52 -0
- data/glfw-src/lib/macosx/macosx_init.c +194 -0
- data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
- data/glfw-src/lib/macosx/macosx_thread.c +414 -0
- data/glfw-src/lib/macosx/macosx_time.c +112 -0
- data/glfw-src/lib/macosx/macosx_window.c +1279 -0
- data/glfw-src/lib/macosx/platform.h +349 -0
- data/glfw-src/lib/stream.c +194 -0
- data/glfw-src/lib/tga.c +405 -0
- data/glfw-src/lib/thread.c +340 -0
- data/glfw-src/lib/time.c +83 -0
- data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
- data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
- data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
- data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
- data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
- data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
- data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
- data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
- data/glfw-src/lib/win32/glfwdll.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
- data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
- data/glfw-src/lib/win32/libglfw.pc.in +11 -0
- data/glfw-src/lib/win32/platform.h +474 -0
- data/glfw-src/lib/win32/win32_dllmain.c +60 -0
- data/glfw-src/lib/win32/win32_enable.c +155 -0
- data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
- data/glfw-src/lib/win32/win32_glext.c +85 -0
- data/glfw-src/lib/win32/win32_init.c +356 -0
- data/glfw-src/lib/win32/win32_joystick.c +234 -0
- data/glfw-src/lib/win32/win32_thread.c +511 -0
- data/glfw-src/lib/win32/win32_time.c +146 -0
- data/glfw-src/lib/win32/win32_window.c +1714 -0
- data/glfw-src/lib/window.c +727 -0
- data/glfw-src/lib/x11/Makefile.x11.in +243 -0
- data/glfw-src/lib/x11/platform.h +415 -0
- data/glfw-src/lib/x11/x11_enable.c +51 -0
- data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
- data/glfw-src/lib/x11/x11_glext.c +69 -0
- data/glfw-src/lib/x11/x11_init.c +275 -0
- data/glfw-src/lib/x11/x11_joystick.c +371 -0
- data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
- data/glfw-src/lib/x11/x11_thread.c +507 -0
- data/glfw-src/lib/x11/x11_time.c +154 -0
- data/glfw-src/lib/x11/x11_window.c +1746 -0
- data/glfw-src/license.txt +21 -0
- data/glfw-src/readme.html +927 -0
- data/glfw-src/support/d/examples/Makefile +59 -0
- data/glfw-src/support/d/examples/boing.d +610 -0
- data/glfw-src/support/d/examples/gears.d +379 -0
- data/glfw-src/support/d/examples/keytest.d +272 -0
- data/glfw-src/support/d/examples/listmodes.d +48 -0
- data/glfw-src/support/d/examples/mipmaps.d +126 -0
- data/glfw-src/support/d/examples/mtbench.d +304 -0
- data/glfw-src/support/d/examples/mthello.d +54 -0
- data/glfw-src/support/d/examples/particles.d +1150 -0
- data/glfw-src/support/d/examples/pong3d.d +840 -0
- data/glfw-src/support/d/examples/splitview.d +486 -0
- data/glfw-src/support/d/examples/triangle.d +108 -0
- data/glfw-src/support/d/examples/wave.d +400 -0
- data/glfw-src/support/d/imports/gl.d +4539 -0
- data/glfw-src/support/d/imports/glfw.d +349 -0
- data/glfw-src/support/d/imports/glu.d +328 -0
- data/glfw-src/support/d/lib/glfwdll.def +64 -0
- data/glfw-src/support/d/lib/glu32.def +56 -0
- data/glfw-src/support/d/lib/makefile +12 -0
- data/glfw-src/support/d/lib/opengl32.def +372 -0
- data/glfw-src/support/d/readme.html +83 -0
- data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
- data/glfw-src/support/delphi/lib/glfw.pas +437 -0
- data/glfw-src/support/delphi/readme.html +97 -0
- data/glfw-src/support/lua/examples/gears.lua +383 -0
- data/glfw-src/support/lua/examples/test1.lua +68 -0
- data/glfw-src/support/lua/readme.html +128 -0
- data/glfw-src/support/lua/src/luaglfw.c +1179 -0
- data/glfw-src/support/lua/src/luaglfw.h +48 -0
- data/glfw-src/support/lua/src/runlua.c +82 -0
- data/glfw-src/support/masm/examples/fpc.mac +47 -0
- data/glfw-src/support/masm/examples/makeit.bat +66 -0
- data/glfw-src/support/masm/examples/triangle.asm +232 -0
- data/glfw-src/support/masm/include/glfw.inc +326 -0
- data/glfw-src/support/masm/include/glu32.inc +55 -0
- data/glfw-src/support/masm/include/opengl32.inc +372 -0
- data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
- data/glfw-src/support/masm/readme.html +170 -0
- data/glfw-src/support/msvc80/GLFW.sln +26 -0
- data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
- data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
- data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
- data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
- data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
- data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
- data/glfw-src/support/visualbasic/readme.html +164 -0
- data/website/index.html +84 -0
- data/website/style.css +110 -0
- metadata +301 -0
|
@@ -0,0 +1,1279 @@
|
|
|
1
|
+
//========================================================================
|
|
2
|
+
// GLFW - An OpenGL framework
|
|
3
|
+
// File: macosx_window.c
|
|
4
|
+
// Platform: Mac OS X
|
|
5
|
+
// API Version: 2.6
|
|
6
|
+
// WWW: http://glfw.sourceforge.net
|
|
7
|
+
//------------------------------------------------------------------------
|
|
8
|
+
// Copyright (c) 2002-2006 Camilla Berglund
|
|
9
|
+
//
|
|
10
|
+
// This software is provided 'as-is', without any express or implied
|
|
11
|
+
// warranty. In no event will the authors be held liable for any damages
|
|
12
|
+
// arising from the use of this software.
|
|
13
|
+
//
|
|
14
|
+
// Permission is granted to anyone to use this software for any purpose,
|
|
15
|
+
// including commercial applications, and to alter it and redistribute it
|
|
16
|
+
// freely, subject to the following restrictions:
|
|
17
|
+
//
|
|
18
|
+
// 1. The origin of this software must not be misrepresented; you must not
|
|
19
|
+
// claim that you wrote the original software. If you use this software
|
|
20
|
+
// in a product, an acknowledgment in the product documentation would
|
|
21
|
+
// be appreciated but is not required.
|
|
22
|
+
//
|
|
23
|
+
// 2. Altered source versions must be plainly marked as such, and must not
|
|
24
|
+
// be misrepresented as being the original software.
|
|
25
|
+
//
|
|
26
|
+
// 3. This notice may not be removed or altered from any source
|
|
27
|
+
// distribution.
|
|
28
|
+
//
|
|
29
|
+
//========================================================================
|
|
30
|
+
|
|
31
|
+
#include "internal.h"
|
|
32
|
+
|
|
33
|
+
static _GLFWmacwindowfunctions _glfwMacFSWindowFunctions =
|
|
34
|
+
{
|
|
35
|
+
_glfwMacFSOpenWindow,
|
|
36
|
+
_glfwMacFSCloseWindow,
|
|
37
|
+
_glfwMacFSSetWindowTitle,
|
|
38
|
+
_glfwMacFSSetWindowSize,
|
|
39
|
+
_glfwMacFSSetWindowPos,
|
|
40
|
+
_glfwMacFSIconifyWindow,
|
|
41
|
+
_glfwMacFSRestoreWindow,
|
|
42
|
+
_glfwMacFSRefreshWindowParams,
|
|
43
|
+
_glfwMacFSSetMouseCursorPos
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
static _GLFWmacwindowfunctions _glfwMacDWWindowFunctions =
|
|
47
|
+
{
|
|
48
|
+
_glfwMacDWOpenWindow,
|
|
49
|
+
_glfwMacDWCloseWindow,
|
|
50
|
+
_glfwMacDWSetWindowTitle,
|
|
51
|
+
_glfwMacDWSetWindowSize,
|
|
52
|
+
_glfwMacDWSetWindowPos,
|
|
53
|
+
_glfwMacDWIconifyWindow,
|
|
54
|
+
_glfwMacDWRestoreWindow,
|
|
55
|
+
_glfwMacDWRefreshWindowParams,
|
|
56
|
+
_glfwMacDWSetMouseCursorPos
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
#define _glfwTestModifier( modifierMask, glfwKey ) \
|
|
60
|
+
if ( changed & modifierMask ) \
|
|
61
|
+
{ \
|
|
62
|
+
_glfwInputKey( glfwKey, (modifiers & modifierMask ? GLFW_PRESS : GLFW_RELEASE) ); \
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
void _glfwHandleMacModifierChange( UInt32 modifiers )
|
|
66
|
+
{
|
|
67
|
+
UInt32 changed = modifiers ^ _glfwInput.Modifiers;
|
|
68
|
+
|
|
69
|
+
_glfwTestModifier( shiftKey, GLFW_KEY_LSHIFT );
|
|
70
|
+
_glfwTestModifier( rightShiftKey, GLFW_KEY_RSHIFT );
|
|
71
|
+
_glfwTestModifier( controlKey, GLFW_KEY_LCTRL );
|
|
72
|
+
_glfwTestModifier( rightControlKey, GLFW_KEY_RCTRL );
|
|
73
|
+
_glfwTestModifier( optionKey, GLFW_KEY_LALT );
|
|
74
|
+
_glfwTestModifier( rightOptionKey, GLFW_KEY_RALT );
|
|
75
|
+
|
|
76
|
+
_glfwInput.Modifiers = modifiers;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void _glfwHandleMacKeyChange( UInt32 keyCode, int action )
|
|
80
|
+
{
|
|
81
|
+
switch ( keyCode )
|
|
82
|
+
{
|
|
83
|
+
case MAC_KEY_ENTER: _glfwInputKey( GLFW_KEY_ENTER, action); break;
|
|
84
|
+
case MAC_KEY_RETURN: _glfwInputKey( GLFW_KEY_KP_ENTER, action); break;
|
|
85
|
+
case MAC_KEY_ESC: _glfwInputKey( GLFW_KEY_ESC, action); break;
|
|
86
|
+
case MAC_KEY_F1: _glfwInputKey( GLFW_KEY_F1, action); break;
|
|
87
|
+
case MAC_KEY_F2: _glfwInputKey( GLFW_KEY_F2, action); break;
|
|
88
|
+
case MAC_KEY_F3: _glfwInputKey( GLFW_KEY_F3, action); break;
|
|
89
|
+
case MAC_KEY_F4: _glfwInputKey( GLFW_KEY_F4, action); break;
|
|
90
|
+
case MAC_KEY_F5: _glfwInputKey( GLFW_KEY_F5, action); break;
|
|
91
|
+
case MAC_KEY_F6: _glfwInputKey( GLFW_KEY_F6, action); break;
|
|
92
|
+
case MAC_KEY_F7: _glfwInputKey( GLFW_KEY_F7, action); break;
|
|
93
|
+
case MAC_KEY_F8: _glfwInputKey( GLFW_KEY_F8, action); break;
|
|
94
|
+
case MAC_KEY_F9: _glfwInputKey( GLFW_KEY_F9, action); break;
|
|
95
|
+
case MAC_KEY_F10: _glfwInputKey( GLFW_KEY_F10, action); break;
|
|
96
|
+
case MAC_KEY_F11: _glfwInputKey( GLFW_KEY_F11, action); break;
|
|
97
|
+
case MAC_KEY_F12: _glfwInputKey( GLFW_KEY_F12, action); break;
|
|
98
|
+
case MAC_KEY_F13: _glfwInputKey( GLFW_KEY_F13, action); break;
|
|
99
|
+
case MAC_KEY_F14: _glfwInputKey( GLFW_KEY_F14, action); break;
|
|
100
|
+
case MAC_KEY_F15: _glfwInputKey( GLFW_KEY_F15, action); break;
|
|
101
|
+
case MAC_KEY_UP: _glfwInputKey( GLFW_KEY_UP, action); break;
|
|
102
|
+
case MAC_KEY_DOWN: _glfwInputKey( GLFW_KEY_DOWN, action); break;
|
|
103
|
+
case MAC_KEY_LEFT: _glfwInputKey( GLFW_KEY_LEFT, action); break;
|
|
104
|
+
case MAC_KEY_RIGHT: _glfwInputKey( GLFW_KEY_RIGHT, action); break;
|
|
105
|
+
case MAC_KEY_TAB: _glfwInputKey( GLFW_KEY_TAB, action); break;
|
|
106
|
+
case MAC_KEY_BACKSPACE: _glfwInputKey( GLFW_KEY_BACKSPACE, action); break;
|
|
107
|
+
case MAC_KEY_HELP: _glfwInputKey( GLFW_KEY_INSERT, action); break;
|
|
108
|
+
case MAC_KEY_DEL: _glfwInputKey( GLFW_KEY_DEL, action); break;
|
|
109
|
+
case MAC_KEY_PAGEUP: _glfwInputKey( GLFW_KEY_PAGEUP, action); break;
|
|
110
|
+
case MAC_KEY_PAGEDOWN: _glfwInputKey( GLFW_KEY_PAGEDOWN, action); break;
|
|
111
|
+
case MAC_KEY_HOME: _glfwInputKey( GLFW_KEY_HOME, action); break;
|
|
112
|
+
case MAC_KEY_END: _glfwInputKey( GLFW_KEY_END, action); break;
|
|
113
|
+
case MAC_KEY_KP_0: _glfwInputKey( GLFW_KEY_KP_0, action); break;
|
|
114
|
+
case MAC_KEY_KP_1: _glfwInputKey( GLFW_KEY_KP_1, action); break;
|
|
115
|
+
case MAC_KEY_KP_2: _glfwInputKey( GLFW_KEY_KP_2, action); break;
|
|
116
|
+
case MAC_KEY_KP_3: _glfwInputKey( GLFW_KEY_KP_3, action); break;
|
|
117
|
+
case MAC_KEY_KP_4: _glfwInputKey( GLFW_KEY_KP_4, action); break;
|
|
118
|
+
case MAC_KEY_KP_5: _glfwInputKey( GLFW_KEY_KP_5, action); break;
|
|
119
|
+
case MAC_KEY_KP_6: _glfwInputKey( GLFW_KEY_KP_6, action); break;
|
|
120
|
+
case MAC_KEY_KP_7: _glfwInputKey( GLFW_KEY_KP_7, action); break;
|
|
121
|
+
case MAC_KEY_KP_8: _glfwInputKey( GLFW_KEY_KP_8, action); break;
|
|
122
|
+
case MAC_KEY_KP_9: _glfwInputKey( GLFW_KEY_KP_9, action); break;
|
|
123
|
+
case MAC_KEY_KP_DIVIDE: _glfwInputKey( GLFW_KEY_KP_DIVIDE, action); break;
|
|
124
|
+
case MAC_KEY_KP_MULTIPLY: _glfwInputKey( GLFW_KEY_KP_MULTIPLY, action); break;
|
|
125
|
+
case MAC_KEY_KP_SUBTRACT: _glfwInputKey( GLFW_KEY_KP_SUBTRACT, action); break;
|
|
126
|
+
case MAC_KEY_KP_ADD: _glfwInputKey( GLFW_KEY_KP_ADD, action); break;
|
|
127
|
+
case MAC_KEY_KP_DECIMAL: _glfwInputKey( GLFW_KEY_KP_DECIMAL, action); break;
|
|
128
|
+
case MAC_KEY_KP_EQUAL: _glfwInputKey( GLFW_KEY_KP_EQUAL, action); break;
|
|
129
|
+
case MAC_KEY_KP_ENTER: _glfwInputKey( GLFW_KEY_KP_ENTER, action); break;
|
|
130
|
+
default:
|
|
131
|
+
{
|
|
132
|
+
extern void *KCHRPtr;
|
|
133
|
+
UInt32 state = 0;
|
|
134
|
+
char charCode = (char)KeyTranslate( KCHRPtr, keyCode, &state );
|
|
135
|
+
UppercaseText( &charCode, 1, smSystemScript );
|
|
136
|
+
_glfwInputKey( (unsigned char)charCode, action );
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
EventTypeSpec GLFW_KEY_EVENT_TYPES[] =
|
|
143
|
+
{
|
|
144
|
+
{ kEventClassKeyboard, kEventRawKeyDown },
|
|
145
|
+
{ kEventClassKeyboard, kEventRawKeyUp },
|
|
146
|
+
{ kEventClassKeyboard, kEventRawKeyModifiersChanged }
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
OSStatus _glfwKeyEventHandler( EventHandlerCallRef handlerCallRef,
|
|
150
|
+
EventRef event,
|
|
151
|
+
void *userData )
|
|
152
|
+
{
|
|
153
|
+
UInt32 keyCode;
|
|
154
|
+
short int keyChar;
|
|
155
|
+
UInt32 modifiers;
|
|
156
|
+
|
|
157
|
+
switch( GetEventKind( event ) )
|
|
158
|
+
{
|
|
159
|
+
case kEventRawKeyDown:
|
|
160
|
+
{
|
|
161
|
+
if( GetEventParameter( event,
|
|
162
|
+
kEventParamKeyCode,
|
|
163
|
+
typeUInt32,
|
|
164
|
+
NULL,
|
|
165
|
+
sizeof( UInt32 ),
|
|
166
|
+
NULL,
|
|
167
|
+
&keyCode ) == noErr )
|
|
168
|
+
{
|
|
169
|
+
_glfwHandleMacKeyChange( keyCode, GLFW_PRESS );
|
|
170
|
+
}
|
|
171
|
+
if( GetEventParameter( event,
|
|
172
|
+
kEventParamKeyUnicodes,
|
|
173
|
+
typeUnicodeText,
|
|
174
|
+
NULL,
|
|
175
|
+
sizeof(keyChar),
|
|
176
|
+
NULL,
|
|
177
|
+
&keyChar) == noErr )
|
|
178
|
+
{
|
|
179
|
+
_glfwInputChar( keyChar, GLFW_PRESS );
|
|
180
|
+
}
|
|
181
|
+
return noErr;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
case kEventRawKeyUp:
|
|
185
|
+
{
|
|
186
|
+
if( GetEventParameter( event,
|
|
187
|
+
kEventParamKeyCode,
|
|
188
|
+
typeUInt32,
|
|
189
|
+
NULL,
|
|
190
|
+
sizeof( UInt32 ),
|
|
191
|
+
NULL,
|
|
192
|
+
&keyCode ) == noErr )
|
|
193
|
+
{
|
|
194
|
+
_glfwHandleMacKeyChange( keyCode, GLFW_RELEASE );
|
|
195
|
+
}
|
|
196
|
+
if( GetEventParameter( event,
|
|
197
|
+
kEventParamKeyUnicodes,
|
|
198
|
+
typeUnicodeText,
|
|
199
|
+
NULL,
|
|
200
|
+
sizeof(keyChar),
|
|
201
|
+
NULL,
|
|
202
|
+
&keyChar) == noErr )
|
|
203
|
+
{
|
|
204
|
+
_glfwInputChar( keyChar, GLFW_RELEASE );
|
|
205
|
+
}
|
|
206
|
+
return noErr;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
case kEventRawKeyModifiersChanged:
|
|
210
|
+
{
|
|
211
|
+
if( GetEventParameter( event,
|
|
212
|
+
kEventParamKeyModifiers,
|
|
213
|
+
typeUInt32,
|
|
214
|
+
NULL,
|
|
215
|
+
sizeof( UInt32 ),
|
|
216
|
+
NULL,
|
|
217
|
+
&modifiers ) == noErr )
|
|
218
|
+
{
|
|
219
|
+
_glfwHandleMacModifierChange( modifiers );
|
|
220
|
+
return noErr;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return eventNotHandledErr;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
EventTypeSpec GLFW_MOUSE_EVENT_TYPES[] =
|
|
230
|
+
{
|
|
231
|
+
{ kEventClassMouse, kEventMouseDown },
|
|
232
|
+
{ kEventClassMouse, kEventMouseUp },
|
|
233
|
+
{ kEventClassMouse, kEventMouseMoved },
|
|
234
|
+
{ kEventClassMouse, kEventMouseDragged },
|
|
235
|
+
{ kEventClassMouse, kEventMouseWheelMoved },
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
OSStatus _glfwMouseEventHandler( EventHandlerCallRef handlerCallRef,
|
|
239
|
+
EventRef event,
|
|
240
|
+
void *userData )
|
|
241
|
+
{
|
|
242
|
+
switch( GetEventKind( event ) )
|
|
243
|
+
{
|
|
244
|
+
case kEventMouseDown:
|
|
245
|
+
{
|
|
246
|
+
WindowRef window;
|
|
247
|
+
EventRecord oldStyleMacEvent;
|
|
248
|
+
ConvertEventRefToEventRecord( event, &oldStyleMacEvent );
|
|
249
|
+
if( FindWindow ( oldStyleMacEvent.where, &window ) == inMenuBar )
|
|
250
|
+
{
|
|
251
|
+
MenuSelect( oldStyleMacEvent.where );
|
|
252
|
+
HiliteMenu(0);
|
|
253
|
+
return noErr;
|
|
254
|
+
}
|
|
255
|
+
else
|
|
256
|
+
{
|
|
257
|
+
EventMouseButton button;
|
|
258
|
+
if( GetEventParameter( event,
|
|
259
|
+
kEventParamMouseButton,
|
|
260
|
+
typeMouseButton,
|
|
261
|
+
NULL,
|
|
262
|
+
sizeof( EventMouseButton ),
|
|
263
|
+
NULL,
|
|
264
|
+
&button ) == noErr )
|
|
265
|
+
{
|
|
266
|
+
button -= kEventMouseButtonPrimary;
|
|
267
|
+
if( button <= GLFW_MOUSE_BUTTON_LAST )
|
|
268
|
+
{
|
|
269
|
+
_glfwInputMouseClick( button
|
|
270
|
+
+ GLFW_MOUSE_BUTTON_LEFT,
|
|
271
|
+
GLFW_PRESS );
|
|
272
|
+
}
|
|
273
|
+
return noErr;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
case kEventMouseUp:
|
|
280
|
+
{
|
|
281
|
+
EventMouseButton button;
|
|
282
|
+
if( GetEventParameter( event,
|
|
283
|
+
kEventParamMouseButton,
|
|
284
|
+
typeMouseButton,
|
|
285
|
+
NULL,
|
|
286
|
+
sizeof( EventMouseButton ),
|
|
287
|
+
NULL,
|
|
288
|
+
&button ) == noErr )
|
|
289
|
+
{
|
|
290
|
+
button -= kEventMouseButtonPrimary;
|
|
291
|
+
if( button <= GLFW_MOUSE_BUTTON_LAST )
|
|
292
|
+
{
|
|
293
|
+
_glfwInputMouseClick( button
|
|
294
|
+
+ GLFW_MOUSE_BUTTON_LEFT,
|
|
295
|
+
GLFW_RELEASE );
|
|
296
|
+
}
|
|
297
|
+
return noErr;
|
|
298
|
+
}
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
case kEventMouseMoved:
|
|
303
|
+
case kEventMouseDragged:
|
|
304
|
+
{
|
|
305
|
+
HIPoint mouseLocation;
|
|
306
|
+
if( _glfwWin.MouseLock )
|
|
307
|
+
{
|
|
308
|
+
if( GetEventParameter( event,
|
|
309
|
+
kEventParamMouseDelta,
|
|
310
|
+
typeHIPoint,
|
|
311
|
+
NULL,
|
|
312
|
+
sizeof( HIPoint ),
|
|
313
|
+
NULL,
|
|
314
|
+
&mouseLocation ) != noErr )
|
|
315
|
+
{
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
_glfwInput.MousePosX += mouseLocation.x;
|
|
320
|
+
_glfwInput.MousePosY += mouseLocation.y;
|
|
321
|
+
}
|
|
322
|
+
else
|
|
323
|
+
{
|
|
324
|
+
if( GetEventParameter( event,
|
|
325
|
+
kEventParamMouseLocation,
|
|
326
|
+
typeHIPoint,
|
|
327
|
+
NULL,
|
|
328
|
+
sizeof( HIPoint ),
|
|
329
|
+
NULL,
|
|
330
|
+
&mouseLocation ) != noErr )
|
|
331
|
+
{
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
_glfwInput.MousePosX = mouseLocation.x;
|
|
336
|
+
_glfwInput.MousePosY = mouseLocation.y;
|
|
337
|
+
|
|
338
|
+
if( !_glfwWin.Fullscreen )
|
|
339
|
+
{
|
|
340
|
+
Rect content;
|
|
341
|
+
GetWindowBounds( _glfwWin.MacWindow,
|
|
342
|
+
kWindowContentRgn,
|
|
343
|
+
&content );
|
|
344
|
+
|
|
345
|
+
_glfwInput.MousePosX -= content.left;
|
|
346
|
+
_glfwInput.MousePosY -= content.top;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if( _glfwWin.MousePosCallback )
|
|
351
|
+
{
|
|
352
|
+
_glfwWin.MousePosCallback( _glfwInput.MousePosX,
|
|
353
|
+
_glfwInput.MousePosY );
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
case kEventMouseWheelMoved:
|
|
360
|
+
{
|
|
361
|
+
EventMouseWheelAxis axis;
|
|
362
|
+
if( GetEventParameter( event,
|
|
363
|
+
kEventParamMouseWheelAxis,
|
|
364
|
+
typeMouseWheelAxis,
|
|
365
|
+
NULL,
|
|
366
|
+
sizeof( EventMouseWheelAxis ),
|
|
367
|
+
NULL,
|
|
368
|
+
&axis) == noErr )
|
|
369
|
+
{
|
|
370
|
+
long wheelDelta;
|
|
371
|
+
if( axis == kEventMouseWheelAxisY &&
|
|
372
|
+
GetEventParameter( event,
|
|
373
|
+
kEventParamMouseWheelDelta,
|
|
374
|
+
typeLongInteger,
|
|
375
|
+
NULL,
|
|
376
|
+
sizeof( long ),
|
|
377
|
+
NULL,
|
|
378
|
+
&wheelDelta ) == noErr )
|
|
379
|
+
{
|
|
380
|
+
_glfwInput.WheelPos += wheelDelta;
|
|
381
|
+
if( _glfwWin.MouseWheelCallback )
|
|
382
|
+
{
|
|
383
|
+
_glfwWin.MouseWheelCallback( _glfwInput.WheelPos );
|
|
384
|
+
}
|
|
385
|
+
return noErr;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return eventNotHandledErr;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
EventTypeSpec GLFW_COMMAND_EVENT_TYPES[] =
|
|
396
|
+
{
|
|
397
|
+
{ kEventClassCommand, kEventCommandProcess }
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
OSStatus _glfwCommandHandler( EventHandlerCallRef handlerCallRef,
|
|
401
|
+
EventRef event,
|
|
402
|
+
void *userData )
|
|
403
|
+
{
|
|
404
|
+
if( _glfwWin.SysKeysDisabled )
|
|
405
|
+
{
|
|
406
|
+
// TO DO: give adequate UI feedback that this is the case
|
|
407
|
+
return eventNotHandledErr;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
HICommand command;
|
|
411
|
+
if( GetEventParameter( event,
|
|
412
|
+
kEventParamDirectObject,
|
|
413
|
+
typeHICommand,
|
|
414
|
+
NULL,
|
|
415
|
+
sizeof( HICommand ),
|
|
416
|
+
NULL,
|
|
417
|
+
&command ) == noErr )
|
|
418
|
+
{
|
|
419
|
+
switch( command.commandID )
|
|
420
|
+
{
|
|
421
|
+
case kHICommandClose:
|
|
422
|
+
case kHICommandQuit:
|
|
423
|
+
{
|
|
424
|
+
// Check if the program wants us to close the window
|
|
425
|
+
if( _glfwWin.WindowCloseCallback )
|
|
426
|
+
{
|
|
427
|
+
if( _glfwWin.WindowCloseCallback() )
|
|
428
|
+
{
|
|
429
|
+
glfwCloseWindow();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
else
|
|
433
|
+
{
|
|
434
|
+
glfwCloseWindow();
|
|
435
|
+
}
|
|
436
|
+
return noErr;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return eventNotHandledErr;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
EventTypeSpec GLFW_WINDOW_EVENT_TYPES[] =
|
|
445
|
+
{
|
|
446
|
+
{ kEventClassWindow, kEventWindowBoundsChanged },
|
|
447
|
+
{ kEventClassWindow, kEventWindowClose },
|
|
448
|
+
{ kEventClassWindow, kEventWindowDrawContent },
|
|
449
|
+
{ kEventClassWindow, kEventWindowActivated },
|
|
450
|
+
{ kEventClassWindow, kEventWindowDeactivated },
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
OSStatus _glfwWindowEventHandler( EventHandlerCallRef handlerCallRef,
|
|
454
|
+
EventRef event,
|
|
455
|
+
void *userData )
|
|
456
|
+
{
|
|
457
|
+
switch( GetEventKind(event) )
|
|
458
|
+
{
|
|
459
|
+
case kEventWindowBoundsChanged:
|
|
460
|
+
{
|
|
461
|
+
WindowRef window;
|
|
462
|
+
GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL,
|
|
463
|
+
sizeof(WindowRef), NULL, &window );
|
|
464
|
+
|
|
465
|
+
Rect rect;
|
|
466
|
+
GetWindowPortBounds( window, &rect );
|
|
467
|
+
|
|
468
|
+
if( _glfwWin.Width != rect.right ||
|
|
469
|
+
_glfwWin.Height != rect.bottom )
|
|
470
|
+
{
|
|
471
|
+
aglUpdateContext(_glfwWin.AGLContext);
|
|
472
|
+
|
|
473
|
+
_glfwWin.Width = rect.right;
|
|
474
|
+
_glfwWin.Height = rect.bottom;
|
|
475
|
+
if( _glfwWin.WindowSizeCallback )
|
|
476
|
+
{
|
|
477
|
+
_glfwWin.WindowSizeCallback( _glfwWin.Width,
|
|
478
|
+
_glfwWin.Height );
|
|
479
|
+
}
|
|
480
|
+
// Emulate (force) content invalidation
|
|
481
|
+
if( _glfwWin.WindowRefreshCallback )
|
|
482
|
+
{
|
|
483
|
+
_glfwWin.WindowRefreshCallback();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
case kEventWindowClose:
|
|
490
|
+
{
|
|
491
|
+
// Check if the program wants us to close the window
|
|
492
|
+
if( _glfwWin.WindowCloseCallback )
|
|
493
|
+
{
|
|
494
|
+
if( _glfwWin.WindowCloseCallback() )
|
|
495
|
+
{
|
|
496
|
+
glfwCloseWindow();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
else
|
|
500
|
+
{
|
|
501
|
+
glfwCloseWindow();
|
|
502
|
+
}
|
|
503
|
+
return noErr;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
case kEventWindowDrawContent:
|
|
507
|
+
{
|
|
508
|
+
// Call user callback function
|
|
509
|
+
if( _glfwWin.WindowRefreshCallback )
|
|
510
|
+
{
|
|
511
|
+
_glfwWin.WindowRefreshCallback();
|
|
512
|
+
}
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
case kEventWindowActivated:
|
|
517
|
+
{
|
|
518
|
+
_glfwWin.Active = GL_TRUE;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
case kEventWindowDeactivated:
|
|
523
|
+
{
|
|
524
|
+
_glfwWin.Active = GL_FALSE;
|
|
525
|
+
_glfwInputDeactivation();
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return eventNotHandledErr;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
int _glfwInstallEventHandlers( void )
|
|
534
|
+
{
|
|
535
|
+
OSStatus error;
|
|
536
|
+
|
|
537
|
+
_glfwWin.MouseUPP = NewEventHandlerUPP( _glfwMouseEventHandler );
|
|
538
|
+
|
|
539
|
+
error = InstallEventHandler( GetApplicationEventTarget(),
|
|
540
|
+
_glfwWin.MouseUPP,
|
|
541
|
+
GetEventTypeCount( GLFW_MOUSE_EVENT_TYPES ),
|
|
542
|
+
GLFW_MOUSE_EVENT_TYPES,
|
|
543
|
+
NULL,
|
|
544
|
+
NULL );
|
|
545
|
+
if( error != noErr )
|
|
546
|
+
{
|
|
547
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't install mouse event handler\n" );
|
|
548
|
+
return GL_FALSE;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
_glfwWin.CommandUPP = NewEventHandlerUPP( _glfwCommandHandler );
|
|
552
|
+
|
|
553
|
+
error = InstallEventHandler( GetApplicationEventTarget(),
|
|
554
|
+
_glfwWin.CommandUPP,
|
|
555
|
+
GetEventTypeCount( GLFW_COMMAND_EVENT_TYPES ),
|
|
556
|
+
GLFW_COMMAND_EVENT_TYPES,
|
|
557
|
+
NULL,
|
|
558
|
+
NULL );
|
|
559
|
+
if( error != noErr )
|
|
560
|
+
{
|
|
561
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't install command event handler\n" );
|
|
562
|
+
return GL_FALSE;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
_glfwWin.KeyboardUPP = NewEventHandlerUPP( _glfwKeyEventHandler );
|
|
566
|
+
|
|
567
|
+
error = InstallEventHandler( GetApplicationEventTarget(),
|
|
568
|
+
_glfwWin.KeyboardUPP,
|
|
569
|
+
GetEventTypeCount( GLFW_KEY_EVENT_TYPES ),
|
|
570
|
+
GLFW_KEY_EVENT_TYPES,
|
|
571
|
+
NULL,
|
|
572
|
+
NULL );
|
|
573
|
+
if( error != noErr )
|
|
574
|
+
{
|
|
575
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't install key event handler\n" );
|
|
576
|
+
return GL_FALSE;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return GL_TRUE;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
#define _setAGLAttribute( aglAttributeName, AGLparameter ) \
|
|
583
|
+
if ( AGLparameter != 0 ) \
|
|
584
|
+
{ \
|
|
585
|
+
AGLpixelFormatAttributes[numAGLAttrs++] = aglAttributeName; \
|
|
586
|
+
AGLpixelFormatAttributes[numAGLAttrs++] = AGLparameter; \
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
#define _getAGLAttribute( aglAttributeName, variableName ) \
|
|
590
|
+
{ \
|
|
591
|
+
GLint aglValue; \
|
|
592
|
+
(void)aglDescribePixelFormat( pixelFormat, aglAttributeName, &aglValue ); \
|
|
593
|
+
variableName = aglValue; \
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
#define _setCGLAttribute( cglAttributeName, CGLparameter ) \
|
|
597
|
+
if ( CGLparameter != 0 ) \
|
|
598
|
+
{ \
|
|
599
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = cglAttributeName; \
|
|
600
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = CGLparameter; \
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
#define _getCGLAttribute( cglAttributeName, variableName ) \
|
|
604
|
+
{ \
|
|
605
|
+
long cglValue; \
|
|
606
|
+
(void)CGLDescribePixelFormat( CGLpfObj, 0, cglAttributeName, &cglValue ); \
|
|
607
|
+
variableName = cglValue; \
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
int _glfwPlatformOpenWindow( int width,
|
|
611
|
+
int height,
|
|
612
|
+
int redbits,
|
|
613
|
+
int greenbits,
|
|
614
|
+
int bluebits,
|
|
615
|
+
int alphabits,
|
|
616
|
+
int depthbits,
|
|
617
|
+
int stencilbits,
|
|
618
|
+
int mode,
|
|
619
|
+
_GLFWhints* hints )
|
|
620
|
+
{
|
|
621
|
+
OSStatus error;
|
|
622
|
+
ProcessSerialNumber psn;
|
|
623
|
+
|
|
624
|
+
unsigned int windowAttributes;
|
|
625
|
+
|
|
626
|
+
// TO DO: Refactor this function!
|
|
627
|
+
_glfwWin.WindowFunctions = ( _glfwWin.Fullscreen ?
|
|
628
|
+
&_glfwMacFSWindowFunctions :
|
|
629
|
+
&_glfwMacDWWindowFunctions );
|
|
630
|
+
|
|
631
|
+
// Windowed or fullscreen; AGL or CGL? Quite the mess...
|
|
632
|
+
// AGL appears to be the only choice for attaching OpenGL contexts to
|
|
633
|
+
// Carbon windows, but it leaves the user no control over fullscreen
|
|
634
|
+
// mode stretching. Solution: AGL for windowed, CGL for fullscreen.
|
|
635
|
+
if( !_glfwWin.Fullscreen )
|
|
636
|
+
{
|
|
637
|
+
// create AGL pixel format attribute list
|
|
638
|
+
GLint AGLpixelFormatAttributes[256];
|
|
639
|
+
int numAGLAttrs = 0;
|
|
640
|
+
|
|
641
|
+
AGLpixelFormatAttributes[numAGLAttrs++] = AGL_RGBA;
|
|
642
|
+
AGLpixelFormatAttributes[numAGLAttrs++] = AGL_DOUBLEBUFFER;
|
|
643
|
+
|
|
644
|
+
if( hints->Stereo )
|
|
645
|
+
{
|
|
646
|
+
AGLpixelFormatAttributes[numAGLAttrs++] = AGL_STEREO;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
_setAGLAttribute( AGL_AUX_BUFFERS, hints->AuxBuffers);
|
|
650
|
+
_setAGLAttribute( AGL_RED_SIZE, redbits );
|
|
651
|
+
_setAGLAttribute( AGL_GREEN_SIZE, greenbits );
|
|
652
|
+
_setAGLAttribute( AGL_BLUE_SIZE, bluebits );
|
|
653
|
+
_setAGLAttribute( AGL_ALPHA_SIZE, alphabits );
|
|
654
|
+
_setAGLAttribute( AGL_DEPTH_SIZE, depthbits );
|
|
655
|
+
_setAGLAttribute( AGL_STENCIL_SIZE, stencilbits );
|
|
656
|
+
_setAGLAttribute( AGL_ACCUM_RED_SIZE, hints->AccumRedBits );
|
|
657
|
+
_setAGLAttribute( AGL_ACCUM_GREEN_SIZE, hints->AccumGreenBits );
|
|
658
|
+
_setAGLAttribute( AGL_ACCUM_BLUE_SIZE, hints->AccumBlueBits );
|
|
659
|
+
_setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, hints->AccumAlphaBits );
|
|
660
|
+
|
|
661
|
+
if( hints->Samples > 1 )
|
|
662
|
+
{
|
|
663
|
+
_setAGLAttribute( AGL_SAMPLE_BUFFERS_ARB, 1 );
|
|
664
|
+
_setAGLAttribute( AGL_SAMPLES_ARB, hints->Samples );
|
|
665
|
+
AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NO_RECOVERY;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NONE;
|
|
669
|
+
|
|
670
|
+
// create pixel format descriptor
|
|
671
|
+
AGLDevice mainMonitor = GetMainDevice();
|
|
672
|
+
AGLPixelFormat pixelFormat = aglChoosePixelFormat( &mainMonitor,
|
|
673
|
+
1,
|
|
674
|
+
AGLpixelFormatAttributes );
|
|
675
|
+
if( pixelFormat == NULL )
|
|
676
|
+
{
|
|
677
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't create a pixel format\n" );
|
|
678
|
+
return GL_FALSE;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// store pixel format's values for _glfwPlatformGetWindowParam's use
|
|
682
|
+
_getAGLAttribute( AGL_ACCELERATED, _glfwWin.Accelerated );
|
|
683
|
+
_getAGLAttribute( AGL_RED_SIZE, _glfwWin.RedBits );
|
|
684
|
+
_getAGLAttribute( AGL_GREEN_SIZE, _glfwWin.GreenBits );
|
|
685
|
+
_getAGLAttribute( AGL_BLUE_SIZE, _glfwWin.BlueBits );
|
|
686
|
+
_getAGLAttribute( AGL_ALPHA_SIZE, _glfwWin.AlphaBits );
|
|
687
|
+
_getAGLAttribute( AGL_DEPTH_SIZE, _glfwWin.DepthBits );
|
|
688
|
+
_getAGLAttribute( AGL_STENCIL_SIZE, _glfwWin.StencilBits );
|
|
689
|
+
_getAGLAttribute( AGL_ACCUM_RED_SIZE, _glfwWin.AccumRedBits );
|
|
690
|
+
_getAGLAttribute( AGL_ACCUM_GREEN_SIZE, _glfwWin.AccumGreenBits );
|
|
691
|
+
_getAGLAttribute( AGL_ACCUM_BLUE_SIZE, _glfwWin.AccumBlueBits );
|
|
692
|
+
_getAGLAttribute( AGL_ACCUM_ALPHA_SIZE, _glfwWin.AccumAlphaBits );
|
|
693
|
+
_getAGLAttribute( AGL_AUX_BUFFERS, _glfwWin.AuxBuffers );
|
|
694
|
+
_getAGLAttribute( AGL_STEREO, _glfwWin.Stereo );
|
|
695
|
+
_getAGLAttribute( AGL_SAMPLES_ARB, _glfwWin.Samples );
|
|
696
|
+
_glfwWin.RefreshRate = hints->RefreshRate;
|
|
697
|
+
|
|
698
|
+
// create AGL context
|
|
699
|
+
_glfwWin.AGLContext = aglCreateContext( pixelFormat, NULL );
|
|
700
|
+
|
|
701
|
+
aglDestroyPixelFormat( pixelFormat );
|
|
702
|
+
|
|
703
|
+
if( _glfwWin.AGLContext == NULL )
|
|
704
|
+
{
|
|
705
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't create an OpenGL context\n" );
|
|
706
|
+
_glfwPlatformCloseWindow();
|
|
707
|
+
return GL_FALSE;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if (_glfwLibrary.Unbundled)
|
|
711
|
+
{
|
|
712
|
+
if( GetCurrentProcess( &psn ) != noErr )
|
|
713
|
+
{
|
|
714
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't get its PSN\n" );
|
|
715
|
+
_glfwPlatformCloseWindow();
|
|
716
|
+
return GL_FALSE;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if( TransformProcessType( &psn, kProcessTransformToForegroundApplication ) != noErr )
|
|
720
|
+
{
|
|
721
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't become a foreground application\n" );
|
|
722
|
+
_glfwPlatformCloseWindow();
|
|
723
|
+
return GL_FALSE;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/* Keith Bauer 2007-07-12 - I don't believe this is desirable
|
|
727
|
+
if( SetFrontProcess( &psn ) != noErr )
|
|
728
|
+
{
|
|
729
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't become the front process\n" );
|
|
730
|
+
_glfwPlatformCloseWindow();
|
|
731
|
+
return GL_FALSE;
|
|
732
|
+
}
|
|
733
|
+
*/
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// create window
|
|
737
|
+
Rect windowContentBounds;
|
|
738
|
+
windowContentBounds.left = 0;
|
|
739
|
+
windowContentBounds.top = 0;
|
|
740
|
+
windowContentBounds.right = width;
|
|
741
|
+
windowContentBounds.bottom = height;
|
|
742
|
+
|
|
743
|
+
windowAttributes = ( kWindowCloseBoxAttribute \
|
|
744
|
+
| kWindowCollapseBoxAttribute \
|
|
745
|
+
| kWindowStandardHandlerAttribute );
|
|
746
|
+
|
|
747
|
+
if( hints->WindowNoResize )
|
|
748
|
+
{
|
|
749
|
+
windowAttributes |= kWindowLiveResizeAttribute;
|
|
750
|
+
}
|
|
751
|
+
else
|
|
752
|
+
{
|
|
753
|
+
windowAttributes |= ( kWindowFullZoomAttribute | kWindowResizableAttribute );
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
error = CreateNewWindow( kDocumentWindowClass,
|
|
757
|
+
windowAttributes,
|
|
758
|
+
&windowContentBounds,
|
|
759
|
+
&( _glfwWin.MacWindow ) );
|
|
760
|
+
if( ( error != noErr ) || ( _glfwWin.MacWindow == NULL ) )
|
|
761
|
+
{
|
|
762
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't create a window\n" );
|
|
763
|
+
_glfwPlatformCloseWindow();
|
|
764
|
+
return GL_FALSE;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
_glfwWin.WindowUPP = NewEventHandlerUPP( _glfwWindowEventHandler );
|
|
768
|
+
|
|
769
|
+
error = InstallWindowEventHandler( _glfwWin.MacWindow,
|
|
770
|
+
_glfwWin.WindowUPP,
|
|
771
|
+
GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ),
|
|
772
|
+
GLFW_WINDOW_EVENT_TYPES,
|
|
773
|
+
NULL,
|
|
774
|
+
NULL );
|
|
775
|
+
if( error != noErr )
|
|
776
|
+
{
|
|
777
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't install window event handlers\n" );
|
|
778
|
+
_glfwPlatformCloseWindow();
|
|
779
|
+
return GL_FALSE;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// Don't care if we fail here
|
|
783
|
+
(void)SetWindowTitleWithCFString( _glfwWin.MacWindow, CFSTR( "GLFW Window" ) );
|
|
784
|
+
(void)RepositionWindow( _glfwWin.MacWindow,
|
|
785
|
+
NULL,
|
|
786
|
+
kWindowCenterOnMainScreen );
|
|
787
|
+
|
|
788
|
+
if( !aglSetDrawable( _glfwWin.AGLContext,
|
|
789
|
+
GetWindowPort( _glfwWin.MacWindow ) ) )
|
|
790
|
+
{
|
|
791
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't draw to the window\n" );
|
|
792
|
+
_glfwPlatformCloseWindow();
|
|
793
|
+
return GL_FALSE;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// Make OpenGL context current
|
|
797
|
+
if( !aglSetCurrentContext( _glfwWin.AGLContext ) )
|
|
798
|
+
{
|
|
799
|
+
fprintf( stderr, "glfwOpenWindow failing because it can't make the OpenGL context current\n" );
|
|
800
|
+
_glfwPlatformCloseWindow();
|
|
801
|
+
return GL_FALSE;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// show window
|
|
805
|
+
ShowWindow( _glfwWin.MacWindow );
|
|
806
|
+
|
|
807
|
+
return GL_TRUE;
|
|
808
|
+
}
|
|
809
|
+
else
|
|
810
|
+
{
|
|
811
|
+
CGDisplayErr cgErr;
|
|
812
|
+
CGLError cglErr;
|
|
813
|
+
|
|
814
|
+
CFDictionaryRef optimalMode;
|
|
815
|
+
|
|
816
|
+
CGLPixelFormatObj CGLpfObj;
|
|
817
|
+
long numCGLvs = 0;
|
|
818
|
+
|
|
819
|
+
CGLPixelFormatAttribute CGLpixelFormatAttributes[64];
|
|
820
|
+
int numCGLAttrs = 0;
|
|
821
|
+
|
|
822
|
+
// variables for enumerating color depths
|
|
823
|
+
long rgbColorDepth;
|
|
824
|
+
long rgbaAccumDepth = 0;
|
|
825
|
+
int rgbChannelDepth = 0;
|
|
826
|
+
|
|
827
|
+
// CGL pixel format attributes
|
|
828
|
+
_setCGLAttribute( kCGLPFADisplayMask,
|
|
829
|
+
CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) );
|
|
830
|
+
|
|
831
|
+
if( hints->Stereo )
|
|
832
|
+
{
|
|
833
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAStereo;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
if( hints->Samples > 1 )
|
|
837
|
+
{
|
|
838
|
+
_setCGLAttribute( kCGLPFASamples, (CGLPixelFormatAttribute)hints->Samples );
|
|
839
|
+
_setCGLAttribute( kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1 );
|
|
840
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAFullScreen;
|
|
844
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFADoubleBuffer;
|
|
845
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAAccelerated;
|
|
846
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery;
|
|
847
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAMinimumPolicy;
|
|
848
|
+
|
|
849
|
+
_setCGLAttribute( kCGLPFAAccumSize,
|
|
850
|
+
(CGLPixelFormatAttribute)( hints->AccumRedBits \
|
|
851
|
+
+ hints->AccumGreenBits \
|
|
852
|
+
+ hints->AccumBlueBits \
|
|
853
|
+
+ hints->AccumAlphaBits ) );
|
|
854
|
+
|
|
855
|
+
_setCGLAttribute( kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphabits );
|
|
856
|
+
_setCGLAttribute( kCGLPFADepthSize, (CGLPixelFormatAttribute)depthbits );
|
|
857
|
+
_setCGLAttribute( kCGLPFAStencilSize, (CGLPixelFormatAttribute)stencilbits );
|
|
858
|
+
_setCGLAttribute( kCGLPFAAuxBuffers, (CGLPixelFormatAttribute)hints->AuxBuffers );
|
|
859
|
+
|
|
860
|
+
CGLpixelFormatAttributes[ numCGLAttrs++ ] = (CGLPixelFormatAttribute)NULL;
|
|
861
|
+
|
|
862
|
+
// create a suitable pixel format with above attributes..
|
|
863
|
+
cglErr = CGLChoosePixelFormat( CGLpixelFormatAttributes,
|
|
864
|
+
&CGLpfObj,
|
|
865
|
+
&numCGLvs );
|
|
866
|
+
if( cglErr != kCGLNoError )
|
|
867
|
+
{
|
|
868
|
+
return GL_FALSE;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// ..and create a rendering context using that pixel format
|
|
872
|
+
cglErr = CGLCreateContext( CGLpfObj, NULL, &_glfwWin.CGLContext );
|
|
873
|
+
if( cglErr != kCGLNoError )
|
|
874
|
+
{
|
|
875
|
+
return GL_FALSE;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// enumerate depth of RGB channels - unlike AGL, CGL works with
|
|
879
|
+
// a single parameter reflecting the full depth of the frame buffer
|
|
880
|
+
(void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAColorSize, &rgbColorDepth );
|
|
881
|
+
if( rgbColorDepth == 24 || rgbColorDepth == 32 )
|
|
882
|
+
{
|
|
883
|
+
rgbChannelDepth = 8;
|
|
884
|
+
}
|
|
885
|
+
if( rgbColorDepth == 16 )
|
|
886
|
+
{
|
|
887
|
+
rgbChannelDepth = 5;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// get pixel depth of accumulator - I haven't got the slightest idea
|
|
891
|
+
// how this number conforms to any other channel depth than 8 bits,
|
|
892
|
+
// so this might end up giving completely knackered results...
|
|
893
|
+
(void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAAccumSize, &rgbaAccumDepth );
|
|
894
|
+
if( rgbaAccumDepth == 32 )
|
|
895
|
+
{
|
|
896
|
+
rgbaAccumDepth = 8;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// store values of pixel format for _glfwPlatformGetWindowParam's use
|
|
900
|
+
_getCGLAttribute( kCGLPFAAccelerated, _glfwWin.Accelerated );
|
|
901
|
+
_getCGLAttribute( rgbChannelDepth, _glfwWin.RedBits );
|
|
902
|
+
_getCGLAttribute( rgbChannelDepth, _glfwWin.GreenBits );
|
|
903
|
+
_getCGLAttribute( rgbChannelDepth, _glfwWin.BlueBits );
|
|
904
|
+
_getCGLAttribute( kCGLPFAAlphaSize, _glfwWin.AlphaBits );
|
|
905
|
+
_getCGLAttribute( kCGLPFADepthSize, _glfwWin.DepthBits );
|
|
906
|
+
_getCGLAttribute( kCGLPFAStencilSize, _glfwWin.StencilBits );
|
|
907
|
+
_getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumRedBits );
|
|
908
|
+
_getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumGreenBits );
|
|
909
|
+
_getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumBlueBits );
|
|
910
|
+
_getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumAlphaBits );
|
|
911
|
+
_getCGLAttribute( kCGLPFAAuxBuffers, _glfwWin.AuxBuffers );
|
|
912
|
+
_getCGLAttribute( kCGLPFAStereo, _glfwWin.Stereo );
|
|
913
|
+
_glfwWin.RefreshRate = hints->RefreshRate;
|
|
914
|
+
|
|
915
|
+
// destroy our pixel format
|
|
916
|
+
(void)CGLDestroyPixelFormat( CGLpfObj );
|
|
917
|
+
|
|
918
|
+
// capture the display for our application
|
|
919
|
+
cgErr = CGCaptureAllDisplays();
|
|
920
|
+
if( cgErr != kCGErrorSuccess )
|
|
921
|
+
{
|
|
922
|
+
return GL_FALSE;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// find closest matching NON-STRETCHED display mode..
|
|
926
|
+
optimalMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty( kCGDirectMainDisplay,
|
|
927
|
+
rgbColorDepth,
|
|
928
|
+
width,
|
|
929
|
+
/* Check further to the right -> */ height,
|
|
930
|
+
hints->RefreshRate,
|
|
931
|
+
NULL,
|
|
932
|
+
NULL );
|
|
933
|
+
if( optimalMode == NULL )
|
|
934
|
+
{
|
|
935
|
+
return GL_FALSE;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// ..and switch to that mode
|
|
939
|
+
cgErr = CGDisplaySwitchToMode( kCGDirectMainDisplay, optimalMode );
|
|
940
|
+
if( cgErr != kCGErrorSuccess )
|
|
941
|
+
{
|
|
942
|
+
return GL_FALSE;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// switch to our OpenGL context, and bring it up fullscreen
|
|
946
|
+
cglErr = CGLSetCurrentContext( _glfwWin.CGLContext );
|
|
947
|
+
if( cglErr != kCGLNoError )
|
|
948
|
+
{
|
|
949
|
+
return GL_FALSE;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
cglErr = CGLSetFullScreen( _glfwWin.CGLContext );
|
|
953
|
+
if( cglErr != kCGLNoError )
|
|
954
|
+
{
|
|
955
|
+
return GL_FALSE;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
return GL_TRUE;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
void _glfwPlatformCloseWindow( void )
|
|
963
|
+
{
|
|
964
|
+
if( _glfwWin.WindowFunctions != NULL )
|
|
965
|
+
{
|
|
966
|
+
if( _glfwWin.WindowUPP != NULL )
|
|
967
|
+
{
|
|
968
|
+
DisposeEventHandlerUPP( _glfwWin.WindowUPP );
|
|
969
|
+
_glfwWin.WindowUPP = NULL;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
_glfwWin.WindowFunctions->CloseWindow();
|
|
973
|
+
|
|
974
|
+
if( !_glfwWin.Fullscreen && _glfwWin.AGLContext != NULL )
|
|
975
|
+
{
|
|
976
|
+
aglSetCurrentContext( NULL );
|
|
977
|
+
aglSetDrawable( _glfwWin.AGLContext, NULL );
|
|
978
|
+
aglDestroyContext( _glfwWin.AGLContext );
|
|
979
|
+
_glfwWin.AGLContext = NULL;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
if( _glfwWin.Fullscreen && _glfwWin.CGLContext != NULL )
|
|
983
|
+
{
|
|
984
|
+
CGLSetCurrentContext( NULL );
|
|
985
|
+
CGLClearDrawable( _glfwWin.CGLContext );
|
|
986
|
+
CGLDestroyContext( _glfwWin.CGLContext );
|
|
987
|
+
CGReleaseAllDisplays();
|
|
988
|
+
_glfwWin.CGLContext = NULL;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
if( _glfwWin.MacWindow != NULL )
|
|
992
|
+
{
|
|
993
|
+
ReleaseWindow( _glfwWin.MacWindow );
|
|
994
|
+
_glfwWin.MacWindow = NULL;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
_glfwWin.WindowFunctions = NULL;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
void _glfwPlatformSetWindowTitle( const char *title )
|
|
1002
|
+
{
|
|
1003
|
+
_glfwWin.WindowFunctions->SetWindowTitle( title );
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
void _glfwPlatformSetWindowSize( int width, int height )
|
|
1007
|
+
{
|
|
1008
|
+
_glfwWin.WindowFunctions->SetWindowSize( width, height );
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
void _glfwPlatformSetWindowPos( int x, int y )
|
|
1012
|
+
{
|
|
1013
|
+
_glfwWin.WindowFunctions->SetWindowPos( x, y );
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
void _glfwPlatformIconifyWindow( void )
|
|
1017
|
+
{
|
|
1018
|
+
_glfwWin.WindowFunctions->IconifyWindow();
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
void _glfwPlatformRestoreWindow( void )
|
|
1022
|
+
{
|
|
1023
|
+
_glfwWin.WindowFunctions->RestoreWindow();
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
void _glfwPlatformSwapBuffers( void )
|
|
1027
|
+
{
|
|
1028
|
+
if( !_glfwWin.Fullscreen )
|
|
1029
|
+
{
|
|
1030
|
+
aglSwapBuffers( _glfwWin.AGLContext );
|
|
1031
|
+
}
|
|
1032
|
+
else
|
|
1033
|
+
{
|
|
1034
|
+
CGLFlushDrawable( _glfwWin.CGLContext );
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
void _glfwPlatformSwapInterval( int interval )
|
|
1039
|
+
{
|
|
1040
|
+
GLint AGLparameter = interval;
|
|
1041
|
+
|
|
1042
|
+
// CGL doesn't seem to like intervals other than 0 (vsync off) or 1 (vsync on)
|
|
1043
|
+
long CGLparameter = ( interval == 0 ? 0 : 1 );
|
|
1044
|
+
|
|
1045
|
+
if( !_glfwWin.Fullscreen )
|
|
1046
|
+
{
|
|
1047
|
+
// Don't care if we fail here..
|
|
1048
|
+
(void)aglSetInteger( _glfwWin.AGLContext,
|
|
1049
|
+
AGL_SWAP_INTERVAL,
|
|
1050
|
+
&AGLparameter );
|
|
1051
|
+
}
|
|
1052
|
+
else
|
|
1053
|
+
{
|
|
1054
|
+
// ..or here
|
|
1055
|
+
(void)CGLSetParameter( _glfwWin.CGLContext,
|
|
1056
|
+
kCGLCPSwapInterval,
|
|
1057
|
+
&CGLparameter );
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
void _glfwPlatformRefreshWindowParams( void )
|
|
1062
|
+
{
|
|
1063
|
+
_glfwWin.WindowFunctions->RefreshWindowParams();
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
int _glfwPlatformGetWindowParam( int param )
|
|
1067
|
+
{
|
|
1068
|
+
switch ( param )
|
|
1069
|
+
{
|
|
1070
|
+
case GLFW_ACCELERATED: return _glfwWin.Accelerated; break;
|
|
1071
|
+
case GLFW_RED_BITS: return _glfwWin.RedBits; break;
|
|
1072
|
+
case GLFW_GREEN_BITS: return _glfwWin.GreenBits; break;
|
|
1073
|
+
case GLFW_BLUE_BITS: return _glfwWin.BlueBits; break;
|
|
1074
|
+
case GLFW_ALPHA_BITS: return _glfwWin.AlphaBits; break;
|
|
1075
|
+
case GLFW_DEPTH_BITS: return _glfwWin.DepthBits; break;
|
|
1076
|
+
case GLFW_STENCIL_BITS: return _glfwWin.StencilBits; break;
|
|
1077
|
+
case GLFW_ACCUM_RED_BITS: return _glfwWin.AccumRedBits; break;
|
|
1078
|
+
case GLFW_ACCUM_GREEN_BITS: return _glfwWin.AccumGreenBits; break;
|
|
1079
|
+
case GLFW_ACCUM_BLUE_BITS: return _glfwWin.AccumBlueBits; break;
|
|
1080
|
+
case GLFW_ACCUM_ALPHA_BITS: return _glfwWin.AccumAlphaBits; break;
|
|
1081
|
+
case GLFW_AUX_BUFFERS: return _glfwWin.AuxBuffers; break;
|
|
1082
|
+
case GLFW_STEREO: return _glfwWin.Stereo; break;
|
|
1083
|
+
case GLFW_REFRESH_RATE: return _glfwWin.RefreshRate; break;
|
|
1084
|
+
default: return GL_FALSE;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
void _glfwPlatformPollEvents( void )
|
|
1089
|
+
{
|
|
1090
|
+
EventRef event;
|
|
1091
|
+
EventTargetRef eventDispatcher = GetEventDispatcherTarget();
|
|
1092
|
+
|
|
1093
|
+
while ( ReceiveNextEvent( 0, NULL, 0.0, TRUE, &event ) == noErr )
|
|
1094
|
+
{
|
|
1095
|
+
SendEventToEventTarget( event, eventDispatcher );
|
|
1096
|
+
ReleaseEvent( event );
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
void _glfwPlatformWaitEvents( void )
|
|
1101
|
+
{
|
|
1102
|
+
EventRef event;
|
|
1103
|
+
|
|
1104
|
+
// Wait for new events
|
|
1105
|
+
ReceiveNextEvent( 0, NULL, kEventDurationForever, FALSE, &event );
|
|
1106
|
+
|
|
1107
|
+
// Poll new events
|
|
1108
|
+
_glfwPlatformPollEvents();
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
void _glfwPlatformHideMouseCursor( void )
|
|
1112
|
+
{
|
|
1113
|
+
// TO DO: What if we fail here?
|
|
1114
|
+
CGDisplayHideCursor( kCGDirectMainDisplay );
|
|
1115
|
+
CGAssociateMouseAndMouseCursorPosition( false );
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
void _glfwPlatformShowMouseCursor( void )
|
|
1119
|
+
{
|
|
1120
|
+
// TO DO: What if we fail here?
|
|
1121
|
+
CGDisplayShowCursor( kCGDirectMainDisplay );
|
|
1122
|
+
CGAssociateMouseAndMouseCursorPosition( true );
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
void _glfwPlatformSetMouseCursorPos( int x, int y )
|
|
1126
|
+
{
|
|
1127
|
+
_glfwWin.WindowFunctions->SetMouseCursorPos( x, y );
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
int _glfwMacFSOpenWindow( int width,
|
|
1131
|
+
int height,
|
|
1132
|
+
int redbits,
|
|
1133
|
+
int greenbits,
|
|
1134
|
+
int bluebits,
|
|
1135
|
+
int alphabits,
|
|
1136
|
+
int depthbits,
|
|
1137
|
+
int stencilbits,
|
|
1138
|
+
int accumredbits,
|
|
1139
|
+
int accumgreenbits,
|
|
1140
|
+
int accumbluebits,
|
|
1141
|
+
int accumalphabits,
|
|
1142
|
+
int auxbuffers,
|
|
1143
|
+
int stereo,
|
|
1144
|
+
int refreshrate )
|
|
1145
|
+
{
|
|
1146
|
+
return GL_FALSE;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
void _glfwMacFSCloseWindow( void )
|
|
1150
|
+
{
|
|
1151
|
+
// TO DO: un-capture displays, &c.
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
void _glfwMacFSSetWindowTitle( const char *title )
|
|
1155
|
+
{
|
|
1156
|
+
// no-op really, change "fake" mini-window title
|
|
1157
|
+
_glfwMacDWSetWindowTitle( title );
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
void _glfwMacFSSetWindowSize( int width, int height )
|
|
1161
|
+
{
|
|
1162
|
+
// TO DO: something funky for full-screen
|
|
1163
|
+
_glfwMacDWSetWindowSize( width, height );
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
void _glfwMacFSSetWindowPos( int x, int y )
|
|
1167
|
+
{
|
|
1168
|
+
// no-op really, change "fake" mini-window position
|
|
1169
|
+
_glfwMacDWSetWindowPos( x, y );
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
void _glfwMacFSIconifyWindow( void )
|
|
1173
|
+
{
|
|
1174
|
+
// TO DO: Something funky for full-screen
|
|
1175
|
+
_glfwMacDWIconifyWindow();
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
void _glfwMacFSRestoreWindow( void )
|
|
1179
|
+
{
|
|
1180
|
+
_glfwMacDWRestoreWindow();
|
|
1181
|
+
// TO DO: Something funky for full-screen
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
void _glfwMacFSRefreshWindowParams( void )
|
|
1185
|
+
{
|
|
1186
|
+
// TO DO: implement this!
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
void _glfwMacFSSetMouseCursorPos( int x, int y )
|
|
1190
|
+
{
|
|
1191
|
+
// TO DO: what if we fail here?
|
|
1192
|
+
CGDisplayMoveCursorToPoint( kCGDirectMainDisplay,
|
|
1193
|
+
CGPointMake( x, y ) );
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
int _glfwMacDWOpenWindow( int width,
|
|
1197
|
+
int height,
|
|
1198
|
+
int redbits,
|
|
1199
|
+
int greenbits,
|
|
1200
|
+
int bluebits,
|
|
1201
|
+
int alphabits,
|
|
1202
|
+
int depthbits,
|
|
1203
|
+
int stencilbits,
|
|
1204
|
+
int accumredbits,
|
|
1205
|
+
int accumgreenbits,
|
|
1206
|
+
int accumbluebits,
|
|
1207
|
+
int accumalphabits,
|
|
1208
|
+
int auxbuffers,
|
|
1209
|
+
int stereo,
|
|
1210
|
+
int refreshrate )
|
|
1211
|
+
{
|
|
1212
|
+
return GL_FALSE;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
void _glfwMacDWCloseWindow( void )
|
|
1216
|
+
{
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
void _glfwMacDWSetWindowTitle( const char *title )
|
|
1220
|
+
{
|
|
1221
|
+
CFStringRef windowTitle = CFStringCreateWithCString( kCFAllocatorDefault,
|
|
1222
|
+
title,
|
|
1223
|
+
kCFStringEncodingISOLatin1 );
|
|
1224
|
+
|
|
1225
|
+
// Don't care if we fail
|
|
1226
|
+
(void)SetWindowTitleWithCFString( _glfwWin.MacWindow, windowTitle );
|
|
1227
|
+
|
|
1228
|
+
CFRelease( windowTitle );
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
void _glfwMacDWSetWindowSize( int width, int height )
|
|
1232
|
+
{
|
|
1233
|
+
SizeWindow( _glfwWin.MacWindow,
|
|
1234
|
+
width,
|
|
1235
|
+
height,
|
|
1236
|
+
TRUE );
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
void _glfwMacDWSetWindowPos( int x, int y )
|
|
1240
|
+
{
|
|
1241
|
+
// TO DO: take main monitor bounds into account
|
|
1242
|
+
MoveWindow( _glfwWin.MacWindow,
|
|
1243
|
+
x,
|
|
1244
|
+
y,
|
|
1245
|
+
FALSE );
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
void _glfwMacDWIconifyWindow( void )
|
|
1249
|
+
{
|
|
1250
|
+
// TO DO: What if we fail here?
|
|
1251
|
+
(void)CollapseWindow( _glfwWin.MacWindow,
|
|
1252
|
+
TRUE );
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
void _glfwMacDWRestoreWindow( void )
|
|
1256
|
+
{
|
|
1257
|
+
// TO DO: What if we fail here?
|
|
1258
|
+
(void)CollapseWindow( _glfwWin.MacWindow,
|
|
1259
|
+
FALSE );
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
void _glfwMacDWRefreshWindowParams( void )
|
|
1263
|
+
{
|
|
1264
|
+
// TO DO: implement this!
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
void _glfwMacDWSetMouseCursorPos( int x, int y )
|
|
1268
|
+
{
|
|
1269
|
+
Rect content;
|
|
1270
|
+
GetWindowBounds(_glfwWin.MacWindow, kWindowContentRgn, &content);
|
|
1271
|
+
|
|
1272
|
+
_glfwInput.MousePosX = x + content.left;
|
|
1273
|
+
_glfwInput.MousePosY = y + content.top;
|
|
1274
|
+
|
|
1275
|
+
CGDisplayMoveCursorToPoint( kCGDirectMainDisplay,
|
|
1276
|
+
CGPointMake( _glfwInput.MousePosX,
|
|
1277
|
+
_glfwInput.MousePosY ) );
|
|
1278
|
+
}
|
|
1279
|
+
|