Merged master and converter
2
.gitignore
vendored
@ -4,3 +4,5 @@ Makefile
|
||||
CMakeLists.txt.user
|
||||
*.cbp
|
||||
*~
|
||||
*.zip
|
||||
|
||||
|
BIN
Blenderfiles/ruins_block.blend
Normal file
BIN
Blenderfiles/ruins_column.blend
Normal file
BIN
Blenderfiles/skydome.blend
Normal file
BIN
Blenderfiles/switch_inner.blend
Normal file
BIN
Blenderfiles/switch_outer.blend
Normal file
@ -118,11 +118,18 @@ FILE(GLOB_RECURSE HEADER_FILES_BULLET ${CMAKE_SOURCE_DIR}/extern/bullet/src/*.h)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/extern/bullet/src)
|
||||
SET(HEADER_FILES ${HEADER_FILES} ${HEADER_FILES_BULLET})
|
||||
|
||||
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/BulletDynamics/libBulletDynamics.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/BulletCollision/libBulletCollision.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/LinearMath/libLinearMath.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/BulletSoftBody/libBulletSoftBody.a)
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/lib/libBulletDynamics.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/lib/libBulletCollision.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/lib/libLinearMath.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/lib/libBulletSoftBody.a)
|
||||
SET (LIBRARIES -static ${LIBRARIES} -static-libgcc -static-libstdc++)
|
||||
else()
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/BulletDynamics/libBulletDynamics.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/BulletCollision/libBulletCollision.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/LinearMath/libLinearMath.a)
|
||||
SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/BulletSoftBody/libBulletSoftBody.a)
|
||||
endif()
|
||||
|
||||
|
||||
ADD_EXECUTABLE(MarbleRaceGroupC ${SOURCE_FILES} ${HEADER_FILES} ${SHADER_FILES} ${README_FILES})
|
||||
|
12
Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
from ubuntu:trusty
|
||||
|
||||
run apt-get update
|
||||
run apt-get upgrade
|
||||
|
||||
run apt-get install -y build-essential
|
||||
run apt-get install -y gcc-mingw-w64
|
||||
run apt-get install -y cmake
|
||||
run apt-get install -y ninja-build
|
||||
run apt-get install -y xorg-dev
|
||||
run apt-get install -y freeglut3-dev
|
||||
run apt-get install -y zip
|
347475
Levels/Geometry/Bunny.obj
@ -1,40 +0,0 @@
|
||||
# Blender v2.72 (sub 0) OBJ File: 'skybox.blend'
|
||||
# www.blender.org
|
||||
o Cube
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v -1.000000 -1.000000 1.000000
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v 1.000000 1.000000 -0.999999
|
||||
v 0.999999 1.000000 1.000001
|
||||
v -1.000000 1.000000 1.000000
|
||||
v -1.000000 1.000000 -1.000000
|
||||
vt 0.250001 0.000001
|
||||
vt 0.500000 0.000000
|
||||
vt 0.500001 0.333336
|
||||
vt 0.250001 0.333335
|
||||
vt 0.499999 0.999998
|
||||
vt 0.250001 0.999999
|
||||
vt 0.250002 0.666669
|
||||
vt 0.500000 0.666668
|
||||
vt 0.749998 0.333334
|
||||
vt 1.000000 0.333334
|
||||
vt 1.000001 0.666666
|
||||
vt 0.750005 0.666664
|
||||
vt 0.000001 0.333334
|
||||
vt -0.000000 0.666666
|
||||
vn -0.577300 0.577300 0.577300
|
||||
vn 0.577300 0.577300 0.577300
|
||||
vn 0.577300 0.577300 -0.577300
|
||||
vn -0.577300 0.577300 -0.577300
|
||||
vn -0.577300 -0.577300 0.577300
|
||||
vn -0.577300 -0.577300 -0.577300
|
||||
vn 0.577300 -0.577300 -0.577300
|
||||
vn 0.577300 -0.577300 0.577300
|
||||
s 1
|
||||
f 1/1/1 4/2/2 3/3/3 2/4/4
|
||||
f 5/5/5 6/6/6 7/7/7 8/8/8
|
||||
f 1/9/1 2/10/4 6/11/6 5/12/5
|
||||
f 2/13/4 3/4/3 7/7/7 6/14/6
|
||||
f 3/4/3 4/3/2 8/8/8 7/7/7
|
||||
f 5/12/5 8/8/8 4/3/2 1/9/1
|
1031
Levels/Geometry/skydome.obj
Normal file
240
Levels/Geometry/switch_inner.obj
Normal file
@ -0,0 +1,240 @@
|
||||
# Blender v2.72 (sub 0) OBJ File: 'switch_inner.blend'
|
||||
# www.blender.org
|
||||
mtllib switch_inner.mtl
|
||||
o switch_Cube
|
||||
v 0.952094 -0.488588 -1.000000
|
||||
v 1.000000 -0.488588 -0.952094
|
||||
v 0.952094 -0.513173 -0.952094
|
||||
v 0.976015 -0.488588 -0.993600
|
||||
v 0.952094 -0.500864 -0.993600
|
||||
v 0.975003 -0.500345 -0.987383
|
||||
v 0.993600 -0.500864 -0.952093
|
||||
v 0.993600 -0.488588 -0.976015
|
||||
v 0.987383 -0.500345 -0.975003
|
||||
v 0.952094 -0.509888 -0.976015
|
||||
v 0.976015 -0.509888 -0.952093
|
||||
v 0.975003 -0.506698 -0.975003
|
||||
v 0.952094 -0.513173 0.952094
|
||||
v 1.000000 -0.488588 0.952094
|
||||
v 0.952094 -0.488588 1.000000
|
||||
v 0.976015 -0.509888 0.952094
|
||||
v 0.952094 -0.509888 0.976015
|
||||
v 0.975003 -0.506698 0.975003
|
||||
v 0.993600 -0.488588 0.976015
|
||||
v 0.993600 -0.500864 0.952094
|
||||
v 0.987383 -0.500345 0.975003
|
||||
v 0.952094 -0.500864 0.993600
|
||||
v 0.976015 -0.488588 0.993600
|
||||
v 0.975003 -0.500345 0.987383
|
||||
v -0.952094 -0.513173 0.952093
|
||||
v -0.952094 -0.488588 1.000000
|
||||
v -1.000000 -0.488588 0.952093
|
||||
v -0.952094 -0.509888 0.976015
|
||||
v -0.976016 -0.509888 0.952093
|
||||
v -0.975003 -0.506698 0.975003
|
||||
v -0.976016 -0.488588 0.993600
|
||||
v -0.952094 -0.500864 0.993600
|
||||
v -0.975003 -0.500345 0.987383
|
||||
v -0.993600 -0.500864 0.952093
|
||||
v -0.993600 -0.488588 0.976015
|
||||
v -0.987383 -0.500345 0.975003
|
||||
v -1.000000 -0.488588 -0.952094
|
||||
v -0.952093 -0.488588 -1.000000
|
||||
v -0.952093 -0.513173 -0.952094
|
||||
v -0.993600 -0.488588 -0.976016
|
||||
v -0.993600 -0.500864 -0.952094
|
||||
v -0.987383 -0.500345 -0.975003
|
||||
v -0.952093 -0.500864 -0.993600
|
||||
v -0.976015 -0.488588 -0.993600
|
||||
v -0.975003 -0.500345 -0.987383
|
||||
v -0.976015 -0.509888 -0.952094
|
||||
v -0.952093 -0.509888 -0.976016
|
||||
v -0.975003 -0.506698 -0.975003
|
||||
v 1.000000 0.488588 -0.952093
|
||||
v 0.952094 0.488588 -0.999999
|
||||
v 0.952094 0.513173 -0.952093
|
||||
v 0.993600 0.488588 -0.976015
|
||||
v 0.993600 0.500864 -0.952093
|
||||
v 0.987383 0.500345 -0.975002
|
||||
v 0.952094 0.500864 -0.993599
|
||||
v 0.976016 0.488588 -0.993599
|
||||
v 0.975003 0.500345 -0.987382
|
||||
v 0.976016 0.509888 -0.952093
|
||||
v 0.952094 0.509888 -0.976015
|
||||
v 0.975003 0.506698 -0.975002
|
||||
v 0.952093 0.513173 0.952094
|
||||
v 0.952093 0.488588 1.000001
|
||||
v 0.999999 0.488588 0.952094
|
||||
v 0.952093 0.509888 0.976016
|
||||
v 0.976015 0.509888 0.952094
|
||||
v 0.975002 0.506698 0.975004
|
||||
v 0.976015 0.488588 0.993601
|
||||
v 0.952093 0.500864 0.993601
|
||||
v 0.975002 0.500345 0.987384
|
||||
v 0.993599 0.500864 0.952094
|
||||
v 0.993599 0.488588 0.976016
|
||||
v 0.987382 0.500345 0.975004
|
||||
v -0.952094 0.513173 0.952093
|
||||
v -1.000000 0.488588 0.952093
|
||||
v -0.952094 0.488588 1.000000
|
||||
v -0.976016 0.509888 0.952093
|
||||
v -0.952094 0.509888 0.976015
|
||||
v -0.975003 0.506698 0.975003
|
||||
v -0.993600 0.488588 0.976015
|
||||
v -0.993600 0.500864 0.952093
|
||||
v -0.987383 0.500345 0.975003
|
||||
v -0.952094 0.500864 0.993600
|
||||
v -0.976016 0.488588 0.993600
|
||||
v -0.975003 0.500345 0.987383
|
||||
v -0.952094 0.488588 -1.000000
|
||||
v -1.000000 0.488588 -0.952094
|
||||
v -0.952094 0.513173 -0.952094
|
||||
v -0.976015 0.488588 -0.993600
|
||||
v -0.952093 0.500864 -0.993600
|
||||
v -0.975003 0.500345 -0.987383
|
||||
v -0.993600 0.500864 -0.952094
|
||||
v -0.993600 0.488588 -0.976015
|
||||
v -0.987383 0.500345 -0.975003
|
||||
v -0.952093 0.509888 -0.976015
|
||||
v -0.976015 0.509888 -0.952094
|
||||
v -0.975003 0.506698 -0.975003
|
||||
vt 0.856329 0.657341
|
||||
vt 0.856328 0.374264
|
||||
vt 0.426513 0.374264
|
||||
vt 0.426513 0.657341
|
||||
vt 0.853302 0.976215
|
||||
vt 0.654950 0.976215
|
||||
vt 0.654950 0.693138
|
||||
vt 0.853302 0.693138
|
||||
vt 0.861728 0.374264
|
||||
vt 0.861500 0.370859
|
||||
vt 0.856328 0.370708
|
||||
vt 0.865697 0.374264
|
||||
vt 0.864294 0.370859
|
||||
vt 0.865697 0.657341
|
||||
vt 0.861728 0.657341
|
||||
vt 0.861500 0.660747
|
||||
vt 0.864294 0.660747
|
||||
vt 0.856328 0.660897
|
||||
vt 0.856328 0.663512
|
||||
vt 0.861500 0.662587
|
||||
vt 0.421113 0.374264
|
||||
vt 0.421342 0.370859
|
||||
vt 0.426513 0.370708
|
||||
vt 0.856328 0.368094
|
||||
vt 0.861500 0.369018
|
||||
vt 0.426513 0.368094
|
||||
vt 0.421342 0.369018
|
||||
vt 0.417144 0.374264
|
||||
vt 0.418547 0.370859
|
||||
vt 0.426513 0.663512
|
||||
vt 0.426513 0.660897
|
||||
vt 0.421342 0.660747
|
||||
vt 0.421342 0.662587
|
||||
vt 0.421113 0.657341
|
||||
vt 0.417144 0.657341
|
||||
vt 0.418547 0.660747
|
||||
vt 0.851966 0.978445
|
||||
vt 0.851966 0.695368
|
||||
vt 0.659461 0.695368
|
||||
vt 0.659461 0.978445
|
||||
usemtl Material
|
||||
s 1
|
||||
f 50/1 1/2 38/3 85/4
|
||||
f 15/2 62/1 75/4 26/3
|
||||
f 27/3 74/4 86/1 37/2
|
||||
f 51/5 87/6 73/7 61/8
|
||||
f 2/2 49/1 63/4 14/3
|
||||
f 1/2 4/9 6/10 5/11
|
||||
f 4/9 8/12 9/13 6/10
|
||||
f 2/2 7/11 9/10 8/9
|
||||
f 7/14 11/15 12/16 9/17
|
||||
f 3/1 10/18 12/16 11/15
|
||||
f 10/18 5/19 6/20 12/16
|
||||
f 6/20 9/17 12/16
|
||||
f 13/2 16/9 18/10 17/11
|
||||
f 16/9 20/12 21/13 18/10
|
||||
f 14/3 19/21 21/22 20/23
|
||||
f 19/12 23/9 24/10 21/13
|
||||
f 15/2 22/11 24/10 23/9
|
||||
f 22/24 17/11 18/10 24/25
|
||||
f 18/10 21/13 24/25
|
||||
f 25/3 28/23 30/22 29/21
|
||||
f 28/23 32/26 33/27 30/22
|
||||
f 26/3 31/21 33/22 32/23
|
||||
f 31/21 35/28 36/29 33/22
|
||||
f 27/3 34/23 36/22 35/21
|
||||
f 34/28 29/21 30/22 36/29
|
||||
f 30/22 33/27 36/29
|
||||
f 37/2 40/9 42/10 41/11
|
||||
f 40/28 44/21 45/22 42/29
|
||||
f 38/3 43/23 45/22 44/21
|
||||
f 43/30 47/31 48/32 45/33
|
||||
f 39/4 46/34 48/32 47/31
|
||||
f 46/34 41/35 42/36 48/32
|
||||
f 42/36 45/33 48/32
|
||||
f 49/1 52/15 54/16 53/18
|
||||
f 52/14 56/15 57/16 54/17
|
||||
f 50/1 55/18 57/16 56/15
|
||||
f 55/19 59/18 60/16 57/20
|
||||
f 51/1 58/15 60/16 59/18
|
||||
f 58/15 53/14 54/17 60/16
|
||||
f 54/17 57/20 60/16
|
||||
f 61/2 64/11 66/10 65/9
|
||||
f 64/11 68/24 69/25 66/10
|
||||
f 62/1 67/15 69/16 68/18
|
||||
f 67/15 71/14 72/17 69/16
|
||||
f 63/4 70/31 72/32 71/34
|
||||
f 70/12 65/9 66/10 72/13
|
||||
f 66/10 69/25 72/13
|
||||
f 73/3 76/21 78/22 77/23
|
||||
f 76/21 80/28 81/29 78/22
|
||||
f 74/4 79/34 81/32 80/31
|
||||
f 79/35 83/34 84/32 81/36
|
||||
f 75/4 82/31 84/32 83/34
|
||||
f 82/26 77/23 78/22 84/27
|
||||
f 78/22 81/29 84/27
|
||||
f 85/4 88/34 90/32 89/31
|
||||
f 88/34 92/35 93/36 90/32
|
||||
f 86/1 91/18 93/16 92/15
|
||||
f 91/35 95/34 96/32 93/36
|
||||
f 87/4 94/31 96/32 95/34
|
||||
f 94/31 89/30 90/33 96/32
|
||||
f 90/33 93/36 96/32
|
||||
f 2/2 14/3 20/23 7/11
|
||||
f 7/14 20/12 16/9 11/15
|
||||
f 11/15 16/9 13/2 3/1
|
||||
f 3/1 39/4 47/31 10/18
|
||||
f 10/18 47/31 43/30 5/19
|
||||
f 5/11 43/23 38/3 1/2
|
||||
f 1/2 50/1 56/15 4/9
|
||||
f 4/9 56/15 52/14 8/12
|
||||
f 8/9 52/15 49/1 2/2
|
||||
f 15/2 26/3 32/23 22/11
|
||||
f 22/24 32/26 28/23 17/11
|
||||
f 17/11 28/23 25/3 13/2
|
||||
f 14/3 63/4 71/34 19/21
|
||||
f 19/12 71/14 67/15 23/9
|
||||
f 23/9 67/15 62/1 15/2
|
||||
f 27/3 37/2 41/11 34/23
|
||||
f 34/28 41/35 46/34 29/21
|
||||
f 29/21 46/34 39/4 25/3
|
||||
f 26/3 75/4 83/34 31/21
|
||||
f 31/21 83/34 79/35 35/28
|
||||
f 35/21 79/34 74/4 27/3
|
||||
f 37/2 86/1 92/15 40/9
|
||||
f 40/28 92/35 88/34 44/21
|
||||
f 44/21 88/34 85/4 38/3
|
||||
f 51/1 61/2 65/9 58/15
|
||||
f 58/15 65/9 70/12 53/14
|
||||
f 53/18 70/31 63/4 49/1
|
||||
f 50/1 85/4 89/31 55/18
|
||||
f 55/19 89/30 94/31 59/18
|
||||
f 59/18 94/31 87/4 51/1
|
||||
f 61/2 73/3 77/23 64/11
|
||||
f 64/11 77/23 82/26 68/24
|
||||
f 68/18 82/31 75/4 62/1
|
||||
f 73/3 87/4 95/34 76/21
|
||||
f 76/21 95/34 91/35 80/28
|
||||
f 80/31 91/18 86/1 74/4
|
||||
f 3/37 13/38 25/39 39/40
|
72
Levels/Geometry/switch_outer.obj
Normal file
@ -0,0 +1,72 @@
|
||||
# Blender v2.72 (sub 0) OBJ File: 'switch_outer.blend'
|
||||
# www.blender.org
|
||||
o switch_Cube
|
||||
v 1.270169 -1.270169 -1.270169
|
||||
v 1.270169 -1.270169 1.270169
|
||||
v -1.270169 -1.270169 1.270169
|
||||
v -1.270169 -1.270169 -1.270170
|
||||
v 1.270170 1.270169 -1.270169
|
||||
v 1.270168 1.270169 1.270170
|
||||
v -1.270170 1.270169 1.270169
|
||||
v -1.270169 1.270169 -1.270169
|
||||
v 0.985712 1.270169 -0.998137
|
||||
v 0.985712 1.270169 0.965003
|
||||
v -0.940154 1.270169 0.973287
|
||||
v -0.940154 1.270170 -0.998137
|
||||
v 0.985712 -1.271890 -0.998137
|
||||
v 0.985712 -1.271890 0.965003
|
||||
v -0.940154 -1.271890 0.973287
|
||||
v -0.940154 -1.271890 -0.998137
|
||||
vt 0.000000 0.000000
|
||||
vt 0.397419 0.000000
|
||||
vt 0.397419 0.499661
|
||||
vt 0.000000 0.499661
|
||||
vt 0.666667 0.333333
|
||||
vt 0.333333 0.333333
|
||||
vt 0.333333 0.000000
|
||||
vt 0.666667 0.000000
|
||||
vt 0.000000 0.333333
|
||||
vt 0.331641 0.335716
|
||||
vt -0.001692 0.335716
|
||||
vt -0.001692 0.002383
|
||||
vt 0.331641 0.002383
|
||||
vt 0.663333 0.003127
|
||||
vt 0.996667 0.003127
|
||||
vt 0.996667 0.336460
|
||||
vt 0.663333 0.336460
|
||||
vt 0.333333 0.666667
|
||||
vt 0.000000 0.666667
|
||||
vt 0.035695 0.629341
|
||||
vt 0.293291 0.629341
|
||||
vt 0.294378 0.376637
|
||||
vt 0.035695 0.376637
|
||||
vt 1.000000 1.000000
|
||||
vt 0.698711 1.000000
|
||||
vt 0.698711 0.500000
|
||||
vt 1.000000 0.500000
|
||||
vt 0.705835 0.500000
|
||||
vt 0.397419 0.500000
|
||||
vt 0.705835 0.000000
|
||||
vt 0.397419 1.000000
|
||||
vt 0.307120 0.499661
|
||||
vt 0.307120 0.999661
|
||||
vt 0.000000 0.999661
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn -0.000000 -0.000000 1.000000
|
||||
vn -1.000000 -0.000000 -0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn -0.004300 0.000000 -1.000000
|
||||
s off
|
||||
f 1/1/1 2/2/1 3/3/1 4/4/1
|
||||
f 1/5/2 5/6/2 6/7/2 2/8/2
|
||||
f 2/9/3 6/1/3 7/7/3 3/6/3
|
||||
f 3/10/4 7/11/4 8/12/4 4/13/4
|
||||
f 5/14/5 1/15/5 4/16/5 8/17/5
|
||||
f 6/18/6 5/19/6 9/20/6 10/21/6 11/22/6 7/6/6
|
||||
f 5/19/6 8/9/6 7/6/6 11/22/6 12/23/6 9/20/6
|
||||
f 9/24/3 12/25/3 16/26/3 13/27/3
|
||||
f 12/28/2 11/29/2 15/2/2 16/30/2
|
||||
f 11/29/7 10/26/7 14/25/7 15/31/7
|
||||
f 10/4/4 9/32/4 13/33/4 14/34/4
|
Before Width: | Height: | Size: 13 MiB |
Before Width: | Height: | Size: 11 MiB |
Before Width: | Height: | Size: 11 MiB |
Before Width: | Height: | Size: 3.1 MiB |
BIN
Levels/Textures/skydome.png
Normal file
After Width: | Height: | Size: 650 KiB |
Before Width: | Height: | Size: 1.1 MiB |
BIN
Levels/Textures/switchTextureInner.png
Normal file
After Width: | Height: | Size: 2.5 MiB |
BIN
Levels/Textures/switchTextureOuter.png
Normal file
After Width: | Height: | Size: 2.8 MiB |
Before Width: | Height: | Size: 344 KiB |
@ -20,7 +20,7 @@ uniform float directionalIntensity;
|
||||
uniform vec3 lightSources[128];
|
||||
uniform vec3 lightColors[128];
|
||||
uniform float lightIntensities[128];
|
||||
uniform float fogStart;
|
||||
uniform float fogEnd;
|
||||
uniform vec4 fogColor;
|
||||
uniform vec3 cameraCenter;
|
||||
|
||||
@ -54,8 +54,8 @@ void main()
|
||||
|
||||
vec3 finalColor = specularColor + diffuseColor + ambientColor;
|
||||
float distanceCameraCenter = distance(cameraCenter, vec3(fragPosition));
|
||||
float fogFactor = clamp((1.0 - exp(-distanceCameraCenter+fogStart)), 0.0, 1.0);
|
||||
fogFactor = mix(fogFactor, 0.0, clamp((1.0 - exp(-fragPosition.y+20.0)), 0.0, 1.0));
|
||||
float fogFactor = clamp((1.0 - (fogEnd-distanceCameraCenter)/30.0), 0.0, 1.0);
|
||||
fogFactor *= clamp((1.0-((fragPosition.y-8.0)/30.0)), 0.0, 1.0);
|
||||
|
||||
vec4 texture = texture(uTexture, vTexCoord).rgba;
|
||||
oColor = vec4(finalColor, 1.0f)*texture;
|
||||
|
69
application.cc
Normal file
@ -0,0 +1,69 @@
|
||||
#include "application.hh"
|
||||
|
||||
|
||||
Application::Application() {
|
||||
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f);
|
||||
}
|
||||
|
||||
void Application::init()
|
||||
{
|
||||
// Don't change this!
|
||||
ignoredMouseUpdates = 0;
|
||||
cameraLock = true;
|
||||
// set Skybox size
|
||||
level.setSkydomeSize((graphics.getFarPlane()/2.0f)-10.0f);
|
||||
|
||||
// define where shaders and textures can be found:
|
||||
ACGL::Base::Settings::the()->setResourcePath("../");
|
||||
ACGL::Base::Settings::the()->setShaderPath("Shader/");
|
||||
ACGL::Base::Settings::the()->setTexturePath("Levels/Textures/");
|
||||
ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/");
|
||||
|
||||
graphics.init();
|
||||
|
||||
// load Level
|
||||
level.load();
|
||||
|
||||
// just in case: check for errors
|
||||
openGLCriticalError();
|
||||
}
|
||||
|
||||
Graphics* Application::getGraphics() {
|
||||
return &graphics;
|
||||
}
|
||||
|
||||
Level* Application::getLevel() {
|
||||
return &level;
|
||||
}
|
||||
|
||||
void Application::setFocused(bool focused) {
|
||||
this->focused = focused;
|
||||
}
|
||||
|
||||
bool Application::isFocused() {
|
||||
return focused;
|
||||
}
|
||||
|
||||
void Application::setCameraLock(bool locked) {
|
||||
// Prevent camera jumping huge distances
|
||||
if (!locked) {
|
||||
ignoreNextMouseUpdate();
|
||||
}
|
||||
cameraLock = locked;
|
||||
}
|
||||
|
||||
void Application::ignoreNextMouseUpdate() {
|
||||
ignoredMouseUpdates++;
|
||||
}
|
||||
|
||||
void Application::ignoredOneMouseUpdate() {
|
||||
ignoredMouseUpdates--;
|
||||
}
|
||||
|
||||
int Application::getIgnoredMouseUpdates() {
|
||||
return ignoredMouseUpdates;
|
||||
}
|
||||
|
||||
bool Application::isLocked() {
|
||||
return cameraLock;
|
||||
}
|
29
application.hh
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef APPLICATION_HH_INCLUDED
|
||||
#define APPLICATION_HH_INCLUDED
|
||||
|
||||
#include "physics.hh"
|
||||
#include "graphics.hh"
|
||||
#include "level.hh"
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application();
|
||||
Graphics* getGraphics();
|
||||
Level* getLevel();
|
||||
void init();
|
||||
void setFocused(bool focused);
|
||||
bool isFocused();
|
||||
void setCameraLock(bool locked);
|
||||
bool isLocked();
|
||||
void ignoreNextMouseUpdate();
|
||||
int getIgnoredMouseUpdates();
|
||||
void ignoredOneMouseUpdate();
|
||||
private:
|
||||
int ignoredMouseUpdates;
|
||||
bool focused;
|
||||
bool cameraLock;
|
||||
Graphics graphics;
|
||||
Level level;
|
||||
};
|
||||
|
||||
#endif
|
27
build.sh
@ -8,6 +8,13 @@ then
|
||||
exit
|
||||
fi
|
||||
|
||||
cmake="cmake"
|
||||
|
||||
if [[ $1 == "windows" ]]
|
||||
then
|
||||
cmake="cmake -DCMAKE_SYSTEM_NAME='Windows' -DCMAKE_FIND_ROOT_PATH='/usr/bin:/usr/x86_64-w64-mingw32' -DCMAKE_CXX_COMPILER='x86_64-w64-mingw32-g++' -DCMAKE_C_COMPILER='x86_64-w64-mingw32-gcc'"
|
||||
fi
|
||||
|
||||
currentDir=$(pwd)
|
||||
threads=$(($(nproc)+1))
|
||||
|
||||
@ -16,8 +23,14 @@ threads=$(($(nproc)+1))
|
||||
cd extern/bullet/
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j$threads
|
||||
if hash ninja 2>/dev/null
|
||||
then
|
||||
$cmake -DBUILD_DEMOS=0 -DBUILD_EXTRAS=0 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=0 -GNinja ..
|
||||
ninja
|
||||
else
|
||||
$cmake -DBUILD_DEMOS=0 -DBUILD_EXTRAS=0 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=0 ..
|
||||
make -j$threads
|
||||
fi
|
||||
|
||||
cd $currentDir
|
||||
|
||||
@ -25,5 +38,11 @@ cd $currentDir
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j$threads
|
||||
if hash ninja 2>/dev/null
|
||||
then
|
||||
$cmake -DGLFW_BUILD_EXAMPLES=0 -DGLFW_BUILD_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=0 -GNinja ..
|
||||
ninja
|
||||
else
|
||||
$cmake -DGLFW_BUILD_EXAMPLES=0 -DGLFW_BUILD_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=0 ..
|
||||
make -j$threads
|
||||
fi
|
||||
|
31
circle.yml
Normal file
@ -0,0 +1,31 @@
|
||||
general:
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
machine:
|
||||
services:
|
||||
- docker
|
||||
|
||||
dependencies:
|
||||
override:
|
||||
# Set up dropbox_uploader
|
||||
- curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
|
||||
- chmod +x dropbox_uploader.sh
|
||||
- echo $db_uploader > ~/.dropbox_uploader
|
||||
|
||||
database:
|
||||
override:
|
||||
|
||||
test:
|
||||
override:
|
||||
- docker run -v ~/swp:/swp/swp -w=/swp/swp -u=$(id -u) faerbit/swp ./package.sh linux
|
||||
- docker run -v ~/swp:/swp/swp -w=/swp/swp -u=$(id -u) faerbit/swp ./package.sh windows
|
||||
- cp MarbleGame_Windows.zip MarbleGame_Linux.zip $CIRCLE_ARTIFACTS
|
||||
|
||||
deployment:
|
||||
master:
|
||||
branch: master
|
||||
commands:
|
||||
- ./dropbox_uploader.sh -p upload MarbleGame_Windows.zip /
|
||||
- ./dropbox_uploader.sh -p upload MarbleGame_Linux.zip /
|
@ -13,6 +13,8 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
|
||||
#include "btCompoundShape.h"
|
||||
#include "btCollisionShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
||||
|
2
extern/glfw/.gitignore
vendored
@ -21,7 +21,7 @@ cmake_uninstall.cmake
|
||||
docs/Doxyfile
|
||||
docs/html
|
||||
docs/warnings.txt
|
||||
src/config.h
|
||||
src/glfw_config.h
|
||||
src/glfw3.pc
|
||||
src/glfwConfig.cmake
|
||||
src/glfwConfigVersion.cmake
|
||||
|
76
extern/glfw/CMakeLists.txt
vendored
@ -4,15 +4,16 @@ cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(GLFW_VERSION_MAJOR "3")
|
||||
set(GLFW_VERSION_MINOR "0")
|
||||
set(GLFW_VERSION_PATCH "2")
|
||||
set(GLFW_VERSION_PATCH "4")
|
||||
set(GLFW_VERSION_EXTRA "")
|
||||
set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}")
|
||||
set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA}")
|
||||
set(LIB_SUFFIX "" CACHE STRING "Takes an empty string or 64. Directory where lib will be installed: lib or lib64")
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
||||
option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF)
|
||||
option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF)
|
||||
option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON)
|
||||
option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON)
|
||||
option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON)
|
||||
option(GLFW_INSTALL "Generate installation target" ON)
|
||||
option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF)
|
||||
|
||||
@ -73,11 +74,13 @@ endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
set(DOXYGEN_SKIP_DOT TRUE)
|
||||
find_package(Doxygen)
|
||||
if (GLFW_BUILD_DOCS)
|
||||
set(DOXYGEN_SKIP_DOT TRUE)
|
||||
find_package(Doxygen)
|
||||
|
||||
if (GLFW_DOCUMENT_INTERNALS)
|
||||
set(GLFW_INTERNAL_DOCS "${GLFW_SOURCE_DIR}/src/internal.h ${GLFW_SOURCE_DIR}/docs/internal.dox")
|
||||
if (GLFW_DOCUMENT_INTERNALS)
|
||||
set(GLFW_INTERNAL_DOCS "${GLFW_SOURCE_DIR}/src/internal.h ${GLFW_SOURCE_DIR}/docs/internal.dox")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
@ -163,6 +166,13 @@ if (_GLFW_WIN32)
|
||||
if (GLFW_USE_OPTIMUS_HPG)
|
||||
set(_GLFW_USE_OPTIMUS_HPG 1)
|
||||
endif()
|
||||
|
||||
# HACK: When building on MinGW, WINVER and UNICODE need to be defined before
|
||||
# the inclusion of stddef.h (by glfw3.h), which is itself included before
|
||||
# win32_platform.h. We define them here until a saner solution can be found
|
||||
# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
|
||||
add_definitions(-DUNICODE)
|
||||
add_definitions(-DWINVER=0x0501)
|
||||
endif()
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
@ -204,7 +214,13 @@ if (_GLFW_X11)
|
||||
endif()
|
||||
|
||||
list(APPEND glfw_INCLUDE_DIRS ${X11_Xinput_INCLUDE_PATH})
|
||||
list(APPEND glfw_LIBRARIES ${X11_Xinput_LIB})
|
||||
|
||||
if (X11_Xinput_LIB)
|
||||
list(APPEND glfw_LIBRARIES ${X11_Xinput_LIB})
|
||||
else()
|
||||
# Backwards compatibility (bug in CMake 2.8.7)
|
||||
list(APPEND glfw_LIBRARIES Xi)
|
||||
endif()
|
||||
set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} xi")
|
||||
|
||||
# Check for Xf86VidMode (fallback gamma control)
|
||||
@ -269,23 +285,15 @@ if (_GLFW_GLX)
|
||||
|
||||
# Check for dlopen support as a fallback
|
||||
|
||||
find_library(DL_LIBRARY dl)
|
||||
mark_as_advanced(DL_LIBRARY)
|
||||
if (DL_LIBRARY)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARY})
|
||||
else()
|
||||
set(CMAKE_REQUIRED_LIBRARIES "")
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
|
||||
check_function_exists(dlopen _GLFW_HAS_DLOPEN)
|
||||
|
||||
if (NOT _GLFW_HAS_DLOPEN)
|
||||
message(FATAL_ERROR "No entry point retrieval mechanism found")
|
||||
endif()
|
||||
|
||||
if (DL_LIBRARY)
|
||||
list(APPEND glfw_LIBRARIES ${DL_LIBRARY})
|
||||
set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -ldl")
|
||||
if (CMAKE_DL_LIBS)
|
||||
list(APPEND glfw_LIBRARIES ${CMAKE_DL_LIBS})
|
||||
set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -l${CMAKE_DL_LIBS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@ -343,13 +351,15 @@ if (_GLFW_COCOA AND _GLFW_NSGL)
|
||||
find_library(COCOA_FRAMEWORK Cocoa)
|
||||
find_library(IOKIT_FRAMEWORK IOKit)
|
||||
find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
|
||||
find_library(CORE_VIDEO_FRAMEWORK CoreVideo)
|
||||
list(APPEND glfw_LIBRARIES ${COCOA_FRAMEWORK}
|
||||
${OPENGL_gl_LIBRARY}
|
||||
${IOKIT_FRAMEWORK}
|
||||
${CORE_FOUNDATION_FRAMEWORK})
|
||||
${CORE_FOUNDATION_FRAMEWORK}
|
||||
${CORE_VIDEO_FRAMEWORK})
|
||||
|
||||
set(GLFW_PKG_DEPS "")
|
||||
set(GLFW_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation")
|
||||
set(GLFW_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo")
|
||||
endif()
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
@ -373,8 +383,8 @@ endif()
|
||||
configure_file(${GLFW_SOURCE_DIR}/docs/Doxyfile.in
|
||||
${GLFW_BINARY_DIR}/docs/Doxyfile @ONLY)
|
||||
|
||||
configure_file(${GLFW_SOURCE_DIR}/src/config.h.in
|
||||
${GLFW_BINARY_DIR}/src/config.h @ONLY)
|
||||
configure_file(${GLFW_SOURCE_DIR}/src/glfw_config.h.in
|
||||
${GLFW_BINARY_DIR}/src/glfw_config.h @ONLY)
|
||||
|
||||
configure_file(${GLFW_SOURCE_DIR}/src/glfwConfig.cmake.in
|
||||
${GLFW_BINARY_DIR}/src/glfwConfig.cmake @ONLY)
|
||||
@ -392,17 +402,17 @@ endif()
|
||||
#--------------------------------------------------------------------
|
||||
add_subdirectory(src)
|
||||
|
||||
#if (GLFW_BUILD_EXAMPLES)
|
||||
# add_subdirectory(examples)
|
||||
#endif()
|
||||
if (GLFW_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
#if (GLFW_BUILD_TESTS)
|
||||
# add_subdirectory(tests)
|
||||
#endif()
|
||||
if (GLFW_BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
#if (DOXYGEN_FOUND)
|
||||
# add_subdirectory(docs)
|
||||
#endif()
|
||||
if (DOXYGEN_FOUND AND GLFW_BUILD_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Install files other than the library
|
||||
|
277
extern/glfw/README.md
vendored
@ -6,9 +6,9 @@ GLFW is a free, Open Source, portable library for OpenGL and OpenGL ES
|
||||
application development. It provides a simple, platform-independent API for
|
||||
creating windows and contexts, reading input, handling events, etc.
|
||||
|
||||
Version 3.0.2 adds support for OpenGL 4 on and precise scrolling deltas on OS
|
||||
X and fixes for a number of bugs that together affect all supported platforms.
|
||||
As this is a patch release, there are no API changes.
|
||||
Version 3.0.4 adds better support for custom build environments and fixes for
|
||||
a large number of bugs that together affect all supported platforms. As this is
|
||||
a patch release, there are no API changes.
|
||||
|
||||
If you are new to GLFW, you may find the
|
||||
[introductory tutorial](http://www.glfw.org/docs/latest/quick.html) for GLFW
|
||||
@ -19,221 +19,69 @@ the GLFW 3 API.
|
||||
|
||||
## Compiling GLFW
|
||||
|
||||
### Dependencies
|
||||
|
||||
To compile GLFW and the accompanying example programs, you will need **CMake**,
|
||||
which will generate the project files or makefiles for your particular
|
||||
development environment. If you are on a Unix-like system such as Linux or
|
||||
FreeBSD or have a package system like Fink, MacPorts, Cygwin or Homebrew, you
|
||||
can simply install its CMake package. If not, you can get installers for
|
||||
Windows and OS X from the [CMake website](http://www.cmake.org/).
|
||||
|
||||
Additional dependencies are listed below.
|
||||
|
||||
|
||||
#### Visual C++ on Windows
|
||||
|
||||
The Microsoft Platform SDK that is installed along with Visual C++ contains all
|
||||
the necessary headers, link libraries and tools except for CMake.
|
||||
|
||||
|
||||
#### MinGW or MinGW-w64 on Windows
|
||||
|
||||
These packages contain all the necessary headers, link libraries and tools
|
||||
except for CMake.
|
||||
|
||||
|
||||
#### MinGW or MinGW-w64 cross-compilation
|
||||
|
||||
Both Cygwin and many Linux distributions have MinGW or MinGW-w64 packages. For
|
||||
example, Cygwin has the `mingw64-i686-gcc` and `mingw64-x86_64-gcc` packages
|
||||
for 32- and 64-bit version of MinGW-w64, while Debian GNU/Linux and derivatives
|
||||
like Ubuntu have the `mingw-w64` package for both.
|
||||
|
||||
GLFW has CMake toolchain files in the `CMake/` directory that allow for easy
|
||||
cross-compilation of Windows binaries. To use these files you need to add a
|
||||
special parameter when generating the project files or makefiles:
|
||||
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=<toolchain-file> .
|
||||
|
||||
The exact toolchain file to use depends on the prefix used by the MinGW or
|
||||
MinGW-w64 binaries on your system. You can usually see this in the /usr
|
||||
directory. For example, both the Debian/Ubuntu and Cygwin MinGW-w64 packages
|
||||
have `/usr/x86_64-w64-mingw32` for the 64-bit compilers, so the correct
|
||||
invocation would be:
|
||||
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake .
|
||||
|
||||
For more details see the article
|
||||
[CMake Cross Compiling](http://www.paraview.org/Wiki/CMake_Cross_Compiling) on
|
||||
the CMake wiki.
|
||||
|
||||
|
||||
#### Xcode on OS X
|
||||
|
||||
Xcode contains all necessary tools except for CMake. The necessary headers and
|
||||
libraries are included in the core OS frameworks. Xcode can be downloaded from
|
||||
the Mac App Store.
|
||||
|
||||
|
||||
#### Unix-like systems with X11
|
||||
|
||||
To compile GLFW for X11, you need to have the X11 and OpenGL header packages
|
||||
installed, as well as the basic development tools like GCC and make. For
|
||||
example, on Ubuntu and other distributions based on Debian GNU/Linux, you need
|
||||
to install the `xorg-dev` and `libglu1-mesa-dev` packages. The former pulls in
|
||||
all X.org header packages and the latter pulls in the Mesa OpenGL and GLU
|
||||
packages. Note that using header files and libraries from Mesa during
|
||||
compilation *will not* tie your binaries to the Mesa implementation of OpenGL.
|
||||
|
||||
|
||||
### Generating with CMake
|
||||
|
||||
Once you have all necessary dependencies, it is time to generate the project
|
||||
files or makefiles for your development environment. CMake needs to know two
|
||||
paths for this: the path to the source directory and the target path for the
|
||||
generated files and compiled binaries. If these are the same, it is called an
|
||||
in-tree build, otherwise it is called an out-of-tree build.
|
||||
|
||||
One of several advantages of out-of-tree builds is that you can generate files
|
||||
and compile for different development environments using a single source tree.
|
||||
|
||||
|
||||
#### Using CMake from the command-line
|
||||
|
||||
To make an in-tree build, enter the root directory of the GLFW source tree and
|
||||
run CMake. The current directory is used as target path, while the path
|
||||
provided as an argument is used to find the source tree.
|
||||
|
||||
cd <glfw-root-dir>
|
||||
cmake .
|
||||
|
||||
To make an out-of-tree build, make another directory, enter it and run CMake
|
||||
with the (relative or absolute) path to the root of the source tree as an
|
||||
argument.
|
||||
|
||||
cd <glfw-root-dir>
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
|
||||
|
||||
#### Using the CMake GUI
|
||||
|
||||
If you are using the GUI version, choose the root of the GLFW source tree as
|
||||
source location and the same directory or another, empty directory as the
|
||||
destination for binaries. Choose *Configure*, change any options you wish to,
|
||||
*Configure* again to let the changes take effect and then *Generate*.
|
||||
|
||||
|
||||
### CMake options
|
||||
|
||||
The CMake files for GLFW provide a number of options, although not all are
|
||||
available on all supported platforms. Some of these are de facto standards
|
||||
among CMake users and so have no `GLFW_` prefix.
|
||||
|
||||
If you are using the GUI version of CMake, these are listed and can be changed
|
||||
from there. If you are using the command-line version, use the `ccmake` tool.
|
||||
Some package systems like Ubuntu and other distributions based on Debian
|
||||
GNU/Linux have this tool in a separate `cmake-curses-gui` package.
|
||||
|
||||
|
||||
#### Shared options
|
||||
|
||||
`BUILD_SHARED_LIBS` determines whether GLFW is built as a static
|
||||
library or as a DLL / shared library / dynamic library.
|
||||
|
||||
`LIB_SUFFIX` affects where the GLFW shared /dynamic library is
|
||||
installed. If it is empty, it is installed to `$PREFIX/lib`. If it is set to
|
||||
`64`, it is installed to `$PREFIX/lib64`.
|
||||
|
||||
`GLFW_BUILD_EXAMPLES` determines whether the GLFW examples are built
|
||||
along with the library.
|
||||
|
||||
`GLFW_BUILD_TESTS` determines whether the GLFW test programs are
|
||||
built along with the library.
|
||||
|
||||
|
||||
#### OS X specific options
|
||||
|
||||
`GLFW_USE_CHDIR` determines whether `glfwInit` changes the current
|
||||
directory of bundled applications to the `Contents/Resources` directory.
|
||||
|
||||
`GLFW_USE_MENUBAR` determines whether the first call to
|
||||
`glfwCreateWindow` sets up a minimal menu bar.
|
||||
|
||||
`GLFW_BUILD_UNIVERSAL` determines whether to build Universal Binaries.
|
||||
|
||||
|
||||
#### Windows specific options
|
||||
|
||||
`USE_MSVC_RUNTIME_LIBRARY_DLL` determines whether to use the DLL version or the
|
||||
static library version of the Visual C++ runtime library.
|
||||
|
||||
`GLFW_USE_DWM_SWAP_INTERVAL` determines whether the swap interval is set even
|
||||
when DWM compositing is enabled. This can lead to severe jitter and is not
|
||||
usually recommended.
|
||||
|
||||
`GLFW_USE_OPTIMUS_HPG` determines whether to export the `NvOptimusEnablement`
|
||||
symbol, which forces the use of the high-performance GPU on nVidia Optimus
|
||||
systems.
|
||||
|
||||
|
||||
#### EGL specific options
|
||||
|
||||
`GLFW_USE_EGL` determines whether to use EGL instead of the platform-specific
|
||||
context creation API. Note that EGL is not yet provided on all supported
|
||||
platforms.
|
||||
|
||||
`GLFW_CLIENT_LIBRARY` determines which client API library to use. If set to
|
||||
`opengl` the OpenGL library is used, if set to `glesv1` for the OpenGL ES 1.x
|
||||
library is used, or if set to `glesv2` the OpenGL ES 2.0 library is used. The
|
||||
selected library and its header files must be present on the system for this to
|
||||
work.
|
||||
|
||||
|
||||
## Installing GLFW
|
||||
|
||||
A rudimentary installation target is provided for all supported platforms via
|
||||
CMake.
|
||||
See the [Compiling GLFW](http://www.glfw.org/docs/latest/compile.html) guide in
|
||||
the GLFW documentation.
|
||||
|
||||
|
||||
## Using GLFW
|
||||
|
||||
See the [GLFW documentation](http://www.glfw.org/docs/latest/).
|
||||
See the
|
||||
[Building programs that use GLFW](http://www.glfw.org/docs/latest/build.html)
|
||||
guide in the GLFW documentation.
|
||||
|
||||
|
||||
## Changelog
|
||||
|
||||
- Allowed character callback to be triggered regardless of modifier keys
|
||||
- Bugfix: The `-Wall` flag was not used with Clang and other GCC compatibles
|
||||
- Bugfix: The default for `GLFW_ALPHA_BITS` was set to zero
|
||||
- Bugfix: `glfwInit` would segfault if monitor enumeration failed and no error
|
||||
callback was set
|
||||
- [Win32] Added `_GLFW_USE_DWM_SWAP_INTERVAL` for forcing the swap interval
|
||||
to be set even when DWM compositing is enabled
|
||||
- [Win32] Added support for forcing the use of the high-performance GPU
|
||||
on nVidia Optimus systems
|
||||
- [Win32] Bugfix: The clipboard string was not freed on terminate
|
||||
- [Win32] Bugfix: Entry points for OpenGL 1.0 and 1.1 functions were not
|
||||
returned by `glfwGetProcAddress`
|
||||
- [Win32] Bugfix: The `user32` and `dwmapi` module handles were not freed on
|
||||
library termination
|
||||
- [Cocoa] Added support for precise scrolling deltas on OS X 10.7 and later
|
||||
- [Cocoa] Enabled explicit creation of OpenGL 3.x and 4.x contexts as supported
|
||||
by OS X 10.9
|
||||
- [Cocoa] Bugfix: The clipboard string was not freed on terminate
|
||||
- [Cocoa] Bugfix: Selectors were used that are not declared by the 10.6 SDK
|
||||
- [Cocoa] Bugfix: The position set by `glfwSetWindowPos` was incorrect
|
||||
- [X11] Bugfix: Override-redirect windows were resized to the desired instead
|
||||
of the actual resolution of the selected video mode
|
||||
- [X11] Bugfix: Screensaver override for full screen windows had a possible
|
||||
race condition
|
||||
- [X11] Bugfix: The reported window position did not account for the size of
|
||||
the window frame on some WMs
|
||||
- [X11] Bugfix: The original video mode of a monitor was overwritten by calls
|
||||
to `glfwSetWindowSize`
|
||||
- [X11] Bugfix: Key release events for `GLFW_KEY_KP_5` were discarded.
|
||||
- Added the `GLFW_BUILD_DOCS` CMake option for controlling whether the
|
||||
documentation is built
|
||||
- Added the `_GLFW_USE_CONFIG_H` configuration macro for controlling whether to
|
||||
include the configuration header
|
||||
- Moved version number macro to `internal.h` for easier manual compilation
|
||||
- Renamed configuration header to `glfw_config.h` to avoid conflicts
|
||||
- Bugfix: The `glfw3.pc` file did not respect the `LIB_SUFFIX` CMake option
|
||||
- Bugfix: The `joysticks` test would segfault if a controller had no axes
|
||||
- [Win32] Allowed swap interval to be explicitly set to zero on DWM systems
|
||||
- [Win32] Bugfix: Removed joystick axis value negation left over from GLFW 2
|
||||
- [Win32] Bugfix: Restoring windows using the Win+D hot key did not trigger the
|
||||
focus callback
|
||||
- [Win32] Bugfix: The disabled cursor mode clip rectangle was updated for
|
||||
unfocused windows
|
||||
- [Win32] Bugfix: Cursor was not properly re-centered over odd-sized windows
|
||||
- [Win32] Bugfix: Negative window positions were reported incorrectly
|
||||
- [Win32] Bugfix: The iconify callback was not triggered when switching away
|
||||
from a full screen window using Alt+Tab
|
||||
- [Win32] Bugfix: Resizing a window with `glfwSetWindowSize` gave it focus
|
||||
- [Cocoa] Added dependency on CoreVideo framework for refresh rate retrieval
|
||||
- [Cocoa] Enabled Lion full screen for resizable windowed mode windows
|
||||
- [Cocoa] Moved to Cocoa API for application transformation and activation
|
||||
- [Cocoa] Bugfix: The `GLFW_KEY_GRAVE_ACCENT` key was reported as
|
||||
`GLFW_KEY_WORLD_1` and vice versa
|
||||
- [Cocoa] Bugfix: The `GLFW_KEY_F13` key was reported as
|
||||
`GLFW_KEY_PRINT_SCREEN`
|
||||
- [Cocoa] Bugfix: Implicit conversion from `NSUInteger` to int caused warnings
|
||||
with Xcode 5
|
||||
- [Cocoa] Bugfix: Use of undeclared selectors with `@selector` caused warnings
|
||||
with Xcode 5
|
||||
- [Cocoa] Bugfix: The cursor remained visible if moved onto client area after
|
||||
having been set to hidden outside it
|
||||
- [Cocoa] Bugfix: The refresh rate was zero for all modes of certain monitors
|
||||
- [Cocoa] Bugfix: The `install_name` field of the dynamic library was not set
|
||||
- [Cocoa] Bugfix: Full screen windows were never reported as having focus
|
||||
- [Cocoa] Bugfix: A superfluous I/O flag test prevented video modes from being
|
||||
listed for Thunderbolt monitor
|
||||
- [Cocoa] Bugfix: Retrieving the name of some external displays caused segfault
|
||||
- [Cocoa] Bugfix: The 10.9 SDK defines `GLintptrARB` and `GLsizeiptrARB`
|
||||
differently from the Khronos `glext.h`
|
||||
- [Cocoa] Bugfix: Creating hidden windows would steal application focus
|
||||
- [Cocoa] Bugfix: Controllers were reported as having zero buttons and axes
|
||||
- [Cocoa] Bugfix: Removed joystick axis value negation left over from GLFW 2
|
||||
- [X11] Added setting of the `WM_CLASS` property to the initial window title
|
||||
- [X11] Added support for `_NET_WM_BYPASS_COMPOSITOR`
|
||||
- [X11] Bugfix: Removed joystick axis value negation left over from GLFW 2
|
||||
- [X11] Bugfix: The position of hidden windows was ignored by Metacity
|
||||
and Compiz
|
||||
- [X11] Bugfix: The `pthread.h` header was not included by the GLX platform
|
||||
header.
|
||||
|
||||
|
||||
## Contact
|
||||
@ -272,12 +120,14 @@ skills.
|
||||
- Doug Binks
|
||||
- blanco
|
||||
- Lambert Clara
|
||||
- Andrew Corrigan
|
||||
- Noel Cower
|
||||
- Jarrod Davis
|
||||
- Olivier Delannoy
|
||||
- Paul R. Deppe
|
||||
- Jonathan Dummer
|
||||
- Ralph Eastwood
|
||||
- Michael Fogleman
|
||||
- Gerald Franz
|
||||
- GeO4d
|
||||
- Marcus Geelnard
|
||||
@ -302,13 +152,18 @@ skills.
|
||||
- Marcel Metz
|
||||
- Kenneth Miller
|
||||
- Bruce Mitchener
|
||||
- Jack Moffitt
|
||||
- Jeff Molofee
|
||||
- Jon Morton
|
||||
- Pierre Moulon
|
||||
- Julian Møller
|
||||
- Kamil Nowakowski
|
||||
- Ozzy
|
||||
- Andri Pálsson
|
||||
- Peoro
|
||||
- Braden Pellett
|
||||
- Arturo J. Pérez
|
||||
- Pieroman
|
||||
- Jorge Rodriguez
|
||||
- Ed Ropple
|
||||
- Riku Salminen
|
||||
@ -316,6 +171,7 @@ skills.
|
||||
- Matt Sealey
|
||||
- SephiRok
|
||||
- Steve Sexton
|
||||
- Systemcluster
|
||||
- Dmitri Shuralyov
|
||||
- Daniel Skorupski
|
||||
- Bradley Smith
|
||||
@ -326,6 +182,7 @@ skills.
|
||||
- TTK-Bandit
|
||||
- Sergey Tikhomirov
|
||||
- Samuli Tuomola
|
||||
- urraka
|
||||
- Jari Vetoniemi
|
||||
- Simon Voordouw
|
||||
- Torsten Walluhn
|
||||
|
877
extern/glfw/deps/GL/glext.h
vendored
4
extern/glfw/deps/GL/glxext.h
vendored
@ -33,10 +33,10 @@ extern "C" {
|
||||
** used to make the header, and the header can be found at
|
||||
** http://www.opengl.org/registry/
|
||||
**
|
||||
** Khronos $Revision$ on $Date$
|
||||
** Khronos $Revision: 23649 $ on $Date: 2013-10-23 00:21:49 -0700 (Wed, 23 Oct 2013) $
|
||||
*/
|
||||
|
||||
#define GLX_GLXEXT_VERSION 20130710
|
||||
#define GLX_GLXEXT_VERSION 20131008
|
||||
|
||||
/* Generated C header for:
|
||||
* API: glx
|
||||
|
12
extern/glfw/deps/GL/wglext.h
vendored
@ -33,7 +33,7 @@ extern "C" {
|
||||
** used to make the header, and the header can be found at
|
||||
** http://www.opengl.org/registry/
|
||||
**
|
||||
** Khronos $Revision$ on $Date$
|
||||
** Khronos $Revision: 23649 $ on $Date: 2013-10-23 00:21:49 -0700 (Wed, 23 Oct 2013) $
|
||||
*/
|
||||
|
||||
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
||||
@ -41,7 +41,7 @@ extern "C" {
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define WGL_WGLEXT_VERSION 20130710
|
||||
#define WGL_WGLEXT_VERSION 20130916
|
||||
|
||||
/* Generated C header for:
|
||||
* API: wgl
|
||||
@ -645,6 +645,14 @@ BOOL WINAPI wglCopyImageSubDataNV (HGLRC hSrcRC, GLuint srcName, GLenum srcTarge
|
||||
#endif
|
||||
#endif /* WGL_NV_copy_image */
|
||||
|
||||
#ifndef WGL_NV_delay_before_swap
|
||||
#define WGL_NV_delay_before_swap 1
|
||||
typedef BOOL (WINAPI * PFNWGLDELAYBEFORESWAPNVPROC) (HDC hDC, GLfloat seconds);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglDelayBeforeSwapNV (HDC hDC, GLfloat seconds);
|
||||
#endif
|
||||
#endif /* WGL_NV_delay_before_swap */
|
||||
|
||||
#ifndef WGL_NV_float_buffer
|
||||
#define WGL_NV_float_buffer 1
|
||||
#define WGL_FLOAT_COMPONENTS_NV 0x20B0
|
||||
|
10
extern/glfw/docs/CMakeLists.txt
vendored
@ -1,5 +1,5 @@
|
||||
|
||||
add_custom_target(docs ALL ${DOXYGEN_EXECUTABLE}
|
||||
WORKING_DIRECTORY ${GLFW_BINARY_DIR}/docs
|
||||
COMMENT "Generating HTML documentation" VERBATIM)
|
||||
|
||||
|
||||
add_custom_target(docs ALL ${DOXYGEN_EXECUTABLE}
|
||||
WORKING_DIRECTORY ${GLFW_BINARY_DIR}/docs
|
||||
COMMENT "Generating HTML documentation" VERBATIM)
|
||||
|
||||
|
7
extern/glfw/docs/Doxyfile.in
vendored
@ -659,6 +659,7 @@ INPUT = @GLFW_INTERNAL_DOCS@ \
|
||||
@GLFW_SOURCE_DIR@/docs/news.dox \
|
||||
@GLFW_SOURCE_DIR@/docs/quick.dox \
|
||||
@GLFW_SOURCE_DIR@/docs/moving.dox \
|
||||
@GLFW_SOURCE_DIR@/docs/compile.dox \
|
||||
@GLFW_SOURCE_DIR@/docs/build.dox \
|
||||
@GLFW_SOURCE_DIR@/docs/context.dox \
|
||||
@GLFW_SOURCE_DIR@/docs/monitor.dox \
|
||||
@ -899,13 +900,13 @@ HTML_FILE_EXTENSION = .html
|
||||
# have to redo this when upgrading to a newer version of doxygen or when
|
||||
# changing the value of configuration settings such as GENERATE_TREEVIEW!
|
||||
|
||||
HTML_HEADER =
|
||||
HTML_HEADER = @GLFW_SOURCE_DIR@/docs/header.html
|
||||
|
||||
# The HTML_FOOTER tag can be used to specify a personal HTML footer for
|
||||
# each generated HTML page. If it is left blank doxygen will generate a
|
||||
# standard footer.
|
||||
|
||||
HTML_FOOTER =
|
||||
HTML_FOOTER = @GLFW_SOURCE_DIR@/docs/footer.html
|
||||
|
||||
# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
|
||||
# style sheet that is used by each HTML page. It can be used to
|
||||
@ -924,7 +925,7 @@ HTML_STYLESHEET =
|
||||
# robust against future updates. Doxygen will copy the style sheet file to
|
||||
# the output directory.
|
||||
|
||||
HTML_EXTRA_STYLESHEET =
|
||||
HTML_EXTRA_STYLESHEET = @GLFW_SOURCE_DIR@/docs/extra.css
|
||||
|
||||
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
|
||||
# other source files which should be copied to the HTML output directory. Note
|
||||
|
22
extern/glfw/docs/build.dox
vendored
@ -1,11 +1,13 @@
|
||||
/*!
|
||||
|
||||
@page build Building programs using GLFW
|
||||
@page build Building programs that use GLFW
|
||||
|
||||
@tableofcontents
|
||||
|
||||
This is about compiling and linking programs that use GLFW. For information on
|
||||
how to *write* such programs, start with the [introductory tutorial](@ref quick).
|
||||
how to write such programs, start with the [introductory tutorial](@ref quick).
|
||||
For information on how to compile the GLFW library itself, see the @ref compile
|
||||
guide.
|
||||
|
||||
|
||||
@section build_include Including the GLFW header file
|
||||
@ -48,7 +50,9 @@ header that the GLFW header includes and GLEW will work as expected.
|
||||
@subsection build_macros GLFW header option macros
|
||||
|
||||
These macros may be defined before the inclusion of the GLFW header and affect
|
||||
how that header behaves.
|
||||
the behavior of the header. Note that GLFW does not provide any of the OpenGL
|
||||
or OpenGL ES headers mentioned below. These are provided by your development
|
||||
environment or your OpenGL or OpenGL ES SDK.
|
||||
|
||||
`GLFW_INCLUDE_GLCOREARB` makes the header include the modern `GL/glcorearb.h`
|
||||
header (`OpenGL/gl3.h` on OS X) instead of the regular OpenGL header.
|
||||
@ -81,8 +85,10 @@ The static version of the GLFW library is named `glfw3`. When using this
|
||||
version, it is also necessary to link with some libraries that GLFW uses.
|
||||
|
||||
When linking a program under Windows that uses the static version of GLFW, you
|
||||
must link with `opengl32`. If you are using GLU, you must also link with
|
||||
`glu32`.
|
||||
must link with `opengl32`. On some versions of MinGW, you must also explicitly
|
||||
link with `gdi32`, while other versions of MinGW include it in the set of
|
||||
default libraries along with other dependencies like `user32` and `kernel32`.
|
||||
If you are using GLU, you must also link with `glu32`.
|
||||
|
||||
The link library for the GLFW DLL is named `glfw3dll`. When compiling a program
|
||||
that uses the DLL version of GLFW, you need to define the `GLFW_DLL` macro
|
||||
@ -158,7 +164,7 @@ If you are using the static library version of GLFW, use the
|
||||
@subsection build_link_pkgconfig With pkg-config on OS X or other Unix
|
||||
|
||||
GLFW supports [pkg-config](http://www.freedesktop.org/wiki/Software/pkg-config/),
|
||||
and `glfw3.pc` file is generated when the GLFW library is built and installed
|
||||
and the `glfw3.pc` file is generated when the GLFW library is built and installed
|
||||
along with it.
|
||||
|
||||
A typical compile and link command-line when using the static may look like this:
|
||||
@ -189,7 +195,7 @@ If you are using the dynamic library version of GLFW, simply add it to the
|
||||
project dependencies.
|
||||
|
||||
If you are using the static library version of GLFW, add it and the Cocoa,
|
||||
OpenGL and IOKit frameworks to the project as dependencies.
|
||||
OpenGL, IOKit and CoreVideo frameworks to the project as dependencies.
|
||||
|
||||
|
||||
@subsection build_link_osx With command-line on OS X
|
||||
@ -198,7 +204,7 @@ If you do not wish to use pkg-config, you need to add the required frameworks
|
||||
and libraries to your command-line using the `-l` and `-framework` switches,
|
||||
i.e.:
|
||||
|
||||
cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit
|
||||
cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
|
||||
|
||||
Note that you do not add the `.framework` extension to a framework when adding
|
||||
it from the command-line.
|
||||
|
16
extern/glfw/docs/compat.dox
vendored
@ -123,15 +123,15 @@ version 2.1.
|
||||
|
||||
Because of this, on OS X 10.7 and later, the `GLFW_CONTEXT_VERSION_MAJOR` and
|
||||
`GLFW_CONTEXT_VERSION_MINOR` hints will cause @ref glfwCreateWindow to fail if
|
||||
given version 3.0 or 3.1, the `GLFW_OPENGL_FORWARD_COMPAT` is required for
|
||||
creating contexts for OpenGL 3.2 and later, the `GLFW_OPENGL_DEBUG_CONTEXT` hint
|
||||
is ignored and setting the `GLFW_OPENGL_PROFILE` hint to anything except
|
||||
`GLFW_OPENGL_CORE_PROFILE` will cause @ref glfwCreateWindow to fail.
|
||||
given version 3.0 or 3.1, the `GLFW_OPENGL_FORWARD_COMPAT` hint must be set to
|
||||
non-zero and the `GLFW_OPENGL_PROFILE` hint must be set to
|
||||
`GLFW_OPENGL_CORE_PROFILE` when creating OpenGL 3.2 and later contexts and the
|
||||
`GLFW_OPENGL_DEBUG_CONTEXT` hint is ignored.
|
||||
|
||||
Also, on Mac OS X 10.6 and below, the `GLFW_CONTEXT_VERSION_MAJOR` and
|
||||
`GLFW_CONTEXT_VERSION_MINOR` hints will fail if given a version above 2.1, the
|
||||
`GLFW_OPENGL_DEBUG_CONTEXT` hint will have no effect, and setting the
|
||||
`GLFW_OPENGL_PROFILE` or `GLFW_OPENGL_FORWARD_COMPAT` hints to a non-zero value
|
||||
will cause @ref glfwCreateWindow to fail.
|
||||
`GLFW_CONTEXT_VERSION_MINOR` hints will fail if given a version above 2.1,
|
||||
setting the `GLFW_OPENGL_PROFILE` or `GLFW_OPENGL_FORWARD_COMPAT` hints to
|
||||
a non-default value will cause @ref glfwCreateWindow to fail and the
|
||||
`GLFW_OPENGL_DEBUG_CONTEXT` hint is ignored.
|
||||
|
||||
*/
|
||||
|
261
extern/glfw/docs/compile.dox
vendored
Normal file
@ -0,0 +1,261 @@
|
||||
/*!
|
||||
|
||||
@page compile Compiling GLFW
|
||||
|
||||
@tableofcontents
|
||||
|
||||
This is about compiling the GLFW library itself. For information on how to
|
||||
build programs that use GLFW, see the @ref build guide.
|
||||
|
||||
|
||||
@section compile_deps Dependencies
|
||||
|
||||
To compile GLFW and the accompanying example programs, you will need **CMake**,
|
||||
which will generate the project files or makefiles for your particular
|
||||
development environment. If you are on a Unix-like system such as Linux or
|
||||
FreeBSD or have a package system like Fink, MacPorts, Cygwin or Homebrew, you
|
||||
can simply install its CMake package. If not, you can get installers for
|
||||
Windows and OS X from the [CMake website](http://www.cmake.org/).
|
||||
|
||||
Additional dependencies are listed below.
|
||||
|
||||
If you wish to compile GLFW without CMake, see @ref compile_manual.
|
||||
|
||||
|
||||
@subsection compile_deps_msvc Dependencies using Visual C++ on Windows
|
||||
|
||||
The Microsoft Platform SDK that is installed along with Visual C++ contains all
|
||||
the necessary headers, link libraries and tools except for CMake.
|
||||
|
||||
|
||||
@subsection compile_deps_mingw Dependencies with MinGW or MinGW-w64 on Windows
|
||||
|
||||
Both the MinGW and the MinGW-w64 packages contain all the necessary headers,
|
||||
link libraries and tools except for CMake.
|
||||
|
||||
|
||||
@subsection compile_deps_mingw_cross Dependencies using MinGW or MinGW-w64 cross-compilation
|
||||
|
||||
Both Cygwin and many Linux distributions have MinGW or MinGW-w64 packages. For
|
||||
example, Cygwin has the `mingw64-i686-gcc` and `mingw64-x86_64-gcc` packages
|
||||
for 32- and 64-bit version of MinGW-w64, while Debian GNU/Linux and derivatives
|
||||
like Ubuntu have the `mingw-w64` package for both.
|
||||
|
||||
GLFW has CMake toolchain files in the `CMake/` directory that allow for easy
|
||||
cross-compilation of Windows binaries. To use these files you need to add a
|
||||
special parameter when generating the project files or makefiles:
|
||||
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=<toolchain-file> .
|
||||
|
||||
The exact toolchain file to use depends on the prefix used by the MinGW or
|
||||
MinGW-w64 binaries on your system. You can usually see this in the /usr
|
||||
directory. For example, both the Debian/Ubuntu and Cygwin MinGW-w64 packages
|
||||
have `/usr/x86_64-w64-mingw32` for the 64-bit compilers, so the correct
|
||||
invocation would be:
|
||||
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake .
|
||||
|
||||
For more details see the article
|
||||
[CMake Cross Compiling](http://www.paraview.org/Wiki/CMake_Cross_Compiling) on
|
||||
the CMake wiki.
|
||||
|
||||
|
||||
@subsection compile_deps_xcode Dependencies using Xcode on OS X
|
||||
|
||||
Xcode contains all necessary tools except for CMake. The necessary headers and
|
||||
libraries are included in the core OS frameworks. Xcode can be downloaded from
|
||||
the Mac App Store or from the ADC Member Center.
|
||||
|
||||
|
||||
@subsection compile_deps_x11 Dependencies using Linux and X11
|
||||
|
||||
To compile GLFW for X11, you need to have the X11 and OpenGL header packages
|
||||
installed, as well as the basic development tools like GCC and make. For
|
||||
example, on Ubuntu and other distributions based on Debian GNU/Linux, you need
|
||||
to install the `xorg-dev` and `libglu1-mesa-dev` packages. The former pulls in
|
||||
all X.org header packages and the latter pulls in the Mesa OpenGL and GLU
|
||||
packages. GLFW itself doesn't need or use GLU, but some of the examples do.
|
||||
Note that using header files and libraries from Mesa during compilation *will
|
||||
not* tie your binaries to the Mesa implementation of OpenGL.
|
||||
|
||||
|
||||
@section compile_cmake Generating files with CMake
|
||||
|
||||
Once you have all necessary dependencies it is time to generate the project
|
||||
files or makefiles for your development environment. CMake needs to know two
|
||||
paths for this: the path to the *root* directory of the GLFW source tree (i.e.
|
||||
*not* the `src` subdirectory) and the target path for the generated files and
|
||||
compiled binaries. If these are the same, it is called an in-tree build,
|
||||
otherwise it is called an out-of-tree build.
|
||||
|
||||
One of several advantages of out-of-tree builds is that you can generate files
|
||||
and compile for different development environments using a single source tree.
|
||||
|
||||
|
||||
@subsection compile_cmake_cli Generating files with the CMake command-line tool
|
||||
|
||||
To make an in-tree build, enter the *root* directory of the GLFW source tree
|
||||
(i.e. *not* the `src` subdirectory) and run CMake. The current directory is
|
||||
used as target path, while the path provided as an argument is used to find the
|
||||
source tree.
|
||||
|
||||
cd <glfw-root-dir>
|
||||
cmake .
|
||||
|
||||
To make an out-of-tree build, make another directory, enter it and run CMake
|
||||
with the (relative or absolute) path to the root of the source tree as an
|
||||
argument.
|
||||
|
||||
cd <glfw-root-dir>
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
|
||||
|
||||
@subsection compile_cmake_gui Generating files with the CMake GUI
|
||||
|
||||
If you are using the GUI version, choose the root of the GLFW source tree as
|
||||
source location and the same directory or another, empty directory as the
|
||||
destination for binaries. Choose *Configure*, change any options you wish to,
|
||||
*Configure* again to let the changes take effect and then *Generate*.
|
||||
|
||||
|
||||
@section compile_options CMake options
|
||||
|
||||
The CMake files for GLFW provide a number of options, although not all are
|
||||
available on all supported platforms. Some of these are de facto standards
|
||||
among CMake users and so have no `GLFW_` prefix.
|
||||
|
||||
If you are using the GUI version of CMake, these are listed and can be changed
|
||||
from there. If you are using the command-line version, use the `ccmake` tool.
|
||||
Some package systems like Ubuntu and other distributions based on Debian
|
||||
GNU/Linux have this tool in a separate `cmake-curses-gui` package.
|
||||
|
||||
|
||||
@subsection compile_options_shared Shared CMake options
|
||||
|
||||
`BUILD_SHARED_LIBS` determines whether GLFW is built as a static
|
||||
library or as a DLL / shared library / dynamic library.
|
||||
|
||||
`LIB_SUFFIX` affects where the GLFW shared /dynamic library is installed. If it
|
||||
is empty, it is installed to `${CMAKE_INSTALL_PREFIX}/lib`. If it is set to
|
||||
`64`, it is installed to `${CMAKE_INSTALL_PREFIX}/lib64`.
|
||||
|
||||
`GLFW_CLIENT_LIBRARY` determines which client API library to use. If set to
|
||||
`opengl` the OpenGL library is used, if set to `glesv1` for the OpenGL ES 1.x
|
||||
library is used, or if set to `glesv2` the OpenGL ES 2.0 library is used. The
|
||||
selected library and its header files must be present on the system for this to
|
||||
work.
|
||||
|
||||
`GLFW_BUILD_EXAMPLES` determines whether the GLFW examples are built
|
||||
along with the library.
|
||||
|
||||
`GLFW_BUILD_TESTS` determines whether the GLFW test programs are
|
||||
built along with the library.
|
||||
|
||||
`GLFW_BUILD_DOCS` determines whether the GLFW documentation is built along with
|
||||
the library.
|
||||
|
||||
|
||||
@subsection compile_options_osx OS X specific CMake options
|
||||
|
||||
`GLFW_USE_CHDIR` determines whether `glfwInit` changes the current
|
||||
directory of bundled applications to the `Contents/Resources` directory.
|
||||
|
||||
`GLFW_USE_MENUBAR` determines whether the first call to
|
||||
`glfwCreateWindow` sets up a minimal menu bar.
|
||||
|
||||
`GLFW_BUILD_UNIVERSAL` determines whether to build Universal Binaries.
|
||||
|
||||
|
||||
@subsection compile_options_win32 Windows specific CMake options
|
||||
|
||||
`USE_MSVC_RUNTIME_LIBRARY_DLL` determines whether to use the DLL version or the
|
||||
static library version of the Visual C++ runtime library. If set to `ON`, the
|
||||
DLL version of the Visual C++ library is used. It is recommended to set this to
|
||||
`ON`, as this keeps the executable smaller and benefits from security and bug
|
||||
fix updates of the Visual C++ runtime.
|
||||
|
||||
`GLFW_USE_DWM_SWAP_INTERVAL` determines whether the swap interval is set even
|
||||
when DWM compositing is enabled. If this is `ON`, the swap interval is set even
|
||||
if DWM is enabled. It is recommended to set this to `OFF`, as doing otherwise
|
||||
can lead to severe jitter.
|
||||
|
||||
`GLFW_USE_OPTIMUS_HPG` determines whether to export the `NvOptimusEnablement`
|
||||
symbol, which forces the use of the high-performance GPU on nVidia Optimus
|
||||
systems.
|
||||
|
||||
|
||||
@subsection compile_options_egl EGL specific CMake options
|
||||
|
||||
`GLFW_USE_EGL` determines whether to use EGL instead of the platform-specific
|
||||
context creation API. Note that EGL is not yet provided on all supported
|
||||
platforms.
|
||||
|
||||
|
||||
@section compile_manual Compiling GLFW manually
|
||||
|
||||
If you wish to compile GLFW without its CMake build environment then you will
|
||||
have to do at least some of the platform detection yourself. GLFW needs
|
||||
a number of configuration macros to be defined in order to know what it's being
|
||||
compiled for and has many optional, platform-specific ones for various features.
|
||||
|
||||
When building with CMake, the `glfw_config.h` configuration header is generated
|
||||
based on the current platform and CMake options. The GLFW CMake environment
|
||||
defines `_GLFW_USE_CONFIG_H`, which causes this header to be included by
|
||||
`internal.h`. Without this macro, GLFW will expect the necessary configuration
|
||||
macros to be defined on the command-line.
|
||||
|
||||
Three macros *must* be defined when compiling GLFW: one for selecting the window
|
||||
creation API, one selecting the context creation API and one client library.
|
||||
Exactly one of each kind must be defined for GLFW to compile and link.
|
||||
|
||||
The window creation API is used to create windows, handle input, monitors, gamma
|
||||
ramps and clipboard. The options are:
|
||||
|
||||
- `_GLFW_COCOA` to use the Cocoa frameworks
|
||||
- `_GLFW_WIN32` to use the Win32 API
|
||||
- `_GLFW_X11` to use the X Window System
|
||||
|
||||
The context creation API is used to enumerate pixel formats / framebuffer
|
||||
configurations and to create contexts. The options are:
|
||||
|
||||
- `_GLFW_NSGL` to use the Cocoa OpenGL framework
|
||||
- `_GLFW_WGL` to use the Win32 WGL API
|
||||
- `_GLFW_GLX` to use the X11 GLX API
|
||||
- `_GLFW_EGL` to use the EGL API (experimental)
|
||||
|
||||
The client library is the one providing the OpenGL or OpenGL ES API, which is
|
||||
used by GLFW to probe the created context. This is not the same thing as the
|
||||
client API, as many desktop OpenGL client libraries now expose the OpenGL ES API
|
||||
through extensions. The options are:
|
||||
|
||||
- `_GLFW_USE_OPENGL` for the desktop OpenGL (opengl32.dll, libGL.so or
|
||||
OpenGL.framework)
|
||||
- `_GLFW_USE_GLESV1` for OpenGL ES 1.x (experimental)
|
||||
- `_GLFW_USE_GLESV2` for OpenGL ES 2.x (experimental)
|
||||
|
||||
Note that `_GLFW_USE_GLESV1` and `_GLFW_USE_GLESV2` may only be used with EGL,
|
||||
as the other context creation APIs do not interface with OpenGL ES client
|
||||
libraries.
|
||||
|
||||
If you are building GLFW as a shared library / dynamic library / DLL then you
|
||||
must also define `_GLFW_BUILD_DLL`. Otherwise, you may not define it.
|
||||
|
||||
If you are using the X11 window creation API then you *must* also select an entry
|
||||
point retrieval mechanism.
|
||||
|
||||
- `_GLFW_HAS_GLXGETPROCADDRESS` to use `glXGetProcAddress` (recommended)
|
||||
- `_GLFW_HAS_GLXGETPROCADDRESSARB` to use `glXGetProcAddressARB` (legacy)
|
||||
- `_GLFW_HAS_GLXGETPROCADDRESSEXT` to use `glXGetProcAddressEXT` (legacy)
|
||||
- `_GLFW_HAS_DLOPEN` to do manual retrieval with `dlopen` (fallback)
|
||||
|
||||
If you are using the Cocoa window creation API, the following options are
|
||||
available:
|
||||
|
||||
- `_GLFW_USE_CHDIR` to `chdir` to the `Resources` subdirectory of the
|
||||
application bundle during @ref glfwInit (recommended)
|
||||
- `_GLFW_USE_MENUBAR` to create and populate the menu bar when the first window
|
||||
is created (recommended)
|
||||
|
||||
*/
|
9
extern/glfw/docs/context.dox
vendored
@ -24,6 +24,15 @@ what kind of context is created. See
|
||||
[context related hints](@ref window_hints_ctx) in the window handling guide.
|
||||
|
||||
|
||||
@section context_sharing Context object sharing
|
||||
|
||||
When creating a window and context with @ref glfwCreateWindow, you can specify
|
||||
another window whose context the new one should share its objects with. OpenGL
|
||||
object sharing is implemented by the operating system and graphics driver and is
|
||||
described in the OpenGL documentation. On platforms where it is possible to
|
||||
choose which types of objects are shared, GLFW requests that all are shared.
|
||||
|
||||
|
||||
@section context_current Current context
|
||||
|
||||
Before you can use the OpenGL or OpenGL ES APIs, you need to have a current
|
||||
|
312
extern/glfw/docs/extra.css
vendored
Normal file
@ -0,0 +1,312 @@
|
||||
html {
|
||||
background-color:hsl(0,0%,95%);
|
||||
}
|
||||
|
||||
.glfwheader {
|
||||
font-size:16px;
|
||||
height:64px;
|
||||
max-width:920px;
|
||||
margin:0em auto;
|
||||
}
|
||||
|
||||
.glfwheader a#glfwhome {
|
||||
line-height:64px;
|
||||
padding-right:48px;
|
||||
float:left;
|
||||
color:hsl(0,0%,40%);
|
||||
font-size:2.5em;
|
||||
background-image:url("http://www.glfw.org/css/arrow.png");
|
||||
background-position:right top;
|
||||
background-repeat:no-repeat;
|
||||
}
|
||||
|
||||
.glfwnavbar {
|
||||
list-style-type:none;
|
||||
margin-top:0px;
|
||||
float:right;
|
||||
}
|
||||
|
||||
.glfwnavbar li {
|
||||
float:left;
|
||||
}
|
||||
|
||||
.glfwnavbar a,.glfwnavbar a:visited {
|
||||
line-height:64px;
|
||||
margin-left:2em;
|
||||
display:block;
|
||||
color:hsl(0,0%,40%);
|
||||
}
|
||||
|
||||
.glfwheader a#glfwhome,.glfwnavbar a,.glfwnavbar a:visited {
|
||||
transition:all 0.35s ease 0s;
|
||||
}
|
||||
|
||||
#titlearea,address.footer {
|
||||
color:hsl(0,0%,40%);
|
||||
background-color:hsl(0,0%,95%);
|
||||
border-bottom:none;
|
||||
}
|
||||
|
||||
address.footer {
|
||||
text-align:center;
|
||||
padding:2em;
|
||||
}
|
||||
|
||||
div#top {
|
||||
background-color:hsl(0,0%,40%);
|
||||
}
|
||||
|
||||
div#navrow1,div#navrow2,div#navrow3,div#navrow4 {
|
||||
background-color:hsl(0,0%,40%);
|
||||
background-image:none;
|
||||
max-width:920px;
|
||||
margin:0em auto;
|
||||
}
|
||||
|
||||
ul.tablist {
|
||||
min-width:700px;
|
||||
}
|
||||
|
||||
.tablist a,.tablist a:hover,.tablist li,.tablist li.current a {
|
||||
background-image:none;
|
||||
text-shadow:none;
|
||||
}
|
||||
|
||||
.tablist a,.tablist a:visited {
|
||||
color:hsl(0,0%,95%);
|
||||
text-shadow:none;
|
||||
}
|
||||
|
||||
.tablist li.current a {
|
||||
background:linear-gradient(to bottom,hsl(34,100%,60%) 0%,hsl(24,100%,50%) 100%);
|
||||
box-shadow:inset 0px 0px 32px hsl(24,100%,50%);
|
||||
text-shadow:0px -1px 1px hsl(24,100%,35%);
|
||||
color:hsl(0,0%,100%);
|
||||
}
|
||||
|
||||
div.contents {
|
||||
min-height:590px;
|
||||
}
|
||||
|
||||
div.contents,div.header {
|
||||
max-width:920px;
|
||||
margin:0em auto;
|
||||
padding:0em 2em 2em 2em;
|
||||
background-color:hsl(0,0%,100%);
|
||||
}
|
||||
|
||||
div.header {
|
||||
background-image:none;
|
||||
border-bottom:none;
|
||||
}
|
||||
|
||||
table.doxtable th,dl.reflist dt,div.levels {
|
||||
background:linear-gradient(to bottom,hsl(34,100%,60%) 0%,hsl(24,100%,50%) 100%);
|
||||
box-shadow:inset 0px 0px 32px hsl(24,100%,50%);
|
||||
text-shadow:0px -1px 1px hsl(24,100%,35%);
|
||||
color:hsl(0,0%,100%);
|
||||
}
|
||||
|
||||
dl.reflist dt a.el,div.levels span {
|
||||
color:hsl(24,100%,50%);
|
||||
padding:0.2em;
|
||||
border-radius:4px;
|
||||
background-color:hsl(24,100%,90%);
|
||||
text-shadow:none;
|
||||
}
|
||||
|
||||
div.memproto,div.qindex,div.ah {
|
||||
background:linear-gradient(to bottom,hsl(34,0%,95%) 0%,hsl(24,0%,90%) 100%);
|
||||
box-shadow:inset 0px 0px 32px hsl(24,0%,90%);
|
||||
text-shadow:0px 1px 1px hsl(24,0%,100%);
|
||||
color:hsl(0,0%,10%);
|
||||
}
|
||||
|
||||
div.memproto a {
|
||||
color:hsl(24,100%,50%);
|
||||
}
|
||||
|
||||
div.memproto td.paramname {
|
||||
text-shadow:0px 1px 1px hsl(24,0%,100%);
|
||||
}
|
||||
|
||||
div.memproto,div.qindex,div.ah {
|
||||
border:2px solid hsl(24,0%,90%);
|
||||
border-radius:4px;
|
||||
}
|
||||
|
||||
div.memdoc {
|
||||
background:none;
|
||||
box-shadow:none;
|
||||
border:none;
|
||||
}
|
||||
|
||||
td.paramname {
|
||||
color:hsl(24,100%,25%);
|
||||
}
|
||||
|
||||
dl.reflist dt {
|
||||
border:2px solid hsl(24,100%,50%);
|
||||
border-top-left-radius:4px;
|
||||
border-top-right-radius:4px;
|
||||
border-bottom:none;
|
||||
}
|
||||
|
||||
dl.reflist dd {
|
||||
border:2px solid hsl(24,100%,50%);
|
||||
border-bottom-right-radius:4px;
|
||||
border-bottom-left-radius:4px;
|
||||
border-top:none;
|
||||
background:none;
|
||||
box-shadow:none;
|
||||
}
|
||||
|
||||
table.doxtable {
|
||||
border-collapse:inherit;
|
||||
border-spacing:0px;
|
||||
border:2px solid hsl(24,100%,50%);
|
||||
border-radius:4px;
|
||||
}
|
||||
|
||||
table.doxtable td,table.doxtable th {
|
||||
border:none;
|
||||
}
|
||||
|
||||
tr.even,.directory tr.even,table.doxtable tr:nth-child(even) {
|
||||
background-color:hsl(0,0%,95%);
|
||||
}
|
||||
|
||||
body {
|
||||
color:hsl(0,0%,30%);
|
||||
}
|
||||
|
||||
h1,h2,h2.groupheader,h3,div.toc h3,h4,h5,h6,strong,em {
|
||||
color:hsl(0,0%,10%);
|
||||
border-bottom:none;
|
||||
}
|
||||
|
||||
a,a:hover,a:visited,a:visited:hover,a.el,a.el:visited,.glfwheader a#glfwhome:hover,.tablist a:hover {
|
||||
color:hsl(24,100%,50%);
|
||||
text-decoration:none;
|
||||
}
|
||||
|
||||
.mdescLeft,.mdescRight,.memItemLeft,.memItemRight {
|
||||
background-color:hsl(0,0%,95%);
|
||||
}
|
||||
|
||||
div.directory {
|
||||
border-collapse:inherit;
|
||||
border-spacing:0px;
|
||||
border:2px solid hsl(24,100%,50%);
|
||||
border-radius:4px;
|
||||
}
|
||||
|
||||
.directory .levels span {
|
||||
color:hsl(24,100%,50%);
|
||||
padding:0.1em 0.5em;
|
||||
margin:auto 0.25em;
|
||||
border-radius:2px;
|
||||
background-color:hsl(24,100%,90%);
|
||||
text-shadow:none;
|
||||
}
|
||||
|
||||
td.memSeparator {
|
||||
height:2px;
|
||||
border:0px;
|
||||
background:linear-gradient(to right,hsl(0,0%,95%) 0%,hsl(0,0%,85%) 50%,hsl(0,0%,95%) 100%);
|
||||
}
|
||||
|
||||
dl.note,dl.pre,dl.post,dl.invariant {
|
||||
background:linear-gradient(to bottom,hsl(103,80%,90%) 0%,hsl(103,80%,85%) 100%);
|
||||
box-shadow:inset 0px 0px 32px hsl(103,40%,80%);
|
||||
color:hsl(103,80%,10%);
|
||||
border:2px solid hsl(103,40%,75%);
|
||||
}
|
||||
|
||||
dl.warning,dl.attention {
|
||||
background:linear-gradient(to bottom,hsl(34,80%,90%) 0%,hsl(34,80%,85%) 100%);
|
||||
box-shadow:inset 0px 0px 32px hsl(34,40%,80%);
|
||||
color:hsl(34,80%,10%);
|
||||
border:2px solid hsl(34,40%,75%);
|
||||
}
|
||||
|
||||
dl.deprecated,dl.bug {
|
||||
background:linear-gradient(to bottom,hsl(333,80%,90%) 0%,hsl(333,80%,85%) 100%);
|
||||
box-shadow:inset 0px 0px 32px hsl(333,40%,80%);
|
||||
color:hsl(333,80%,10%);
|
||||
border:2px solid hsl(333,40%,75%);
|
||||
}
|
||||
|
||||
dl.todo,dl.test {
|
||||
background:linear-gradient(to bottom,hsl(200,80%,90%) 0%,hsl(200,80%,85%) 100%);
|
||||
box-shadow:inset 0px 0px 32px hsl(200,40%,80%);
|
||||
color:hsl(200,80%,10%);
|
||||
border:2px solid hsl(200,40%,75%);
|
||||
}
|
||||
|
||||
dl.note,dl.pre,dl.post,dl.invariant,dl.warning,dl.attention,dl.deprecated,dl.bug,dl.todo,dl.test {
|
||||
border-radius:4px;
|
||||
padding:1em;
|
||||
text-shadow:0px 1px 1px hsl(0,0%,100%);
|
||||
}
|
||||
|
||||
div.toc {
|
||||
background:linear-gradient(to bottom,hsl(34,0%,95%) 0%,hsl(24,0%,90%) 100%);
|
||||
box-shadow:inset 0px 0px 32px hsl(24,0%,90%);
|
||||
text-shadow:0px 1px 1px hsl(24,0%,100%);
|
||||
color:hsl(0,0%,10%);
|
||||
border:2px solid hsl(24,0%,90%);
|
||||
border-radius:4px;
|
||||
float:none;
|
||||
width:auto;
|
||||
}
|
||||
|
||||
div.toc h3 {
|
||||
font-size:1.17em;
|
||||
}
|
||||
|
||||
div.toc ul {
|
||||
padding-left:1.5em;
|
||||
}
|
||||
|
||||
div.toc li {
|
||||
background:none;
|
||||
font-size:1em;
|
||||
padding-left:0em;
|
||||
list-style-type:disc;
|
||||
}
|
||||
|
||||
div.ah {
|
||||
background-image:none;
|
||||
}
|
||||
|
||||
div.fragment,pre.fragment {
|
||||
background-color:hsl(0,0%,20%);
|
||||
border-radius:4px;
|
||||
border-width:0px;
|
||||
padding:0.5em 2em;
|
||||
overflow:auto;
|
||||
border-left:4px solid hsl(0,0%,80%);
|
||||
}
|
||||
|
||||
div.line,pre.fragment {
|
||||
color:hsl(60,30%,96%);
|
||||
}
|
||||
|
||||
a.code,a.code:visited,span.preprocessor,span.comment {
|
||||
color:hsl(80,76%,53%);
|
||||
}
|
||||
|
||||
span.keyword,span.keywordtype,span.keywordflow {
|
||||
color:hsl(190,81%,67%);
|
||||
}
|
||||
|
||||
span.stringliteral {
|
||||
color:hsl(54,70%,68%);
|
||||
}
|
||||
|
||||
code {
|
||||
background-color:hsl(0,0%,95%);
|
||||
padding:0.1em;
|
||||
border-radius: 4px;
|
||||
}
|
7
extern/glfw/docs/footer.html
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<address class="footer">
|
||||
<p>
|
||||
Last update on $date for $projectname $projectnumber
|
||||
</p>
|
||||
</address>
|
||||
</body>
|
||||
</html>
|
34
extern/glfw/docs/header.html
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||||
<meta name="generator" content="Doxygen $doxygenversion"/>
|
||||
<!--BEGIN PROJECT_NAME--><title>$projectname: $title</title><!--END PROJECT_NAME-->
|
||||
<!--BEGIN !PROJECT_NAME--><title>$title</title><!--END !PROJECT_NAME-->
|
||||
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
||||
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
||||
$treeview
|
||||
$search
|
||||
$mathjax
|
||||
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
||||
$extrastylesheet
|
||||
</head>
|
||||
<body>
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
|
||||
<!--BEGIN TITLEAREA-->
|
||||
<div id="titlearea">
|
||||
<div class="glfwheader">
|
||||
<a href="http://www.glfw.org/" id="glfwhome">GLFW</a>
|
||||
<ul class="glfwnavbar">
|
||||
<li><a href="http://www.glfw.org/documentation.html">Documentation</a></li>
|
||||
<li><a href="http://www.glfw.org/download.html">Download</a></li>
|
||||
<li><a href="http://www.glfw.org/media.html">Media</a></li>
|
||||
<li><a href="http://www.glfw.org/community.html">Community</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!--END TITLEAREA-->
|
||||
<!-- end header part -->
|
4
extern/glfw/docs/internal.dox
vendored
@ -105,8 +105,8 @@ Examples: `clearScrollOffsets`
|
||||
@section internals_config Configuration macros
|
||||
|
||||
GLFW uses a number of configuration macros to select at compile time which
|
||||
interfaces and code paths to use. They are defined in the config.h header file,
|
||||
which is generated from the `config.h.in` file by CMake.
|
||||
interfaces and code paths to use. They are defined in the glfw_config.h header file,
|
||||
which is generated from the `glfw_config.h.in` file by CMake.
|
||||
|
||||
Configuration macros the same style as tokens in the public interface, except
|
||||
with a leading underscore.
|
||||
|
4
extern/glfw/docs/main.dox
vendored
@ -11,7 +11,9 @@ existing applications and does not lay claim to the main loop.
|
||||
This is the documentation for version 3.0, which has [many new features](@ref news).
|
||||
|
||||
There is a [quick tutorial](@ref quick) for people new to GLFW, which shows how
|
||||
to write a small but complete program.
|
||||
to write a small but complete program, and guides for
|
||||
[compiling GLFW](@ref compile) and
|
||||
[building programs that use GLFW](@ref build).
|
||||
|
||||
If you have used GLFW 2.x in the past, there is a
|
||||
[transition guide](@ref moving) that explains what has changed and how to update
|
||||
|
21
extern/glfw/docs/moving.dox
vendored
@ -176,13 +176,24 @@ similar to that of GLFW 2.
|
||||
|
||||
@subsection moving_window_close Window closing
|
||||
|
||||
Window closing is now just an event like any other. GLFW 3 windows won't
|
||||
disappear from underfoot even when no close callback is set; instead the
|
||||
window's close flag is set. You can query this flag using @ref
|
||||
glfwWindowShouldClose, or capture close events by setting a close callback. The
|
||||
close flag can be modified from any point in your program using @ref
|
||||
Window closing initiated by the user is now just an event like any other.
|
||||
Unlike GLFW 2, windows and contexts created with GLFW 3 will not disappear from
|
||||
underfoot. Each window now has a close flag, which is set when the user
|
||||
attempts to close it. By default, nothing else happens and the window stays
|
||||
open and visible. It is then up to you to either destroy the window, take some
|
||||
other action or simply ignore the request. You can query the close flag at any
|
||||
time with @ref glfwWindowShouldClose and set it at any time with @ref
|
||||
glfwSetWindowShouldClose.
|
||||
|
||||
The close callback no longer returns a value. Instead, it is called after the
|
||||
close flag has been set so it can override its value, if it chooses to, before
|
||||
event processing completes. You may however not call @ref glfwDestroyWindow
|
||||
from the close callback (or any other window related callback).
|
||||
|
||||
GLFW itself never clears the close flag, allowing you to set it for other
|
||||
reasons for the window to close as well, for example the user choosing Quit from
|
||||
the main menu.
|
||||
|
||||
|
||||
@subsection moving_context Explicit context management
|
||||
|
||||
|
4
extern/glfw/docs/news.dox
vendored
@ -18,7 +18,7 @@ For more information on how to use CMake, see the
|
||||
[CMake manual](http://cmake.org/cmake/help/documentation.html).
|
||||
|
||||
|
||||
@subsection new_30_multiwnd Multi-window support
|
||||
@subsection news_30_multiwnd Multi-window support
|
||||
|
||||
GLFW now supports the creation of multiple windows, each with their own OpenGL
|
||||
or OpenGL ES context, and all window functions now take a window handle. Event
|
||||
@ -79,7 +79,7 @@ through CMake options.
|
||||
GLFW now supports high-DPI monitors on both Windows and OS X, giving windows full
|
||||
resolution framebuffers where other UI elements are scaled up. To achieve this,
|
||||
@ref glfwGetFramebufferSize and @ref glfwSetFramebufferSizeCallback have been
|
||||
added. These work with pixels, while the rest of the GLFW API work with screen
|
||||
added. These work with pixels, while the rest of the GLFW API works with screen
|
||||
coordinates.
|
||||
|
||||
|
||||
|
3
extern/glfw/docs/quick.dox
vendored
@ -302,4 +302,7 @@ the screen, rendering a triangle and processing events until the user closes the
|
||||
window. It can be found in the source distribution as `examples/simple.c`, and
|
||||
is by default compiled along with all other examples when you build GLFW.
|
||||
|
||||
To learn more about how to compile and link programs that use GLFW, see
|
||||
@ref build.
|
||||
|
||||
*/
|
||||
|
20
extern/glfw/docs/window.dox
vendored
@ -62,6 +62,14 @@ Once this function is called, no more events will be delivered for that window
|
||||
and its handle becomes invalid.
|
||||
|
||||
|
||||
@section window_userptr Window user pointer
|
||||
|
||||
Each window has a user pointer that can be set with @ref
|
||||
glfwSetWindowUserPointer and fetched with @ref glfwGetWindowUserPointer. This
|
||||
can be used for any purpose you need and will not modified by GLFW throughout
|
||||
the life-time of the window.
|
||||
|
||||
|
||||
@section window_hints Window creation hints
|
||||
|
||||
There are a number of hints that can be set before the creation of a window and
|
||||
@ -440,7 +448,9 @@ context is an OpenGL debug context, or `GL_FALSE` otherwise.
|
||||
The `GLFW_OPENGL_PROFILE` attribute indicates the OpenGL profile used by the
|
||||
context. This is `GLFW_OPENGL_CORE_PROFILE` or `GLFW_OPENGL_COMPAT_PROFILE`
|
||||
if the context uses a known profile, or `GLFW_OPENGL_ANY_PROFILE` if the
|
||||
OpenGL profile is unknown or the context is for another client API.
|
||||
OpenGL profile is unknown or the context is for another client API. Note that
|
||||
the returned profile may not match the profile bits of the context flags, as
|
||||
GLFW will try other means of detecting the profile when no bits are set.
|
||||
|
||||
The `GLFW_CONTEXT_ROBUSTNESS` attribute indicates the robustness strategy
|
||||
used by the context. This is `GLFW_LOSE_CONTEXT_ON_RESET` or
|
||||
@ -477,8 +487,10 @@ zero can be useful for benchmarking purposes, when it is not desirable to
|
||||
measure the time it takes to wait for the vertical retrace. However, a swap
|
||||
interval of one lets you avoid tearing.
|
||||
|
||||
Note that not all OpenGL implementations properly implement this function, in
|
||||
which case @ref glfwSwapInterval will have no effect. Some drivers also have
|
||||
user settings that override requests by GLFW.
|
||||
Note that this may not work on all machines, as some drivers have
|
||||
user-controlled settings that override any swap interval the application
|
||||
requests. It is also by default disabled on Windows Vista and later when using
|
||||
DWM (Aero), as using it there sometimes leads to severe jitter. You can
|
||||
forcibly enable it for machines using DWM using @ref compile_options_win32.
|
||||
|
||||
*/
|
||||
|
60
extern/glfw/examples/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
|
||||
link_libraries(glfw ${OPENGL_glu_LIBRARY})
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
add_definitions(-DGLFW_DLL)
|
||||
link_libraries(${OPENGL_gl_LIBRARY} ${MATH_LIBRARY})
|
||||
else()
|
||||
link_libraries(${glfw_LIBRARIES})
|
||||
endif()
|
||||
|
||||
include_directories(${GLFW_SOURCE_DIR}/include
|
||||
${GLFW_SOURCE_DIR}/deps)
|
||||
|
||||
if (NOT APPLE)
|
||||
# HACK: This is NOTFOUND on OS X 10.8
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
set(GETOPT ${GLFW_SOURCE_DIR}/deps/getopt.h
|
||||
${GLFW_SOURCE_DIR}/deps/getopt.c)
|
||||
|
||||
if (APPLE)
|
||||
# Set fancy names for bundles
|
||||
add_executable(Boing MACOSX_BUNDLE boing.c)
|
||||
add_executable(Gears MACOSX_BUNDLE gears.c)
|
||||
add_executable(Simple MACOSX_BUNDLE simple.c)
|
||||
add_executable("Split View" MACOSX_BUNDLE splitview.c)
|
||||
add_executable(Wave MACOSX_BUNDLE wave.c)
|
||||
|
||||
set_target_properties(Boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing")
|
||||
set_target_properties(Gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears")
|
||||
set_target_properties(Simple PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simple")
|
||||
set_target_properties("Split View" PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Split View")
|
||||
set_target_properties(Wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave")
|
||||
else()
|
||||
# Set boring names for executables
|
||||
add_executable(boing WIN32 boing.c)
|
||||
add_executable(gears WIN32 gears.c)
|
||||
add_executable(heightmap WIN32 heightmap.c ${GETOPT})
|
||||
add_executable(simple WIN32 simple.c)
|
||||
add_executable(splitview WIN32 splitview.c)
|
||||
add_executable(wave WIN32 wave.c)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
set(WINDOWS_BINARIES boing gears heightmap simple splitview wave)
|
||||
|
||||
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
||||
set_target_properties(${WINDOWS_BINARIES} PROPERTIES
|
||||
LINK_FLAGS "/ENTRY:mainCRTStartup")
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
set(BUNDLE_BINARIES Boing Gears Simple "Split View" Wave)
|
||||
|
||||
set_target_properties(${BUNDLE_BINARIES} PROPERTIES
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION}
|
||||
MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL})
|
||||
endif()
|
||||
|
628
extern/glfw/examples/boing.c
vendored
Normal file
@ -0,0 +1,628 @@
|
||||
/*****************************************************************************
|
||||
* Title: GLBoing
|
||||
* Desc: Tribute to Amiga Boing.
|
||||
* Author: Jim Brooks <gfx@jimbrooks.org>
|
||||
* Original Amiga authors were R.J. Mical and Dale Luck.
|
||||
* GLFW conversion by Marcus Geelnard
|
||||
* Notes: - 360' = 2*PI [radian]
|
||||
*
|
||||
* - Distances between objects are created by doing a relative
|
||||
* Z translations.
|
||||
*
|
||||
* - Although OpenGL enticingly supports alpha-blending,
|
||||
* the shadow of the original Boing didn't affect the color
|
||||
* of the grid.
|
||||
*
|
||||
* - [Marcus] Changed timing scheme from interval driven to frame-
|
||||
* time based animation steps (which results in much smoother
|
||||
* movement)
|
||||
*
|
||||
* History of Amiga Boing:
|
||||
*
|
||||
* Boing was demonstrated on the prototype Amiga (codenamed "Lorraine") in
|
||||
* 1985. According to legend, it was written ad-hoc in one night by
|
||||
* R. J. Mical and Dale Luck. Because the bouncing ball animation was so fast
|
||||
* and smooth, attendees did not believe the Amiga prototype was really doing
|
||||
* the rendering. Suspecting a trick, they began looking around the booth for
|
||||
* a hidden computer or VCR.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Various declarations and macros
|
||||
*****************************************************************************/
|
||||
|
||||
/* Prototypes */
|
||||
void init( void );
|
||||
void display( void );
|
||||
void reshape( GLFWwindow* window, int w, int h );
|
||||
void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods );
|
||||
void DrawBoingBall( void );
|
||||
void BounceBall( double dt );
|
||||
void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
|
||||
void DrawGrid( void );
|
||||
|
||||
#define RADIUS 70.f
|
||||
#define STEP_LONGITUDE 22.5f /* 22.5 makes 8 bands like original Boing */
|
||||
#define STEP_LATITUDE 22.5f
|
||||
|
||||
#define DIST_BALL (RADIUS * 2.f + RADIUS * 0.1f)
|
||||
|
||||
#define VIEW_SCENE_DIST (DIST_BALL * 3.f + 200.f)/* distance from viewer to middle of boing area */
|
||||
#define GRID_SIZE (RADIUS * 4.5f) /* length (width) of grid */
|
||||
#define BOUNCE_HEIGHT (RADIUS * 2.1f)
|
||||
#define BOUNCE_WIDTH (RADIUS * 2.1f)
|
||||
|
||||
#define SHADOW_OFFSET_X -20.f
|
||||
#define SHADOW_OFFSET_Y 10.f
|
||||
#define SHADOW_OFFSET_Z 0.f
|
||||
|
||||
#define WALL_L_OFFSET 0.f
|
||||
#define WALL_R_OFFSET 5.f
|
||||
|
||||
/* Animation speed (50.0 mimics the original GLUT demo speed) */
|
||||
#define ANIMATION_SPEED 50.f
|
||||
|
||||
/* Maximum allowed delta time per physics iteration */
|
||||
#define MAX_DELTA_T 0.02f
|
||||
|
||||
/* Draw ball, or its shadow */
|
||||
typedef enum { DRAW_BALL, DRAW_BALL_SHADOW } DRAW_BALL_ENUM;
|
||||
|
||||
/* Vertex type */
|
||||
typedef struct {float x; float y; float z;} vertex_t;
|
||||
|
||||
/* Global vars */
|
||||
GLfloat deg_rot_y = 0.f;
|
||||
GLfloat deg_rot_y_inc = 2.f;
|
||||
GLfloat ball_x = -RADIUS;
|
||||
GLfloat ball_y = -RADIUS;
|
||||
GLfloat ball_x_inc = 1.f;
|
||||
GLfloat ball_y_inc = 2.f;
|
||||
DRAW_BALL_ENUM drawBallHow;
|
||||
double t;
|
||||
double t_old = 0.f;
|
||||
double dt;
|
||||
|
||||
/* Random number generator */
|
||||
#ifndef RAND_MAX
|
||||
#define RAND_MAX 4095
|
||||
#endif
|
||||
|
||||
/* PI */
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
#endif
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Truncate a degree.
|
||||
*****************************************************************************/
|
||||
GLfloat TruncateDeg( GLfloat deg )
|
||||
{
|
||||
if ( deg >= 360.f )
|
||||
return (deg - 360.f);
|
||||
else
|
||||
return deg;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Convert a degree (360-based) into a radian.
|
||||
* 360' = 2 * PI
|
||||
*****************************************************************************/
|
||||
double deg2rad( double deg )
|
||||
{
|
||||
return deg / 360 * (2 * M_PI);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* 360' sin().
|
||||
*****************************************************************************/
|
||||
double sin_deg( double deg )
|
||||
{
|
||||
return sin( deg2rad( deg ) );
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* 360' cos().
|
||||
*****************************************************************************/
|
||||
double cos_deg( double deg )
|
||||
{
|
||||
return cos( deg2rad( deg ) );
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Compute a cross product (for a normal vector).
|
||||
*
|
||||
* c = a x b
|
||||
*****************************************************************************/
|
||||
void CrossProduct( vertex_t a, vertex_t b, vertex_t c, vertex_t *n )
|
||||
{
|
||||
GLfloat u1, u2, u3;
|
||||
GLfloat v1, v2, v3;
|
||||
|
||||
u1 = b.x - a.x;
|
||||
u2 = b.y - a.y;
|
||||
u3 = b.y - a.z;
|
||||
|
||||
v1 = c.x - a.x;
|
||||
v2 = c.y - a.y;
|
||||
v3 = c.z - a.z;
|
||||
|
||||
n->x = u2 * v3 - v2 * v3;
|
||||
n->y = u3 * v1 - v3 * u1;
|
||||
n->z = u1 * v2 - v1 * u2;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Calculate the angle to be passed to gluPerspective() so that a scene
|
||||
* is visible. This function originates from the OpenGL Red Book.
|
||||
*
|
||||
* Parms : size
|
||||
* The size of the segment when the angle is intersected at "dist"
|
||||
* (ie at the outermost edge of the angle of vision).
|
||||
*
|
||||
* dist
|
||||
* Distance from viewpoint to scene.
|
||||
*****************************************************************************/
|
||||
GLfloat PerspectiveAngle( GLfloat size,
|
||||
GLfloat dist )
|
||||
{
|
||||
GLfloat radTheta, degTheta;
|
||||
|
||||
radTheta = 2.f * (GLfloat) atan2( size / 2.f, dist );
|
||||
degTheta = (180.f * radTheta) / (GLfloat) M_PI;
|
||||
return degTheta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define BOING_DEBUG 0
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* init()
|
||||
*****************************************************************************/
|
||||
void init( void )
|
||||
{
|
||||
/*
|
||||
* Clear background.
|
||||
*/
|
||||
glClearColor( 0.55f, 0.55f, 0.55f, 0.f );
|
||||
|
||||
glShadeModel( GL_FLAT );
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* display()
|
||||
*****************************************************************************/
|
||||
void display(void)
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
glPushMatrix();
|
||||
|
||||
drawBallHow = DRAW_BALL_SHADOW;
|
||||
DrawBoingBall();
|
||||
|
||||
DrawGrid();
|
||||
|
||||
drawBallHow = DRAW_BALL;
|
||||
DrawBoingBall();
|
||||
|
||||
glPopMatrix();
|
||||
glFlush();
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* reshape()
|
||||
*****************************************************************************/
|
||||
void reshape( GLFWwindow* window, int w, int h )
|
||||
{
|
||||
glViewport( 0, 0, (GLsizei)w, (GLsizei)h );
|
||||
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
|
||||
gluPerspective( PerspectiveAngle( RADIUS * 2, 200 ),
|
||||
(GLfloat)w / (GLfloat)h,
|
||||
1.0,
|
||||
VIEW_SCENE_DIST );
|
||||
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
|
||||
gluLookAt( 0.0, 0.0, VIEW_SCENE_DIST,/* eye */
|
||||
0.0, 0.0, 0.0, /* center of vision */
|
||||
0.0, -1.0, 0.0 ); /* up vector */
|
||||
}
|
||||
|
||||
void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods )
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Draw the Boing ball.
|
||||
*
|
||||
* The Boing ball is sphere in which each facet is a rectangle.
|
||||
* Facet colors alternate between red and white.
|
||||
* The ball is built by stacking latitudinal circles. Each circle is composed
|
||||
* of a widely-separated set of points, so that each facet is noticably large.
|
||||
*****************************************************************************/
|
||||
void DrawBoingBall( void )
|
||||
{
|
||||
GLfloat lon_deg; /* degree of longitude */
|
||||
double dt_total, dt2;
|
||||
|
||||
glPushMatrix();
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
|
||||
/*
|
||||
* Another relative Z translation to separate objects.
|
||||
*/
|
||||
glTranslatef( 0.0, 0.0, DIST_BALL );
|
||||
|
||||
/* Update ball position and rotation (iterate if necessary) */
|
||||
dt_total = dt;
|
||||
while( dt_total > 0.0 )
|
||||
{
|
||||
dt2 = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
|
||||
dt_total -= dt2;
|
||||
BounceBall( dt2 );
|
||||
deg_rot_y = TruncateDeg( deg_rot_y + deg_rot_y_inc*((float)dt2*ANIMATION_SPEED) );
|
||||
}
|
||||
|
||||
/* Set ball position */
|
||||
glTranslatef( ball_x, ball_y, 0.0 );
|
||||
|
||||
/*
|
||||
* Offset the shadow.
|
||||
*/
|
||||
if ( drawBallHow == DRAW_BALL_SHADOW )
|
||||
{
|
||||
glTranslatef( SHADOW_OFFSET_X,
|
||||
SHADOW_OFFSET_Y,
|
||||
SHADOW_OFFSET_Z );
|
||||
}
|
||||
|
||||
/*
|
||||
* Tilt the ball.
|
||||
*/
|
||||
glRotatef( -20.0, 0.0, 0.0, 1.0 );
|
||||
|
||||
/*
|
||||
* Continually rotate ball around Y axis.
|
||||
*/
|
||||
glRotatef( deg_rot_y, 0.0, 1.0, 0.0 );
|
||||
|
||||
/*
|
||||
* Set OpenGL state for Boing ball.
|
||||
*/
|
||||
glCullFace( GL_FRONT );
|
||||
glEnable( GL_CULL_FACE );
|
||||
glEnable( GL_NORMALIZE );
|
||||
|
||||
/*
|
||||
* Build a faceted latitude slice of the Boing ball,
|
||||
* stepping same-sized vertical bands of the sphere.
|
||||
*/
|
||||
for ( lon_deg = 0;
|
||||
lon_deg < 180;
|
||||
lon_deg += STEP_LONGITUDE )
|
||||
{
|
||||
/*
|
||||
* Draw a latitude circle at this longitude.
|
||||
*/
|
||||
DrawBoingBallBand( lon_deg,
|
||||
lon_deg + STEP_LONGITUDE );
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Bounce the ball.
|
||||
*****************************************************************************/
|
||||
void BounceBall( double delta_t )
|
||||
{
|
||||
GLfloat sign;
|
||||
GLfloat deg;
|
||||
|
||||
/* Bounce on walls */
|
||||
if ( ball_x > (BOUNCE_WIDTH/2 + WALL_R_OFFSET ) )
|
||||
{
|
||||
ball_x_inc = -0.5f - 0.75f * (GLfloat)rand() / (GLfloat)RAND_MAX;
|
||||
deg_rot_y_inc = -deg_rot_y_inc;
|
||||
}
|
||||
if ( ball_x < -(BOUNCE_HEIGHT/2 + WALL_L_OFFSET) )
|
||||
{
|
||||
ball_x_inc = 0.5f + 0.75f * (GLfloat)rand() / (GLfloat)RAND_MAX;
|
||||
deg_rot_y_inc = -deg_rot_y_inc;
|
||||
}
|
||||
|
||||
/* Bounce on floor / roof */
|
||||
if ( ball_y > BOUNCE_HEIGHT/2 )
|
||||
{
|
||||
ball_y_inc = -0.75f - 1.f * (GLfloat)rand() / (GLfloat)RAND_MAX;
|
||||
}
|
||||
if ( ball_y < -BOUNCE_HEIGHT/2*0.85 )
|
||||
{
|
||||
ball_y_inc = 0.75f + 1.f * (GLfloat)rand() / (GLfloat)RAND_MAX;
|
||||
}
|
||||
|
||||
/* Update ball position */
|
||||
ball_x += ball_x_inc * ((float)delta_t*ANIMATION_SPEED);
|
||||
ball_y += ball_y_inc * ((float)delta_t*ANIMATION_SPEED);
|
||||
|
||||
/*
|
||||
* Simulate the effects of gravity on Y movement.
|
||||
*/
|
||||
if ( ball_y_inc < 0 ) sign = -1.0; else sign = 1.0;
|
||||
|
||||
deg = (ball_y + BOUNCE_HEIGHT/2) * 90 / BOUNCE_HEIGHT;
|
||||
if ( deg > 80 ) deg = 80;
|
||||
if ( deg < 10 ) deg = 10;
|
||||
|
||||
ball_y_inc = sign * 4.f * (float) sin_deg( deg );
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Draw a faceted latitude band of the Boing ball.
|
||||
*
|
||||
* Parms: long_lo, long_hi
|
||||
* Low and high longitudes of slice, resp.
|
||||
*****************************************************************************/
|
||||
void DrawBoingBallBand( GLfloat long_lo,
|
||||
GLfloat long_hi )
|
||||
{
|
||||
vertex_t vert_ne; /* "ne" means south-east, so on */
|
||||
vertex_t vert_nw;
|
||||
vertex_t vert_sw;
|
||||
vertex_t vert_se;
|
||||
vertex_t vert_norm;
|
||||
GLfloat lat_deg;
|
||||
static int colorToggle = 0;
|
||||
|
||||
/*
|
||||
* Iterate thru the points of a latitude circle.
|
||||
* A latitude circle is a 2D set of X,Z points.
|
||||
*/
|
||||
for ( lat_deg = 0;
|
||||
lat_deg <= (360 - STEP_LATITUDE);
|
||||
lat_deg += STEP_LATITUDE )
|
||||
{
|
||||
/*
|
||||
* Color this polygon with red or white.
|
||||
*/
|
||||
if ( colorToggle )
|
||||
glColor3f( 0.8f, 0.1f, 0.1f );
|
||||
else
|
||||
glColor3f( 0.95f, 0.95f, 0.95f );
|
||||
#if 0
|
||||
if ( lat_deg >= 180 )
|
||||
if ( colorToggle )
|
||||
glColor3f( 0.1f, 0.8f, 0.1f );
|
||||
else
|
||||
glColor3f( 0.5f, 0.5f, 0.95f );
|
||||
#endif
|
||||
colorToggle = ! colorToggle;
|
||||
|
||||
/*
|
||||
* Change color if drawing shadow.
|
||||
*/
|
||||
if ( drawBallHow == DRAW_BALL_SHADOW )
|
||||
glColor3f( 0.35f, 0.35f, 0.35f );
|
||||
|
||||
/*
|
||||
* Assign each Y.
|
||||
*/
|
||||
vert_ne.y = vert_nw.y = (float) cos_deg(long_hi) * RADIUS;
|
||||
vert_sw.y = vert_se.y = (float) cos_deg(long_lo) * RADIUS;
|
||||
|
||||
/*
|
||||
* Assign each X,Z with sin,cos values scaled by latitude radius indexed by longitude.
|
||||
* Eg, long=0 and long=180 are at the poles, so zero scale is sin(longitude),
|
||||
* while long=90 (sin(90)=1) is at equator.
|
||||
*/
|
||||
vert_ne.x = (float) cos_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE ));
|
||||
vert_se.x = (float) cos_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo ));
|
||||
vert_nw.x = (float) cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE ));
|
||||
vert_sw.x = (float) cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo ));
|
||||
|
||||
vert_ne.z = (float) sin_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE ));
|
||||
vert_se.z = (float) sin_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo ));
|
||||
vert_nw.z = (float) sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE ));
|
||||
vert_sw.z = (float) sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo ));
|
||||
|
||||
/*
|
||||
* Draw the facet.
|
||||
*/
|
||||
glBegin( GL_POLYGON );
|
||||
|
||||
CrossProduct( vert_ne, vert_nw, vert_sw, &vert_norm );
|
||||
glNormal3f( vert_norm.x, vert_norm.y, vert_norm.z );
|
||||
|
||||
glVertex3f( vert_ne.x, vert_ne.y, vert_ne.z );
|
||||
glVertex3f( vert_nw.x, vert_nw.y, vert_nw.z );
|
||||
glVertex3f( vert_sw.x, vert_sw.y, vert_sw.z );
|
||||
glVertex3f( vert_se.x, vert_se.y, vert_se.z );
|
||||
|
||||
glEnd();
|
||||
|
||||
#if BOING_DEBUG
|
||||
printf( "----------------------------------------------------------- \n" );
|
||||
printf( "lat = %f long_lo = %f long_hi = %f \n", lat_deg, long_lo, long_hi );
|
||||
printf( "vert_ne x = %.8f y = %.8f z = %.8f \n", vert_ne.x, vert_ne.y, vert_ne.z );
|
||||
printf( "vert_nw x = %.8f y = %.8f z = %.8f \n", vert_nw.x, vert_nw.y, vert_nw.z );
|
||||
printf( "vert_se x = %.8f y = %.8f z = %.8f \n", vert_se.x, vert_se.y, vert_se.z );
|
||||
printf( "vert_sw x = %.8f y = %.8f z = %.8f \n", vert_sw.x, vert_sw.y, vert_sw.z );
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Toggle color so that next band will opposite red/white colors than this one.
|
||||
*/
|
||||
colorToggle = ! colorToggle;
|
||||
|
||||
/*
|
||||
* This circular band is done.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Draw the purple grid of lines, behind the Boing ball.
|
||||
* When the Workbench is dropped to the bottom, Boing shows 12 rows.
|
||||
*****************************************************************************/
|
||||
void DrawGrid( void )
|
||||
{
|
||||
int row, col;
|
||||
const int rowTotal = 12; /* must be divisible by 2 */
|
||||
const int colTotal = rowTotal; /* must be same as rowTotal */
|
||||
const GLfloat widthLine = 2.0; /* should be divisible by 2 */
|
||||
const GLfloat sizeCell = GRID_SIZE / rowTotal;
|
||||
const GLfloat z_offset = -40.0;
|
||||
GLfloat xl, xr;
|
||||
GLfloat yt, yb;
|
||||
|
||||
glPushMatrix();
|
||||
glDisable( GL_CULL_FACE );
|
||||
|
||||
/*
|
||||
* Another relative Z translation to separate objects.
|
||||
*/
|
||||
glTranslatef( 0.0, 0.0, DIST_BALL );
|
||||
|
||||
/*
|
||||
* Draw vertical lines (as skinny 3D rectangles).
|
||||
*/
|
||||
for ( col = 0; col <= colTotal; col++ )
|
||||
{
|
||||
/*
|
||||
* Compute co-ords of line.
|
||||
*/
|
||||
xl = -GRID_SIZE / 2 + col * sizeCell;
|
||||
xr = xl + widthLine;
|
||||
|
||||
yt = GRID_SIZE / 2;
|
||||
yb = -GRID_SIZE / 2 - widthLine;
|
||||
|
||||
glBegin( GL_POLYGON );
|
||||
|
||||
glColor3f( 0.6f, 0.1f, 0.6f ); /* purple */
|
||||
|
||||
glVertex3f( xr, yt, z_offset ); /* NE */
|
||||
glVertex3f( xl, yt, z_offset ); /* NW */
|
||||
glVertex3f( xl, yb, z_offset ); /* SW */
|
||||
glVertex3f( xr, yb, z_offset ); /* SE */
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw horizontal lines (as skinny 3D rectangles).
|
||||
*/
|
||||
for ( row = 0; row <= rowTotal; row++ )
|
||||
{
|
||||
/*
|
||||
* Compute co-ords of line.
|
||||
*/
|
||||
yt = GRID_SIZE / 2 - row * sizeCell;
|
||||
yb = yt - widthLine;
|
||||
|
||||
xl = -GRID_SIZE / 2;
|
||||
xr = GRID_SIZE / 2 + widthLine;
|
||||
|
||||
glBegin( GL_POLYGON );
|
||||
|
||||
glColor3f( 0.6f, 0.1f, 0.6f ); /* purple */
|
||||
|
||||
glVertex3f( xr, yt, z_offset ); /* NE */
|
||||
glVertex3f( xl, yt, z_offset ); /* NW */
|
||||
glVertex3f( xl, yb, z_offset ); /* SW */
|
||||
glVertex3f( xr, yb, z_offset ); /* SE */
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*
|
||||
* main()
|
||||
*======================================================================*/
|
||||
|
||||
int main( void )
|
||||
{
|
||||
GLFWwindow* window;
|
||||
int width, height;
|
||||
|
||||
/* Init GLFW */
|
||||
if( !glfwInit() )
|
||||
exit( EXIT_FAILURE );
|
||||
|
||||
glfwWindowHint(GLFW_DEPTH_BITS, 16);
|
||||
|
||||
window = glfwCreateWindow( 400, 400, "Boing (classic Amiga demo)", NULL, NULL );
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
glfwSetFramebufferSizeCallback(window, reshape);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval( 1 );
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
reshape(window, width, height);
|
||||
|
||||
glfwSetTime( 0.0 );
|
||||
|
||||
init();
|
||||
|
||||
/* Main loop */
|
||||
for (;;)
|
||||
{
|
||||
/* Timing */
|
||||
t = glfwGetTime();
|
||||
dt = t - t_old;
|
||||
t_old = t;
|
||||
|
||||
/* Draw one frame */
|
||||
display();
|
||||
|
||||
/* Swap buffers */
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
/* Check if we are still running */
|
||||
if (glfwWindowShouldClose(window))
|
||||
break;
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit( EXIT_SUCCESS );
|
||||
}
|
||||
|
372
extern/glfw/examples/gears.c
vendored
Normal file
@ -0,0 +1,372 @@
|
||||
/*
|
||||
* 3-D gear wheels. This program is in the public domain.
|
||||
*
|
||||
* Command line options:
|
||||
* -info print GL implementation information
|
||||
* -exit automatically exit after 30 seconds
|
||||
*
|
||||
*
|
||||
* Brian Paul
|
||||
*
|
||||
*
|
||||
* Marcus Geelnard:
|
||||
* - Conversion to GLFW
|
||||
* - Time based rendering (frame rate independent)
|
||||
* - Slightly modified camera that should work better for stereo viewing
|
||||
*
|
||||
*
|
||||
* Camilla Berglund:
|
||||
* - Removed FPS counter (this is not a benchmark)
|
||||
* - Added a few comments
|
||||
* - Enabled vsync
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592654
|
||||
#endif
|
||||
|
||||
/* If non-zero, the program exits after that many seconds
|
||||
*/
|
||||
static int autoexit = 0;
|
||||
|
||||
/**
|
||||
|
||||
Draw a gear wheel. You'll probably want to call this function when
|
||||
building a display list since we do a lot of trig here.
|
||||
|
||||
Input: inner_radius - radius of hole at center
|
||||
outer_radius - radius at center of teeth
|
||||
width - width of gear teeth - number of teeth
|
||||
tooth_depth - depth of tooth
|
||||
|
||||
**/
|
||||
|
||||
static void
|
||||
gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
|
||||
GLint teeth, GLfloat tooth_depth)
|
||||
{
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth / 2.f;
|
||||
r2 = outer_radius + tooth_depth / 2.f;
|
||||
|
||||
da = 2.f * (float) M_PI / teeth / 4.f;
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glNormal3f(0.f, 0.f, 1.f);
|
||||
|
||||
/* draw front face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.f * (float) M_PI / teeth;
|
||||
glVertex3f(r0 * (float) cos(angle), r0 * (float) sin(angle), width * 0.5f);
|
||||
glVertex3f(r1 * (float) cos(angle), r1 * (float) sin(angle), width * 0.5f);
|
||||
if (i < teeth) {
|
||||
glVertex3f(r0 * (float) cos(angle), r0 * (float) sin(angle), width * 0.5f);
|
||||
glVertex3f(r1 * (float) cos(angle + 3 * da), r1 * (float) sin(angle + 3 * da), width * 0.5f);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.f * (float) M_PI / teeth / 4.f;
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.f * (float) M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * (float) cos(angle), r1 * (float) sin(angle), width * 0.5f);
|
||||
glVertex3f(r2 * (float) cos(angle + da), r2 * (float) sin(angle + da), width * 0.5f);
|
||||
glVertex3f(r2 * (float) cos(angle + 2 * da), r2 * (float) sin(angle + 2 * da), width * 0.5f);
|
||||
glVertex3f(r1 * (float) cos(angle + 3 * da), r1 * (float) sin(angle + 3 * da), width * 0.5f);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f(0.0, 0.0, -1.0);
|
||||
|
||||
/* draw back face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.f * (float) M_PI / teeth;
|
||||
glVertex3f(r1 * (float) cos(angle), r1 * (float) sin(angle), -width * 0.5f);
|
||||
glVertex3f(r0 * (float) cos(angle), r0 * (float) sin(angle), -width * 0.5f);
|
||||
if (i < teeth) {
|
||||
glVertex3f(r1 * (float) cos(angle + 3 * da), r1 * (float) sin(angle + 3 * da), -width * 0.5f);
|
||||
glVertex3f(r0 * (float) cos(angle), r0 * (float) sin(angle), -width * 0.5f);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.f * (float) M_PI / teeth / 4.f;
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.f * (float) M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * (float) cos(angle + 3 * da), r1 * (float) sin(angle + 3 * da), -width * 0.5f);
|
||||
glVertex3f(r2 * (float) cos(angle + 2 * da), r2 * (float) sin(angle + 2 * da), -width * 0.5f);
|
||||
glVertex3f(r2 * (float) cos(angle + da), r2 * (float) sin(angle + da), -width * 0.5f);
|
||||
glVertex3f(r1 * (float) cos(angle), r1 * (float) sin(angle), -width * 0.5f);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.f * (float) M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * (float) cos(angle), r1 * (float) sin(angle), width * 0.5f);
|
||||
glVertex3f(r1 * (float) cos(angle), r1 * (float) sin(angle), -width * 0.5f);
|
||||
u = r2 * (float) cos(angle + da) - r1 * (float) cos(angle);
|
||||
v = r2 * (float) sin(angle + da) - r1 * (float) sin(angle);
|
||||
len = (float) sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r2 * (float) cos(angle + da), r2 * (float) sin(angle + da), width * 0.5f);
|
||||
glVertex3f(r2 * (float) cos(angle + da), r2 * (float) sin(angle + da), -width * 0.5f);
|
||||
glNormal3f((float) cos(angle), (float) sin(angle), 0.f);
|
||||
glVertex3f(r2 * (float) cos(angle + 2 * da), r2 * (float) sin(angle + 2 * da), width * 0.5f);
|
||||
glVertex3f(r2 * (float) cos(angle + 2 * da), r2 * (float) sin(angle + 2 * da), -width * 0.5f);
|
||||
u = r1 * (float) cos(angle + 3 * da) - r2 * (float) cos(angle + 2 * da);
|
||||
v = r1 * (float) sin(angle + 3 * da) - r2 * (float) sin(angle + 2 * da);
|
||||
glNormal3f(v, -u, 0.f);
|
||||
glVertex3f(r1 * (float) cos(angle + 3 * da), r1 * (float) sin(angle + 3 * da), width * 0.5f);
|
||||
glVertex3f(r1 * (float) cos(angle + 3 * da), r1 * (float) sin(angle + 3 * da), -width * 0.5f);
|
||||
glNormal3f((float) cos(angle), (float) sin(angle), 0.f);
|
||||
}
|
||||
|
||||
glVertex3f(r1 * (float) cos(0), r1 * (float) sin(0), width * 0.5f);
|
||||
glVertex3f(r1 * (float) cos(0), r1 * (float) sin(0), -width * 0.5f);
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.f * (float) M_PI / teeth;
|
||||
glNormal3f(-(float) cos(angle), -(float) sin(angle), 0.f);
|
||||
glVertex3f(r0 * (float) cos(angle), r0 * (float) sin(angle), -width * 0.5f);
|
||||
glVertex3f(r0 * (float) cos(angle), r0 * (float) sin(angle), width * 0.5f);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static GLfloat view_rotx = 20.f, view_roty = 30.f, view_rotz = 0.f;
|
||||
static GLint gear1, gear2, gear3;
|
||||
static GLfloat angle = 0.f;
|
||||
|
||||
/* OpenGL draw function & timing */
|
||||
static void draw(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(view_rotx, 1.0, 0.0, 0.0);
|
||||
glRotatef(view_roty, 0.0, 1.0, 0.0);
|
||||
glRotatef(view_rotz, 0.0, 0.0, 1.0);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.0, -2.0, 0.0);
|
||||
glRotatef(angle, 0.0, 0.0, 1.0);
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(3.1f, -2.f, 0.f);
|
||||
glRotatef(-2.f * angle - 9.f, 0.f, 0.f, 1.f);
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.1f, 4.2f, 0.f);
|
||||
glRotatef(-2.f * angle - 25.f, 0.f, 0.f, 1.f);
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
/* update animation parameters */
|
||||
static void animate(void)
|
||||
{
|
||||
angle = 100.f * (float) glfwGetTime();
|
||||
}
|
||||
|
||||
|
||||
/* change view angle, exit upon ESC */
|
||||
void key( GLFWwindow* window, int k, int s, int action, int mods )
|
||||
{
|
||||
if( action != GLFW_PRESS ) return;
|
||||
|
||||
switch (k) {
|
||||
case GLFW_KEY_Z:
|
||||
if( mods & GLFW_MOD_SHIFT )
|
||||
view_rotz -= 5.0;
|
||||
else
|
||||
view_rotz += 5.0;
|
||||
break;
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
break;
|
||||
case GLFW_KEY_UP:
|
||||
view_rotx += 5.0;
|
||||
break;
|
||||
case GLFW_KEY_DOWN:
|
||||
view_rotx -= 5.0;
|
||||
break;
|
||||
case GLFW_KEY_LEFT:
|
||||
view_roty += 5.0;
|
||||
break;
|
||||
case GLFW_KEY_RIGHT:
|
||||
view_roty -= 5.0;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* new window size */
|
||||
void reshape( GLFWwindow* window, int width, int height )
|
||||
{
|
||||
GLfloat h = (GLfloat) height / (GLfloat) width;
|
||||
GLfloat xmax, znear, zfar;
|
||||
|
||||
znear = 5.0f;
|
||||
zfar = 30.0f;
|
||||
xmax = znear * 0.5f;
|
||||
|
||||
glViewport( 0, 0, (GLint) width, (GLint) height );
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
glFrustum( -xmax, xmax, -xmax*h, xmax*h, znear, zfar );
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
glTranslatef( 0.0, 0.0, -20.0 );
|
||||
}
|
||||
|
||||
|
||||
/* program & OpenGL initialization */
|
||||
static void init(int argc, char *argv[])
|
||||
{
|
||||
static GLfloat pos[4] = {5.f, 5.f, 10.f, 0.f};
|
||||
static GLfloat red[4] = {0.8f, 0.1f, 0.f, 1.f};
|
||||
static GLfloat green[4] = {0.f, 0.8f, 0.2f, 1.f};
|
||||
static GLfloat blue[4] = {0.2f, 0.2f, 1.f, 1.f};
|
||||
GLint i;
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(1.f, 4.f, 1.f, 20, 0.7f);
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
|
||||
gear(0.5f, 2.f, 2.f, 10, 0.7f);
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
gear(1.3f, 2.f, 0.5f, 10, 0.7f);
|
||||
glEndList();
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
for ( i=1; i<argc; i++ ) {
|
||||
if (strcmp(argv[i], "-info")==0) {
|
||||
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
|
||||
printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
|
||||
printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
|
||||
printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
|
||||
}
|
||||
else if ( strcmp(argv[i], "-exit")==0) {
|
||||
autoexit = 30;
|
||||
printf("Auto Exit after %i seconds.\n", autoexit );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* program entry */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
GLFWwindow* window;
|
||||
int width, height;
|
||||
|
||||
if( !glfwInit() )
|
||||
{
|
||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_DEPTH_BITS, 16);
|
||||
|
||||
window = glfwCreateWindow( 300, 300, "Gears", NULL, NULL );
|
||||
if (!window)
|
||||
{
|
||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||
glfwTerminate();
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
// Set callback functions
|
||||
glfwSetFramebufferSizeCallback(window, reshape);
|
||||
glfwSetKeyCallback(window, key);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval( 1 );
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
reshape(window, width, height);
|
||||
|
||||
// Parse command-line options
|
||||
init(argc, argv);
|
||||
|
||||
// Main loop
|
||||
while( !glfwWindowShouldClose(window) )
|
||||
{
|
||||
// Draw gears
|
||||
draw();
|
||||
|
||||
// Update animation
|
||||
animate();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// Terminate GLFW
|
||||
glfwTerminate();
|
||||
|
||||
// Exit program
|
||||
exit( EXIT_SUCCESS );
|
||||
}
|
||||
|
678
extern/glfw/examples/heightmap.c
vendored
Normal file
@ -0,0 +1,678 @@
|
||||
//========================================================================
|
||||
// Heightmap example program using OpenGL 3 core profile
|
||||
// Copyright (c) 2010 Olivier Delannoy
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include "getopt.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
/* OpenGL function pointers */
|
||||
static PFNGLGENBUFFERSPROC pglGenBuffers = NULL;
|
||||
static PFNGLGENVERTEXARRAYSPROC pglGenVertexArrays = NULL;
|
||||
static PFNGLDELETEVERTEXARRAYSPROC pglDeleteVertexArrays = NULL;
|
||||
static PFNGLCREATESHADERPROC pglCreateShader = NULL;
|
||||
static PFNGLSHADERSOURCEPROC pglShaderSource = NULL;
|
||||
static PFNGLCOMPILESHADERPROC pglCompileShader = NULL;
|
||||
static PFNGLGETSHADERIVPROC pglGetShaderiv = NULL;
|
||||
static PFNGLGETSHADERINFOLOGPROC pglGetShaderInfoLog = NULL;
|
||||
static PFNGLDELETESHADERPROC pglDeleteShader = NULL;
|
||||
static PFNGLCREATEPROGRAMPROC pglCreateProgram = NULL;
|
||||
static PFNGLATTACHSHADERPROC pglAttachShader = NULL;
|
||||
static PFNGLLINKPROGRAMPROC pglLinkProgram = NULL;
|
||||
static PFNGLUSEPROGRAMPROC pglUseProgram = NULL;
|
||||
static PFNGLGETPROGRAMIVPROC pglGetProgramiv = NULL;
|
||||
static PFNGLGETPROGRAMINFOLOGPROC pglGetProgramInfoLog = NULL;
|
||||
static PFNGLDELETEPROGRAMPROC pglDeleteProgram = NULL;
|
||||
static PFNGLGETUNIFORMLOCATIONPROC pglGetUniformLocation = NULL;
|
||||
static PFNGLUNIFORMMATRIX4FVPROC pglUniformMatrix4fv = NULL;
|
||||
static PFNGLGETATTRIBLOCATIONPROC pglGetAttribLocation = NULL;
|
||||
static PFNGLBINDVERTEXARRAYPROC pglBindVertexArray = NULL;
|
||||
static PFNGLBUFFERDATAPROC pglBufferData = NULL;
|
||||
static PFNGLBINDBUFFERPROC pglBindBuffer = NULL;
|
||||
static PFNGLBUFFERSUBDATAPROC pglBufferSubData = NULL;
|
||||
static PFNGLENABLEVERTEXATTRIBARRAYPROC pglEnableVertexAttribArray = NULL;
|
||||
static PFNGLVERTEXATTRIBPOINTERPROC pglVertexAttribPointer = NULL;
|
||||
|
||||
/* Map height updates */
|
||||
#define MAX_CIRCLE_SIZE (5.0f)
|
||||
#define MAX_DISPLACEMENT (1.0f)
|
||||
#define DISPLACEMENT_SIGN_LIMIT (0.3f)
|
||||
#define MAX_ITER (200)
|
||||
#define NUM_ITER_AT_A_TIME (1)
|
||||
|
||||
/* Map general information */
|
||||
#define MAP_SIZE (10.0f)
|
||||
#define MAP_NUM_VERTICES (80)
|
||||
#define MAP_NUM_TOTAL_VERTICES (MAP_NUM_VERTICES*MAP_NUM_VERTICES)
|
||||
#define MAP_NUM_LINES (3* (MAP_NUM_VERTICES - 1) * (MAP_NUM_VERTICES - 1) + \
|
||||
2 * (MAP_NUM_VERTICES - 1))
|
||||
|
||||
|
||||
/* OpenGL function pointers */
|
||||
|
||||
#define RESOLVE_GL_FCN(type, var, name) \
|
||||
if (status == GL_TRUE) \
|
||||
{\
|
||||
var = (type) glfwGetProcAddress((name));\
|
||||
if ((var) == NULL)\
|
||||
{\
|
||||
status = GL_FALSE;\
|
||||
}\
|
||||
}
|
||||
|
||||
|
||||
static GLboolean init_opengl(void)
|
||||
{
|
||||
GLboolean status = GL_TRUE;
|
||||
RESOLVE_GL_FCN(PFNGLCREATESHADERPROC, pglCreateShader, "glCreateShader");
|
||||
RESOLVE_GL_FCN(PFNGLSHADERSOURCEPROC, pglShaderSource, "glShaderSource");
|
||||
RESOLVE_GL_FCN(PFNGLCOMPILESHADERPROC, pglCompileShader, "glCompileShader");
|
||||
RESOLVE_GL_FCN(PFNGLGETSHADERIVPROC, pglGetShaderiv, "glGetShaderiv");
|
||||
RESOLVE_GL_FCN(PFNGLGETSHADERINFOLOGPROC, pglGetShaderInfoLog, "glGetShaderInfoLog");
|
||||
RESOLVE_GL_FCN(PFNGLDELETESHADERPROC, pglDeleteShader, "glDeleteShader");
|
||||
RESOLVE_GL_FCN(PFNGLCREATEPROGRAMPROC, pglCreateProgram, "glCreateProgram");
|
||||
RESOLVE_GL_FCN(PFNGLATTACHSHADERPROC, pglAttachShader, "glAttachShader");
|
||||
RESOLVE_GL_FCN(PFNGLLINKPROGRAMPROC, pglLinkProgram, "glLinkProgram");
|
||||
RESOLVE_GL_FCN(PFNGLUSEPROGRAMPROC, pglUseProgram, "glUseProgram");
|
||||
RESOLVE_GL_FCN(PFNGLGETPROGRAMIVPROC, pglGetProgramiv, "glGetProgramiv");
|
||||
RESOLVE_GL_FCN(PFNGLGETPROGRAMINFOLOGPROC, pglGetProgramInfoLog, "glGetProgramInfoLog");
|
||||
RESOLVE_GL_FCN(PFNGLDELETEPROGRAMPROC, pglDeleteProgram, "glDeleteProgram");
|
||||
RESOLVE_GL_FCN(PFNGLGETUNIFORMLOCATIONPROC, pglGetUniformLocation, "glGetUniformLocation");
|
||||
RESOLVE_GL_FCN(PFNGLUNIFORMMATRIX4FVPROC, pglUniformMatrix4fv, "glUniformMatrix4fv");
|
||||
RESOLVE_GL_FCN(PFNGLGETATTRIBLOCATIONPROC, pglGetAttribLocation, "glGetAttribLocation");
|
||||
RESOLVE_GL_FCN(PFNGLGENVERTEXARRAYSPROC, pglGenVertexArrays, "glGenVertexArrays");
|
||||
RESOLVE_GL_FCN(PFNGLDELETEVERTEXARRAYSPROC, pglDeleteVertexArrays, "glDeleteVertexArrays");
|
||||
RESOLVE_GL_FCN(PFNGLBINDVERTEXARRAYPROC, pglBindVertexArray, "glBindVertexArray");
|
||||
RESOLVE_GL_FCN(PFNGLGENBUFFERSPROC, pglGenBuffers, "glGenBuffers");
|
||||
RESOLVE_GL_FCN(PFNGLBINDBUFFERPROC, pglBindBuffer, "glBindBuffer");
|
||||
RESOLVE_GL_FCN(PFNGLBUFFERDATAPROC, pglBufferData, "glBufferData");
|
||||
RESOLVE_GL_FCN(PFNGLBUFFERSUBDATAPROC, pglBufferSubData, "glBufferSubData");
|
||||
RESOLVE_GL_FCN(PFNGLENABLEVERTEXATTRIBARRAYPROC, pglEnableVertexAttribArray, "glEnableVertexAttribArray");
|
||||
RESOLVE_GL_FCN(PFNGLVERTEXATTRIBPOINTERPROC, pglVertexAttribPointer, "glVertexAttribPointer");
|
||||
return status;
|
||||
}
|
||||
/**********************************************************************
|
||||
* Default shader programs
|
||||
*********************************************************************/
|
||||
|
||||
static const char* default_vertex_shader =
|
||||
"#version 150\n"
|
||||
"uniform mat4 project;\n"
|
||||
"uniform mat4 modelview;\n"
|
||||
"in float x;\n"
|
||||
"in float y;\n"
|
||||
"in float z;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = project * modelview * vec4(x, y, z, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* default_fragment_shader =
|
||||
"#version 150\n"
|
||||
"out vec4 gl_FragColor;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = vec4(0.2, 1.0, 0.2, 1.0); \n"
|
||||
"}\n";
|
||||
|
||||
/**********************************************************************
|
||||
* Values for shader uniforms
|
||||
*********************************************************************/
|
||||
|
||||
/* Frustum configuration */
|
||||
static GLfloat view_angle = 45.0f;
|
||||
static GLfloat aspect_ratio = 4.0f/3.0f;
|
||||
static GLfloat z_near = 1.0f;
|
||||
static GLfloat z_far = 100.f;
|
||||
|
||||
/* Projection matrix */
|
||||
static GLfloat projection_matrix[16] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
/* Model view matrix */
|
||||
static GLfloat modelview_matrix[16] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
/**********************************************************************
|
||||
* Heightmap vertex and index data
|
||||
*********************************************************************/
|
||||
|
||||
static GLfloat map_vertices[3][MAP_NUM_TOTAL_VERTICES];
|
||||
static GLuint map_line_indices[2*MAP_NUM_LINES];
|
||||
|
||||
/* Store uniform location for the shaders
|
||||
* Those values are setup as part of the process of creating
|
||||
* the shader program. They should not be used before creating
|
||||
* the program.
|
||||
*/
|
||||
static GLuint mesh;
|
||||
static GLuint mesh_vbo[4];
|
||||
|
||||
/**********************************************************************
|
||||
* OpenGL helper functions
|
||||
*********************************************************************/
|
||||
|
||||
/* Load a (text) file into memory and return its contents
|
||||
*/
|
||||
static char* read_file_content(const char* filename)
|
||||
{
|
||||
FILE* fd;
|
||||
size_t size = 0;
|
||||
char* result = NULL;
|
||||
|
||||
fd = fopen(filename, "r");
|
||||
if (fd != NULL)
|
||||
{
|
||||
size = fseek(fd, 0, SEEK_END);
|
||||
(void) fseek(fd, 0, SEEK_SET);
|
||||
|
||||
result = malloc(size + 1);
|
||||
result[size] = '\0';
|
||||
if (fread(result, size, 1, fd) != 1)
|
||||
{
|
||||
free(result);
|
||||
result = NULL;
|
||||
}
|
||||
(void) fclose(fd);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Creates a shader object of the specified type using the specified text
|
||||
*/
|
||||
static GLuint make_shader(GLenum type, const char* shader_src)
|
||||
{
|
||||
GLuint shader;
|
||||
GLint shader_ok;
|
||||
GLsizei log_length;
|
||||
char info_log[8192];
|
||||
|
||||
shader = pglCreateShader(type);
|
||||
if (shader != 0)
|
||||
{
|
||||
pglShaderSource(shader, 1, (const GLchar**)&shader_src, NULL);
|
||||
pglCompileShader(shader);
|
||||
pglGetShaderiv(shader, GL_COMPILE_STATUS, &shader_ok);
|
||||
if (shader_ok != GL_TRUE)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to compile %s shader\n", (type == GL_FRAGMENT_SHADER) ? "fragment" : "vertex" );
|
||||
pglGetShaderInfoLog(shader, 8192, &log_length,info_log);
|
||||
fprintf(stderr, "ERROR: \n%s\n\n", info_log);
|
||||
pglDeleteShader(shader);
|
||||
shader = 0;
|
||||
}
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
/* Creates a program object using the specified vertex and fragment text
|
||||
*/
|
||||
static GLuint make_shader_program(const char* vertex_shader_src, const char* fragment_shader_src)
|
||||
{
|
||||
GLuint program = 0u;
|
||||
GLint program_ok;
|
||||
GLuint vertex_shader = 0u;
|
||||
GLuint fragment_shader = 0u;
|
||||
GLsizei log_length;
|
||||
char info_log[8192];
|
||||
|
||||
vertex_shader = make_shader(GL_VERTEX_SHADER, (vertex_shader_src == NULL) ? default_vertex_shader : vertex_shader_src);
|
||||
if (vertex_shader != 0u)
|
||||
{
|
||||
fragment_shader = make_shader(GL_FRAGMENT_SHADER, (fragment_shader_src == NULL) ? default_fragment_shader : fragment_shader_src);
|
||||
if (fragment_shader != 0u)
|
||||
{
|
||||
/* make the program that connect the two shader and link it */
|
||||
program = pglCreateProgram();
|
||||
if (program != 0u)
|
||||
{
|
||||
/* attach both shader and link */
|
||||
pglAttachShader(program, vertex_shader);
|
||||
pglAttachShader(program, fragment_shader);
|
||||
pglLinkProgram(program);
|
||||
pglGetProgramiv(program, GL_LINK_STATUS, &program_ok);
|
||||
|
||||
if (program_ok != GL_TRUE)
|
||||
{
|
||||
fprintf(stderr, "ERROR, failed to link shader program\n");
|
||||
pglGetProgramInfoLog(program, 8192, &log_length, info_log);
|
||||
fprintf(stderr, "ERROR: \n%s\n\n", info_log);
|
||||
pglDeleteProgram(program);
|
||||
pglDeleteShader(fragment_shader);
|
||||
pglDeleteShader(vertex_shader);
|
||||
program = 0u;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unable to load fragment shader\n");
|
||||
pglDeleteShader(vertex_shader);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unable to load vertex shader\n");
|
||||
}
|
||||
return program;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* Geometry creation functions
|
||||
*********************************************************************/
|
||||
|
||||
/* Generate vertices and indices for the heightmap
|
||||
*/
|
||||
static void init_map(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
GLfloat step = MAP_SIZE / (MAP_NUM_VERTICES - 1);
|
||||
GLfloat x = 0.0f;
|
||||
GLfloat z = 0.0f;
|
||||
/* Create a flat grid */
|
||||
k = 0;
|
||||
for (i = 0 ; i < MAP_NUM_VERTICES ; ++i)
|
||||
{
|
||||
for (j = 0 ; j < MAP_NUM_VERTICES ; ++j)
|
||||
{
|
||||
map_vertices[0][k] = x;
|
||||
map_vertices[1][k] = 0.0f;
|
||||
map_vertices[2][k] = z;
|
||||
z += step;
|
||||
++k;
|
||||
}
|
||||
x += step;
|
||||
z = 0.0f;
|
||||
}
|
||||
#if DEBUG_ENABLED
|
||||
for (i = 0 ; i < MAP_NUM_TOTAL_VERTICES ; ++i)
|
||||
{
|
||||
printf ("Vertice %d (%f, %f, %f)\n",
|
||||
i, map_vertices[0][i], map_vertices[1][i], map_vertices[2][i]);
|
||||
|
||||
}
|
||||
#endif
|
||||
/* create indices */
|
||||
/* line fan based on i
|
||||
* i+1
|
||||
* | / i + n + 1
|
||||
* | /
|
||||
* |/
|
||||
* i --- i + n
|
||||
*/
|
||||
|
||||
/* close the top of the square */
|
||||
k = 0;
|
||||
for (i = 0 ; i < MAP_NUM_VERTICES -1 ; ++i)
|
||||
{
|
||||
map_line_indices[k++] = (i + 1) * MAP_NUM_VERTICES -1;
|
||||
map_line_indices[k++] = (i + 2) * MAP_NUM_VERTICES -1;
|
||||
}
|
||||
/* close the right of the square */
|
||||
for (i = 0 ; i < MAP_NUM_VERTICES -1 ; ++i)
|
||||
{
|
||||
map_line_indices[k++] = (MAP_NUM_VERTICES - 1) * MAP_NUM_VERTICES + i;
|
||||
map_line_indices[k++] = (MAP_NUM_VERTICES - 1) * MAP_NUM_VERTICES + i + 1;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < (MAP_NUM_VERTICES - 1) ; ++i)
|
||||
{
|
||||
for (j = 0 ; j < (MAP_NUM_VERTICES - 1) ; ++j)
|
||||
{
|
||||
int ref = i * (MAP_NUM_VERTICES) + j;
|
||||
map_line_indices[k++] = ref;
|
||||
map_line_indices[k++] = ref + 1;
|
||||
|
||||
map_line_indices[k++] = ref;
|
||||
map_line_indices[k++] = ref + MAP_NUM_VERTICES;
|
||||
|
||||
map_line_indices[k++] = ref;
|
||||
map_line_indices[k++] = ref + MAP_NUM_VERTICES + 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
for (k = 0 ; k < 2 * MAP_NUM_LINES ; k += 2)
|
||||
{
|
||||
int beg, end;
|
||||
beg = map_line_indices[k];
|
||||
end = map_line_indices[k+1];
|
||||
printf ("Line %d: %d -> %d (%f, %f, %f) -> (%f, %f, %f)\n",
|
||||
k / 2, beg, end,
|
||||
map_vertices[0][beg], map_vertices[1][beg], map_vertices[2][beg],
|
||||
map_vertices[0][end], map_vertices[1][end], map_vertices[2][end]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void generate_heightmap__circle(float* center_x, float* center_y,
|
||||
float* size, float* displacement)
|
||||
{
|
||||
float sign;
|
||||
/* random value for element in between [0-1.0] */
|
||||
*center_x = (MAP_SIZE * rand()) / (1.0f * RAND_MAX);
|
||||
*center_y = (MAP_SIZE * rand()) / (1.0f * RAND_MAX);
|
||||
*size = (MAX_CIRCLE_SIZE * rand()) / (1.0f * RAND_MAX);
|
||||
sign = (1.0f * rand()) / (1.0f * RAND_MAX);
|
||||
sign = (sign < DISPLACEMENT_SIGN_LIMIT) ? -1.0f : 1.0f;
|
||||
*displacement = (sign * (MAX_DISPLACEMENT * rand())) / (1.0f * RAND_MAX);
|
||||
}
|
||||
|
||||
/* Run the specified number of iterations of the generation process for the
|
||||
* heightmap
|
||||
*/
|
||||
static void update_map(int num_iter)
|
||||
{
|
||||
assert(num_iter > 0);
|
||||
while(num_iter)
|
||||
{
|
||||
/* center of the circle */
|
||||
float center_x;
|
||||
float center_z;
|
||||
float circle_size;
|
||||
float disp;
|
||||
size_t ii;
|
||||
generate_heightmap__circle(¢er_x, ¢er_z, &circle_size, &disp);
|
||||
disp = disp / 2.0f;
|
||||
for (ii = 0u ; ii < MAP_NUM_TOTAL_VERTICES ; ++ii)
|
||||
{
|
||||
GLfloat dx = center_x - map_vertices[0][ii];
|
||||
GLfloat dz = center_z - map_vertices[2][ii];
|
||||
GLfloat pd = (2.0f * sqrtf((dx * dx) + (dz * dz))) / circle_size;
|
||||
if (fabs(pd) <= 1.0f)
|
||||
{
|
||||
/* tx,tz is within the circle */
|
||||
GLfloat new_height = disp + (float) (cos(pd*3.14f)*disp);
|
||||
map_vertices[1][ii] += new_height;
|
||||
}
|
||||
}
|
||||
--num_iter;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* OpenGL helper functions
|
||||
*********************************************************************/
|
||||
|
||||
/* Create VBO, IBO and VAO objects for the heightmap geometry and bind them to
|
||||
* the specified program object
|
||||
*/
|
||||
static void make_mesh(GLuint program)
|
||||
{
|
||||
GLuint attrloc;
|
||||
|
||||
pglGenVertexArrays(1, &mesh);
|
||||
pglGenBuffers(4, mesh_vbo);
|
||||
pglBindVertexArray(mesh);
|
||||
/* Prepare the data for drawing through a buffer inidices */
|
||||
pglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh_vbo[3]);
|
||||
pglBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)* MAP_NUM_LINES * 2, map_line_indices, GL_STATIC_DRAW);
|
||||
|
||||
/* Prepare the attributes for rendering */
|
||||
attrloc = pglGetAttribLocation(program, "x");
|
||||
pglBindBuffer(GL_ARRAY_BUFFER, mesh_vbo[0]);
|
||||
pglBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * MAP_NUM_TOTAL_VERTICES, &map_vertices[0][0], GL_STATIC_DRAW);
|
||||
pglEnableVertexAttribArray(attrloc);
|
||||
pglVertexAttribPointer(attrloc, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
|
||||
attrloc = pglGetAttribLocation(program, "z");
|
||||
pglBindBuffer(GL_ARRAY_BUFFER, mesh_vbo[2]);
|
||||
pglBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * MAP_NUM_TOTAL_VERTICES, &map_vertices[2][0], GL_STATIC_DRAW);
|
||||
pglEnableVertexAttribArray(attrloc);
|
||||
pglVertexAttribPointer(attrloc, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
|
||||
attrloc = pglGetAttribLocation(program, "y");
|
||||
pglBindBuffer(GL_ARRAY_BUFFER, mesh_vbo[1]);
|
||||
pglBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * MAP_NUM_TOTAL_VERTICES, &map_vertices[1][0], GL_DYNAMIC_DRAW);
|
||||
pglEnableVertexAttribArray(attrloc);
|
||||
pglVertexAttribPointer(attrloc, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
}
|
||||
|
||||
/* Update VBO vertices from source data
|
||||
*/
|
||||
static void update_mesh(void)
|
||||
{
|
||||
pglBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLfloat) * MAP_NUM_TOTAL_VERTICES, &map_vertices[1][0]);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* GLFW callback functions
|
||||
*********************************************************************/
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
/* Exit program on Escape */
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print usage information */
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: heightmap [-v <vertex_shader_path>] [-f <fragment_shader_path>]\n");
|
||||
printf(" heightmap [-h]\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
int ch, iter;
|
||||
double dt;
|
||||
double last_update_time;
|
||||
int frame;
|
||||
float f;
|
||||
GLint uloc_modelview;
|
||||
GLint uloc_project;
|
||||
|
||||
char* vertex_shader_path = NULL;
|
||||
char* fragment_shader_path = NULL;
|
||||
char* vertex_shader_src = NULL;
|
||||
char* fragment_shader_src = NULL;
|
||||
GLuint shader_program;
|
||||
|
||||
while ((ch = getopt(argc, argv, "f:v:h")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'f':
|
||||
fragment_shader_path = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
vertex_shader_path = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
default:
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (fragment_shader_path)
|
||||
{
|
||||
vertex_shader_src = read_file_content(fragment_shader_path);
|
||||
if (!fragment_shader_src)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to load fragment shader from '%s'\n",
|
||||
fragment_shader_path);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (vertex_shader_path)
|
||||
{
|
||||
vertex_shader_src = read_file_content(vertex_shader_path);
|
||||
if (!vertex_shader_src)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to load vertex shader from '%s'\n",
|
||||
fragment_shader_path);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (!glfwInit())
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unable to initialize GLFW\n");
|
||||
usage();
|
||||
|
||||
free(vertex_shader_src);
|
||||
free(fragment_shader_src);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
|
||||
|
||||
window = glfwCreateWindow(800, 600, "GLFW OpenGL3 Heightmap demo", NULL, NULL);
|
||||
if (! window )
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unable to create the OpenGL context and associated window\n");
|
||||
usage();
|
||||
|
||||
free(vertex_shader_src);
|
||||
free(fragment_shader_src);
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Register events callback */
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
if (GL_TRUE != init_opengl())
|
||||
{
|
||||
fprintf(stderr, "ERROR: unable to resolve OpenGL function pointers\n");
|
||||
free(vertex_shader_src);
|
||||
free(fragment_shader_src);
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* Prepare opengl resources for rendering */
|
||||
shader_program = make_shader_program(vertex_shader_src , fragment_shader_src);
|
||||
free(vertex_shader_src);
|
||||
free(fragment_shader_src);
|
||||
|
||||
if (shader_program == 0u)
|
||||
{
|
||||
fprintf(stderr, "ERROR: during creation of the shader program\n");
|
||||
usage();
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
pglUseProgram(shader_program);
|
||||
uloc_project = pglGetUniformLocation(shader_program, "project");
|
||||
uloc_modelview = pglGetUniformLocation(shader_program, "modelview");
|
||||
|
||||
/* Compute the projection matrix */
|
||||
f = 1.0f / tanf(view_angle / 2.0f);
|
||||
projection_matrix[0] = f / aspect_ratio;
|
||||
projection_matrix[5] = f;
|
||||
projection_matrix[10] = (z_far + z_near)/ (z_near - z_far);
|
||||
projection_matrix[11] = -1.0f;
|
||||
projection_matrix[14] = 2.0f * (z_far * z_near) / (z_near - z_far);
|
||||
pglUniformMatrix4fv(uloc_project, 1, GL_FALSE, projection_matrix);
|
||||
|
||||
/* Set the camera position */
|
||||
modelview_matrix[12] = -5.0f;
|
||||
modelview_matrix[13] = -5.0f;
|
||||
modelview_matrix[14] = -20.0f;
|
||||
pglUniformMatrix4fv(uloc_modelview, 1, GL_FALSE, modelview_matrix);
|
||||
|
||||
/* Create mesh data */
|
||||
init_map();
|
||||
make_mesh(shader_program);
|
||||
|
||||
/* Create vao + vbo to store the mesh */
|
||||
/* Create the vbo to store all the information for the grid and the height */
|
||||
|
||||
/* setup the scene ready for rendering */
|
||||
glViewport(0, 0, 800, 600);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
/* main loop */
|
||||
frame = 0;
|
||||
iter = 0;
|
||||
last_update_time = glfwGetTime();
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
++frame;
|
||||
/* render the next frame */
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glDrawElements(GL_LINES, 2* MAP_NUM_LINES , GL_UNSIGNED_INT, 0);
|
||||
|
||||
/* display and process events through callbacks */
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
/* Check the frame rate and update the heightmap if needed */
|
||||
dt = glfwGetTime();
|
||||
if ((dt - last_update_time) > 0.2)
|
||||
{
|
||||
/* generate the next iteration of the heightmap */
|
||||
if (iter < MAX_ITER)
|
||||
{
|
||||
update_map(NUM_ITER_AT_A_TIME);
|
||||
update_mesh();
|
||||
iter += NUM_ITER_AT_A_TIME;
|
||||
}
|
||||
last_update_time = dt;
|
||||
frame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
101
extern/glfw/examples/simple.c
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
//========================================================================
|
||||
// Simple GLFW example
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//! [code]
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fputs(description, stderr);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
float ratio;
|
||||
int width, height;
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
ratio = width / (float) height;
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glLoadIdentity();
|
||||
glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3f(1.f, 0.f, 0.f);
|
||||
glVertex3f(-0.6f, -0.4f, 0.f);
|
||||
glColor3f(0.f, 1.f, 0.f);
|
||||
glVertex3f(0.6f, -0.4f, 0.f);
|
||||
glColor3f(0.f, 0.f, 1.f);
|
||||
glVertex3f(0.f, 0.6f, 0.f);
|
||||
glEnd();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
//! [code]
|
511
extern/glfw/examples/splitview.c
vendored
Normal file
@ -0,0 +1,511 @@
|
||||
//========================================================================
|
||||
// This is an example program for the GLFW library
|
||||
//
|
||||
// The program uses a "split window" view, rendering four views of the
|
||||
// same scene in one window (e.g. uesful for 3D modelling software). This
|
||||
// demo uses scissors to separete the four different rendering areas from
|
||||
// each other.
|
||||
//
|
||||
// (If the code seems a little bit strange here and there, it may be
|
||||
// because I am not a friend of orthogonal projections)
|
||||
//========================================================================
|
||||
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Global variables
|
||||
//========================================================================
|
||||
|
||||
// Mouse position
|
||||
static double xpos = 0, ypos = 0;
|
||||
|
||||
// Window size
|
||||
static int width, height;
|
||||
|
||||
// Active view: 0 = none, 1 = upper left, 2 = upper right, 3 = lower left,
|
||||
// 4 = lower right
|
||||
static int active_view = 0;
|
||||
|
||||
// Rotation around each axis
|
||||
static int rot_x = 0, rot_y = 0, rot_z = 0;
|
||||
|
||||
// Do redraw?
|
||||
static int do_redraw = 1;
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Draw a solid torus (use a display list for the model)
|
||||
//========================================================================
|
||||
|
||||
#define TORUS_MAJOR 1.5
|
||||
#define TORUS_MINOR 0.5
|
||||
#define TORUS_MAJOR_RES 32
|
||||
#define TORUS_MINOR_RES 32
|
||||
|
||||
static void drawTorus(void)
|
||||
{
|
||||
static GLuint torus_list = 0;
|
||||
int i, j, k;
|
||||
double s, t, x, y, z, nx, ny, nz, scale, twopi;
|
||||
|
||||
if (!torus_list)
|
||||
{
|
||||
// Start recording displaylist
|
||||
torus_list = glGenLists(1);
|
||||
glNewList(torus_list, GL_COMPILE_AND_EXECUTE);
|
||||
|
||||
// Draw torus
|
||||
twopi = 2.0 * M_PI;
|
||||
for (i = 0; i < TORUS_MINOR_RES; i++)
|
||||
{
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (j = 0; j <= TORUS_MAJOR_RES; j++)
|
||||
{
|
||||
for (k = 1; k >= 0; k--)
|
||||
{
|
||||
s = (i + k) % TORUS_MINOR_RES + 0.5;
|
||||
t = j % TORUS_MAJOR_RES;
|
||||
|
||||
// Calculate point on surface
|
||||
x = (TORUS_MAJOR + TORUS_MINOR * cos(s * twopi / TORUS_MINOR_RES)) * cos(t * twopi / TORUS_MAJOR_RES);
|
||||
y = TORUS_MINOR * sin(s * twopi / TORUS_MINOR_RES);
|
||||
z = (TORUS_MAJOR + TORUS_MINOR * cos(s * twopi / TORUS_MINOR_RES)) * sin(t * twopi / TORUS_MAJOR_RES);
|
||||
|
||||
// Calculate surface normal
|
||||
nx = x - TORUS_MAJOR * cos(t * twopi / TORUS_MAJOR_RES);
|
||||
ny = y;
|
||||
nz = z - TORUS_MAJOR * sin(t * twopi / TORUS_MAJOR_RES);
|
||||
scale = 1.0 / sqrt(nx*nx + ny*ny + nz*nz);
|
||||
nx *= scale;
|
||||
ny *= scale;
|
||||
nz *= scale;
|
||||
|
||||
glNormal3f((float) nx, (float) ny, (float) nz);
|
||||
glVertex3f((float) x, (float) y, (float) z);
|
||||
}
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// Stop recording displaylist
|
||||
glEndList();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Playback displaylist
|
||||
glCallList(torus_list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Draw the scene (a rotating torus)
|
||||
//========================================================================
|
||||
|
||||
static void drawScene(void)
|
||||
{
|
||||
const GLfloat model_diffuse[4] = {1.0f, 0.8f, 0.8f, 1.0f};
|
||||
const GLfloat model_specular[4] = {0.6f, 0.6f, 0.6f, 1.0f};
|
||||
const GLfloat model_shininess = 20.0f;
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
// Rotate the object
|
||||
glRotatef((GLfloat) rot_x * 0.5f, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef((GLfloat) rot_y * 0.5f, 0.0f, 1.0f, 0.0f);
|
||||
glRotatef((GLfloat) rot_z * 0.5f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Set model color (used for orthogonal views, lighting disabled)
|
||||
glColor4fv(model_diffuse);
|
||||
|
||||
// Set model material (used for perspective view, lighting enabled)
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, model_diffuse);
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, model_specular);
|
||||
glMaterialf(GL_FRONT, GL_SHININESS, model_shininess);
|
||||
|
||||
// Draw torus
|
||||
drawTorus();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Draw a 2D grid (used for orthogonal views)
|
||||
//========================================================================
|
||||
|
||||
static void drawGrid(float scale, int steps)
|
||||
{
|
||||
int i;
|
||||
float x, y;
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
// Set background to some dark bluish grey
|
||||
glClearColor(0.05f, 0.05f, 0.2f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Setup modelview matrix (flat XY view)
|
||||
glLoadIdentity();
|
||||
gluLookAt(0.0, 0.0, 1.0,
|
||||
0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0);
|
||||
|
||||
// We don't want to update the Z-buffer
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
// Set grid color
|
||||
glColor3f(0.0f, 0.5f, 0.5f);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
|
||||
// Horizontal lines
|
||||
x = scale * 0.5f * (float) (steps - 1);
|
||||
y = -scale * 0.5f * (float) (steps - 1);
|
||||
for (i = 0; i < steps; i++)
|
||||
{
|
||||
glVertex3f(-x, y, 0.0f);
|
||||
glVertex3f(x, y, 0.0f);
|
||||
y += scale;
|
||||
}
|
||||
|
||||
// Vertical lines
|
||||
x = -scale * 0.5f * (float) (steps - 1);
|
||||
y = scale * 0.5f * (float) (steps - 1);
|
||||
for (i = 0; i < steps; i++)
|
||||
{
|
||||
glVertex3f(x, -y, 0.0f);
|
||||
glVertex3f(x, y, 0.0f);
|
||||
x += scale;
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
// Enable Z-buffer writing again
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Draw all views
|
||||
//========================================================================
|
||||
|
||||
static void drawAllViews(void)
|
||||
{
|
||||
const GLfloat light_position[4] = {0.0f, 8.0f, 8.0f, 1.0f};
|
||||
const GLfloat light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
const GLfloat light_specular[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
const GLfloat light_ambient[4] = {0.2f, 0.2f, 0.3f, 1.0f};
|
||||
double aspect;
|
||||
|
||||
// Calculate aspect of window
|
||||
if (height > 0)
|
||||
aspect = (double) width / (double) height;
|
||||
else
|
||||
aspect = 1.0;
|
||||
|
||||
// Clear screen
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Enable scissor test
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
// Enable depth test
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
// ** ORTHOGONAL VIEWS **
|
||||
|
||||
// For orthogonal views, use wireframe rendering
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
// Enable line anti-aliasing
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Setup orthogonal projection matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-3.0 * aspect, 3.0 * aspect, -3.0, 3.0, 1.0, 50.0);
|
||||
|
||||
// Upper left view (TOP VIEW)
|
||||
glViewport(0, height / 2, width / 2, height / 2);
|
||||
glScissor(0, height / 2, width / 2, height / 2);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(0.0f, 10.0f, 1e-3f, // Eye-position (above)
|
||||
0.0f, 0.0f, 0.0f, // View-point
|
||||
0.0f, 1.0f, 0.0f); // Up-vector
|
||||
drawGrid(0.5, 12);
|
||||
drawScene();
|
||||
|
||||
// Lower left view (FRONT VIEW)
|
||||
glViewport(0, 0, width / 2, height / 2);
|
||||
glScissor(0, 0, width / 2, height / 2);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(0.0f, 0.0f, 10.0f, // Eye-position (in front of)
|
||||
0.0f, 0.0f, 0.0f, // View-point
|
||||
0.0f, 1.0f, 0.0f); // Up-vector
|
||||
drawGrid(0.5, 12);
|
||||
drawScene();
|
||||
|
||||
// Lower right view (SIDE VIEW)
|
||||
glViewport(width / 2, 0, width / 2, height / 2);
|
||||
glScissor(width / 2, 0, width / 2, height / 2);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(10.0f, 0.0f, 0.0f, // Eye-position (to the right)
|
||||
0.0f, 0.0f, 0.0f, // View-point
|
||||
0.0f, 1.0f, 0.0f); // Up-vector
|
||||
drawGrid(0.5, 12);
|
||||
drawScene();
|
||||
|
||||
// Disable line anti-aliasing
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
// ** PERSPECTIVE VIEW **
|
||||
|
||||
// For perspective view, use solid rendering
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
// Enable face culling (faster rendering)
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
// Setup perspective projection matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(65.0f, aspect, 1.0f, 50.0f);
|
||||
|
||||
// Upper right view (PERSPECTIVE VIEW)
|
||||
glViewport(width / 2, height / 2, width / 2, height / 2);
|
||||
glScissor(width / 2, height / 2, width / 2, height / 2);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(3.0f, 1.5f, 3.0f, // Eye-position
|
||||
0.0f, 0.0f, 0.0f, // View-point
|
||||
0.0f, 1.0f, 0.0f); // Up-vector
|
||||
|
||||
// Configure and enable light source 1
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position);
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
||||
glEnable(GL_LIGHT1);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
// Draw scene
|
||||
drawScene();
|
||||
|
||||
// Disable lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
// Disable face culling
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
// Disable depth test
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
// Disable scissor test
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
// Draw a border around the active view
|
||||
if (active_view > 0 && active_view != 2)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0.0, 2.0, 0.0, 2.0, 0.0, 1.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef((GLfloat) ((active_view - 1) & 1), (GLfloat) (1 - (active_view - 1) / 2), 0.0f);
|
||||
|
||||
glColor3f(1.0f, 1.0f, 0.6f);
|
||||
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2i(0, 0);
|
||||
glVertex2i(1, 0);
|
||||
glVertex2i(1, 1);
|
||||
glVertex2i(0, 1);
|
||||
glVertex2i(0, 0);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Framebuffer size callback function
|
||||
//========================================================================
|
||||
|
||||
static void framebufferSizeFun(GLFWwindow* window, int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h > 0 ? h : 1;
|
||||
do_redraw = 1;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Window refresh callback function
|
||||
//========================================================================
|
||||
|
||||
static void windowRefreshFun(GLFWwindow* window)
|
||||
{
|
||||
do_redraw = 1;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Mouse position callback function
|
||||
//========================================================================
|
||||
|
||||
static void cursorPosFun(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
// Depending on which view was selected, rotate around different axes
|
||||
switch (active_view)
|
||||
{
|
||||
case 1:
|
||||
rot_x += (int) (y - ypos);
|
||||
rot_z += (int) (x - xpos);
|
||||
do_redraw = 1;
|
||||
break;
|
||||
case 3:
|
||||
rot_x += (int) (y - ypos);
|
||||
rot_y += (int) (x - xpos);
|
||||
do_redraw = 1;
|
||||
break;
|
||||
case 4:
|
||||
rot_y += (int) (x - xpos);
|
||||
rot_z += (int) (y - ypos);
|
||||
do_redraw = 1;
|
||||
break;
|
||||
default:
|
||||
// Do nothing for perspective view, or if no view is selected
|
||||
break;
|
||||
}
|
||||
|
||||
// Remember cursor position
|
||||
xpos = x;
|
||||
ypos = y;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Mouse button callback function
|
||||
//========================================================================
|
||||
|
||||
static void mouseButtonFun(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
if ((button == GLFW_MOUSE_BUTTON_LEFT) && action == GLFW_PRESS)
|
||||
{
|
||||
// Detect which of the four views was clicked
|
||||
active_view = 1;
|
||||
if (xpos >= width / 2)
|
||||
active_view += 1;
|
||||
if (ypos >= height / 2)
|
||||
active_view += 2;
|
||||
}
|
||||
else if (button == GLFW_MOUSE_BUTTON_LEFT)
|
||||
{
|
||||
// Deselect any previously selected view
|
||||
active_view = 0;
|
||||
}
|
||||
|
||||
do_redraw = 1;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// main
|
||||
//========================================================================
|
||||
|
||||
int main(void)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
|
||||
// Initialise GLFW
|
||||
if (!glfwInit())
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Open OpenGL window
|
||||
window = glfwCreateWindow(500, 500, "Split view demo", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
fprintf(stderr, "Failed to open GLFW window\n");
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Set callback functions
|
||||
glfwSetFramebufferSizeCallback(window, framebufferSizeFun);
|
||||
glfwSetWindowRefreshCallback(window, windowRefreshFun);
|
||||
glfwSetCursorPosCallback(window, cursorPosFun);
|
||||
glfwSetMouseButtonCallback(window, mouseButtonFun);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
// Enable vsync
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
framebufferSizeFun(window, width, height);
|
||||
|
||||
// Main loop
|
||||
for (;;)
|
||||
{
|
||||
// Only redraw if we need to
|
||||
if (do_redraw)
|
||||
{
|
||||
// Draw all views
|
||||
drawAllViews();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
do_redraw = 0;
|
||||
}
|
||||
|
||||
// Wait for new events
|
||||
glfwWaitEvents();
|
||||
|
||||
// Check if the window should be closed
|
||||
if (glfwWindowShouldClose(window))
|
||||
break;
|
||||
}
|
||||
|
||||
// Close OpenGL window and terminate GLFW
|
||||
glfwTerminate();
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
457
extern/glfw/examples/wave.c
vendored
Normal file
@ -0,0 +1,457 @@
|
||||
/*****************************************************************************
|
||||
* Wave Simulation in OpenGL
|
||||
* (C) 2002 Jakob Thomsen
|
||||
* http://home.in.tum.de/~thomsen
|
||||
* Modified for GLFW by Sylvain Hellegouarch - sh@programmationworld.com
|
||||
* Modified for variable frame rate by Marcus Geelnard
|
||||
* 2003-Jan-31: Minor cleanups and speedups / MG
|
||||
* 2010-10-24: Formatting and cleanup - Camilla Berglund
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
#endif
|
||||
|
||||
// Maximum delta T to allow for differential calculations
|
||||
#define MAX_DELTA_T 0.01
|
||||
|
||||
// Animation speed (10.0 looks good)
|
||||
#define ANIMATION_SPEED 10.0
|
||||
|
||||
GLfloat alpha = 210.f, beta = -70.f;
|
||||
GLfloat zoom = 2.f;
|
||||
|
||||
GLboolean locked = GL_FALSE;
|
||||
|
||||
int cursorX;
|
||||
int cursorY;
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
GLfloat x, y, z;
|
||||
GLfloat r, g, b;
|
||||
};
|
||||
|
||||
#define GRIDW 50
|
||||
#define GRIDH 50
|
||||
#define VERTEXNUM (GRIDW*GRIDH)
|
||||
|
||||
#define QUADW (GRIDW - 1)
|
||||
#define QUADH (GRIDH - 1)
|
||||
#define QUADNUM (QUADW*QUADH)
|
||||
|
||||
GLuint quad[4 * QUADNUM];
|
||||
struct Vertex vertex[VERTEXNUM];
|
||||
|
||||
/* The grid will look like this:
|
||||
*
|
||||
* 3 4 5
|
||||
* *---*---*
|
||||
* | | |
|
||||
* | 0 | 1 |
|
||||
* | | |
|
||||
* *---*---*
|
||||
* 0 1 2
|
||||
*/
|
||||
|
||||
//========================================================================
|
||||
// Initialize grid geometry
|
||||
//========================================================================
|
||||
|
||||
void init_vertices(void)
|
||||
{
|
||||
int x, y, p;
|
||||
|
||||
// Place the vertices in a grid
|
||||
for (y = 0; y < GRIDH; y++)
|
||||
{
|
||||
for (x = 0; x < GRIDW; x++)
|
||||
{
|
||||
p = y * GRIDW + x;
|
||||
|
||||
vertex[p].x = (GLfloat) (x - GRIDW / 2) / (GLfloat) (GRIDW / 2);
|
||||
vertex[p].y = (GLfloat) (y - GRIDH / 2) / (GLfloat) (GRIDH / 2);
|
||||
vertex[p].z = 0;
|
||||
|
||||
if ((x % 4 < 2) ^ (y % 4 < 2))
|
||||
vertex[p].r = 0.0;
|
||||
else
|
||||
vertex[p].r = 1.0;
|
||||
|
||||
vertex[p].g = (GLfloat) y / (GLfloat) GRIDH;
|
||||
vertex[p].b = 1.f - ((GLfloat) x / (GLfloat) GRIDW + (GLfloat) y / (GLfloat) GRIDH) / 2.f;
|
||||
}
|
||||
}
|
||||
|
||||
for (y = 0; y < QUADH; y++)
|
||||
{
|
||||
for (x = 0; x < QUADW; x++)
|
||||
{
|
||||
p = 4 * (y * QUADW + x);
|
||||
|
||||
quad[p + 0] = y * GRIDW + x; // Some point
|
||||
quad[p + 1] = y * GRIDW + x + 1; // Neighbor at the right side
|
||||
quad[p + 2] = (y + 1) * GRIDW + x + 1; // Upper right neighbor
|
||||
quad[p + 3] = (y + 1) * GRIDW + x; // Upper neighbor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double dt;
|
||||
double p[GRIDW][GRIDH];
|
||||
double vx[GRIDW][GRIDH], vy[GRIDW][GRIDH];
|
||||
double ax[GRIDW][GRIDH], ay[GRIDW][GRIDH];
|
||||
|
||||
//========================================================================
|
||||
// Initialize grid
|
||||
//========================================================================
|
||||
|
||||
void init_grid(void)
|
||||
{
|
||||
int x, y;
|
||||
double dx, dy, d;
|
||||
|
||||
for (y = 0; y < GRIDH; y++)
|
||||
{
|
||||
for (x = 0; x < GRIDW; x++)
|
||||
{
|
||||
dx = (double) (x - GRIDW / 2);
|
||||
dy = (double) (y - GRIDH / 2);
|
||||
d = sqrt(dx * dx + dy * dy);
|
||||
if (d < 0.1 * (double) (GRIDW / 2))
|
||||
{
|
||||
d = d * 10.0;
|
||||
p[x][y] = -cos(d * (M_PI / (double)(GRIDW * 4))) * 100.0;
|
||||
}
|
||||
else
|
||||
p[x][y] = 0.0;
|
||||
|
||||
vx[x][y] = 0.0;
|
||||
vy[x][y] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Draw scene
|
||||
//========================================================================
|
||||
|
||||
void draw_scene(GLFWwindow* window)
|
||||
{
|
||||
// Clear the color and depth buffers
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// We don't want to modify the projection matrix
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// Move back
|
||||
glTranslatef(0.0, 0.0, -zoom);
|
||||
// Rotate the view
|
||||
glRotatef(beta, 1.0, 0.0, 0.0);
|
||||
glRotatef(alpha, 0.0, 0.0, 1.0);
|
||||
|
||||
glDrawElements(GL_QUADS, 4 * QUADNUM, GL_UNSIGNED_INT, quad);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Initialize Miscellaneous OpenGL state
|
||||
//========================================================================
|
||||
|
||||
void init_opengl(void)
|
||||
{
|
||||
// Use Gouraud (smooth) shading
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
// Switch on the z-buffer
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(struct Vertex), vertex);
|
||||
glColorPointer(3, GL_FLOAT, sizeof(struct Vertex), &vertex[0].r); // Pointer to the first color
|
||||
|
||||
glPointSize(2.0);
|
||||
|
||||
// Background color is black
|
||||
glClearColor(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Modify the height of each vertex according to the pressure
|
||||
//========================================================================
|
||||
|
||||
void adjust_grid(void)
|
||||
{
|
||||
int pos;
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < GRIDH; y++)
|
||||
{
|
||||
for (x = 0; x < GRIDW; x++)
|
||||
{
|
||||
pos = y * GRIDW + x;
|
||||
vertex[pos].z = (float) (p[x][y] * (1.0 / 50.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Calculate wave propagation
|
||||
//========================================================================
|
||||
|
||||
void calc_grid(void)
|
||||
{
|
||||
int x, y, x2, y2;
|
||||
double time_step = dt * ANIMATION_SPEED;
|
||||
|
||||
// Compute accelerations
|
||||
for (x = 0; x < GRIDW; x++)
|
||||
{
|
||||
x2 = (x + 1) % GRIDW;
|
||||
for(y = 0; y < GRIDH; y++)
|
||||
ax[x][y] = p[x][y] - p[x2][y];
|
||||
}
|
||||
|
||||
for (y = 0; y < GRIDH; y++)
|
||||
{
|
||||
y2 = (y + 1) % GRIDH;
|
||||
for(x = 0; x < GRIDW; x++)
|
||||
ay[x][y] = p[x][y] - p[x][y2];
|
||||
}
|
||||
|
||||
// Compute speeds
|
||||
for (x = 0; x < GRIDW; x++)
|
||||
{
|
||||
for (y = 0; y < GRIDH; y++)
|
||||
{
|
||||
vx[x][y] = vx[x][y] + ax[x][y] * time_step;
|
||||
vy[x][y] = vy[x][y] + ay[x][y] * time_step;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute pressure
|
||||
for (x = 1; x < GRIDW; x++)
|
||||
{
|
||||
x2 = x - 1;
|
||||
for (y = 1; y < GRIDH; y++)
|
||||
{
|
||||
y2 = y - 1;
|
||||
p[x][y] = p[x][y] + (vx[x2][y] - vx[x][y] + vy[x][y2] - vy[x][y]) * time_step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Print errors
|
||||
//========================================================================
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Handle key strokes
|
||||
//========================================================================
|
||||
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
break;
|
||||
case GLFW_KEY_SPACE:
|
||||
init_grid();
|
||||
break;
|
||||
case GLFW_KEY_LEFT:
|
||||
alpha += 5;
|
||||
break;
|
||||
case GLFW_KEY_RIGHT:
|
||||
alpha -= 5;
|
||||
break;
|
||||
case GLFW_KEY_UP:
|
||||
beta -= 5;
|
||||
break;
|
||||
case GLFW_KEY_DOWN:
|
||||
beta += 5;
|
||||
break;
|
||||
case GLFW_KEY_PAGE_UP:
|
||||
zoom -= 0.25f;
|
||||
if (zoom < 0.f)
|
||||
zoom = 0.f;
|
||||
break;
|
||||
case GLFW_KEY_PAGE_DOWN:
|
||||
zoom += 0.25f;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Callback function for mouse button events
|
||||
//========================================================================
|
||||
|
||||
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
if (button != GLFW_MOUSE_BUTTON_LEFT)
|
||||
return;
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
locked = GL_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
locked = GL_FALSE;
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Callback function for cursor motion events
|
||||
//========================================================================
|
||||
|
||||
void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
if (locked)
|
||||
{
|
||||
alpha += (GLfloat) (x - cursorX) / 10.f;
|
||||
beta += (GLfloat) (y - cursorY) / 10.f;
|
||||
}
|
||||
|
||||
cursorX = (int) x;
|
||||
cursorY = (int) y;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Callback function for scroll events
|
||||
//========================================================================
|
||||
|
||||
void scroll_callback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
zoom += (float) y / 4.f;
|
||||
if (zoom < 0)
|
||||
zoom = 0;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Callback function for framebuffer resize events
|
||||
//========================================================================
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
float ratio = 1.f;
|
||||
|
||||
if (height > 0)
|
||||
ratio = (float) width / (float) height;
|
||||
|
||||
// Setup viewport
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
// Change to the projection matrix and set our viewing volume
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60.0, ratio, 1.0, 1024.0);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// main
|
||||
//========================================================================
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
GLFWwindow* window;
|
||||
double t, dt_total, t_old;
|
||||
int width, height;
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Wave Simulation", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
glfwSetScrollCallback(window, scroll_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
framebuffer_size_callback(window, width, height);
|
||||
|
||||
// Initialize OpenGL
|
||||
init_opengl();
|
||||
|
||||
// Initialize simulation
|
||||
init_vertices();
|
||||
init_grid();
|
||||
adjust_grid();
|
||||
|
||||
// Initialize timer
|
||||
t_old = glfwGetTime() - 0.01;
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
t = glfwGetTime();
|
||||
dt_total = t - t_old;
|
||||
t_old = t;
|
||||
|
||||
// Safety - iterate if dt_total is too large
|
||||
while (dt_total > 0.f)
|
||||
{
|
||||
// Select iteration time step
|
||||
dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
|
||||
dt_total -= dt;
|
||||
|
||||
// Calculate wave propagation
|
||||
calc_grid();
|
||||
}
|
||||
|
||||
// Compute height of each vertex
|
||||
adjust_grid();
|
||||
|
||||
// Draw wave grid to OpenGL display
|
||||
draw_scene(window);
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
152
extern/glfw/include/GLFW/glfw3.h
vendored
@ -133,10 +133,38 @@ extern "C" {
|
||||
|
||||
/* Most GL/glu.h variants on Windows need wchar_t
|
||||
* OpenGL/gl.h blocks the definition of ptrdiff_t by glext.h on OS X */
|
||||
#include <stddef.h>
|
||||
#if !defined(GLFW_INCLUDE_NONE)
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------------- GLFW related system specific defines ----------------- */
|
||||
/* Include the chosen client API headers.
|
||||
*/
|
||||
#if defined(__APPLE_CC__)
|
||||
#if defined(GLFW_INCLUDE_GLCOREARB)
|
||||
#include <OpenGL/gl3.h>
|
||||
#elif !defined(GLFW_INCLUDE_NONE)
|
||||
#define GL_GLEXT_LEGACY
|
||||
#include <OpenGL/gl.h>
|
||||
#endif
|
||||
#if defined(GLFW_INCLUDE_GLU)
|
||||
#include <OpenGL/glu.h>
|
||||
#endif
|
||||
#else
|
||||
#if defined(GLFW_INCLUDE_GLCOREARB)
|
||||
#include <GL/glcorearb.h>
|
||||
#elif defined(GLFW_INCLUDE_ES1)
|
||||
#include <GLES/gl.h>
|
||||
#elif defined(GLFW_INCLUDE_ES2)
|
||||
#include <GLES2/gl2.h>
|
||||
#elif defined(GLFW_INCLUDE_ES3)
|
||||
#include <GLES3/gl3.h>
|
||||
#elif !defined(GLFW_INCLUDE_NONE)
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#if defined(GLFW_INCLUDE_GLU)
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_DLL) && defined(_GLFW_BUILD_DLL)
|
||||
/* GLFW_DLL is defined by users of GLFW when compiling programs that will link
|
||||
@ -173,35 +201,6 @@ extern "C" {
|
||||
|
||||
/* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */
|
||||
|
||||
/* Include the chosen client API headers.
|
||||
*/
|
||||
#if defined(__APPLE_CC__)
|
||||
#if defined(GLFW_INCLUDE_GLCOREARB)
|
||||
#include <OpenGL/gl3.h>
|
||||
#elif !defined(GLFW_INCLUDE_NONE)
|
||||
#define GL_GLEXT_LEGACY
|
||||
#include <OpenGL/gl.h>
|
||||
#endif
|
||||
#if defined(GLFW_INCLUDE_GLU)
|
||||
#include <OpenGL/glu.h>
|
||||
#endif
|
||||
#else
|
||||
#if defined(GLFW_INCLUDE_GLCOREARB)
|
||||
#include <GL/glcorearb.h>
|
||||
#elif defined(GLFW_INCLUDE_ES1)
|
||||
#include <GLES/gl.h>
|
||||
#elif defined(GLFW_INCLUDE_ES2)
|
||||
#include <GLES2/gl2.h>
|
||||
#elif defined(GLFW_INCLUDE_ES3)
|
||||
#include <GLES3/gl3.h>
|
||||
#elif !defined(GLFW_INCLUDE_NONE)
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#if defined(GLFW_INCLUDE_GLU)
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* GLFW API tokens
|
||||
@ -228,7 +227,7 @@ extern "C" {
|
||||
* API changes.
|
||||
* @ingroup init
|
||||
*/
|
||||
#define GLFW_VERSION_REVISION 2
|
||||
#define GLFW_VERSION_REVISION 4
|
||||
/*! @} */
|
||||
|
||||
/*! @name Key and button actions
|
||||
@ -707,8 +706,8 @@ typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int);
|
||||
* This is the function signature for cursor position callback functions.
|
||||
*
|
||||
* @param[in] window The window that received the event.
|
||||
* @param[in] xpos The new x-coordinate of the cursor.
|
||||
* @param[in] ypos The new y-coordinate of the cursor.
|
||||
* @param[in] xpos The new x-coordinate, in screen coordinates, of the cursor.
|
||||
* @param[in] ypos The new y-coordinate, in screen coordinates, of the cursor.
|
||||
*
|
||||
* @sa glfwSetCursorPosCallback
|
||||
*
|
||||
@ -766,7 +765,7 @@ typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int);
|
||||
* This is the function signature for Unicode character callback functions.
|
||||
*
|
||||
* @param[in] window The window that received the event.
|
||||
* @param[in] character The Unicode code point of the character.
|
||||
* @param[in] codepoint The Unicode code point of the character.
|
||||
*
|
||||
* @sa glfwSetCharCallback
|
||||
*
|
||||
@ -793,7 +792,7 @@ typedef void (* GLFWmonitorfun)(GLFWmonitor*,int);
|
||||
*
|
||||
* @ingroup monitor
|
||||
*/
|
||||
typedef struct
|
||||
typedef struct GLFWvidmode
|
||||
{
|
||||
/*! The width, in screen coordinates, of the video mode.
|
||||
*/
|
||||
@ -823,7 +822,7 @@ typedef struct
|
||||
*
|
||||
* @ingroup monitor
|
||||
*/
|
||||
typedef struct
|
||||
typedef struct GLFWgammaramp
|
||||
{
|
||||
/*! An array of value describing the response of the red channel.
|
||||
*/
|
||||
@ -864,10 +863,7 @@ typedef struct
|
||||
*
|
||||
* @note This function may only be called from the main thread.
|
||||
*
|
||||
* @note This function may take several seconds to complete on some systems,
|
||||
* while on other systems it may take only a fraction of a second to complete.
|
||||
*
|
||||
* @note **Mac OS X:** This function will change the current directory of the
|
||||
* @note **OS X:** This function will change the current directory of the
|
||||
* application to the `Contents/Resources` subdirectory of the application's
|
||||
* bundle, if present.
|
||||
*
|
||||
@ -1233,17 +1229,26 @@ GLFWAPI void glfwWindowHint(int target, int hint);
|
||||
* to not share resources.
|
||||
* @return The handle of the created window, or `NULL` if an error occurred.
|
||||
*
|
||||
* @remarks **Windows:** Window creation will fail if the Microsoft GDI
|
||||
* software OpenGL implementation is the only one available.
|
||||
*
|
||||
* @remarks **Windows:** If the executable has an icon resource named
|
||||
* `GLFW_ICON,` it will be set as the icon for the window. If no such icon is
|
||||
* present, the `IDI_WINLOGO` icon will be used instead.
|
||||
*
|
||||
* @remarks **Mac OS X:** The GLFW window has no icon, as it is not a document
|
||||
* @remarks **OS X:** The GLFW window has no icon, as it is not a document
|
||||
* window, but the dock icon will be the same as the application bundle's icon.
|
||||
* Also, the first time a window is opened the menu bar is populated with
|
||||
* common commands like Hide, Quit and About. The (minimal) about dialog uses
|
||||
* information from the application's bundle. For more information on bundles,
|
||||
* see the Bundle Programming Guide provided by Apple.
|
||||
*
|
||||
* @remarks **X11:** There is no mechanism for setting the window icon yet.
|
||||
*
|
||||
* @remarks The swap interval is not set during window creation, but is left at
|
||||
* the default value for that platform. For more information, see @ref
|
||||
* glfwSwapInterval.
|
||||
*
|
||||
* @note This function may only be called from the main thread.
|
||||
*
|
||||
* @sa glfwDestroyWindow
|
||||
@ -1355,10 +1360,6 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos);
|
||||
*
|
||||
* @note The window manager may put limits on what positions are allowed.
|
||||
*
|
||||
* @bug **X11:** Some window managers ignore the set position of hidden (i.e.
|
||||
* unmapped) windows, instead placing them where it thinks is appropriate once
|
||||
* they are shown.
|
||||
*
|
||||
* @sa glfwGetWindowPos
|
||||
*
|
||||
* @ingroup window
|
||||
@ -1368,7 +1369,8 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos);
|
||||
/*! @brief Retrieves the size of the client area of the specified window.
|
||||
*
|
||||
* This function retrieves the size, in screen coordinates, of the client area
|
||||
* of the specified window.
|
||||
* of the specified window. If you wish to retrieve the size of the
|
||||
* framebuffer in pixels, see @ref glfwGetFramebufferSize.
|
||||
*
|
||||
* @param[in] window The window whose size to retrieve.
|
||||
* @param[out] width Where to store the width, in screen coordinates, of the
|
||||
@ -1409,7 +1411,8 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow* window, int width, int height);
|
||||
/*! @brief Retrieves the size of the framebuffer of the specified window.
|
||||
*
|
||||
* This function retrieves the size, in pixels, of the framebuffer of the
|
||||
* specified window.
|
||||
* specified window. If you wish to retrieve the size of the window in screen
|
||||
* coordinates, see @ref glfwGetWindowSize.
|
||||
*
|
||||
* @param[in] window The window whose framebuffer to query.
|
||||
* @param[out] width Where to store the width, in pixels, of the framebuffer,
|
||||
@ -1592,7 +1595,10 @@ GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwind
|
||||
* @return The previously set callback, or `NULL` if no callback was set or an
|
||||
* error occurred.
|
||||
*
|
||||
* @remarks **Mac OS X:** Selecting Quit from the application menu will
|
||||
* @par New in GLFW 3
|
||||
* The close callback no longer returns a value.
|
||||
*
|
||||
* @remarks **OS X:** Selecting Quit from the application menu will
|
||||
* trigger the close callback for all windows.
|
||||
*
|
||||
* @ingroup window
|
||||
@ -1685,6 +1691,12 @@ GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window
|
||||
* This function is no longer called by @ref glfwSwapBuffers. You need to call
|
||||
* it or @ref glfwWaitEvents yourself.
|
||||
*
|
||||
* @remarks On some platforms, a window move, resize or menu operation will
|
||||
* cause event processing to block. This is due to how event processing is
|
||||
* designed on those platforms. You can use the
|
||||
* [window refresh callback](@ref GLFWwindowrefreshfun) to redraw the contents
|
||||
* of your window when necessary during the operation.
|
||||
*
|
||||
* @note This function may only be called from the main thread.
|
||||
*
|
||||
* @note This function may not be called from a callback.
|
||||
@ -1712,6 +1724,12 @@ GLFWAPI void glfwPollEvents(void);
|
||||
*
|
||||
* This function is not required for joystick input to work.
|
||||
*
|
||||
* @remarks On some platforms, a window move, resize or menu operation will
|
||||
* cause event processing to block. This is due to how event processing is
|
||||
* designed on those platforms. You can use the
|
||||
* [window refresh callback](@ref GLFWwindowrefreshfun) to redraw the contents
|
||||
* of your window when necessary during the operation.
|
||||
*
|
||||
* @note This function may only be called from the main thread.
|
||||
*
|
||||
* @note This function may not be called from a callback.
|
||||
@ -1747,9 +1765,12 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode);
|
||||
* modes:
|
||||
* - `GLFW_CURSOR_NORMAL` makes the cursor visible and behaving normally.
|
||||
* - `GLFW_CURSOR_HIDDEN` makes the cursor invisible when it is over the client
|
||||
* area of the window.
|
||||
* - `GLFW_CURSOR_DISABLED` disables the cursor and removes any limitations on
|
||||
* cursor movement.
|
||||
* area of the window but does not restrict the cursor from leaving. This is
|
||||
* useful if you wish to render your own cursor or have no visible cursor at
|
||||
* all.
|
||||
* - `GLFW_CURSOR_DISABLED` hides and grabs the cursor, providing virtual
|
||||
* and unlimited cursor movement. This is useful for implementing for
|
||||
* example 3D camera controls.
|
||||
*
|
||||
* If `mode` is `GLFW_STICKY_KEYS`, the value must be either `GL_TRUE` to
|
||||
* enable sticky keys, or `GL_FALSE` to disable it. If sticky keys are
|
||||
@ -1819,7 +1840,8 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button);
|
||||
/*! @brief Retrieves the last reported cursor position, relative to the client
|
||||
* area of the window.
|
||||
*
|
||||
* This function returns the last reported position of the cursor to the
|
||||
* This function returns the last reported position of the cursor, in screen
|
||||
* coordinates, relative to the upper-left corner of the client area of the
|
||||
* specified window.
|
||||
*
|
||||
* If the cursor is disabled (with `GLFW_CURSOR_DISABLED`) then the cursor
|
||||
@ -1842,11 +1864,13 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button);
|
||||
*/
|
||||
GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos);
|
||||
|
||||
/*! @brief Sets the position of the cursor, relative to the client area of the window.
|
||||
/*! @brief Sets the position of the cursor, relative to the client area of the
|
||||
* window.
|
||||
*
|
||||
* This function sets the position of the cursor. The specified window must be
|
||||
* focused. If the window does not have focus when this function is called, it
|
||||
* fails silently.
|
||||
* This function sets the position, in screen coordinates, of the cursor
|
||||
* relative to the upper-left corner of the client area of the specified
|
||||
* window. The window must be focused. If the window does not have focus when
|
||||
* this function is called, it fails silently.
|
||||
*
|
||||
* If the cursor is disabled (with `GLFW_CURSOR_DISABLED`) then the cursor
|
||||
* position is unbounded and limited only by the minimum and maximum values of
|
||||
@ -1854,9 +1878,9 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos);
|
||||
*
|
||||
* @param[in] window The desired window.
|
||||
* @param[in] xpos The desired x-coordinate, relative to the left edge of the
|
||||
* client area, or `NULL`.
|
||||
* client area.
|
||||
* @param[in] ypos The desired y-coordinate, relative to the top edge of the
|
||||
* client area, or `NULL`.
|
||||
* client area.
|
||||
*
|
||||
* @sa glfwGetCursorPos
|
||||
*
|
||||
@ -1942,7 +1966,8 @@ GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmo
|
||||
*
|
||||
* This function sets the cursor position callback of the specified window,
|
||||
* which is called when the cursor is moved. The callback is provided with the
|
||||
* position relative to the upper-left corner of the client area of the window.
|
||||
* position, in screen coordinates, relative to the upper-left corner of the
|
||||
* client area of the window.
|
||||
*
|
||||
* @param[in] window The window whose callback to set.
|
||||
* @param[in] cbfun The new callback, or `NULL` to remove the currently set
|
||||
@ -2202,6 +2227,11 @@ GLFWAPI void glfwSwapBuffers(GLFWwindow* window);
|
||||
*
|
||||
* @remarks This function may be called from secondary threads.
|
||||
*
|
||||
* @note This function is not called during window creation, leaving the swap
|
||||
* interval set to whatever is the default on that platform. This is done
|
||||
* because some swap interval extensions used by GLFW do not allow the swap
|
||||
* interval to be reset to zero once it has been set to a non-zero value.
|
||||
*
|
||||
* @note Some GPU drivers do not honor the requested swap interval, either
|
||||
* because of user settings that override the request or due to bugs in the
|
||||
* driver.
|
||||
|
7
extern/glfw/src/CMakeLists.txt
vendored
@ -3,7 +3,9 @@ include_directories(${GLFW_SOURCE_DIR}/src
|
||||
${GLFW_BINARY_DIR}/src
|
||||
${glfw_INCLUDE_DIRS})
|
||||
|
||||
set(common_HEADERS ${GLFW_BINARY_DIR}/src/config.h internal.h
|
||||
add_definitions(-D_GLFW_USE_CONFIG_H)
|
||||
|
||||
set(common_HEADERS ${GLFW_BINARY_DIR}/src/glfw_config.h internal.h
|
||||
${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h
|
||||
${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h)
|
||||
set(common_SOURCES clipboard.c context.c gamma.c init.c input.c joystick.c
|
||||
@ -72,7 +74,8 @@ if (BUILD_SHARED_LIBS)
|
||||
set(glfw_CFLAGS "")
|
||||
endif()
|
||||
set_target_properties(glfw PROPERTIES
|
||||
COMPILE_FLAGS "${glfw_CFLAGS} -fno-common")
|
||||
COMPILE_FLAGS "${glfw_CFLAGS} -fno-common"
|
||||
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
|
||||
endif()
|
||||
|
||||
target_link_libraries(glfw ${glfw_LIBRARIES})
|
||||
|
2
extern/glfw/src/cocoa_init.m
vendored
@ -122,7 +122,7 @@ void _glfwPlatformTerminate(void)
|
||||
|
||||
const char* _glfwPlatformGetVersionString(void)
|
||||
{
|
||||
const char* version = _GLFW_VERSION_FULL " Cocoa"
|
||||
const char* version = _GLFW_VERSION_NUMBER " Cocoa"
|
||||
#if defined(_GLFW_NSGL)
|
||||
" NSGL"
|
||||
#endif
|
||||
|
32
extern/glfw/src/cocoa_joystick.m
vendored
@ -251,9 +251,6 @@ static void pollJoystickEvents(void)
|
||||
joystick->axes[i] = value;
|
||||
else
|
||||
joystick->axes[i] = (2.f * (value - axis->minReport) / readScale) - 1.f;
|
||||
|
||||
if (i & 1)
|
||||
joystick->axes[i] = -joystick->axes[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++)
|
||||
@ -319,8 +316,9 @@ void _glfwInitJoysticks(void)
|
||||
|
||||
while ((ioHIDDeviceObject = IOIteratorNext(objectIterator)))
|
||||
{
|
||||
CFMutableDictionaryRef propsRef = NULL;
|
||||
CFTypeRef valueRef = NULL;
|
||||
kern_return_t result;
|
||||
CFTypeRef valueRef = 0;
|
||||
|
||||
IOCFPlugInInterface** ppPlugInInterface = NULL;
|
||||
HRESULT plugInResult = S_OK;
|
||||
@ -329,26 +327,29 @@ void _glfwInitJoysticks(void)
|
||||
long usagePage, usage;
|
||||
|
||||
// Check device type
|
||||
valueRef = IORegistryEntryCreateCFProperty(ioHIDDeviceObject,
|
||||
CFSTR(kIOHIDPrimaryUsagePageKey),
|
||||
result = IORegistryEntryCreateCFProperties(ioHIDDeviceObject,
|
||||
&propsRef,
|
||||
kCFAllocatorDefault,
|
||||
kNilOptions);
|
||||
|
||||
if (result != kIOReturnSuccess)
|
||||
continue;
|
||||
|
||||
valueRef = CFDictionaryGetValue(propsRef, CFSTR(kIOHIDPrimaryUsagePageKey));
|
||||
if (valueRef)
|
||||
{
|
||||
CFNumberGetValue(valueRef, kCFNumberLongType, &usagePage);
|
||||
if (usagePage != kHIDPage_GenericDesktop)
|
||||
{
|
||||
// This device is not relevant to GLFW
|
||||
CFRelease(valueRef);
|
||||
continue;
|
||||
}
|
||||
|
||||
CFRelease(valueRef);
|
||||
}
|
||||
|
||||
valueRef = IORegistryEntryCreateCFProperty(ioHIDDeviceObject,
|
||||
CFSTR(kIOHIDPrimaryUsageKey),
|
||||
kCFAllocatorDefault,
|
||||
kNilOptions);
|
||||
valueRef = CFDictionaryGetValue(propsRef, CFSTR(kIOHIDPrimaryUsageKey));
|
||||
if (valueRef)
|
||||
{
|
||||
CFNumberGetValue(valueRef, kCFNumberLongType, &usage);
|
||||
@ -358,6 +359,7 @@ void _glfwInitJoysticks(void)
|
||||
usage != kHIDUsage_GD_MultiAxisController))
|
||||
{
|
||||
// This device is not relevant to GLFW
|
||||
CFRelease(valueRef);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -393,10 +395,7 @@ void _glfwInitJoysticks(void)
|
||||
joystick);
|
||||
|
||||
// Get product string
|
||||
valueRef = IORegistryEntryCreateCFProperty(ioHIDDeviceObject,
|
||||
CFSTR(kIOHIDProductKey),
|
||||
kCFAllocatorDefault,
|
||||
kNilOptions);
|
||||
valueRef = CFDictionaryGetValue(propsRef, CFSTR(kIOHIDProductKey));
|
||||
if (valueRef)
|
||||
{
|
||||
CFStringGetCString(valueRef,
|
||||
@ -410,10 +409,7 @@ void _glfwInitJoysticks(void)
|
||||
joystick->buttonElements = CFArrayCreateMutable(NULL, 0, NULL);
|
||||
joystick->hatElements = CFArrayCreateMutable(NULL, 0, NULL);
|
||||
|
||||
valueRef = IORegistryEntryCreateCFProperty(ioHIDDeviceObject,
|
||||
CFSTR(kIOHIDElementKey),
|
||||
kCFAllocatorDefault,
|
||||
kNilOptions);
|
||||
valueRef = CFDictionaryGetValue(propsRef, CFSTR(kIOHIDElementKey));
|
||||
if (CFGetTypeID(valueRef) == CFArrayGetTypeID())
|
||||
{
|
||||
CFRange range = { 0, CFArrayGetCount(valueRef) };
|
||||
|
40
extern/glfw/src/cocoa_monitor.m
vendored
@ -31,6 +31,9 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include <IOKit/graphics/IOGraphicsLib.h>
|
||||
#include <IOKit/graphics/IOGraphicsLib.h>
|
||||
#include <CoreVideo/CVBase.h>
|
||||
#include <CoreVideo/CVDisplayLink.h>
|
||||
|
||||
|
||||
// Get the name of the specified display
|
||||
@ -46,9 +49,11 @@ static const char* getDisplayName(CGDirectDisplayID displayID)
|
||||
kIODisplayOnlyPreferredName);
|
||||
names = CFDictionaryGetValue(info, CFSTR(kDisplayProductName));
|
||||
|
||||
if (!CFDictionaryGetValueIfPresent(names, CFSTR("en_US"),
|
||||
(const void**) &value))
|
||||
if (!names || !CFDictionaryGetValueIfPresent(names, CFSTR("en_US"),
|
||||
(const void**) &value))
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR, "Failed to retrieve display name");
|
||||
|
||||
CFRelease(info);
|
||||
return strdup("Unknown");
|
||||
}
|
||||
@ -74,9 +79,6 @@ static GLboolean modeIsGood(CGDisplayModeRef mode)
|
||||
if (flags & kDisplayModeInterlacedFlag)
|
||||
return GL_FALSE;
|
||||
|
||||
if (flags & kDisplayModeTelevisionFlag)
|
||||
return GL_FALSE;
|
||||
|
||||
if (flags & kDisplayModeStretchedFlag)
|
||||
return GL_FALSE;
|
||||
|
||||
@ -94,13 +96,21 @@ static GLboolean modeIsGood(CGDisplayModeRef mode)
|
||||
|
||||
// Convert Core Graphics display mode to GLFW video mode
|
||||
//
|
||||
static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode)
|
||||
static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode,
|
||||
CVDisplayLinkRef link)
|
||||
{
|
||||
GLFWvidmode result;
|
||||
result.width = CGDisplayModeGetWidth(mode);
|
||||
result.height = CGDisplayModeGetHeight(mode);
|
||||
result.width = (int) CGDisplayModeGetWidth(mode);
|
||||
result.height = (int) CGDisplayModeGetHeight(mode);
|
||||
result.refreshRate = (int) CGDisplayModeGetRefreshRate(mode);
|
||||
|
||||
if (result.refreshRate == 0)
|
||||
{
|
||||
const CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
|
||||
if (!(time.flags & kCVTimeIsIndefinite))
|
||||
result.refreshRate = (int) (time.timeScale / (double) time.timeValue);
|
||||
}
|
||||
|
||||
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
|
||||
|
||||
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0)
|
||||
@ -334,6 +344,9 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
|
||||
CFArrayRef modes;
|
||||
CFIndex count, i;
|
||||
GLFWvidmode* result;
|
||||
CVDisplayLinkRef link;
|
||||
|
||||
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
|
||||
|
||||
modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
|
||||
count = CFArrayGetCount(modes);
|
||||
@ -348,21 +361,28 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
|
||||
mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
|
||||
if (modeIsGood(mode))
|
||||
{
|
||||
result[*found] = vidmodeFromCGDisplayMode(mode);
|
||||
result[*found] = vidmodeFromCGDisplayMode(mode, link);
|
||||
(*found)++;
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(modes);
|
||||
|
||||
CVDisplayLinkRelease(link);
|
||||
return result;
|
||||
}
|
||||
|
||||
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
|
||||
{
|
||||
CGDisplayModeRef displayMode;
|
||||
CVDisplayLinkRef link;
|
||||
|
||||
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
|
||||
|
||||
displayMode = CGDisplayCopyDisplayMode(monitor->ns.displayID);
|
||||
*mode = vidmodeFromCGDisplayMode(displayMode);
|
||||
*mode = vidmodeFromCGDisplayMode(displayMode, link);
|
||||
CGDisplayModeRelease(displayMode);
|
||||
|
||||
CVDisplayLinkRelease(link);
|
||||
}
|
||||
|
||||
|
2
extern/glfw/src/cocoa_platform.h
vendored
@ -105,8 +105,6 @@ typedef struct _GLFWlibraryNS
|
||||
id autoreleasePool;
|
||||
id cursor;
|
||||
|
||||
GLboolean cursorHidden;
|
||||
|
||||
char* clipboardString;
|
||||
|
||||
_GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1];
|
||||
|
148
extern/glfw/src/cocoa_window.m
vendored
@ -30,6 +30,25 @@
|
||||
#include <crt_externs.h>
|
||||
|
||||
|
||||
// Center the cursor in the view of the window
|
||||
//
|
||||
static void centerCursor(_GLFWwindow *window)
|
||||
{
|
||||
int width, height;
|
||||
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||
_glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
|
||||
}
|
||||
|
||||
// Update the cursor to match the specified cursor mode
|
||||
//
|
||||
static void setModeCursor(_GLFWwindow* window, int mode)
|
||||
{
|
||||
if (mode == GLFW_CURSOR_NORMAL)
|
||||
[[NSCursor arrowCursor] set];
|
||||
else
|
||||
[(NSCursor*) _glfw.ns.cursor set];
|
||||
}
|
||||
|
||||
// Enter fullscreen mode
|
||||
//
|
||||
static void enterFullscreenMode(_GLFWwindow* window)
|
||||
@ -39,8 +58,18 @@ static void enterFullscreenMode(_GLFWwindow* window)
|
||||
|
||||
_glfwSetVideoMode(window->monitor, &window->videoMode);
|
||||
|
||||
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithBool:NO],
|
||||
NSFullScreenModeAllScreens,
|
||||
nil];
|
||||
|
||||
[window->ns.view enterFullScreenMode:window->monitor->ns.screen
|
||||
withOptions:nil];
|
||||
withOptions:options];
|
||||
|
||||
// HACK: Synthesize focus event as window does not become key when the view
|
||||
// is made full screen
|
||||
// TODO: Remove this when moving to a full screen window
|
||||
_glfwInputWindowFocus(window, GL_TRUE);
|
||||
}
|
||||
|
||||
// Leave fullscreen mode
|
||||
@ -50,6 +79,11 @@ static void leaveFullscreenMode(_GLFWwindow* window)
|
||||
if (![window->ns.view isInFullScreenMode])
|
||||
return;
|
||||
|
||||
// HACK: Synthesize focus event as window does not become key when the view
|
||||
// is made full screen
|
||||
// TODO: Remove this when moving to a full screen window
|
||||
_glfwInputWindowFocus(window, GL_FALSE);
|
||||
|
||||
_glfwRestoreVideoMode(window->monitor);
|
||||
|
||||
// Exit full screen after the video restore to avoid a nasty display
|
||||
@ -71,7 +105,7 @@ static float transformY(float y)
|
||||
static NSRect convertRectToBacking(_GLFWwindow* window, NSRect contentRect)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7)
|
||||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
|
||||
return [window->ns.view convertRectToBacking:contentRect];
|
||||
else
|
||||
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
||||
@ -94,13 +128,6 @@ static NSRect convertRectToBacking(_GLFWwindow* window, NSRect contentRect)
|
||||
|
||||
@implementation GLFWWindowDelegate
|
||||
|
||||
static void centerCursor(_GLFWwindow *window)
|
||||
{
|
||||
int width, height;
|
||||
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||
_glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
|
||||
}
|
||||
|
||||
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
||||
{
|
||||
self = [super init];
|
||||
@ -159,14 +186,13 @@ static void centerCursor(_GLFWwindow *window)
|
||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||
{
|
||||
_glfwInputWindowFocus(window, GL_TRUE);
|
||||
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||
centerCursor(window);
|
||||
_glfwPlatformSetCursorMode(window, window->cursorMode);
|
||||
}
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification *)notification
|
||||
{
|
||||
_glfwInputWindowFocus(window, GL_FALSE);
|
||||
_glfwPlatformSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
@end
|
||||
@ -240,7 +266,6 @@ static int translateFlags(NSUInteger flags)
|
||||
static int translateKey(unsigned int key)
|
||||
{
|
||||
// Keyboard symbol translation table
|
||||
// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
|
||||
static const unsigned int table[128] =
|
||||
{
|
||||
/* 00 */ GLFW_KEY_A,
|
||||
@ -253,7 +278,7 @@ static int translateKey(unsigned int key)
|
||||
/* 07 */ GLFW_KEY_X,
|
||||
/* 08 */ GLFW_KEY_C,
|
||||
/* 09 */ GLFW_KEY_V,
|
||||
/* 0a */ GLFW_KEY_GRAVE_ACCENT,
|
||||
/* 0a */ GLFW_KEY_WORLD_1,
|
||||
/* 0b */ GLFW_KEY_B,
|
||||
/* 0c */ GLFW_KEY_Q,
|
||||
/* 0d */ GLFW_KEY_W,
|
||||
@ -293,7 +318,7 @@ static int translateKey(unsigned int key)
|
||||
/* 2f */ GLFW_KEY_PERIOD,
|
||||
/* 30 */ GLFW_KEY_TAB,
|
||||
/* 31 */ GLFW_KEY_SPACE,
|
||||
/* 32 */ GLFW_KEY_WORLD_1,
|
||||
/* 32 */ GLFW_KEY_GRAVE_ACCENT,
|
||||
/* 33 */ GLFW_KEY_BACKSPACE,
|
||||
/* 34 */ GLFW_KEY_UNKNOWN,
|
||||
/* 35 */ GLFW_KEY_ESCAPE,
|
||||
@ -348,7 +373,7 @@ static int translateKey(unsigned int key)
|
||||
/* 66 */ GLFW_KEY_UNKNOWN,
|
||||
/* 67 */ GLFW_KEY_F11,
|
||||
/* 68 */ GLFW_KEY_UNKNOWN,
|
||||
/* 69 */ GLFW_KEY_PRINT_SCREEN,
|
||||
/* 69 */ GLFW_KEY_F13,
|
||||
/* 6a */ GLFW_KEY_F16,
|
||||
/* 6b */ GLFW_KEY_F14,
|
||||
/* 6c */ GLFW_KEY_UNKNOWN,
|
||||
@ -445,6 +470,11 @@ static int translateKey(unsigned int key)
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)cursorUpdate:(NSEvent *)event
|
||||
{
|
||||
setModeCursor(window, window->cursorMode);
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window,
|
||||
@ -503,7 +533,7 @@ static int translateKey(unsigned int key)
|
||||
- (void)otherMouseDown:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window,
|
||||
[event buttonNumber],
|
||||
(int) [event buttonNumber],
|
||||
GLFW_PRESS,
|
||||
translateFlags([event modifierFlags]));
|
||||
}
|
||||
@ -516,7 +546,7 @@ static int translateKey(unsigned int key)
|
||||
- (void)otherMouseUp:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window,
|
||||
[event buttonNumber],
|
||||
(int) [event buttonNumber],
|
||||
GLFW_RELEASE,
|
||||
translateFlags([event modifierFlags]));
|
||||
}
|
||||
@ -548,7 +578,8 @@ static int translateKey(unsigned int key)
|
||||
}
|
||||
|
||||
NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
|
||||
NSTrackingActiveAlways |
|
||||
NSTrackingActiveInKeyWindow |
|
||||
NSTrackingCursorUpdate |
|
||||
NSTrackingInVisibleRect;
|
||||
|
||||
trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
||||
@ -603,7 +634,7 @@ static int translateKey(unsigned int key)
|
||||
double deltaX, deltaY;
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7)
|
||||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
|
||||
{
|
||||
deltaX = [event scrollingDeltaX];
|
||||
deltaY = [event scrollingDeltaY];
|
||||
@ -625,12 +656,6 @@ static int translateKey(unsigned int key)
|
||||
_glfwInputScroll(window, deltaX, deltaY);
|
||||
}
|
||||
|
||||
- (void)resetCursorRects
|
||||
{
|
||||
[self discardCursorRects];
|
||||
[self addCursorRect:[self bounds] cursor:_glfw.ns.cursor];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -759,7 +784,7 @@ static void createMenuBar(void)
|
||||
[NSApp setWindowsMenu:windowMenu];
|
||||
[windowMenuItem setSubmenu:windowMenu];
|
||||
|
||||
[windowMenu addItemWithTitle:@"Miniaturize"
|
||||
[windowMenu addItemWithTitle:@"Minimize"
|
||||
action:@selector(performMiniaturize:)
|
||||
keyEquivalent:@"m"];
|
||||
[windowMenu addItemWithTitle:@"Zoom"
|
||||
@ -770,9 +795,23 @@ static void createMenuBar(void)
|
||||
action:@selector(arrangeInFront:)
|
||||
keyEquivalent:@""];
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
|
||||
{
|
||||
// TODO: Make this appear at the bottom of the menu (for consistency)
|
||||
|
||||
[windowMenu addItem:[NSMenuItem separatorItem]];
|
||||
[[windowMenu addItemWithTitle:@"Enter Full Screen"
|
||||
action:@selector(toggleFullScreen:)
|
||||
keyEquivalent:@"f"]
|
||||
setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
|
||||
}
|
||||
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
||||
|
||||
// Prior to Snow Leopard, we need to use this oddly-named semi-private API
|
||||
// to get the application menu working properly.
|
||||
[NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu];
|
||||
SEL setAppleMenuSelector = NSSelectorFromString(@"setAppleMenu:");
|
||||
[NSApp performSelector:setAppleMenuSelector withObject:appMenu];
|
||||
}
|
||||
|
||||
#endif /* _GLFW_USE_MENUBAR */
|
||||
@ -787,13 +826,8 @@ static GLboolean initializeAppKit(void)
|
||||
// Implicitly create shared NSApplication instance
|
||||
[GLFWApplication sharedApplication];
|
||||
|
||||
// If we get here, the application is unbundled
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
|
||||
// Having the app in front of the terminal window is also generally
|
||||
// handy. There is an NSApplication API to do this, but...
|
||||
SetFrontProcess(&psn);
|
||||
// In case we are unbundled, make us a proper UI application
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
|
||||
#if defined(_GLFW_USE_MENUBAR)
|
||||
// Menu bar setup must go between sharedApplication above and
|
||||
@ -840,19 +874,23 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window];
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7)
|
||||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
|
||||
{
|
||||
[window->ns.view setWantsBestResolutionOpenGLSurface:YES];
|
||||
|
||||
if (wndconfig->resizable)
|
||||
[window->ns.object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
||||
}
|
||||
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
||||
|
||||
[window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]];
|
||||
[window->ns.object setContentView:window->ns.view];
|
||||
[window->ns.object setDelegate:window->ns.delegate];
|
||||
[window->ns.object setAcceptsMouseMovedEvents:YES];
|
||||
[window->ns.object disableCursorRects];
|
||||
[window->ns.object center];
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7)
|
||||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
|
||||
[window->ns.object setRestorable:NO];
|
||||
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
||||
|
||||
@ -996,6 +1034,12 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||
|
||||
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
||||
{
|
||||
// Make us the active application
|
||||
// HACK: This has been moved here from initializeAppKit to prevent
|
||||
// applications using only hidden windows from being activated, but
|
||||
// should probably not be done every time any window is shown
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
|
||||
[window->ns.object makeKeyAndOrderFront:nil];
|
||||
_glfwInputWindowVisibility(window, GL_TRUE);
|
||||
}
|
||||
@ -1040,6 +1084,8 @@ void _glfwPlatformWaitEvents(void)
|
||||
|
||||
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
||||
{
|
||||
setModeCursor(window, window->cursorMode);
|
||||
|
||||
if (window->monitor)
|
||||
{
|
||||
CGDisplayMoveCursorToPoint(window->monitor->ns.displayID,
|
||||
@ -1058,37 +1104,15 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
||||
|
||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
||||
{
|
||||
if (mode == GLFW_CURSOR_HIDDEN)
|
||||
{
|
||||
[window->ns.object enableCursorRects];
|
||||
[window->ns.object invalidateCursorRectsForView:window->ns.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
[window->ns.object disableCursorRects];
|
||||
[window->ns.object invalidateCursorRectsForView:window->ns.view];
|
||||
}
|
||||
setModeCursor(window, mode);
|
||||
|
||||
if (mode == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
CGAssociateMouseAndMouseCursorPosition(false);
|
||||
|
||||
if (!_glfw.ns.cursorHidden)
|
||||
{
|
||||
[NSCursor hide];
|
||||
_glfw.ns.cursorHidden = GL_TRUE;
|
||||
}
|
||||
centerCursor(window);
|
||||
}
|
||||
else
|
||||
{
|
||||
CGAssociateMouseAndMouseCursorPosition(true);
|
||||
|
||||
if (_glfw.ns.cursorHidden)
|
||||
{
|
||||
[NSCursor unhide];
|
||||
_glfw.ns.cursorHidden = GL_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
45
extern/glfw/src/context.c
vendored
@ -98,7 +98,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||
|
||||
if (wndconfig->clientAPI == GLFW_OPENGL_API)
|
||||
{
|
||||
if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0 ||
|
||||
if ((wndconfig->glMajor < 1 || wndconfig->glMinor < 0) ||
|
||||
(wndconfig->glMajor == 1 && wndconfig->glMinor > 5) ||
|
||||
(wndconfig->glMajor == 2 && wndconfig->glMinor > 1) ||
|
||||
(wndconfig->glMajor == 3 && wndconfig->glMinor > 3))
|
||||
@ -402,8 +402,8 @@ GLboolean _glfwRefreshContextAttribs(void)
|
||||
else if (glfwExtensionSupported("GL_ARB_debug_output"))
|
||||
{
|
||||
// HACK: This is a workaround for older drivers (pre KHR_debug)
|
||||
// not setting the debug bit in the context flags for debug
|
||||
// contexts
|
||||
// not setting the debug bit in the context flags for
|
||||
// debug contexts
|
||||
window->glDebug = GL_TRUE;
|
||||
}
|
||||
}
|
||||
@ -419,13 +419,21 @@ GLboolean _glfwRefreshContextAttribs(void)
|
||||
window->glProfile = GLFW_OPENGL_COMPAT_PROFILE;
|
||||
else if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
|
||||
window->glProfile = GLFW_OPENGL_CORE_PROFILE;
|
||||
else if (glfwExtensionSupported("GL_ARB_compatibility"))
|
||||
{
|
||||
// HACK: This is a workaround for the compatibility profile bit
|
||||
// not being set in the context flags if an OpenGL 3.2+
|
||||
// context was created without having requested a specific
|
||||
// version
|
||||
window->glProfile = GLFW_OPENGL_COMPAT_PROFILE;
|
||||
}
|
||||
}
|
||||
|
||||
// Read back robustness strategy
|
||||
if (glfwExtensionSupported("GL_ARB_robustness"))
|
||||
{
|
||||
// NOTE: We avoid using the context flags for detection, as they are
|
||||
// only present from 3.0 while the extension applies from 1.1
|
||||
// only present from 3.0 while the extension applies from 1.1
|
||||
|
||||
GLint strategy;
|
||||
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy);
|
||||
@ -442,7 +450,7 @@ GLboolean _glfwRefreshContextAttribs(void)
|
||||
if (glfwExtensionSupported("GL_EXT_robustness"))
|
||||
{
|
||||
// NOTE: The values of these constants match those of the OpenGL ARB
|
||||
// one, so we can reuse them here
|
||||
// one, so we can reuse them here
|
||||
|
||||
GLint strategy;
|
||||
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy);
|
||||
@ -566,7 +574,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (extension == NULL || *extension == '\0')
|
||||
if (!extension || *extension == '\0')
|
||||
{
|
||||
_glfwInputError(GLFW_INVALID_VALUE, NULL);
|
||||
return GL_FALSE;
|
||||
@ -577,11 +585,15 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
||||
// Check if extension is in the old style OpenGL extensions string
|
||||
|
||||
extensions = glGetString(GL_EXTENSIONS);
|
||||
if (extensions != NULL)
|
||||
if (!extensions)
|
||||
{
|
||||
if (_glfwStringInExtensionString(extension, extensions))
|
||||
return GL_TRUE;
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"Failed to retrieve extension string");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (_glfwStringInExtensionString(extension, extensions))
|
||||
return GL_TRUE;
|
||||
}
|
||||
#if defined(_GLFW_USE_OPENGL)
|
||||
else
|
||||
@ -595,11 +607,16 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (strcmp((const char*) window->GetStringi(GL_EXTENSIONS, i),
|
||||
extension) == 0)
|
||||
{
|
||||
return GL_TRUE;
|
||||
}
|
||||
const char* en = (const char*) window->GetStringi(GL_EXTENSIONS, i);
|
||||
if (!en)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"Failed to retrieve extension string %i", i);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (strcmp(en, extension) == 0)
|
||||
return GL_TRUE;
|
||||
}
|
||||
}
|
||||
#endif // _GLFW_USE_OPENGL
|
||||
|
2
extern/glfw/src/glfw3.pc.in
vendored
@ -1,7 +1,7 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
includedir=${prefix}/include
|
||||
libdir=${exec_prefix}/lib
|
||||
libdir=${exec_prefix}/lib@LIB_SUFFIX@
|
||||
|
||||
Name: GLFW
|
||||
Description: A portable library for OpenGL, window and input
|
||||
|
@ -23,13 +23,15 @@
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
// As config.h.in, this file is used by CMake to produce the config.h shared
|
||||
// configuration header file. If you are adding a feature requiring
|
||||
// conditional compilation, this is the proper place to add the macros.
|
||||
// As glfw_config.h.in, this file is used by CMake to produce the
|
||||
// glfw_config.h configuration header file. If you are adding a feature
|
||||
// requiring conditional compilation, this is where to add the macro.
|
||||
//========================================================================
|
||||
// As config.h, this file defines compile-time build options and macros for
|
||||
// all platforms supported by GLFW. As this is a generated file, don't modify
|
||||
// it. Instead, you should modify the config.h.in file.
|
||||
// As glfw_config.h, this file defines compile-time option macros for a
|
||||
// specific platform and development environment. If you are using the
|
||||
// GLFW CMake files, modify glfw_config.h.in instead of this file. If you
|
||||
// are using your own build system, make this file define the appropriate
|
||||
// macros in whatever way is suitable.
|
||||
//========================================================================
|
||||
|
||||
// Define this to 1 if building GLFW for X11
|
||||
@ -79,6 +81,3 @@
|
||||
// Define this to 1 if using OpenGL ES 2.0 as the client library
|
||||
#cmakedefine _GLFW_USE_GLESV2
|
||||
|
||||
// The GLFW version as used by glfwGetVersionString
|
||||
#define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@"
|
||||
|
12
extern/glfw/src/glx_context.c
vendored
@ -30,7 +30,6 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
// This is the only glXGetProcAddress variant not declared by glxext.h
|
||||
@ -75,7 +74,7 @@ static GLboolean chooseFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* resul
|
||||
if (strcmp(vendor, "Chromium") == 0)
|
||||
{
|
||||
// HACK: This is a (hopefully temporary) workaround for Chromium
|
||||
// (VirtualBox GL) not setting the window bit on any GLXFBConfigs
|
||||
// (VirtualBox GL) not setting the window bit on any GLXFBConfigs
|
||||
trustWindowBit = GL_FALSE;
|
||||
}
|
||||
|
||||
@ -457,8 +456,8 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
|
||||
{
|
||||
// NOTE: Only request an explicitly versioned context when
|
||||
// necessary, as explicitly requesting version 1.0 does not always
|
||||
// return the highest available version
|
||||
// necessary, as explicitly requesting version 1.0 does not
|
||||
// always return the highest available version
|
||||
|
||||
setGLXattrib(GLX_CONTEXT_MAJOR_VERSION_ARB, wndconfig->glMajor);
|
||||
setGLXattrib(GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor);
|
||||
@ -485,8 +484,9 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (window->glx.context == NULL)
|
||||
{
|
||||
// HACK: This is a fallback for the broken Mesa implementation of
|
||||
// GLX_ARB_create_context_profile, which fails default 1.0 context
|
||||
// creation with a GLXBadProfileARB error in violation of the spec
|
||||
// GLX_ARB_create_context_profile, which fails default 1.0
|
||||
// context creation with a GLXBadProfileARB error in violation
|
||||
// of the extension spec
|
||||
if (_glfw.x11.errorCode == _glfw.glx.errorBase + GLXBadProfileARB &&
|
||||
wndconfig->clientAPI == GLFW_OPENGL_API &&
|
||||
wndconfig->glProfile == GLFW_OPENGL_ANY_PROFILE &&
|
||||
|
2
extern/glfw/src/glx_platform.h
vendored
@ -41,6 +41,8 @@
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
// We support four different ways for getting addresses for GL/GLX
|
||||
// extension functions: glXGetProcAddress, glXGetProcAddressARB,
|
||||
// glXGetProcAddressEXT, and dlsym
|
||||
|
13
extern/glfw/src/input.c
vendored
@ -35,7 +35,7 @@
|
||||
//
|
||||
static void setCursorMode(_GLFWwindow* window, int newMode)
|
||||
{
|
||||
int oldMode;
|
||||
const int oldMode = window->cursorMode;
|
||||
|
||||
if (newMode != GLFW_CURSOR_NORMAL &&
|
||||
newMode != GLFW_CURSOR_HIDDEN &&
|
||||
@ -45,10 +45,11 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
|
||||
return;
|
||||
}
|
||||
|
||||
oldMode = window->cursorMode;
|
||||
if (oldMode == newMode)
|
||||
return;
|
||||
|
||||
window->cursorMode = newMode;
|
||||
|
||||
if (window == _glfw.focusedWindow)
|
||||
{
|
||||
if (oldMode == GLFW_CURSOR_DISABLED)
|
||||
@ -71,8 +72,6 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
|
||||
|
||||
_glfwPlatformSetCursorMode(window, newMode);
|
||||
}
|
||||
|
||||
window->cursorMode = newMode;
|
||||
}
|
||||
|
||||
// Set sticky keys mode for the specified window
|
||||
@ -149,13 +148,13 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m
|
||||
window->callbacks.key((GLFWwindow*) window, key, scancode, action, mods);
|
||||
}
|
||||
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int character)
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint)
|
||||
{
|
||||
if (character < 32 || (character > 126 && character < 160))
|
||||
if (codepoint < 32 || (codepoint > 126 && codepoint < 160))
|
||||
return;
|
||||
|
||||
if (window->callbacks.character)
|
||||
window->callbacks.character((GLFWwindow*) window, character);
|
||||
window->callbacks.character((GLFWwindow*) window, codepoint);
|
||||
}
|
||||
|
||||
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
|
||||
|
21
extern/glfw/src/internal.h
vendored
@ -29,7 +29,11 @@
|
||||
#define _internal_h_
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#if defined(_GLFW_USE_CONFIG_H)
|
||||
#include "glfw_config.h"
|
||||
#endif
|
||||
|
||||
#define _GLFW_VERSION_NUMBER "3.0.4"
|
||||
|
||||
#if defined(_GLFW_USE_OPENGL)
|
||||
// This is the default for glfw3.h
|
||||
@ -624,10 +628,10 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m
|
||||
|
||||
/*! @brief Notifies shared code of a Unicode character input event.
|
||||
* @param[in] window The window that received the event.
|
||||
* @param[in] character The Unicode code point of the input character.
|
||||
* @param[in] codepoint The Unicode code point of the input character.
|
||||
* @ingroup event
|
||||
*/
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int character);
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint);
|
||||
|
||||
/*! @brief Notifies shared code of a scroll event.
|
||||
* @param[in] window The window that received the event.
|
||||
@ -750,11 +754,18 @@ void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size);
|
||||
*/
|
||||
void _glfwFreeGammaArrays(GLFWgammaramp* ramp);
|
||||
|
||||
/*! @ingroup utility
|
||||
/*! @brief Allocates and returns a monitor object with the specified name
|
||||
* and dimensions.
|
||||
* @param[in] name The name of the monitor.
|
||||
* @param[in] widthMM The width, in mm, of the monitor's display area.
|
||||
* @param[in] heightMM The height, in mm, of the monitor's display area.
|
||||
* @return The newly created object.
|
||||
* @ingroup utility
|
||||
*/
|
||||
_GLFWmonitor* _glfwCreateMonitor(const char* name, int widthMM, int heightMM);
|
||||
|
||||
/*! @ingroup utility
|
||||
/*! @brief Frees a monitor object and any data associated with it.
|
||||
* @ingroup utility
|
||||
*/
|
||||
void _glfwDestroyMonitor(_GLFWmonitor* monitor);
|
||||
|
||||
|
21
extern/glfw/src/nsgl_context.m
vendored
@ -40,7 +40,7 @@ int _glfwInitContextAPI(void)
|
||||
if (pthread_key_create(&_glfw.nsgl.current, NULL) != 0)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"NSOpenGL: Failed to create context TLS");
|
||||
"NSGL: Failed to create context TLS");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
@ -81,16 +81,15 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
|
||||
{
|
||||
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
||||
"NSOpenGL: This API does not support OpenGL ES");
|
||||
"NSGL: This API does not support OpenGL ES");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
// Fail if any OpenGL version above 2.1 other than 3.2 was requested
|
||||
if (wndconfig->glMajor == 3 && wndconfig->glMinor < 2)
|
||||
{
|
||||
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
||||
"NSOpenGL: The targeted version of OS X does not "
|
||||
"NSGL: The targeted version of OS X does not "
|
||||
"support OpenGL 3.0 or 3.1");
|
||||
return GL_FALSE;
|
||||
}
|
||||
@ -100,7 +99,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (!wndconfig->glForward)
|
||||
{
|
||||
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
||||
"NSOpenGL: The targeted version of OS X only "
|
||||
"NSGL: The targeted version of OS X only "
|
||||
"supports OpenGL 3.2 and later versions if they "
|
||||
"are forward-compatible");
|
||||
return GL_FALSE;
|
||||
@ -109,7 +108,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE)
|
||||
{
|
||||
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
||||
"NSOpenGL: The targeted version of OS X only "
|
||||
"NSGL: The targeted version of OS X only "
|
||||
"supports OpenGL 3.2 and later versions if they "
|
||||
"use the core profile");
|
||||
return GL_FALSE;
|
||||
@ -120,7 +119,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (wndconfig->glMajor > 2)
|
||||
{
|
||||
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
||||
"NSOpenGL: The targeted version of OS X does not "
|
||||
"NSGL: The targeted version of OS X does not "
|
||||
"support OpenGL version 3.0 or above");
|
||||
return GL_FALSE;
|
||||
}
|
||||
@ -130,7 +129,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (wndconfig->glRobustness)
|
||||
{
|
||||
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
||||
"NSOpenGL: OS X does not support OpenGL robustness "
|
||||
"NSGL: OS X does not support OpenGL robustness "
|
||||
"strategies");
|
||||
return GL_FALSE;
|
||||
}
|
||||
@ -179,7 +178,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
}
|
||||
|
||||
// NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
|
||||
// frambuffer, so there's no need (and no way) to request it
|
||||
// frambuffer, so there's no need (and no way) to request it
|
||||
|
||||
ADD_ATTR(0);
|
||||
|
||||
@ -191,7 +190,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (window->nsgl.pixelFormat == nil)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"NSOpenGL: Failed to create OpenGL pixel format");
|
||||
"NSGL: Failed to create OpenGL pixel format");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
@ -206,7 +205,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
if (window->nsgl.context == nil)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"NSOpenGL: Failed to create OpenGL context");
|
||||
"NSGL: Failed to create OpenGL context");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
|
18
extern/glfw/src/wgl_context.c
vendored
@ -272,9 +272,21 @@ static GLboolean choosePixelFormat(_GLFWwindow* window,
|
||||
usableCount++;
|
||||
}
|
||||
|
||||
if (!usableCount)
|
||||
{
|
||||
_glfwInputError(GLFW_API_UNAVAILABLE,
|
||||
"WGL: The driver does not appear to support OpenGL");
|
||||
|
||||
free(usableConfigs);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount);
|
||||
if (!closest)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"WGL: Failed to find a suitable pixel format");
|
||||
|
||||
free(usableConfigs);
|
||||
return GL_FALSE;
|
||||
}
|
||||
@ -355,11 +367,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||
}
|
||||
|
||||
if (!choosePixelFormat(window, fbconfig, &pixelFormat))
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"WGL: Failed to find a suitable pixel format");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (!DescribePixelFormat(window->wgl.dc, pixelFormat, sizeof(pfd), &pfd))
|
||||
{
|
||||
@ -598,7 +606,7 @@ void _glfwPlatformSwapInterval(int interval)
|
||||
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
||||
|
||||
#if !defined(_GLFW_USE_DWM_SWAP_INTERVAL)
|
||||
if (_glfwIsCompositionEnabled())
|
||||
if (_glfwIsCompositionEnabled() && interval)
|
||||
{
|
||||
// Don't enabled vsync when desktop compositing is enabled, as it leads
|
||||
// to frame jitter
|
||||
|
4
extern/glfw/src/win32_init.c
vendored
@ -243,7 +243,7 @@ void _glfwPlatformTerminate(void)
|
||||
|
||||
const char* _glfwPlatformGetVersionString(void)
|
||||
{
|
||||
const char* version = _GLFW_VERSION_FULL " Win32"
|
||||
const char* version = _GLFW_VERSION_NUMBER " Win32"
|
||||
#if defined(_GLFW_WGL)
|
||||
" WGL"
|
||||
#elif defined(_GLFW_EGL)
|
||||
@ -252,7 +252,7 @@ const char* _glfwPlatformGetVersionString(void)
|
||||
#if defined(__MINGW32__)
|
||||
" MinGW"
|
||||
#elif defined(_MSC_VER)
|
||||
" VisualC "
|
||||
" VisualC"
|
||||
#elif defined(__BORLANDC__)
|
||||
" BorlandC"
|
||||
#endif
|
||||
|
4
extern/glfw/src/win32_joystick.c
vendored
@ -97,7 +97,7 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
|
||||
return NULL;
|
||||
|
||||
axes[(*count)++] = calcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax);
|
||||
axes[(*count)++] = -calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax);
|
||||
axes[(*count)++] = calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax);
|
||||
|
||||
if (jc.wCaps & JOYCAPS_HASZ)
|
||||
axes[(*count)++] = calcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax);
|
||||
@ -109,7 +109,7 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
|
||||
axes[(*count)++] = calcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax);
|
||||
|
||||
if (jc.wCaps & JOYCAPS_HASV)
|
||||
axes[(*count)++] = -calcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax);
|
||||
axes[(*count)++] = calcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax);
|
||||
|
||||
return axes;
|
||||
}
|
||||
|
14
extern/glfw/src/win32_platform.h
vendored
@ -52,10 +52,15 @@
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
// GLFW requires Windows XP
|
||||
#ifndef WINVER
|
||||
// GLFW requires Windows XP or later
|
||||
#if WINVER < 0x0501
|
||||
#undef WINVER
|
||||
#define WINVER 0x0501
|
||||
#endif
|
||||
#if _WIN32_WINNT < 0x0501
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
@ -152,7 +157,7 @@ typedef struct _GLFWwindowWin32
|
||||
GLboolean cursorCentered;
|
||||
GLboolean cursorInside;
|
||||
GLboolean cursorHidden;
|
||||
double oldCursorX, oldCursorY;
|
||||
int oldCursorX, oldCursorY;
|
||||
} _GLFWwindowWin32;
|
||||
|
||||
|
||||
@ -169,8 +174,7 @@ typedef struct _GLFWlibraryWin32
|
||||
struct {
|
||||
GLboolean hasPC;
|
||||
double resolution;
|
||||
unsigned int t0_32;
|
||||
__int64 t0_64;
|
||||
unsigned __int64 base;
|
||||
} timer;
|
||||
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
|
52
extern/glfw/src/win32_time.c
vendored
@ -28,6 +28,21 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
// Return raw time
|
||||
//
|
||||
static unsigned __int64 getRawTime(void)
|
||||
{
|
||||
if (_glfw.win32.timer.hasPC)
|
||||
{
|
||||
unsigned __int64 time;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*) &time);
|
||||
return time;
|
||||
}
|
||||
else
|
||||
return (unsigned __int64) _glfw_timeGetTime();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -36,20 +51,20 @@
|
||||
//
|
||||
void _glfwInitTimer(void)
|
||||
{
|
||||
__int64 freq;
|
||||
unsigned __int64 frequency;
|
||||
|
||||
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
|
||||
if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency))
|
||||
{
|
||||
_glfw.win32.timer.hasPC = GL_TRUE;
|
||||
_glfw.win32.timer.resolution = 1.0 / (double) freq;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*) &_glfw.win32.timer.t0_64);
|
||||
_glfw.win32.timer.resolution = 1.0 / (double) frequency;
|
||||
}
|
||||
else
|
||||
{
|
||||
_glfw.win32.timer.hasPC = GL_FALSE;
|
||||
_glfw.win32.timer.resolution = 0.001; // winmm resolution is 1 ms
|
||||
_glfw.win32.timer.t0_32 = _glfw_timeGetTime();
|
||||
}
|
||||
|
||||
_glfw.win32.timer.base = getRawTime();
|
||||
}
|
||||
|
||||
|
||||
@ -59,30 +74,13 @@ void _glfwInitTimer(void)
|
||||
|
||||
double _glfwPlatformGetTime(void)
|
||||
{
|
||||
double t;
|
||||
__int64 t_64;
|
||||
|
||||
if (_glfw.win32.timer.hasPC)
|
||||
{
|
||||
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
|
||||
t = (double)(t_64 - _glfw.win32.timer.t0_64);
|
||||
}
|
||||
else
|
||||
t = (double)(_glfw_timeGetTime() - _glfw.win32.timer.t0_32);
|
||||
|
||||
return t * _glfw.win32.timer.resolution;
|
||||
return (double) (getRawTime() - _glfw.win32.timer.base) *
|
||||
_glfw.win32.timer.resolution;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetTime(double t)
|
||||
void _glfwPlatformSetTime(double time)
|
||||
{
|
||||
__int64 t_64;
|
||||
|
||||
if (_glfw.win32.timer.hasPC)
|
||||
{
|
||||
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
|
||||
_glfw.win32.timer.t0_64 = t_64 - (__int64) (t / _glfw.win32.timer.resolution);
|
||||
}
|
||||
else
|
||||
_glfw.win32.timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
|
||||
_glfw.win32.timer.base = getRawTime() -
|
||||
(unsigned __int64) (time / _glfw.win32.timer.resolution);
|
||||
}
|
||||
|
||||
|
64
extern/glfw/src/win32_window.c
vendored
@ -145,7 +145,7 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// Check for numeric keypad keys
|
||||
// NOTE: This way we always force "NumLock = ON", which is intentional since
|
||||
// the returned key code should correspond to a physical location.
|
||||
// the returned key code should correspond to a physical location.
|
||||
if ((HIWORD(lParam) & 0x100) == 0)
|
||||
{
|
||||
switch (MapVirtualKey(HIWORD(lParam) & 0xFF, 1))
|
||||
@ -388,10 +388,21 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
|
||||
if (focused && iconified)
|
||||
{
|
||||
// This is a workaround for window iconification using the
|
||||
// taskbar leading to windows being told they're focused and
|
||||
// iconified and then never told they're defocused
|
||||
focused = FALSE;
|
||||
if (window->iconified && _glfw.focusedWindow != window)
|
||||
{
|
||||
// This is a workaround for window restoration using the
|
||||
// Win+D hot key leading to windows being told they're
|
||||
// focused and iconified and then never told they're
|
||||
// restored
|
||||
iconified = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is a workaround for window iconification using the
|
||||
// taskbar leading to windows being told they're focused and
|
||||
// iconified and then never told they're defocused
|
||||
focused = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!focused && _glfw.focusedWindow == window)
|
||||
@ -431,6 +442,19 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_ACTIVATEAPP:
|
||||
{
|
||||
if (!wParam && IsIconic(hWnd))
|
||||
{
|
||||
// This is a workaround for full screen windows losing focus
|
||||
// through Alt+Tab leading to windows being told they're
|
||||
// unfocused and restored and then never told they're iconified
|
||||
_glfwInputWindowIconify(window, GL_TRUE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_SHOWWINDOW:
|
||||
{
|
||||
_glfwInputWindowVisibility(window, wParam ? GL_TRUE : GL_FALSE);
|
||||
@ -593,7 +617,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
if (newCursorX != window->win32.oldCursorX ||
|
||||
newCursorY != window->win32.oldCursorY)
|
||||
{
|
||||
double x, y;
|
||||
int x, y;
|
||||
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
@ -654,8 +678,11 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
|
||||
case WM_SIZE:
|
||||
{
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED &&
|
||||
_glfw.focusedWindow == window)
|
||||
{
|
||||
updateClipRect(window);
|
||||
}
|
||||
|
||||
_glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam));
|
||||
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
|
||||
@ -664,10 +691,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
|
||||
case WM_MOVE:
|
||||
{
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED &&
|
||||
_glfw.focusedWindow == window)
|
||||
{
|
||||
updateClipRect(window);
|
||||
}
|
||||
|
||||
_glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
|
||||
// NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as
|
||||
// those macros do not handle negative window positions correctly
|
||||
_glfwInputWindowPos(window,
|
||||
GET_X_LPARAM(lParam),
|
||||
GET_Y_LPARAM(lParam));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -679,8 +713,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
|
||||
case WM_SETCURSOR:
|
||||
{
|
||||
if (window->cursorMode == GLFW_CURSOR_HIDDEN &&
|
||||
window->win32.handle == GetForegroundWindow() &&
|
||||
if (window->cursorMode != GLFW_CURSOR_NORMAL &&
|
||||
_glfw.focusedWindow == window &&
|
||||
LOWORD(lParam) == HTCLIENT)
|
||||
{
|
||||
SetCursor(NULL);
|
||||
@ -902,7 +936,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
||||
|
||||
// First we clear the current context (the one we just created)
|
||||
// This is usually done by glfwDestroyWindow, but as we're not doing
|
||||
// full window destruction, it's duplicated here
|
||||
// full GLFW window destruction, it's duplicated here
|
||||
_glfwPlatformMakeContextCurrent(NULL);
|
||||
|
||||
// Next destroy the Win32 window and WGL context (without resetting or
|
||||
@ -1000,7 +1034,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||
|
||||
SetWindowPos(window->win32.handle, HWND_TOP,
|
||||
0, 0, fullWidth, fullHeight,
|
||||
SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
|
||||
SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1104,8 +1138,8 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
|
||||
ClientToScreen(window->win32.handle, &pos);
|
||||
SetCursorPos(pos.x, pos.y);
|
||||
|
||||
window->win32.oldCursorX = xpos;
|
||||
window->win32.oldCursorY = ypos;
|
||||
window->win32.oldCursorX = (int) xpos;
|
||||
window->win32.oldCursorY = (int) ypos;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
||||
|
10
extern/glfw/src/window.c
vendored
@ -129,7 +129,7 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
|
||||
|
||||
void _glfwInputWindowCloseRequest(_GLFWwindow* window)
|
||||
{
|
||||
window->closed = GL_TRUE;
|
||||
window->closed = GL_TRUE;
|
||||
|
||||
if (window->callbacks.close)
|
||||
window->callbacks.close((GLFWwindow*) window);
|
||||
@ -213,10 +213,10 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
|
||||
window->videoMode.refreshRate = Max(_glfw.hints.refreshRate, 0);
|
||||
}
|
||||
|
||||
window->monitor = wndconfig.monitor;
|
||||
window->resizable = wndconfig.resizable;
|
||||
window->decorated = wndconfig.decorated;
|
||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||
window->monitor = wndconfig.monitor;
|
||||
window->resizable = wndconfig.resizable;
|
||||
window->decorated = wndconfig.decorated;
|
||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||
|
||||
// Save the currently current context so it can be restored later
|
||||
previous = (_GLFWwindow*) glfwGetCurrentContext();
|
||||
|
4
extern/glfw/src/x11_init.c
vendored
@ -409,6 +409,8 @@ static void detectEWMH(void)
|
||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING");
|
||||
_glfw.x11.NET_ACTIVE_WINDOW =
|
||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW");
|
||||
_glfw.x11.NET_WM_BYPASS_COMPOSITOR =
|
||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_BYPASS_COMPOSITOR");
|
||||
|
||||
XFree(supportedAtoms);
|
||||
|
||||
@ -680,7 +682,7 @@ void _glfwPlatformTerminate(void)
|
||||
|
||||
const char* _glfwPlatformGetVersionString(void)
|
||||
{
|
||||
const char* version = _GLFW_VERSION_FULL " X11"
|
||||
const char* version = _GLFW_VERSION_NUMBER " X11"
|
||||
#if defined(_GLFW_GLX)
|
||||
" GLX"
|
||||
#elif defined(_GLFW_EGL)
|
||||
|
9
extern/glfw/src/x11_joystick.c
vendored
@ -125,15 +125,6 @@ static void pollJoystickEvents(void)
|
||||
case JS_EVENT_AXIS:
|
||||
_glfw.x11.joystick[i].axes[e.number] =
|
||||
(float) e.value / 32767.0f;
|
||||
|
||||
// We need to change the sign for the Y axes, so that
|
||||
// positive = up/forward, according to the GLFW spec.
|
||||
if (e.number & 1)
|
||||
{
|
||||
_glfw.x11.joystick[i].axes[e.number] =
|
||||
-_glfw.x11.joystick[i].axes[e.number];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case JS_EVENT_BUTTON:
|
||||
|
3
extern/glfw/src/x11_monitor.c
vendored
@ -111,6 +111,9 @@ void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
|
||||
}
|
||||
}
|
||||
|
||||
if (bestMode == ci->mode)
|
||||
return;
|
||||
|
||||
if (monitor->x11.oldMode == None)
|
||||
monitor->x11.oldMode = ci->mode;
|
||||
|
||||
|
1
extern/glfw/src/x11_platform.h
vendored
@ -117,6 +117,7 @@ typedef struct _GLFWlibraryX11
|
||||
Atom NET_WM_PING;
|
||||
Atom NET_WM_STATE;
|
||||
Atom NET_WM_STATE_FULLSCREEN;
|
||||
Atom NET_WM_BYPASS_COMPOSITOR;
|
||||
Atom NET_ACTIVE_WINDOW;
|
||||
Atom MOTIF_WM_HINTS;
|
||||
|
||||
|
106
extern/glfw/src/x11_window.c
vendored
@ -129,13 +129,15 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
if (wndconfig->monitor == NULL)
|
||||
{
|
||||
// HACK: This is a workaround for windows without a background pixel
|
||||
// not getting any decorations on certain older versions of Compiz
|
||||
// running on Intel hardware
|
||||
// not getting any decorations on certain older versions of
|
||||
// Compiz running on Intel hardware
|
||||
wa.background_pixel = BlackPixel(_glfw.x11.display,
|
||||
_glfw.x11.screen);
|
||||
wamask |= CWBackPixel;
|
||||
}
|
||||
|
||||
_glfwGrabXErrorHandler();
|
||||
|
||||
window->x11.handle = XCreateWindow(_glfw.x11.display,
|
||||
_glfw.x11.root,
|
||||
0, 0,
|
||||
@ -147,12 +149,12 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
wamask,
|
||||
&wa);
|
||||
|
||||
_glfwReleaseXErrorHandler();
|
||||
|
||||
if (!window->x11.handle)
|
||||
{
|
||||
// TODO: Handle all the various error codes here and translate them
|
||||
// to GLFW errors
|
||||
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to create window");
|
||||
_glfwInputXError(GLFW_PLATFORM_ERROR,
|
||||
"X11: Failed to create window");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
@ -203,13 +205,13 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
|
||||
// The WM_DELETE_WINDOW ICCCM protocol
|
||||
// Basic window close notification protocol
|
||||
if (_glfw.x11.WM_DELETE_WINDOW != None)
|
||||
if (_glfw.x11.WM_DELETE_WINDOW)
|
||||
protocols[count++] = _glfw.x11.WM_DELETE_WINDOW;
|
||||
|
||||
// The _NET_WM_PING EWMH protocol
|
||||
// Tells the WM to ping the GLFW window and flag the application as
|
||||
// unresponsive if the WM doesn't get a reply within a few seconds
|
||||
if (_glfw.x11.NET_WM_PING != None)
|
||||
if (_glfw.x11.NET_WM_PING)
|
||||
protocols[count++] = _glfw.x11.NET_WM_PING;
|
||||
|
||||
if (count > 0)
|
||||
@ -219,7 +221,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
}
|
||||
}
|
||||
|
||||
if (_glfw.x11.NET_WM_PID != None)
|
||||
if (_glfw.x11.NET_WM_PID)
|
||||
{
|
||||
const pid_t pid = getpid();
|
||||
|
||||
@ -256,6 +258,14 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
hints->flags |= PPosition;
|
||||
_glfwPlatformGetMonitorPos(wndconfig->monitor, &hints->x, &hints->y);
|
||||
}
|
||||
else
|
||||
{
|
||||
// HACK: Explicitly setting PPosition to any value causes some WMs,
|
||||
// notably Compiz and Metacity, to honor the position of
|
||||
// unmapped windows set by XMoveWindow
|
||||
hints->flags |= PPosition;
|
||||
hints->x = hints->y = 0;
|
||||
}
|
||||
|
||||
if (!wndconfig->resizable)
|
||||
{
|
||||
@ -268,6 +278,19 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
XFree(hints);
|
||||
}
|
||||
|
||||
// Set ICCCM WM_CLASS property
|
||||
// HACK: Until a mechanism for specifying the application name is added, the
|
||||
// initial window title is used as the window class name
|
||||
if (strlen(wndconfig->title))
|
||||
{
|
||||
XClassHint* hint = XAllocClassHint();
|
||||
hint->res_name = (char*) wndconfig->title;
|
||||
hint->res_class = (char*) wndconfig->title;
|
||||
|
||||
XSetClassHint(_glfw.x11.display, window->x11.handle, hint);
|
||||
XFree(hint);
|
||||
}
|
||||
|
||||
if (_glfw.x11.xi.available)
|
||||
{
|
||||
// Select for XInput2 events
|
||||
@ -376,15 +399,22 @@ static void enterFullscreenMode(_GLFWwindow* window)
|
||||
|
||||
_glfwSetVideoMode(window->monitor, &window->videoMode);
|
||||
|
||||
if (_glfw.x11.hasEWMH &&
|
||||
_glfw.x11.NET_WM_STATE != None &&
|
||||
_glfw.x11.NET_WM_STATE_FULLSCREEN != None)
|
||||
if (_glfw.x11.NET_WM_BYPASS_COMPOSITOR)
|
||||
{
|
||||
const unsigned long value = 1;
|
||||
|
||||
XChangeProperty(_glfw.x11.display, window->x11.handle,
|
||||
_glfw.x11.NET_WM_BYPASS_COMPOSITOR, XA_CARDINAL, 32,
|
||||
PropModeReplace, (unsigned char*) &value, 1);
|
||||
}
|
||||
|
||||
if (_glfw.x11.NET_WM_STATE && _glfw.x11.NET_WM_STATE_FULLSCREEN)
|
||||
{
|
||||
int x, y;
|
||||
_glfwPlatformGetMonitorPos(window->monitor, &x, &y);
|
||||
_glfwPlatformSetWindowPos(window, x, y);
|
||||
|
||||
if (_glfw.x11.NET_ACTIVE_WINDOW != None)
|
||||
if (_glfw.x11.NET_ACTIVE_WINDOW)
|
||||
{
|
||||
// Ask the window manager to raise and focus the GLFW window
|
||||
// Only focused windows with the _NET_WM_STATE_FULLSCREEN state end
|
||||
@ -464,9 +494,16 @@ static void leaveFullscreenMode(_GLFWwindow* window)
|
||||
_glfw.x11.saver.exposure);
|
||||
}
|
||||
|
||||
if (_glfw.x11.hasEWMH &&
|
||||
_glfw.x11.NET_WM_STATE != None &&
|
||||
_glfw.x11.NET_WM_STATE_FULLSCREEN != None)
|
||||
if (_glfw.x11.NET_WM_BYPASS_COMPOSITOR)
|
||||
{
|
||||
const unsigned long value = 0;
|
||||
|
||||
XChangeProperty(_glfw.x11.display, window->x11.handle,
|
||||
_glfw.x11.NET_WM_BYPASS_COMPOSITOR, XA_CARDINAL, 32,
|
||||
PropModeReplace, (unsigned char*) &value, 1);
|
||||
}
|
||||
|
||||
if (_glfw.x11.NET_WM_STATE && _glfw.x11.NET_WM_STATE_FULLSCREEN)
|
||||
{
|
||||
// Ask the window manager to make the GLFW window a normal window
|
||||
// Normal windows usually have frames and other decorations
|
||||
@ -553,6 +590,16 @@ static void processEvent(XEvent *event)
|
||||
else if (event->xbutton.button == Button7)
|
||||
_glfwInputScroll(window, 1.0, 0.0);
|
||||
|
||||
else
|
||||
{
|
||||
// Additional buttons after 7 are treated as regular buttons
|
||||
// We subtract 4 to fill the gap left by scroll input above
|
||||
_glfwInputMouseClick(window,
|
||||
event->xbutton.button - 4,
|
||||
GLFW_PRESS,
|
||||
mods);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -581,6 +628,15 @@ static void processEvent(XEvent *event)
|
||||
GLFW_RELEASE,
|
||||
mods);
|
||||
}
|
||||
else if (event->xbutton.button > Button7)
|
||||
{
|
||||
// Additional buttons after 7 are treated as regular buttons
|
||||
// We subtract 4 to fill the gap left by scroll input above
|
||||
_glfwInputMouseClick(window,
|
||||
event->xbutton.button - 4,
|
||||
GLFW_RELEASE,
|
||||
mods);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -675,7 +731,7 @@ static void processEvent(XEvent *event)
|
||||
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
}
|
||||
else if (_glfw.x11.NET_WM_PING != None &&
|
||||
else if (_glfw.x11.NET_WM_PING &&
|
||||
(Atom) event->xclient.data.l[0] == _glfw.x11.NET_WM_PING)
|
||||
{
|
||||
// The window manager is pinging the application to ensure it's
|
||||
@ -957,7 +1013,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
||||
NULL, NULL, NULL);
|
||||
#endif
|
||||
|
||||
if (_glfw.x11.NET_WM_NAME != None)
|
||||
if (_glfw.x11.NET_WM_NAME)
|
||||
{
|
||||
XChangeProperty(_glfw.x11.display, window->x11.handle,
|
||||
_glfw.x11.NET_WM_NAME, _glfw.x11.UTF8_STRING, 8,
|
||||
@ -965,7 +1021,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
||||
(unsigned char*) title, strlen(title));
|
||||
}
|
||||
|
||||
if (_glfw.x11.NET_WM_ICON_NAME != None)
|
||||
if (_glfw.x11.NET_WM_ICON_NAME)
|
||||
{
|
||||
XChangeProperty(_glfw.x11.display, window->x11.handle,
|
||||
_glfw.x11.NET_WM_ICON_NAME, _glfw.x11.UTF8_STRING, 8,
|
||||
@ -982,7 +1038,7 @@ void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
|
||||
XTranslateCoordinates(_glfw.x11.display, window->x11.handle, _glfw.x11.root,
|
||||
0, 0, &x, &y, &child);
|
||||
|
||||
if (child != None)
|
||||
if (child)
|
||||
{
|
||||
int left, top;
|
||||
|
||||
@ -1063,6 +1119,9 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
||||
{
|
||||
// Override-redirect windows cannot be iconified or restored, as those
|
||||
// tasks are performed by the window manager
|
||||
_glfwInputError(GLFW_API_UNAVAILABLE,
|
||||
"X11: Iconification of full screen windows requires "
|
||||
"a WM that supports EWMH");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1075,6 +1134,9 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||
{
|
||||
// Override-redirect windows cannot be iconified or restored, as those
|
||||
// tasks are performed by the window manager
|
||||
_glfwInputError(GLFW_API_UNAVAILABLE,
|
||||
"X11: Iconification of full screen windows requires "
|
||||
"a WM that supports EWMH");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1116,10 +1178,8 @@ void _glfwPlatformWaitEvents(void)
|
||||
{
|
||||
if (!XPending(_glfw.x11.display))
|
||||
{
|
||||
int fd;
|
||||
fd_set fds;
|
||||
|
||||
fd = ConnectionNumber(_glfw.x11.display);
|
||||
const int fd = ConnectionNumber(_glfw.x11.display);
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(fd, &fds);
|
||||
|
71
extern/glfw/tests/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
link_libraries(glfw ${OPENGL_glu_LIBRARY})
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
add_definitions(-DGLFW_DLL)
|
||||
link_libraries(${OPENGL_gl_LIBRARY} ${MATH_LIBRARY})
|
||||
else()
|
||||
link_libraries(${glfw_LIBRARIES})
|
||||
endif()
|
||||
|
||||
include_directories(${GLFW_SOURCE_DIR}/include
|
||||
${GLFW_SOURCE_DIR}/deps)
|
||||
|
||||
if (NOT APPLE)
|
||||
# HACK: This is NOTFOUND on OS X 10.8
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
set(GETOPT ${GLFW_SOURCE_DIR}/deps/getopt.h
|
||||
${GLFW_SOURCE_DIR}/deps/getopt.c)
|
||||
set(TINYCTHREAD ${GLFW_SOURCE_DIR}/deps/tinycthread.h
|
||||
${GLFW_SOURCE_DIR}/deps/tinycthread.c)
|
||||
|
||||
add_executable(clipboard clipboard.c ${GETOPT})
|
||||
add_executable(defaults defaults.c)
|
||||
add_executable(events events.c ${GETOPT})
|
||||
add_executable(fsaa fsaa.c ${GETOPT})
|
||||
add_executable(gamma gamma.c ${GETOPT})
|
||||
add_executable(glfwinfo glfwinfo.c ${GETOPT})
|
||||
add_executable(iconify iconify.c ${GETOPT})
|
||||
add_executable(joysticks joysticks.c)
|
||||
add_executable(modes modes.c ${GETOPT})
|
||||
add_executable(peter peter.c)
|
||||
add_executable(reopen reopen.c)
|
||||
|
||||
add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
|
||||
set_target_properties(accuracy PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Accuracy")
|
||||
|
||||
add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
|
||||
set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing")
|
||||
|
||||
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
|
||||
set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing")
|
||||
|
||||
add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD})
|
||||
set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads")
|
||||
|
||||
add_executable(title WIN32 MACOSX_BUNDLE title.c)
|
||||
set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title")
|
||||
|
||||
add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
|
||||
set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows")
|
||||
|
||||
target_link_libraries(threads ${CMAKE_THREAD_LIBS_INIT} ${RT_LIBRARY})
|
||||
|
||||
set(WINDOWS_BINARIES accuracy sharing tearing threads title windows)
|
||||
set(CONSOLE_BINARIES clipboard defaults events fsaa gamma glfwinfo
|
||||
iconify joysticks modes peter reopen)
|
||||
|
||||
if (MSVC)
|
||||
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
||||
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
|
||||
LINK_FLAGS "/ENTRY:mainCRTStartup")
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION}
|
||||
MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL})
|
||||
endif()
|
||||
|
129
extern/glfw/tests/accuracy.c
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
//========================================================================
|
||||
// Mouse cursor accuracy test
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test came about as the result of bug #1867804
|
||||
//
|
||||
// No sign of said bug has so far been detected
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static double cursor_x = 0.0, cursor_y = 0.0;
|
||||
static int window_width = 640, window_height = 480;
|
||||
static int swap_interval = 1;
|
||||
|
||||
static void set_swap_interval(GLFWwindow* window, int interval)
|
||||
{
|
||||
char title[256];
|
||||
|
||||
swap_interval = interval;
|
||||
glfwSwapInterval(swap_interval);
|
||||
|
||||
sprintf(title, "Cursor Inaccuracy Detector (interval %i)", swap_interval);
|
||||
|
||||
glfwSetWindowTitle(window, title);
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
window_width = width;
|
||||
window_height = height;
|
||||
|
||||
glViewport(0, 0, window_width, window_height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(0.f, window_width, 0.f, window_height);
|
||||
}
|
||||
|
||||
static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
cursor_x = x;
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
||||
set_swap_interval(window, 1 - swap_interval);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
int width, height;
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
window = glfwCreateWindow(window_width, window_height, "", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
framebuffer_size_callback(window, width, height);
|
||||
|
||||
set_swap_interval(window, swap_interval);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(0.f, (GLfloat) (window_height - cursor_y));
|
||||
glVertex2f((GLfloat) window_width, (GLfloat) (window_height - cursor_y));
|
||||
glVertex2f((GLfloat) cursor_x, 0.f);
|
||||
glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
|
||||
glEnd();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
149
extern/glfw/tests/clipboard.c
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
//========================================================================
|
||||
// Clipboard test program
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This program is used to test the clipboard functionality.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: clipboard [-h]\n");
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_V:
|
||||
if (mods == GLFW_MOD_CONTROL)
|
||||
{
|
||||
const char* string;
|
||||
|
||||
string = glfwGetClipboardString(window);
|
||||
if (string)
|
||||
printf("Clipboard contains \"%s\"\n", string);
|
||||
else
|
||||
printf("Clipboard does not contain a string\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case GLFW_KEY_C:
|
||||
if (mods == GLFW_MOD_CONTROL)
|
||||
{
|
||||
const char* string = "Hello GLFW World!";
|
||||
glfwSetClipboardString(window, string);
|
||||
printf("Setting clipboard to \"%s\"\n", string);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ch;
|
||||
GLFWwindow* window;
|
||||
|
||||
while ((ch = getopt(argc, argv, "h")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
default:
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(200, 200, "Clipboard Test", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
||||
fprintf(stderr, "Failed to open GLFW window\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glColor3f(0.8f, 0.2f, 0.4f);
|
||||
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwWaitEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
131
extern/glfw/tests/defaults.c
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
//========================================================================
|
||||
// Default window/context test
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test creates a windowed mode window with all window hints set to
|
||||
// default values and then reports the actual attributes of the created
|
||||
// window and context
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int attrib;
|
||||
const char* ext;
|
||||
const char* name;
|
||||
} AttribGL;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int attrib;
|
||||
const char* name;
|
||||
} AttribGLFW;
|
||||
|
||||
static AttribGL gl_attribs[] =
|
||||
{
|
||||
{ GL_RED_BITS, NULL, "red bits" },
|
||||
{ GL_GREEN_BITS, NULL, "green bits" },
|
||||
{ GL_BLUE_BITS, NULL, "blue bits" },
|
||||
{ GL_ALPHA_BITS, NULL, "alpha bits" },
|
||||
{ GL_DEPTH_BITS, NULL, "depth bits" },
|
||||
{ GL_STENCIL_BITS, NULL, "stencil bits" },
|
||||
{ GL_STEREO, NULL, "stereo" },
|
||||
{ GL_SAMPLES_ARB, "GL_ARB_multisample", "FSAA samples" },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
static AttribGLFW glfw_attribs[] =
|
||||
{
|
||||
{ GLFW_CONTEXT_VERSION_MAJOR, "Context version major" },
|
||||
{ GLFW_CONTEXT_VERSION_MINOR, "Context version minor" },
|
||||
{ GLFW_OPENGL_FORWARD_COMPAT, "OpenGL forward compatible" },
|
||||
{ GLFW_OPENGL_DEBUG_CONTEXT, "OpenGL debug context" },
|
||||
{ GLFW_OPENGL_PROFILE, "OpenGL profile" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, width, height;
|
||||
GLFWwindow* window;
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Defaults", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
|
||||
printf("framebuffer size: %ix%i\n", width, height);
|
||||
|
||||
for (i = 0; glfw_attribs[i].name; i++)
|
||||
{
|
||||
printf("%s: %i\n",
|
||||
glfw_attribs[i].name,
|
||||
glfwGetWindowAttrib(window, glfw_attribs[i].attrib));
|
||||
}
|
||||
|
||||
for (i = 0; gl_attribs[i].name; i++)
|
||||
{
|
||||
GLint value = 0;
|
||||
|
||||
if (gl_attribs[i].ext)
|
||||
{
|
||||
if (!glfwExtensionSupported(gl_attribs[i].ext))
|
||||
continue;
|
||||
}
|
||||
|
||||
glGetIntegerv(gl_attribs[i].attrib, &value);
|
||||
|
||||
printf("%s: %i\n", gl_attribs[i].name, value);
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
window = NULL;
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
480
extern/glfw/tests/events.c
vendored
Normal file
@ -0,0 +1,480 @@
|
||||
//========================================================================
|
||||
// Event linter (event spewer)
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test hooks every available callback and outputs their arguments
|
||||
//
|
||||
// Log messages go to stdout, error messages to stderr
|
||||
//
|
||||
// Every event also gets a (sequential) number to aid discussion of logs
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
// These must match the input mode defaults
|
||||
static GLboolean closeable = GL_TRUE;
|
||||
|
||||
// Event index
|
||||
static unsigned int counter = 0;
|
||||
|
||||
static const char* get_key_name(int key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
// Printable keys
|
||||
case GLFW_KEY_A: return "A";
|
||||
case GLFW_KEY_B: return "B";
|
||||
case GLFW_KEY_C: return "C";
|
||||
case GLFW_KEY_D: return "D";
|
||||
case GLFW_KEY_E: return "E";
|
||||
case GLFW_KEY_F: return "F";
|
||||
case GLFW_KEY_G: return "G";
|
||||
case GLFW_KEY_H: return "H";
|
||||
case GLFW_KEY_I: return "I";
|
||||
case GLFW_KEY_J: return "J";
|
||||
case GLFW_KEY_K: return "K";
|
||||
case GLFW_KEY_L: return "L";
|
||||
case GLFW_KEY_M: return "M";
|
||||
case GLFW_KEY_N: return "N";
|
||||
case GLFW_KEY_O: return "O";
|
||||
case GLFW_KEY_P: return "P";
|
||||
case GLFW_KEY_Q: return "Q";
|
||||
case GLFW_KEY_R: return "R";
|
||||
case GLFW_KEY_S: return "S";
|
||||
case GLFW_KEY_T: return "T";
|
||||
case GLFW_KEY_U: return "U";
|
||||
case GLFW_KEY_V: return "V";
|
||||
case GLFW_KEY_W: return "W";
|
||||
case GLFW_KEY_X: return "X";
|
||||
case GLFW_KEY_Y: return "Y";
|
||||
case GLFW_KEY_Z: return "Z";
|
||||
case GLFW_KEY_1: return "1";
|
||||
case GLFW_KEY_2: return "2";
|
||||
case GLFW_KEY_3: return "3";
|
||||
case GLFW_KEY_4: return "4";
|
||||
case GLFW_KEY_5: return "5";
|
||||
case GLFW_KEY_6: return "6";
|
||||
case GLFW_KEY_7: return "7";
|
||||
case GLFW_KEY_8: return "8";
|
||||
case GLFW_KEY_9: return "9";
|
||||
case GLFW_KEY_0: return "0";
|
||||
case GLFW_KEY_SPACE: return "SPACE";
|
||||
case GLFW_KEY_MINUS: return "MINUS";
|
||||
case GLFW_KEY_EQUAL: return "EQUAL";
|
||||
case GLFW_KEY_LEFT_BRACKET: return "LEFT BRACKET";
|
||||
case GLFW_KEY_RIGHT_BRACKET: return "RIGHT BRACKET";
|
||||
case GLFW_KEY_BACKSLASH: return "BACKSLASH";
|
||||
case GLFW_KEY_SEMICOLON: return "SEMICOLON";
|
||||
case GLFW_KEY_APOSTROPHE: return "APOSTROPHE";
|
||||
case GLFW_KEY_GRAVE_ACCENT: return "GRAVE ACCENT";
|
||||
case GLFW_KEY_COMMA: return "COMMA";
|
||||
case GLFW_KEY_PERIOD: return "PERIOD";
|
||||
case GLFW_KEY_SLASH: return "SLASH";
|
||||
case GLFW_KEY_WORLD_1: return "WORLD 1";
|
||||
case GLFW_KEY_WORLD_2: return "WORLD 2";
|
||||
|
||||
// Function keys
|
||||
case GLFW_KEY_ESCAPE: return "ESCAPE";
|
||||
case GLFW_KEY_F1: return "F1";
|
||||
case GLFW_KEY_F2: return "F2";
|
||||
case GLFW_KEY_F3: return "F3";
|
||||
case GLFW_KEY_F4: return "F4";
|
||||
case GLFW_KEY_F5: return "F5";
|
||||
case GLFW_KEY_F6: return "F6";
|
||||
case GLFW_KEY_F7: return "F7";
|
||||
case GLFW_KEY_F8: return "F8";
|
||||
case GLFW_KEY_F9: return "F9";
|
||||
case GLFW_KEY_F10: return "F10";
|
||||
case GLFW_KEY_F11: return "F11";
|
||||
case GLFW_KEY_F12: return "F12";
|
||||
case GLFW_KEY_F13: return "F13";
|
||||
case GLFW_KEY_F14: return "F14";
|
||||
case GLFW_KEY_F15: return "F15";
|
||||
case GLFW_KEY_F16: return "F16";
|
||||
case GLFW_KEY_F17: return "F17";
|
||||
case GLFW_KEY_F18: return "F18";
|
||||
case GLFW_KEY_F19: return "F19";
|
||||
case GLFW_KEY_F20: return "F20";
|
||||
case GLFW_KEY_F21: return "F21";
|
||||
case GLFW_KEY_F22: return "F22";
|
||||
case GLFW_KEY_F23: return "F23";
|
||||
case GLFW_KEY_F24: return "F24";
|
||||
case GLFW_KEY_F25: return "F25";
|
||||
case GLFW_KEY_UP: return "UP";
|
||||
case GLFW_KEY_DOWN: return "DOWN";
|
||||
case GLFW_KEY_LEFT: return "LEFT";
|
||||
case GLFW_KEY_RIGHT: return "RIGHT";
|
||||
case GLFW_KEY_LEFT_SHIFT: return "LEFT SHIFT";
|
||||
case GLFW_KEY_RIGHT_SHIFT: return "RIGHT SHIFT";
|
||||
case GLFW_KEY_LEFT_CONTROL: return "LEFT CONTROL";
|
||||
case GLFW_KEY_RIGHT_CONTROL: return "RIGHT CONTROL";
|
||||
case GLFW_KEY_LEFT_ALT: return "LEFT ALT";
|
||||
case GLFW_KEY_RIGHT_ALT: return "RIGHT ALT";
|
||||
case GLFW_KEY_TAB: return "TAB";
|
||||
case GLFW_KEY_ENTER: return "ENTER";
|
||||
case GLFW_KEY_BACKSPACE: return "BACKSPACE";
|
||||
case GLFW_KEY_INSERT: return "INSERT";
|
||||
case GLFW_KEY_DELETE: return "DELETE";
|
||||
case GLFW_KEY_PAGE_UP: return "PAGE UP";
|
||||
case GLFW_KEY_PAGE_DOWN: return "PAGE DOWN";
|
||||
case GLFW_KEY_HOME: return "HOME";
|
||||
case GLFW_KEY_END: return "END";
|
||||
case GLFW_KEY_KP_0: return "KEYPAD 0";
|
||||
case GLFW_KEY_KP_1: return "KEYPAD 1";
|
||||
case GLFW_KEY_KP_2: return "KEYPAD 2";
|
||||
case GLFW_KEY_KP_3: return "KEYPAD 3";
|
||||
case GLFW_KEY_KP_4: return "KEYPAD 4";
|
||||
case GLFW_KEY_KP_5: return "KEYPAD 5";
|
||||
case GLFW_KEY_KP_6: return "KEYPAD 6";
|
||||
case GLFW_KEY_KP_7: return "KEYPAD 7";
|
||||
case GLFW_KEY_KP_8: return "KEYPAD 8";
|
||||
case GLFW_KEY_KP_9: return "KEYPAD 9";
|
||||
case GLFW_KEY_KP_DIVIDE: return "KEYPAD DIVIDE";
|
||||
case GLFW_KEY_KP_MULTIPLY: return "KEYPAD MULTPLY";
|
||||
case GLFW_KEY_KP_SUBTRACT: return "KEYPAD SUBTRACT";
|
||||
case GLFW_KEY_KP_ADD: return "KEYPAD ADD";
|
||||
case GLFW_KEY_KP_DECIMAL: return "KEYPAD DECIMAL";
|
||||
case GLFW_KEY_KP_EQUAL: return "KEYPAD EQUAL";
|
||||
case GLFW_KEY_KP_ENTER: return "KEYPAD ENTER";
|
||||
case GLFW_KEY_PRINT_SCREEN: return "PRINT SCREEN";
|
||||
case GLFW_KEY_NUM_LOCK: return "NUM LOCK";
|
||||
case GLFW_KEY_CAPS_LOCK: return "CAPS LOCK";
|
||||
case GLFW_KEY_SCROLL_LOCK: return "SCROLL LOCK";
|
||||
case GLFW_KEY_PAUSE: return "PAUSE";
|
||||
case GLFW_KEY_LEFT_SUPER: return "LEFT SUPER";
|
||||
case GLFW_KEY_RIGHT_SUPER: return "RIGHT SUPER";
|
||||
case GLFW_KEY_MENU: return "MENU";
|
||||
case GLFW_KEY_UNKNOWN: return "UNKNOWN";
|
||||
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static const char* get_action_name(int action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GLFW_PRESS:
|
||||
return "pressed";
|
||||
case GLFW_RELEASE:
|
||||
return "released";
|
||||
case GLFW_REPEAT:
|
||||
return "repeated";
|
||||
}
|
||||
|
||||
return "caused unknown action";
|
||||
}
|
||||
|
||||
static const char* get_button_name(int button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case GLFW_MOUSE_BUTTON_LEFT:
|
||||
return "left";
|
||||
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||
return "right";
|
||||
case GLFW_MOUSE_BUTTON_MIDDLE:
|
||||
return "middle";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* get_mods_name(int mods)
|
||||
{
|
||||
static char name[512];
|
||||
|
||||
name[0] = '\0';
|
||||
|
||||
if (mods & GLFW_MOD_SHIFT)
|
||||
strcat(name, " shift");
|
||||
if (mods & GLFW_MOD_CONTROL)
|
||||
strcat(name, " control");
|
||||
if (mods & GLFW_MOD_ALT)
|
||||
strcat(name, " alt");
|
||||
if (mods & GLFW_MOD_SUPER)
|
||||
strcat(name, " super");
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
static const char* get_character_string(int codepoint)
|
||||
{
|
||||
// This assumes UTF-8, which is stupid
|
||||
static char result[6 + 1];
|
||||
|
||||
int length = wctomb(result, codepoint);
|
||||
if (length == -1)
|
||||
length = 0;
|
||||
|
||||
result[length] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void window_pos_callback(GLFWwindow* window, int x, int y)
|
||||
{
|
||||
printf("%08x at %0.3f: Window position: %i %i\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
x,
|
||||
y);
|
||||
}
|
||||
|
||||
static void window_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
printf("%08x at %0.3f: Window size: %i %i\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
width,
|
||||
height);
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
printf("%08x at %0.3f: Framebuffer size: %i %i\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
width,
|
||||
height);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void window_close_callback(GLFWwindow* window)
|
||||
{
|
||||
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
|
||||
|
||||
glfwSetWindowShouldClose(window, closeable);
|
||||
}
|
||||
|
||||
static void window_refresh_callback(GLFWwindow* window)
|
||||
{
|
||||
printf("%08x at %0.3f: Window refresh\n", counter++, glfwGetTime());
|
||||
|
||||
if (glfwGetCurrentContext())
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
}
|
||||
|
||||
static void window_focus_callback(GLFWwindow* window, int focused)
|
||||
{
|
||||
printf("%08x at %0.3f: Window %s\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
focused ? "focused" : "defocused");
|
||||
}
|
||||
|
||||
static void window_iconify_callback(GLFWwindow* window, int iconified)
|
||||
{
|
||||
printf("%08x at %0.3f: Window was %s\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
iconified ? "iconified" : "restored");
|
||||
}
|
||||
|
||||
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
const char* name = get_button_name(button);
|
||||
|
||||
printf("%08x at %0.3f: Mouse button %i", counter++, glfwGetTime(), button);
|
||||
|
||||
if (name)
|
||||
printf(" (%s)", name);
|
||||
|
||||
if (mods)
|
||||
printf(" (with%s)", get_mods_name(mods));
|
||||
|
||||
printf(" was %s\n", get_action_name(action));
|
||||
}
|
||||
|
||||
static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
printf("%08x at %0.3f: Cursor position: %f %f\n", counter++, glfwGetTime(), x, y);
|
||||
}
|
||||
|
||||
static void cursor_enter_callback(GLFWwindow* window, int entered)
|
||||
{
|
||||
printf("%08x at %0.3f: Cursor %s window\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
entered ? "entered" : "left");
|
||||
}
|
||||
|
||||
static void scroll_callback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
printf("%08x at %0.3f: Scroll: %0.3f %0.3f\n", counter++, glfwGetTime(), x, y);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
const char* name = get_key_name(key);
|
||||
|
||||
printf("%08x at %0.3f: Key 0x%04x Scancode 0x%04x",
|
||||
counter++, glfwGetTime(), key, scancode);
|
||||
|
||||
if (name)
|
||||
printf(" (%s)", name);
|
||||
|
||||
if (mods)
|
||||
printf(" (with%s)", get_mods_name(mods));
|
||||
|
||||
printf(" was %s\n", get_action_name(action));
|
||||
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_C:
|
||||
{
|
||||
closeable = !closeable;
|
||||
|
||||
printf("(( closing %s ))\n", closeable ? "enabled" : "disabled");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void char_callback(GLFWwindow* window, unsigned int codepoint)
|
||||
{
|
||||
printf("%08x at %0.3f: Character 0x%08x (%s) input\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
codepoint,
|
||||
get_character_string(codepoint));
|
||||
}
|
||||
|
||||
void monitor_callback(GLFWmonitor* monitor, int event)
|
||||
{
|
||||
if (event == GLFW_CONNECTED)
|
||||
{
|
||||
int x, y, widthMM, heightMM;
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
|
||||
glfwGetMonitorPos(monitor, &x, &y);
|
||||
glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM);
|
||||
|
||||
printf("%08x at %0.3f: Monitor %s (%ix%i at %ix%i, %ix%i mm) was connected\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
glfwGetMonitorName(monitor),
|
||||
mode->width, mode->height,
|
||||
x, y,
|
||||
widthMM, heightMM);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%08x at %0.3f: Monitor %s was disconnected\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
glfwGetMonitorName(monitor));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
GLFWmonitor* monitor = NULL;
|
||||
int ch, width, height;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
printf("Library initialized\n");
|
||||
|
||||
while ((ch = getopt(argc, argv, "f")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'f':
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Event Linter", monitor, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Window opened\n");
|
||||
|
||||
glfwSetMonitorCallback(monitor_callback);
|
||||
|
||||
glfwSetWindowPosCallback(window, window_pos_callback);
|
||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetWindowCloseCallback(window, window_close_callback);
|
||||
glfwSetWindowRefreshCallback(window, window_refresh_callback);
|
||||
glfwSetWindowFocusCallback(window, window_focus_callback);
|
||||
glfwSetWindowIconifyCallback(window, window_iconify_callback);
|
||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
glfwSetCursorEnterCallback(window, cursor_enter_callback);
|
||||
glfwSetScrollCallback(window, scroll_callback);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetCharCallback(window, char_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwGetWindowSize(window, &width, &height);
|
||||
printf("Window size should be %ix%i\n", width, height);
|
||||
|
||||
printf("Main loop starting\n");
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
glfwWaitEvents();
|
||||
|
||||
// Workaround for an issue with msvcrt and mintty
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
158
extern/glfw/tests/fsaa.c
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
//========================================================================
|
||||
// Fullscreen anti-aliasing test
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test renders two high contrast, slowly rotating quads, one aliased
|
||||
// and one (hopefully) anti-aliased, thus allowing for visual verification
|
||||
// of whether FSAA is indeed enabled
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_SPACE:
|
||||
glfwSetTime(0.0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: fsaa [-h] [-s SAMPLES]\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ch, samples = 4;
|
||||
GLFWwindow* window;
|
||||
|
||||
while ((ch = getopt(argc, argv, "hs:")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 's':
|
||||
samples = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (samples)
|
||||
printf("Requesting FSAA with %i samples\n", samples);
|
||||
else
|
||||
printf("Requesting that FSAA not be available\n");
|
||||
|
||||
glfwWindowHint(GLFW_SAMPLES, samples);
|
||||
|
||||
window = glfwCreateWindow(800, 400, "Aliasing Detector", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
if (!glfwExtensionSupported("GL_ARB_multisample"))
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glGetIntegerv(GL_SAMPLES_ARB, &samples);
|
||||
if (samples)
|
||||
printf("Context reports FSAA is available with %i samples\n", samples);
|
||||
else
|
||||
printf("Context reports FSAA is unavailable\n");
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
gluOrtho2D(0.f, 1.f, 0.f, 0.5f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
GLfloat time = (GLfloat) glfwGetTime();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.25f, 0.25f, 0.f);
|
||||
glRotatef(time, 0.f, 0.f, 1.f);
|
||||
|
||||
glDisable(GL_MULTISAMPLE_ARB);
|
||||
glRectf(-0.15f, -0.15f, 0.15f, 0.15f);
|
||||
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.75f, 0.25f, 0.f);
|
||||
glRotatef(time, 0.f, 0.f, 1.f);
|
||||
|
||||
glEnable(GL_MULTISAMPLE_ARB);
|
||||
glRectf(-0.15f, -0.15f, 0.15f, 0.15f);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
175
extern/glfw/tests/gamma.c
vendored
Normal file
@ -0,0 +1,175 @@
|
||||
//========================================================================
|
||||
// Gamma correction test program
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This program is used to test the gamma correction functionality for
|
||||
// both fullscreen and windowed mode windows
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
#define STEP_SIZE 0.1f
|
||||
|
||||
static GLfloat gamma_value = 1.0f;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: gamma [-h] [-f]\n");
|
||||
}
|
||||
|
||||
static void set_gamma(GLFWwindow* window, float value)
|
||||
{
|
||||
GLFWmonitor* monitor = glfwGetWindowMonitor(window);
|
||||
if (!monitor)
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
|
||||
gamma_value = value;
|
||||
printf("Gamma: %f\n", gamma_value);
|
||||
glfwSetGamma(monitor, gamma_value);
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
{
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
case GLFW_KEY_KP_ADD:
|
||||
case GLFW_KEY_Q:
|
||||
{
|
||||
set_gamma(window, gamma_value + STEP_SIZE);
|
||||
break;
|
||||
}
|
||||
|
||||
case GLFW_KEY_KP_SUBTRACT:
|
||||
case GLFW_KEY_W:
|
||||
{
|
||||
if (gamma_value - STEP_SIZE > 0.f)
|
||||
set_gamma(window, gamma_value - STEP_SIZE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int width, height, ch;
|
||||
GLFWmonitor* monitor = NULL;
|
||||
GLFWwindow* window;
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
while ((ch = getopt(argc, argv, "fh")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case 'f':
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (monitor)
|
||||
{
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
width = mode->width;
|
||||
height = mode->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = 200;
|
||||
height = 200;
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(width, height, "Gamma Test", monitor, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
set_gamma(window, 1.f);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glColor3f(0.8f, 0.2f, 0.4f);
|
||||
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwWaitEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
396
extern/glfw/tests/glfwinfo.c
vendored
Normal file
@ -0,0 +1,396 @@
|
||||
//========================================================================
|
||||
// Version information dumper
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test is a pale imitation of glxinfo(1), except not really
|
||||
//
|
||||
// It dumps GLFW and OpenGL version information
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define strcasecmp(x, y) _stricmp(x, y)
|
||||
#endif
|
||||
|
||||
#define API_OPENGL "gl"
|
||||
#define API_OPENGL_ES "es"
|
||||
|
||||
#define PROFILE_NAME_CORE "core"
|
||||
#define PROFILE_NAME_COMPAT "compat"
|
||||
|
||||
#define STRATEGY_NAME_NONE "none"
|
||||
#define STRATEGY_NAME_LOSE "lose"
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: glfwinfo [-h] [-a API] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
|
||||
printf("Options:\n");
|
||||
printf(" -a the client API to use (" API_OPENGL " or " API_OPENGL_ES ")\n");
|
||||
printf(" -d request a debug context\n");
|
||||
printf(" -f require a forward-compatible context\n");
|
||||
printf(" -h show this help\n");
|
||||
printf(" -l list all client API extensions after context creation\n");
|
||||
printf(" -m the major number of the requred client API version\n");
|
||||
printf(" -n the minor number of the requred client API version\n");
|
||||
printf(" -p the OpenGL profile to use (" PROFILE_NAME_CORE " or " PROFILE_NAME_COMPAT ")\n");
|
||||
printf(" -r the robustness strategy to use (" STRATEGY_NAME_NONE " or " STRATEGY_NAME_LOSE ")\n");
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static const char* get_client_api_name(int api)
|
||||
{
|
||||
if (api == GLFW_OPENGL_API)
|
||||
return "OpenGL";
|
||||
else if (api == GLFW_OPENGL_ES_API)
|
||||
return "OpenGL ES";
|
||||
|
||||
return "Unknown API";
|
||||
}
|
||||
|
||||
static const char* get_profile_name_gl(GLint mask)
|
||||
{
|
||||
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
|
||||
return PROFILE_NAME_COMPAT;
|
||||
if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
|
||||
return PROFILE_NAME_CORE;
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static const char* get_profile_name_glfw(int profile)
|
||||
{
|
||||
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
|
||||
return PROFILE_NAME_COMPAT;
|
||||
if (profile == GLFW_OPENGL_CORE_PROFILE)
|
||||
return PROFILE_NAME_CORE;
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static const char* get_strategy_name_gl(GLint strategy)
|
||||
{
|
||||
if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
|
||||
return STRATEGY_NAME_LOSE;
|
||||
if (strategy == GL_NO_RESET_NOTIFICATION_ARB)
|
||||
return STRATEGY_NAME_NONE;
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static const char* get_strategy_name_glfw(int strategy)
|
||||
{
|
||||
if (strategy == GLFW_LOSE_CONTEXT_ON_RESET)
|
||||
return STRATEGY_NAME_LOSE;
|
||||
if (strategy == GLFW_NO_RESET_NOTIFICATION)
|
||||
return STRATEGY_NAME_NONE;
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static void list_extensions(int api, int major, int minor)
|
||||
{
|
||||
int i;
|
||||
GLint count;
|
||||
const GLubyte* extensions;
|
||||
|
||||
printf("%s context supported extensions:\n", get_client_api_name(api));
|
||||
|
||||
if (api == GLFW_OPENGL_API && major > 2)
|
||||
{
|
||||
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
|
||||
if (!glGetStringi)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
puts((const char*) glGetStringi(GL_EXTENSIONS, i));
|
||||
}
|
||||
else
|
||||
{
|
||||
extensions = glGetString(GL_EXTENSIONS);
|
||||
while (*extensions != '\0')
|
||||
{
|
||||
if (*extensions == ' ')
|
||||
putchar('\n');
|
||||
else
|
||||
putchar(*extensions);
|
||||
|
||||
extensions++;
|
||||
}
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static GLboolean valid_version(void)
|
||||
{
|
||||
int major, minor, revision;
|
||||
|
||||
glfwGetVersion(&major, &minor, &revision);
|
||||
|
||||
printf("GLFW header version: %u.%u.%u\n",
|
||||
GLFW_VERSION_MAJOR,
|
||||
GLFW_VERSION_MINOR,
|
||||
GLFW_VERSION_REVISION);
|
||||
|
||||
printf("GLFW library version: %u.%u.%u\n", major, minor, revision);
|
||||
|
||||
if (major != GLFW_VERSION_MAJOR)
|
||||
{
|
||||
printf("*** ERROR: GLFW major version mismatch! ***\n");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION)
|
||||
printf("*** WARNING: GLFW version mismatch! ***\n");
|
||||
|
||||
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ch, api = 0, profile = 0, strategy = 0, major = 1, minor = 0, revision;
|
||||
GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE;
|
||||
GLint flags, mask;
|
||||
GLFWwindow* window;
|
||||
|
||||
while ((ch = getopt(argc, argv, "a:dfhlm:n:p:r:")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'a':
|
||||
if (strcasecmp(optarg, API_OPENGL) == 0)
|
||||
api = GLFW_OPENGL_API;
|
||||
else if (strcasecmp(optarg, API_OPENGL_ES) == 0)
|
||||
api = GLFW_OPENGL_ES_API;
|
||||
else
|
||||
{
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
case 'd':
|
||||
debug = GL_TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forward = GL_TRUE;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'l':
|
||||
list = GL_TRUE;
|
||||
break;
|
||||
case 'm':
|
||||
major = atoi(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
minor = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
|
||||
profile = GLFW_OPENGL_CORE_PROFILE;
|
||||
else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
|
||||
profile = GLFW_OPENGL_COMPAT_PROFILE;
|
||||
else
|
||||
{
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
|
||||
strategy = GLFW_NO_RESET_NOTIFICATION;
|
||||
else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0)
|
||||
strategy = GLFW_LOSE_CONTEXT_ON_RESET;
|
||||
else
|
||||
{
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize GLFW and create window
|
||||
|
||||
if (!valid_version())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (major != 1 || minor != 0)
|
||||
{
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
|
||||
}
|
||||
|
||||
if (api != 0)
|
||||
glfwWindowHint(GLFW_CLIENT_API, api);
|
||||
|
||||
if (debug)
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
||||
|
||||
if (forward)
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
|
||||
if (profile != 0)
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, profile);
|
||||
|
||||
if (strategy)
|
||||
glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, strategy);
|
||||
|
||||
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
|
||||
|
||||
window = glfwCreateWindow(200, 200, "Version", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
// Report client API version
|
||||
|
||||
api = glfwGetWindowAttrib(window, GLFW_CLIENT_API);
|
||||
major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
|
||||
minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
|
||||
revision = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
|
||||
|
||||
printf("%s context version string: \"%s\"\n",
|
||||
get_client_api_name(api),
|
||||
glGetString(GL_VERSION));
|
||||
|
||||
printf("%s context version parsed by GLFW: %u.%u.%u\n",
|
||||
get_client_api_name(api),
|
||||
major, minor, revision);
|
||||
|
||||
// Report client API context properties
|
||||
|
||||
if (api == GLFW_OPENGL_API)
|
||||
{
|
||||
if (major >= 3)
|
||||
{
|
||||
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
|
||||
printf("%s context flags (0x%08x):", get_client_api_name(api), flags);
|
||||
|
||||
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
|
||||
printf(" forward-compatible");
|
||||
if (flags & GL_CONTEXT_FLAG_DEBUG_BIT)
|
||||
printf(" debug");
|
||||
if (flags & GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB)
|
||||
printf(" robustness");
|
||||
putchar('\n');
|
||||
|
||||
printf("%s context flags parsed by GLFW:", get_client_api_name(api));
|
||||
|
||||
if (glfwGetWindowAttrib(window, GLFW_OPENGL_FORWARD_COMPAT))
|
||||
printf(" forward-compatible");
|
||||
if (glfwGetWindowAttrib(window, GLFW_OPENGL_DEBUG_CONTEXT))
|
||||
printf(" debug");
|
||||
if (glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS) != GLFW_NO_ROBUSTNESS)
|
||||
printf(" robustness");
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
if (major > 3 || (major == 3 && minor >= 2))
|
||||
{
|
||||
int profile = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE);
|
||||
|
||||
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
|
||||
printf("%s profile mask (0x%08x): %s\n",
|
||||
get_client_api_name(api),
|
||||
mask,
|
||||
get_profile_name_gl(mask));
|
||||
|
||||
printf("%s profile mask parsed by GLFW: %s\n",
|
||||
get_client_api_name(api),
|
||||
get_profile_name_glfw(profile));
|
||||
}
|
||||
|
||||
if (glfwExtensionSupported("GL_ARB_robustness"))
|
||||
{
|
||||
int robustness;
|
||||
GLint strategy;
|
||||
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy);
|
||||
|
||||
printf("%s robustness strategy (0x%08x): %s\n",
|
||||
get_client_api_name(api),
|
||||
strategy,
|
||||
get_strategy_name_gl(strategy));
|
||||
|
||||
robustness = glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS);
|
||||
|
||||
printf("%s robustness strategy parsed by GLFW: %s\n",
|
||||
get_client_api_name(api),
|
||||
get_strategy_name_glfw(robustness));
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s context renderer string: \"%s\"\n",
|
||||
get_client_api_name(api),
|
||||
glGetString(GL_RENDERER));
|
||||
printf("%s context vendor string: \"%s\"\n",
|
||||
get_client_api_name(api),
|
||||
glGetString(GL_VENDOR));
|
||||
|
||||
if (major > 1)
|
||||
{
|
||||
printf("%s context shading language version: \"%s\"\n",
|
||||
get_client_api_name(api),
|
||||
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
}
|
||||
|
||||
// Report client API extensions
|
||||
if (list)
|
||||
list_extensions(api, major, minor);
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
176
extern/glfw/tests/iconify.c
vendored
Normal file
@ -0,0 +1,176 @@
|
||||
//========================================================================
|
||||
// Iconify/restore test program
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This program is used to test the iconify/restore functionality for
|
||||
// both fullscreen and windowed mode windows
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: iconify [-h] [-f]\n");
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
printf("%0.2f Key %s\n",
|
||||
glfwGetTime(),
|
||||
action == GLFW_PRESS ? "pressed" : "released");
|
||||
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_SPACE:
|
||||
glfwIconifyWindow(window);
|
||||
break;
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void window_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
printf("%0.2f Window resized to %ix%i\n", glfwGetTime(), width, height);
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
printf("%0.2f Framebuffer resized to %ix%i\n", glfwGetTime(), width, height);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void window_focus_callback(GLFWwindow* window, int focused)
|
||||
{
|
||||
printf("%0.2f Window %s\n",
|
||||
glfwGetTime(),
|
||||
focused ? "focused" : "defocused");
|
||||
}
|
||||
|
||||
static void window_iconify_callback(GLFWwindow* window, int iconified)
|
||||
{
|
||||
printf("%0.2f Window %s\n",
|
||||
glfwGetTime(),
|
||||
iconified ? "iconified" : "restored");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int width, height, ch;
|
||||
GLFWmonitor* monitor = NULL;
|
||||
GLFWwindow* window;
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
while ((ch = getopt(argc, argv, "fh")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case 'f':
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (monitor)
|
||||
{
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
width = mode->width;
|
||||
height = mode->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = 640;
|
||||
height = 480;
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(width, height, "Iconify", monitor, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||
glfwSetWindowFocusCallback(window, window_focus_callback);
|
||||
glfwSetWindowIconifyCallback(window, window_iconify_callback);
|
||||
|
||||
printf("Window is %s and %s\n",
|
||||
glfwGetWindowAttrib(window, GLFW_ICONIFIED) ? "iconified" : "restored",
|
||||
glfwGetWindowAttrib(window, GLFW_FOCUSED) ? "focused" : "defocused");
|
||||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
|
||||
glScissor(0, 0, width, height);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glScissor(0, 0, 640, 480);
|
||||
glClearColor(1, 1, 1, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
234
extern/glfw/tests/joysticks.c
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
//========================================================================
|
||||
// Joystick input test
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test displays the state of every button and axis of every connected
|
||||
// joystick and/or gamepad
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define strdup(x) _strdup(x)
|
||||
#endif
|
||||
|
||||
typedef struct Joystick
|
||||
{
|
||||
GLboolean present;
|
||||
char* name;
|
||||
float* axes;
|
||||
unsigned char* buttons;
|
||||
int axis_count;
|
||||
int button_count;
|
||||
} Joystick;
|
||||
|
||||
static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1];
|
||||
static int joystick_count = 0;
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void draw_joystick(Joystick* j, int x, int y, int width, int height)
|
||||
{
|
||||
int i;
|
||||
const int axis_height = 3 * height / 4;
|
||||
const int button_height = height / 4;
|
||||
|
||||
if (j->axis_count)
|
||||
{
|
||||
const int axis_width = width / j->axis_count;
|
||||
|
||||
for (i = 0; i < j->axis_count; i++)
|
||||
{
|
||||
float value = j->axes[i] / 2.f + 0.5f;
|
||||
|
||||
glColor3f(0.3f, 0.3f, 0.3f);
|
||||
glRecti(x + i * axis_width,
|
||||
y,
|
||||
x + (i + 1) * axis_width,
|
||||
y + axis_height);
|
||||
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
glRecti(x + i * axis_width,
|
||||
y + (int) (value * (axis_height - 5)),
|
||||
x + (i + 1) * axis_width,
|
||||
y + 5 + (int) (value * (axis_height - 5)));
|
||||
}
|
||||
}
|
||||
|
||||
if (j->button_count)
|
||||
{
|
||||
const int button_width = width / j->button_count;
|
||||
|
||||
for (i = 0; i < j->button_count; i++)
|
||||
{
|
||||
if (j->buttons[i])
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
else
|
||||
glColor3f(0.3f, 0.3f, 0.3f);
|
||||
|
||||
glRecti(x + i * button_width,
|
||||
y + axis_height,
|
||||
x + (i + 1) * button_width,
|
||||
y + axis_height + button_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_joysticks(GLFWwindow* window)
|
||||
{
|
||||
int i, width, height;
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0.f, width, height, 0.f, 1.f, -1.f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
for (i = 0; i < sizeof(joysticks) / sizeof(Joystick); i++)
|
||||
{
|
||||
Joystick* j = joysticks + i;
|
||||
|
||||
if (j->present)
|
||||
{
|
||||
draw_joystick(j,
|
||||
0, i * height / joystick_count,
|
||||
width, height / joystick_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void refresh_joysticks(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(joysticks) / sizeof(Joystick); i++)
|
||||
{
|
||||
Joystick* j = joysticks + i;
|
||||
|
||||
if (glfwJoystickPresent(GLFW_JOYSTICK_1 + i))
|
||||
{
|
||||
const float* axes;
|
||||
const unsigned char* buttons;
|
||||
int axis_count, button_count;
|
||||
|
||||
free(j->name);
|
||||
j->name = strdup(glfwGetJoystickName(GLFW_JOYSTICK_1 + i));
|
||||
|
||||
axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1 + i, &axis_count);
|
||||
if (axis_count != j->axis_count)
|
||||
{
|
||||
j->axis_count = axis_count;
|
||||
j->axes = realloc(j->axes, j->axis_count * sizeof(float));
|
||||
}
|
||||
|
||||
memcpy(j->axes, axes, axis_count * sizeof(float));
|
||||
|
||||
buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1 + i, &button_count);
|
||||
if (button_count != j->button_count)
|
||||
{
|
||||
j->button_count = button_count;
|
||||
j->buttons = realloc(j->buttons, j->button_count);
|
||||
}
|
||||
|
||||
memcpy(j->buttons, buttons, button_count * sizeof(unsigned char));
|
||||
|
||||
if (!j->present)
|
||||
{
|
||||
printf("Found joystick %i named \'%s\' with %i axes, %i buttons\n",
|
||||
i + 1, j->name, j->axis_count, j->button_count);
|
||||
|
||||
joystick_count++;
|
||||
}
|
||||
|
||||
j->present = GL_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j->present)
|
||||
{
|
||||
printf("Lost joystick %i named \'%s\'\n", i + 1, j->name);
|
||||
|
||||
free(j->name);
|
||||
free(j->axes);
|
||||
free(j->buttons);
|
||||
memset(j, 0, sizeof(Joystick));
|
||||
|
||||
joystick_count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
|
||||
memset(joysticks, 0, sizeof(joysticks));
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Joystick Test", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
refresh_joysticks();
|
||||
draw_joysticks(window);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
239
extern/glfw/tests/modes.c
vendored
Normal file
@ -0,0 +1,239 @@
|
||||
//========================================================================
|
||||
// Video mode test
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test enumerates or verifies video modes
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
enum Mode
|
||||
{
|
||||
LIST_MODE,
|
||||
TEST_MODE
|
||||
};
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: modes [-t]\n");
|
||||
printf(" modes -h\n");
|
||||
}
|
||||
|
||||
static const char* format_mode(const GLFWvidmode* mode)
|
||||
{
|
||||
static char buffer[512];
|
||||
|
||||
sprintf(buffer,
|
||||
"%i x %i x %i (%i %i %i) %i Hz",
|
||||
mode->width, mode->height,
|
||||
mode->redBits + mode->greenBits + mode->blueBits,
|
||||
mode->redBits, mode->greenBits, mode->blueBits,
|
||||
mode->refreshRate);
|
||||
|
||||
buffer[sizeof(buffer) - 1] = '\0';
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
printf("Framebuffer resized to %ix%i\n", width, height);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
|
||||
static void list_modes(GLFWmonitor* monitor)
|
||||
{
|
||||
int count, x, y, widthMM, heightMM, dpi, i;
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
|
||||
|
||||
glfwGetMonitorPos(monitor, &x, &y);
|
||||
glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM);
|
||||
|
||||
printf("Name: %s (%s)\n",
|
||||
glfwGetMonitorName(monitor),
|
||||
glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary");
|
||||
printf("Current mode: %s\n", format_mode(mode));
|
||||
printf("Virtual position: %i %i\n", x, y);
|
||||
|
||||
dpi = (int) ((float) mode->width * 25.4f / (float) widthMM);
|
||||
printf("Physical size: %i x %i mm (%i dpi)\n", widthMM, heightMM, dpi);
|
||||
|
||||
printf("Modes:\n");
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
printf("%3u: %s", (unsigned int) i, format_mode(modes + i));
|
||||
|
||||
if (memcmp(mode, modes + i, sizeof(GLFWvidmode)) == 0)
|
||||
printf(" (current mode)");
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
static void test_modes(GLFWmonitor* monitor)
|
||||
{
|
||||
int i, count;
|
||||
GLFWwindow* window;
|
||||
const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
const GLFWvidmode* mode = modes + i;
|
||||
GLFWvidmode current;
|
||||
|
||||
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
||||
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
||||
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
||||
|
||||
printf("Testing mode %u on monitor %s: %s\n",
|
||||
(unsigned int) i,
|
||||
glfwGetMonitorName(monitor),
|
||||
format_mode(mode));
|
||||
|
||||
window = glfwCreateWindow(mode->width, mode->height,
|
||||
"Video Mode Test",
|
||||
glfwGetPrimaryMonitor(),
|
||||
NULL);
|
||||
if (!window)
|
||||
{
|
||||
printf("Failed to enter mode %u: %s\n",
|
||||
(unsigned int) i,
|
||||
format_mode(mode));
|
||||
continue;
|
||||
}
|
||||
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetTime(0.0);
|
||||
|
||||
while (glfwGetTime() < 5.0)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
if (glfwWindowShouldClose(window))
|
||||
{
|
||||
printf("User terminated program\n");
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
glGetIntegerv(GL_RED_BITS, ¤t.redBits);
|
||||
glGetIntegerv(GL_GREEN_BITS, ¤t.greenBits);
|
||||
glGetIntegerv(GL_BLUE_BITS, ¤t.blueBits);
|
||||
|
||||
glfwGetWindowSize(window, ¤t.width, ¤t.height);
|
||||
|
||||
if (current.redBits != mode->redBits ||
|
||||
current.greenBits != mode->greenBits ||
|
||||
current.blueBits != mode->blueBits)
|
||||
{
|
||||
printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
|
||||
current.redBits, current.greenBits, current.blueBits,
|
||||
mode->redBits, mode->greenBits, mode->blueBits);
|
||||
}
|
||||
|
||||
if (current.width != mode->width || current.height != mode->height)
|
||||
{
|
||||
printf("*** Size mismatch: %ix%i instead of %ix%i\n",
|
||||
current.width, current.height,
|
||||
mode->width, mode->height);
|
||||
}
|
||||
|
||||
printf("Closing window\n");
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
window = NULL;
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ch, i, count, mode = LIST_MODE;
|
||||
GLFWmonitor** monitors;
|
||||
|
||||
while ((ch = getopt(argc, argv, "th")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 't':
|
||||
mode = TEST_MODE;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
monitors = glfwGetMonitors(&count);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (mode == LIST_MODE)
|
||||
list_modes(monitors[i]);
|
||||
else if (mode == TEST_MODE)
|
||||
test_modes(monitors[i]);
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
156
extern/glfw/tests/peter.c
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
//========================================================================
|
||||
// Cursor input bug test
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test came about as the result of bugs #1262764, #1726540 and
|
||||
// #1726592, all reported by the user peterpp, hence the name
|
||||
//
|
||||
// The utility of this test outside of these bugs is uncertain
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static GLboolean reopen = GL_FALSE;
|
||||
static double cursor_x;
|
||||
static double cursor_y;
|
||||
|
||||
static void toggle_cursor(GLFWwindow* window)
|
||||
{
|
||||
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
printf("Released cursor\n");
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Captured cursor\n");
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
printf("Cursor moved to: %f %f (%f %f)\n", x, y, x - cursor_x, y - cursor_y);
|
||||
cursor_x = x;
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_SPACE:
|
||||
{
|
||||
if (action == GLFW_PRESS)
|
||||
toggle_cursor(window);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GLFW_KEY_R:
|
||||
{
|
||||
if (action == GLFW_PRESS)
|
||||
reopen = GL_TRUE;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static GLFWwindow* open_window(void)
|
||||
{
|
||||
GLFWwindow* window = glfwCreateWindow(640, 480, "Peter Detector", NULL, NULL);
|
||||
if (!window)
|
||||
return NULL;
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwGetCursorPos(window, &cursor_x, &cursor_y);
|
||||
printf("Cursor position: %f %f\n", cursor_x, cursor_y);
|
||||
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
window = open_window();
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwWaitEvents();
|
||||
|
||||
if (reopen)
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
window = open_window();
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
reopen = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
177
extern/glfw/tests/reopen.c
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
//========================================================================
|
||||
// Window re-opener (open/close stress test)
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test came about as the result of bug #1262773
|
||||
//
|
||||
// It closes and re-opens the GLFW window every five seconds, alternating
|
||||
// between windowed and fullscreen mode
|
||||
//
|
||||
// It also times and logs opening and closing actions and attempts to separate
|
||||
// user initiated window closing from its own
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void window_close_callback(GLFWwindow* window)
|
||||
{
|
||||
printf("Close callback triggered\n");
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_Q:
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static GLFWwindow* open_window(int width, int height, GLFWmonitor* monitor)
|
||||
{
|
||||
double base;
|
||||
GLFWwindow* window;
|
||||
|
||||
base = glfwGetTime();
|
||||
|
||||
window = glfwCreateWindow(width, height, "Window Re-opener", monitor, NULL);
|
||||
if (!window)
|
||||
return NULL;
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetWindowCloseCallback(window, window_close_callback);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
if (monitor)
|
||||
{
|
||||
printf("Opening full screen window on monitor %s took %0.3f seconds\n",
|
||||
glfwGetMonitorName(monitor),
|
||||
glfwGetTime() - base);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Opening regular window took %0.3f seconds\n",
|
||||
glfwGetTime() - base);
|
||||
}
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
static void close_window(GLFWwindow* window)
|
||||
{
|
||||
double base = glfwGetTime();
|
||||
glfwDestroyWindow(window);
|
||||
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int count = 0;
|
||||
GLFWwindow* window;
|
||||
|
||||
srand((unsigned int) time(NULL));
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
GLFWmonitor* monitor = NULL;
|
||||
|
||||
if (count & 1)
|
||||
{
|
||||
int monitorCount;
|
||||
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||
monitor = monitors[rand() % monitorCount];
|
||||
}
|
||||
|
||||
window = open_window(640, 480, monitor);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glfwSetTime(0.0);
|
||||
|
||||
while (glfwGetTime() < 5.0)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef((GLfloat) glfwGetTime() * 100.f, 0.f, 0.f, 1.f);
|
||||
glRectf(-0.5f, -0.5f, 1.f, 1.f);
|
||||
glPopMatrix();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
if (glfwWindowShouldClose(window))
|
||||
{
|
||||
close_window(window);
|
||||
printf("User closed window\n");
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Closing window\n");
|
||||
close_window(window);
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|