Compare commits
920 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c10c458169 | ||
![]() |
59df9d0d88 | ||
![]() |
a96057866d | ||
![]() |
0d82b99c7d | ||
![]() |
77145c130f | ||
![]() |
a2fde65113 | ||
![]() |
9cb67520c7 | ||
![]() |
d93cd6dd30 | ||
![]() |
603bc9ee41 | ||
![]() |
aaf8ef1c89 | ||
![]() |
54ac286a67 | ||
![]() |
fc573bc584 | ||
![]() |
9b596cc8d9 | ||
![]() |
d4ebba3aaf | ||
![]() |
5eea8032db | ||
![]() |
241b542ca3 | ||
![]() |
3557c46ae6 | ||
![]() |
95c98093e9 | ||
![]() |
0337568846 | ||
![]() |
43187455e4 | ||
![]() |
f93372f98a | ||
![]() |
f57d4620ab | ||
![]() |
50e173e403 | ||
![]() |
632a015663 | ||
![]() |
1d20edebc7 | ||
![]() |
110fb75513 | ||
![]() |
519e1f9572 | ||
![]() |
bf98acc61f | ||
![]() |
a1d4bc80c2 | ||
![]() |
80c3bdc23c | ||
![]() |
6a79ebf1b3 | ||
![]() |
689f468e36 | ||
![]() |
6272f853c1 | ||
![]() |
8886134156 | ||
![]() |
2eb70c6537 | ||
![]() |
f2b8e6397b | ||
![]() |
ea71dd2fe0 | ||
![]() |
ca21695521 | ||
![]() |
27a4c83ebc | ||
![]() |
81a1da6a59 | ||
![]() |
b00317e90c | ||
![]() |
86672a3724 | ||
![]() |
4043f71156 | ||
![]() |
6d8143088e | ||
![]() |
7e7216f598 | ||
![]() |
1d768839e7 | ||
![]() |
53972ed5f2 | ||
![]() |
2c3a321afd | ||
![]() |
c626332e03 | ||
![]() |
d53858afb1 | ||
![]() |
bc7258006c | ||
![]() |
d3a072fb63 | ||
![]() |
a88e854dc3 | ||
![]() |
d402ce5a5d | ||
![]() |
7d496095a5 | ||
![]() |
11b3fe4283 | ||
![]() |
c3e5a35a6e | ||
![]() |
620c9989d6 | ||
![]() |
5b08f8133f | ||
![]() |
a85dc6dabb | ||
![]() |
3d46e39e6d | ||
![]() |
9c8cc19f96 | ||
![]() |
4dfad062e4 | ||
![]() |
0980e90ee4 | ||
![]() |
bf92efe9a4 | ||
![]() |
353c846c87 | ||
![]() |
9f4a0c3c4f | ||
![]() |
5ab36271c7 | ||
![]() |
1272b704d6 | ||
![]() |
82c2f4c05e | ||
![]() |
b516a3ae2b | ||
![]() |
7e40f80f52 | ||
![]() |
53d8f66d43 | ||
![]() |
195f5d7409 | ||
![]() |
489482a630 | ||
![]() |
ae337952a9 | ||
![]() |
04131e1607 | ||
![]() |
db80f6a60f | ||
![]() |
b9fdaf487f | ||
![]() |
1bf3ae77b9 | ||
![]() |
b81de898bf | ||
![]() |
fbc0f17198 | ||
![]() |
077af21f37 | ||
![]() |
119195ac20 | ||
![]() |
2be4e54d4a | ||
![]() |
1159ac5c52 | ||
![]() |
de0ba77d3b | ||
![]() |
ac98be760b | ||
![]() |
3f4bc3683b | ||
![]() |
d1d788fcb3 | ||
![]() |
ae0ec9d552 | ||
![]() |
a5d45b910f | ||
![]() |
3aa156c278 | ||
![]() |
8554d210df | ||
![]() |
5e10e1f0c9 | ||
![]() |
46ce05cd9c | ||
![]() |
87aaa9e145 | ||
![]() |
be3556d76a | ||
![]() |
2bba983f1d | ||
![]() |
aeca3dce41 | ||
![]() |
0bcb2992a7 | ||
![]() |
1cd7ad6a24 | ||
![]() |
83d05ea822 | ||
![]() |
43f0292cb8 | ||
![]() |
e3c65090ea | ||
![]() |
9712bb1ec8 | ||
![]() |
ff87e1c922 | ||
![]() |
f4f7ef0d70 | ||
![]() |
dc0dfd601a | ||
![]() |
bcb013b45b | ||
![]() |
44d3e26766 | ||
![]() |
ac38b17827 | ||
![]() |
8d96976e4b | ||
![]() |
bc570b22bf | ||
![]() |
2853b6b629 | ||
![]() |
f22b9b7b71 | ||
![]() |
235abae134 | ||
![]() |
b97a5be615 | ||
![]() |
ff011dc51d | ||
![]() |
93ad872f9e | ||
![]() |
d2ececed05 | ||
![]() |
1dcad60878 | ||
![]() |
b012266258 | ||
![]() |
bb3bd05823 | ||
![]() |
88bb3f89a5 | ||
![]() |
c828314d12 | ||
![]() |
192eb968a4 | ||
![]() |
859db83af7 | ||
![]() |
8a0d9b414f | ||
![]() |
de2d49e3af | ||
![]() |
b21039452e | ||
![]() |
f2ccc64536 | ||
![]() |
35725cd2df | ||
![]() |
ceee41eaf4 | ||
![]() |
d7fffae727 | ||
![]() |
3da81aeecb | ||
![]() |
4c4e961f39 | ||
![]() |
cd1387479e | ||
![]() |
ee957f3420 | ||
![]() |
b922b04b5e | ||
![]() |
5ebfef4803 | ||
![]() |
f25589e309 | ||
![]() |
2cd4797557 | ||
![]() |
9bdd6d46dd | ||
![]() |
9da895da8b | ||
![]() |
763a9fb44e | ||
![]() |
4d0d331272 | ||
![]() |
f4c25ac3fa | ||
![]() |
1e800d9551 | ||
![]() |
3a96024f6b | ||
![]() |
0adde249ec | ||
![]() |
c706f11f29 | ||
![]() |
d032050ccf | ||
![]() |
fe1407b6b5 | ||
![]() |
a1065737db | ||
![]() |
15d0f789c7 | ||
![]() |
7be2111d61 | ||
![]() |
fc655f52b9 | ||
![]() |
09e24adf2e | ||
![]() |
a94b3e9e24 | ||
![]() |
ee08e18726 | ||
![]() |
fc02cf004a | ||
![]() |
949e7aecae | ||
![]() |
421e8bb812 | ||
![]() |
b0f3611ab9 | ||
![]() |
5c20c67469 | ||
![]() |
49d611ee69 | ||
![]() |
8b7a50a914 | ||
![]() |
f963faa694 | ||
![]() |
910458cfb3 | ||
![]() |
b196aac5c7 | ||
![]() |
0118776b7e | ||
![]() |
deeb3a95f3 | ||
![]() |
186294607f | ||
![]() |
66369645b5 | ||
![]() |
806813e937 | ||
![]() |
0da25a0b87 | ||
![]() |
989367e345 | ||
![]() |
5d7843c58a | ||
![]() |
22f1b85515 | ||
![]() |
d972216c57 | ||
![]() |
511c16329e | ||
![]() |
14dd503c8a | ||
![]() |
1062e95e39 | ||
![]() |
d6c6345d4c | ||
![]() |
6d4e870e32 | ||
![]() |
6d122e96e1 | ||
![]() |
341bc2a130 | ||
![]() |
65d26be74d | ||
![]() |
73892dfa12 | ||
![]() |
7ef1cff5d1 | ||
![]() |
812dea70d0 | ||
![]() |
9e2f2eb27f | ||
![]() |
e31b925234 | ||
![]() |
61cdcd47ca | ||
![]() |
fe39af4ec8 | ||
![]() |
ce7ced5488 | ||
![]() |
777ec2c04d | ||
![]() |
c24de5fcaf | ||
![]() |
b6c1acab3c | ||
![]() |
bba5808717 | ||
![]() |
30ec3edd8b | ||
![]() |
247b03172c | ||
![]() |
6f3282623f | ||
![]() |
714ed41b6f | ||
![]() |
5a135a3b7d | ||
![]() |
883ec9391d | ||
![]() |
dd307cc23e | ||
![]() |
c352f5228b | ||
![]() |
8a02dc0ad5 | ||
![]() |
3871e01a9f | ||
![]() |
013d053277 | ||
![]() |
898c2350f7 | ||
![]() |
516678fe1f | ||
![]() |
b3d6e4811d | ||
![]() |
fc54dba3d7 | ||
![]() |
2aa70def6f | ||
![]() |
44944989e8 | ||
![]() |
0dd24c8f1f | ||
![]() |
158f410ab5 | ||
![]() |
23a345512d | ||
![]() |
a2f448ab4c | ||
![]() |
58b7c2c48a | ||
![]() |
93a2e9502d | ||
![]() |
6b3061d9c2 | ||
![]() |
ffd9c94381 | ||
![]() |
cd27b7df07 | ||
![]() |
0637a2ef99 | ||
![]() |
f30c896780 | ||
![]() |
967db6c6f9 | ||
![]() |
692fa5ab33 | ||
![]() |
4bc3c6f8bf | ||
![]() |
bc8a90b33a | ||
![]() |
745b446440 | ||
![]() |
5a4b592bbc | ||
![]() |
49776092d1 | ||
![]() |
34ea68bd1d | ||
![]() |
219c14b0c2 | ||
![]() |
b0b1f13269 | ||
![]() |
f65459d0e1 | ||
![]() |
6f5a7d1b1b | ||
![]() |
bd479c4454 | ||
![]() |
c43b5991af | ||
![]() |
700fc7d9e0 | ||
![]() |
0b2ac85f11 | ||
![]() |
973ac8ddcd | ||
![]() |
858c9ce924 | ||
![]() |
4595562de4 | ||
![]() |
9b16bc7c67 | ||
![]() |
756cb09bc3 | ||
![]() |
6b71456a55 | ||
![]() |
f053871a6c | ||
![]() |
4cde8bb69c | ||
![]() |
5fe5e5d6d7 | ||
![]() |
40ae477cc3 | ||
![]() |
e4ae4f9cc3 | ||
![]() |
113152673a | ||
![]() |
dacee0462e | ||
![]() |
d10d205bb3 | ||
![]() |
af5244d85d | ||
![]() |
022f1590d8 | ||
![]() |
c678cae498 | ||
![]() |
8c7c48481b | ||
![]() |
5eaa748adb | ||
![]() |
746bb9c8ca | ||
![]() |
77d19859bc | ||
![]() |
67ef694443 | ||
![]() |
2207af41e4 | ||
![]() |
2df9abf341 | ||
![]() |
39208efb55 | ||
![]() |
95828a85a2 | ||
![]() |
3d41e28e6a | ||
![]() |
550fb2b60a | ||
![]() |
9996b7abb6 | ||
![]() |
fae3b65f05 | ||
![]() |
68850d331f | ||
![]() |
340ebfb272 | ||
![]() |
ae23cb39ba | ||
![]() |
7c0f534877 | ||
![]() |
e199ef3790 | ||
![]() |
b16d29b4ae | ||
![]() |
9558c6d689 | ||
![]() |
ca03b646ef | ||
![]() |
8df8493515 | ||
![]() |
8e7bf64162 | ||
![]() |
818a8d1659 | ||
![]() |
a43be42999 | ||
![]() |
ac50bf8648 | ||
![]() |
3a2e176e59 | ||
![]() |
757094a25b | ||
![]() |
36bb3c4531 | ||
![]() |
61526628d1 | ||
![]() |
6f3273b7a6 | ||
![]() |
427ce77d4e | ||
![]() |
90c01d3030 | ||
![]() |
f7dcc10a70 | ||
![]() |
ba9383f25e | ||
![]() |
b1827ddb6d | ||
![]() |
193e54773d | ||
![]() |
afb8254b6d | ||
![]() |
fb40e7e43f | ||
![]() |
c15172e3fd | ||
![]() |
556371ea10 | ||
![]() |
f49c156a31 | ||
![]() |
259811d59c | ||
![]() |
2c7b58f406 | ||
![]() |
9f6f02f988 | ||
![]() |
845c684ec8 | ||
![]() |
ab09af3eae | ||
![]() |
b457f5fa6c | ||
![]() |
2f53489f2a | ||
![]() |
7b20093650 | ||
![]() |
4c7edbcaf8 | ||
![]() |
9d70da3aaa | ||
![]() |
c98a84a5d8 | ||
![]() |
1ee6d1dbc6 | ||
![]() |
e00d160224 | ||
![]() |
c4956857fa | ||
![]() |
3ff1d251a8 | ||
![]() |
23ea17eab7 | ||
![]() |
e77e680cad | ||
![]() |
77609e166a | ||
![]() |
2bd897c513 | ||
![]() |
687f260a46 | ||
![]() |
b61502b69a | ||
![]() |
c78c8106da | ||
![]() |
698bbccd6a | ||
![]() |
499eb09642 | ||
![]() |
fe9b9c0cc7 | ||
![]() |
043fb83cd8 | ||
![]() |
146f63874a | ||
![]() |
1763861b26 | ||
![]() |
1217699fe0 | ||
![]() |
957cabb816 | ||
![]() |
7ff9478061 | ||
![]() |
63fba49d96 | ||
![]() |
0df97b4813 | ||
![]() |
127bc77497 | ||
![]() |
9c5c750e60 | ||
![]() |
fcb05fb975 | ||
![]() |
d4683692e0 | ||
![]() |
3a12fc6505 | ||
![]() |
6b9781475d | ||
![]() |
f80f501885 | ||
![]() |
ecede1119a | ||
![]() |
aa4f0681db | ||
![]() |
811dfe1cf7 | ||
![]() |
2d1fab374f | ||
![]() |
0c9ce3bef3 | ||
![]() |
c4be28bd0f | ||
![]() |
2752bbcfb0 | ||
![]() |
b7d7ac44f3 | ||
![]() |
221e0700f7 | ||
![]() |
4f3c26660e | ||
![]() |
1b2c50a0d8 | ||
![]() |
58643d78f9 | ||
![]() |
01d72438de | ||
![]() |
c55b8c17e1 | ||
![]() |
0f1dc5a754 | ||
![]() |
df8260a1c4 | ||
![]() |
64ddb10f3d | ||
![]() |
b7d984cdac | ||
![]() |
18193a5cde | ||
![]() |
506ec95fde | ||
![]() |
e5f98a6575 | ||
![]() |
0bcd7d39f2 | ||
![]() |
110feeb7f2 | ||
![]() |
94dd1d73fa | ||
![]() |
d53a69755e | ||
![]() |
e84286ca17 | ||
![]() |
20756e3539 | ||
![]() |
a2e7dadf2a | ||
![]() |
8f4d07319d | ||
![]() |
b3b48a507d | ||
![]() |
df99d5fee2 | ||
![]() |
561eb82f14 | ||
![]() |
fa1bc737d5 | ||
![]() |
7c179193e6 | ||
![]() |
f6020c5f8e | ||
![]() |
7fba68ac52 | ||
![]() |
b8e4b087cd | ||
![]() |
a0c1302428 | ||
![]() |
da8a325fa3 | ||
![]() |
26fc872844 | ||
![]() |
b735777c4a | ||
![]() |
2d56b41265 | ||
![]() |
11357b354f | ||
![]() |
cadc4d801c | ||
![]() |
0df1c97af7 | ||
![]() |
6de027f198 | ||
![]() |
6cec972338 | ||
![]() |
1b1d92d6bb | ||
![]() |
717bd85537 | ||
![]() |
11e2901403 | ||
![]() |
45577de60a | ||
![]() |
e38a26ec25 | ||
![]() |
d2adccfe2e | ||
![]() |
46a625dde5 | ||
![]() |
608b4fb28d | ||
![]() |
80214d1cb9 | ||
![]() |
947427cb8d | ||
![]() |
93f389e92e | ||
![]() |
653c0fdb30 | ||
![]() |
e0174545e6 | ||
![]() |
e0d27358fb | ||
![]() |
db8c237f6a | ||
![]() |
17570c324e | ||
![]() |
e80bf0ba92 | ||
![]() |
075d7b3b50 | ||
![]() |
4992243857 | ||
![]() |
53f61e9596 | ||
![]() |
ac3a5394ca | ||
![]() |
bbe2c656e6 | ||
![]() |
01f46ce231 | ||
![]() |
22c9674389 | ||
![]() |
534a23e074 | ||
![]() |
3ec672afe9 | ||
![]() |
3d0ab05e7b | ||
![]() |
0b221921ed | ||
![]() |
0076ea50db | ||
![]() |
bbfef72fc6 | ||
![]() |
5ce73e9274 | ||
![]() |
c0bee34d42 | ||
![]() |
e78f1bd4ea | ||
![]() |
4add6faf06 | ||
![]() |
b9cc6f5c0d | ||
![]() |
7287b77c5d | ||
![]() |
5aaf9a6115 | ||
![]() |
39cdebfe71 | ||
![]() |
bd34935f2a | ||
![]() |
c229877313 | ||
![]() |
623f63a48a | ||
![]() |
3faf2a93d6 | ||
![]() |
c08a56bf9f | ||
![]() |
20f213bfac | ||
![]() |
23cc8cfe3f | ||
![]() |
7b4610b55b | ||
![]() |
3ca6e0f346 | ||
![]() |
ce16554763 | ||
![]() |
ae53cfd0d9 | ||
![]() |
cee6263a01 | ||
![]() |
3996faa54c | ||
![]() |
c17486857f | ||
![]() |
650e792350 | ||
![]() |
e2420dfe76 | ||
![]() |
97bdf72ce1 | ||
![]() |
1d16748ed7 | ||
![]() |
6b3c7f0cd6 | ||
![]() |
c30a3da8d5 | ||
![]() |
38f0464ab0 | ||
![]() |
3e397bff4b | ||
![]() |
ea2bf65186 | ||
![]() |
d53338298a | ||
![]() |
426b137516 | ||
![]() |
e17cc520d6 | ||
![]() |
81a8e4e4ca | ||
![]() |
9d3024e13e | ||
![]() |
bbfa3d5a76 | ||
![]() |
95ec9180ad | ||
![]() |
b2b35d0a43 | ||
![]() |
b758f9a1dd | ||
![]() |
cd9b8b9a15 | ||
![]() |
cc05fc785a | ||
![]() |
f39e7a9869 | ||
![]() |
01d5d1b463 | ||
![]() |
20af2a4dfa | ||
![]() |
aa9a6dec89 | ||
![]() |
0c2f306c17 | ||
![]() |
42a6967128 | ||
![]() |
6ab8d43b04 | ||
![]() |
f17ea5872b | ||
![]() |
af4dac6fed | ||
![]() |
66eab23b10 | ||
![]() |
3424467896 | ||
![]() |
62933114ec | ||
![]() |
0d29d38d20 | ||
![]() |
26f8c74c43 | ||
![]() |
592a25b768 | ||
![]() |
5cdb432d60 | ||
![]() |
1d24b52220 | ||
![]() |
e22bb627c7 | ||
![]() |
599a16b1f2 | ||
![]() |
d45364b753 | ||
![]() |
3fbfde39a5 | ||
![]() |
5e0e645f46 | ||
![]() |
6096d22091 | ||
![]() |
f0608eaed8 | ||
![]() |
34692d5a39 | ||
![]() |
1de7644277 | ||
![]() |
d790114df8 | ||
![]() |
67c7663c80 | ||
![]() |
f47f89a759 | ||
![]() |
6ca9f66a06 | ||
![]() |
d83ddd56e3 | ||
![]() |
1f2bc148fe | ||
![]() |
88ec48cb85 | ||
![]() |
8dd31f2f52 | ||
![]() |
9f2aecf9cf | ||
![]() |
cac4d58b3d | ||
![]() |
2cab5789af | ||
![]() |
9b0ce8888e | ||
![]() |
66f38262f7 | ||
![]() |
5dbfb477a0 | ||
![]() |
5139a7ac82 | ||
![]() |
976c4219e5 | ||
![]() |
c303d1f73b | ||
![]() |
8a8793e00c | ||
![]() |
b7c0af3a58 | ||
![]() |
f464e2502a | ||
![]() |
132ae26ce1 | ||
![]() |
92ca32b2f9 | ||
![]() |
758735092e | ||
![]() |
d4e6b84afc | ||
![]() |
896bd51b22 | ||
![]() |
17090367dc | ||
![]() |
d17b4bad96 | ||
![]() |
c7549cd292 | ||
![]() |
135c1716e8 | ||
![]() |
19920f572f | ||
![]() |
c4e450cac4 | ||
![]() |
1cfa5c6f1d | ||
![]() |
b0d6c2bea9 | ||
![]() |
8b7ac65aa3 | ||
![]() |
274b9331f0 | ||
![]() |
32bafa98a4 | ||
![]() |
0ad401cc97 | ||
![]() |
f44c903e56 | ||
![]() |
fc850ed99f | ||
![]() |
2a8015be93 | ||
![]() |
1c46ec7c37 | ||
![]() |
21756145cb | ||
![]() |
fa3ea62695 | ||
![]() |
7ee0734470 | ||
![]() |
188f713900 | ||
![]() |
0a64f50605 | ||
![]() |
45810a1345 | ||
![]() |
610111c687 | ||
![]() |
aef8f826f1 | ||
![]() |
40ae3ce175 | ||
![]() |
6ef3cb27a1 | ||
![]() |
e257909a65 | ||
![]() |
1271dff960 | ||
![]() |
c2761c317e | ||
![]() |
8928baa5ce | ||
![]() |
ab4d4d7477 | ||
![]() |
53e3409cbf | ||
![]() |
e2c378e9d1 | ||
![]() |
27e373c5c5 | ||
![]() |
e2b3cdacc2 | ||
![]() |
c348171f24 | ||
![]() |
b2ba2307b3 | ||
![]() |
9a8ba74c62 | ||
![]() |
ba1488ec97 | ||
![]() |
60c4f95795 | ||
![]() |
c4435b8a31 | ||
![]() |
c98bd1eaba | ||
![]() |
93d2789f70 | ||
![]() |
4155b2e449 | ||
![]() |
6a24eb5eec | ||
![]() |
85291debb4 | ||
![]() |
b965ad198b | ||
![]() |
ef6391678e | ||
![]() |
f99035bea1 | ||
![]() |
f24ca9a840 | ||
![]() |
b27cbd5036 | ||
![]() |
c36ea074d8 | ||
![]() |
7159e4ba43 | ||
![]() |
330ea0bbe3 | ||
![]() |
6d122f428a | ||
![]() |
dcba593e8f | ||
![]() |
2427aaf3bb | ||
![]() |
eec9f7750f | ||
![]() |
86c81f7458 | ||
![]() |
e157e7a7a8 | ||
![]() |
c37e442cee | ||
![]() |
20bf0e0b9c | ||
![]() |
e5a98aa1d5 | ||
![]() |
ef1b9d6b20 | ||
![]() |
fc7637681d | ||
![]() |
c016ab5d0a | ||
![]() |
7c63c5885e | ||
![]() |
f9ed3fdcb3 | ||
![]() |
b96d330b9f | ||
![]() |
3b9e246c83 | ||
![]() |
eaab2c1c68 | ||
![]() |
34933520ac | ||
![]() |
6959c1a826 | ||
![]() |
7defb17e8c | ||
![]() |
713407e159 | ||
![]() |
6ad7b21203 | ||
![]() |
7ace90986b | ||
![]() |
386f56d6a4 | ||
![]() |
700c2e3823 | ||
![]() |
1fa2ff0458 | ||
![]() |
83e019e7d3 | ||
![]() |
ca77ea58d0 | ||
![]() |
621793a354 | ||
![]() |
3f69629d0c | ||
![]() |
f7561f5fa1 | ||
![]() |
796c87295c | ||
![]() |
5f3b6cb57a | ||
![]() |
520025d904 | ||
![]() |
337df1ea5f | ||
![]() |
8db958042e | ||
![]() |
0a64da654c | ||
![]() |
f491e94297 | ||
![]() |
e625d79a04 | ||
![]() |
e73e408885 | ||
![]() |
57941c1696 | ||
![]() |
74e425a9ed | ||
![]() |
09aae0240d | ||
![]() |
362a590454 | ||
![]() |
1851dcb109 | ||
![]() |
471873dff9 | ||
![]() |
dd6b54d0eb | ||
![]() |
c462f7cd0a | ||
![]() |
57ca180d8d | ||
![]() |
73008293ba | ||
![]() |
cf52687203 | ||
![]() |
fb81ddfdcb | ||
![]() |
d73418261b | ||
![]() |
ed7c80f6bb | ||
![]() |
a06ecb0c7f | ||
![]() |
9e3b466ee0 | ||
![]() |
06b73f36bd | ||
![]() |
e726c24de4 | ||
![]() |
3e9f842e59 | ||
![]() |
b542785ed9 | ||
![]() |
f0345d5201 | ||
![]() |
a88bab1d59 | ||
![]() |
a4846db016 | ||
![]() |
214c9b0662 | ||
![]() |
c522f6d596 | ||
![]() |
775277b8fb | ||
![]() |
6302cc0762 | ||
![]() |
121c3b2fd7 | ||
![]() |
1bd62b4d14 | ||
![]() |
bc73b12428 | ||
![]() |
5b559f1c08 | ||
![]() |
86983acaa4 | ||
![]() |
60c34bff19 | ||
![]() |
2874ac4aab | ||
![]() |
e56d697755 | ||
![]() |
bdcdfffe11 | ||
![]() |
da79517b36 | ||
![]() |
0124ad0a85 | ||
![]() |
228038fa8a | ||
![]() |
159176f5ba | ||
![]() |
9690a7edee | ||
![]() |
265c411c39 | ||
![]() |
46be2159cb | ||
![]() |
bc1127da5b | ||
![]() |
5912d205d3 | ||
![]() |
4f2c6c4489 | ||
![]() |
1dae89a8e0 | ||
![]() |
ff869777a9 | ||
![]() |
3fa1d0e03d | ||
![]() |
0375d7588f | ||
![]() |
e6b5ce1f27 | ||
![]() |
3f61214571 | ||
![]() |
7d4235a38f | ||
![]() |
a3ab6efa23 | ||
![]() |
2215f55ef9 | ||
![]() |
aa47dd5d33 | ||
![]() |
7ae381533e | ||
![]() |
6c802952fb | ||
![]() |
ea0364d568 | ||
![]() |
2d08ed684b | ||
![]() |
6e01d1fde7 | ||
![]() |
6a5391c0b6 | ||
![]() |
e33e061e96 | ||
![]() |
b9f5f19f7c | ||
![]() |
a8ab8fb061 | ||
![]() |
1fe22e24d0 | ||
![]() |
749cbb2ff8 | ||
![]() |
5250cc97d5 | ||
![]() |
44a192d9b1 | ||
![]() |
c45039e907 | ||
![]() |
2e09dd225b | ||
![]() |
83951d1cae | ||
![]() |
47913ee0aa | ||
![]() |
0c3d361ceb | ||
![]() |
cdf32a7881 | ||
![]() |
b7c536c710 | ||
![]() |
b188814937 | ||
![]() |
597d133dcb | ||
![]() |
27eadf2a7c | ||
![]() |
f1431e416c | ||
![]() |
208164898b | ||
![]() |
3a7b425fb7 | ||
![]() |
efe4354bc5 | ||
![]() |
1ce8a42954 | ||
![]() |
ee336a3037 | ||
![]() |
6469f35d99 | ||
![]() |
f99bbfc534 | ||
![]() |
7f0f89bac9 | ||
![]() |
c222c28aa7 | ||
![]() |
52bb192cff | ||
![]() |
2c96d49a03 | ||
![]() |
2eb4f69e41 | ||
![]() |
d8812f0f5c | ||
![]() |
8f0037d84d | ||
![]() |
5a4b54cb9c | ||
![]() |
86b29c539d | ||
![]() |
f6edb83acd | ||
![]() |
6e3103464a | ||
![]() |
42f6e83dfb | ||
![]() |
6edc4b9518 | ||
![]() |
1bfc735a9e | ||
![]() |
a348428476 | ||
![]() |
273ad4c9ee | ||
![]() |
dd7a3cb30b | ||
![]() |
03acb2ad9f | ||
![]() |
80431deef4 | ||
![]() |
ffd4b71722 | ||
![]() |
2d682d324f | ||
![]() |
67c7a5d176 | ||
![]() |
76fddc0729 | ||
![]() |
83306e72a2 | ||
![]() |
84bd8c6c5b | ||
![]() |
75ddae7e90 | ||
![]() |
038401b8d5 | ||
![]() |
050dd6f5dc | ||
![]() |
595df2a1a9 | ||
![]() |
2caec961ee | ||
![]() |
a1b0e73ac5 | ||
![]() |
349fe380e4 | ||
![]() |
7daaaa649e | ||
![]() |
59c3c2c0b0 | ||
![]() |
ba0555fd1a | ||
![]() |
2627c3579f | ||
![]() |
43aa313280 | ||
![]() |
e12b94c989 | ||
![]() |
45f23cdbbb | ||
![]() |
565bc69a4e | ||
![]() |
d40399e431 | ||
![]() |
1c9a8310ff | ||
![]() |
62941c4264 | ||
![]() |
2c259c8f49 | ||
![]() |
6e57380e4f | ||
![]() |
860c232507 | ||
![]() |
17430ef372 | ||
![]() |
2ab49ece2f | ||
![]() |
634c3dc2a7 | ||
![]() |
891cd261b8 | ||
![]() |
728f11701b | ||
![]() |
cd89e462fa | ||
![]() |
d908ffa498 | ||
![]() |
de791c05dc | ||
![]() |
fbd21962f0 | ||
![]() |
4626e95491 | ||
![]() |
77567e9656 | ||
![]() |
67177ce55c | ||
![]() |
218c0897c8 | ||
![]() |
d6f98229a8 | ||
![]() |
663dad18f2 | ||
![]() |
bc46dfb8f5 | ||
![]() |
f60ab60263 | ||
![]() |
00d3bf1e7f | ||
![]() |
3f7486323a | ||
![]() |
2c409e5145 | ||
![]() |
c77b8a3496 | ||
![]() |
4180e6b31f | ||
![]() |
90d8b37442 | ||
![]() |
cc0d982f72 | ||
![]() |
60894d1c1a | ||
![]() |
f9e80e1a3b | ||
![]() |
b167c7a8d5 | ||
![]() |
293b85af53 | ||
![]() |
ea3a29f150 | ||
![]() |
c35b48bcea | ||
![]() |
8f459cd1af | ||
![]() |
3872b27569 | ||
![]() |
b9fd685a60 | ||
![]() |
4bd1a66915 | ||
![]() |
cac645076f | ||
![]() |
ca29498653 | ||
![]() |
239921b456 | ||
![]() |
4e8e1629d1 | ||
![]() |
cefb4fcee0 | ||
![]() |
8c906a7a3d | ||
![]() |
63bbe2c91e | ||
![]() |
01b745185e | ||
![]() |
e20ff86330 | ||
![]() |
d50f94ca97 | ||
![]() |
e5ee38fc26 | ||
![]() |
f2ef524b57 | ||
![]() |
e9243b7ef6 | ||
![]() |
19012c66ea | ||
![]() |
0a5f38157f | ||
![]() |
b1c062d84f | ||
![]() |
f6c94451fb | ||
![]() |
324d4a18e7 | ||
![]() |
0d47056132 | ||
![]() |
ac28902b57 | ||
![]() |
0d6ddde07f | ||
![]() |
49f2a76d93 | ||
![]() |
b868833191 | ||
![]() |
2204838384 | ||
![]() |
816bc93b04 | ||
![]() |
83fd76c40b | ||
![]() |
18bbd23886 | ||
![]() |
e9334db424 | ||
![]() |
c584ddeea6 | ||
![]() |
666da801a1 | ||
![]() |
59e920cf10 | ||
![]() |
1319a0a096 | ||
![]() |
0227e5c51e | ||
![]() |
2c5cab5454 | ||
![]() |
f9233e792b | ||
![]() |
50e3052773 | ||
![]() |
d97e5244af | ||
![]() |
1fd6fae073 | ||
![]() |
9d5eb14dde | ||
![]() |
83eab47c05 | ||
![]() |
ec494babbe | ||
![]() |
330db58bc1 | ||
![]() |
fab46cdfd7 | ||
![]() |
75784dbb9a | ||
![]() |
05d196d86d | ||
![]() |
d7c9df7600 | ||
![]() |
fe7d6f513d | ||
![]() |
185c09a95c | ||
![]() |
6b2a4c27db | ||
![]() |
951b774c70 | ||
![]() |
29c0f14911 | ||
![]() |
a8ba35171a | ||
![]() |
e1c40c9c77 | ||
![]() |
53f7ae5d09 | ||
![]() |
79134ba665 | ||
![]() |
83ea194f07 | ||
![]() |
52661339de | ||
![]() |
09860f7a02 | ||
![]() |
aeed9dddac | ||
![]() |
12d81304e6 | ||
![]() |
48db71fb69 | ||
![]() |
e074b6775e | ||
![]() |
b5e7e431a5 | ||
![]() |
4a300547f3 | ||
![]() |
58f60f2279 | ||
![]() |
de3ea71631 | ||
![]() |
5fae13f8b3 | ||
![]() |
ab361c4903 | ||
![]() |
ef1d29bf73 | ||
![]() |
f1c30f106a | ||
![]() |
4063f5d9eb | ||
![]() |
c3813f71ee | ||
![]() |
4cddde79fe | ||
![]() |
c06243c0f6 | ||
![]() |
ff555d6f85 | ||
![]() |
f69a35e63d | ||
![]() |
0c39c1b146 | ||
![]() |
56c2eb8cea | ||
![]() |
306b77bfc5 | ||
![]() |
dbf01a775b | ||
![]() |
c2a9ed6b83 | ||
![]() |
004c12cfd2 | ||
![]() |
3670eec5dd | ||
![]() |
08b49cc15c | ||
![]() |
2ff58edd9a | ||
![]() |
db77b76d91 | ||
![]() |
a66fe2721b | ||
![]() |
b1ad9dceac | ||
![]() |
9b0ed300b5 | ||
![]() |
fe12270d62 | ||
![]() |
cc3dc29ef4 | ||
![]() |
713aed7079 | ||
![]() |
5931236858 | ||
![]() |
50332a8186 | ||
![]() |
42cf79bfc3 | ||
![]() |
cd68d66204 | ||
![]() |
b8f15d5a71 | ||
![]() |
4dcd1f9c75 | ||
![]() |
980477c1f1 | ||
![]() |
eee18a515a | ||
![]() |
cd84e84286 | ||
![]() |
9d3ea9399b | ||
![]() |
2ea3beb1f6 | ||
![]() |
3a809d98f1 | ||
![]() |
735aed62b0 | ||
![]() |
5bf065a709 | ||
![]() |
d77fce1b77 | ||
![]() |
00bc73f1f3 | ||
![]() |
c83027ec9c | ||
![]() |
a6dba586ee | ||
![]() |
369b7faa1c | ||
![]() |
d77f241938 | ||
![]() |
e5c6f6cd7a | ||
![]() |
1b113c2c22 | ||
![]() |
6f68192272 | ||
![]() |
2b8f20c89f | ||
![]() |
c0f3587a7c | ||
![]() |
718588ff1d | ||
![]() |
7c4b058c9a | ||
![]() |
44b98b4406 | ||
![]() |
77238767ee | ||
![]() |
ed1c17a236 | ||
![]() |
5ffe258320 | ||
![]() |
c6651bfd30 | ||
![]() |
a89874f733 | ||
![]() |
de0401a02e | ||
![]() |
6cf30e1751 | ||
![]() |
5f4257187e | ||
![]() |
c6767d0af1 | ||
![]() |
5173f51d52 | ||
![]() |
d9ba54f285 | ||
![]() |
424c424376 | ||
![]() |
a7f7c57a72 | ||
![]() |
5feca74178 | ||
![]() |
b9d0295c89 | ||
![]() |
5624948042 | ||
![]() |
7caf2e64b6 | ||
![]() |
6d4c844959 | ||
![]() |
c697623689 | ||
![]() |
d077210750 | ||
![]() |
92ed9fd1db | ||
![]() |
93b2152a08 | ||
![]() |
90f4dbc89b | ||
![]() |
0c0b3c2a3a | ||
![]() |
20db4969c5 |
18
.editorconfig
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Configuration file for EditorConfig
|
||||
# More information is available under http://EditorConfig.org
|
||||
|
||||
# Ignore any other files further up in the file system
|
||||
root = true
|
||||
|
||||
# Configuration for all files
|
||||
[*]
|
||||
# Enforce Unix style line endings (\n only)
|
||||
end_of_line = lf
|
||||
# Always end files with a blank line
|
||||
insert_final_newline = true
|
||||
# Force space characters for indentation
|
||||
indent_style = space
|
||||
# Always indent by 4 characters
|
||||
indent_size = 4
|
||||
# Remove whitespace characters at the end of line
|
||||
trim_trailing_whitespace = true
|
13
.gitattributes
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
* text=auto eol=lf
|
||||
|
||||
extlibs/**/* -text -eol linguist-vendored
|
||||
cmake/toolchains/android.toolchain.cmake -text -eol
|
||||
|
||||
*.png -text -eol
|
||||
*.jpg -text -eol
|
||||
*.wav -text -eol
|
||||
*.ogg -text -eol
|
||||
*.flac -text -eol
|
||||
*.tff -text -eol
|
||||
*.icns -text -eol
|
||||
*.rtf -text -eol
|
54
.github/ISSUE_TEMPLATE.md
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
Thanks for raising your issue here! 🙂
|
||||
|
||||
Before you submit the issue however, we'd like you to consider the follow points.
|
||||
|
||||
* We like to use the issue tracker for confirmed issues.
|
||||
* If you're stuck with SFML, please use [the forum](https://en.sfml-dev.org/forums/index.php#c3) to get help.
|
||||
|
||||
----
|
||||
|
||||
## Subject of the issue
|
||||
|
||||
Describe your issue here.
|
||||
|
||||
## Your environment
|
||||
|
||||
* Your OS / distro / window manager used
|
||||
* Your version of SFML (2.5.0, git master, etc)
|
||||
* Your compiler and compiler version used
|
||||
* Special compiler flags used
|
||||
|
||||
## Steps to reproduce
|
||||
|
||||
Tell us how to reproduce this issue. Please provide a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve), you can use the follow template as a start:
|
||||
|
||||
```cpp
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
sf::RenderWindow window(sf::VideoMode(1280, 720), "Minimal, complete and verifiable example");
|
||||
window.setFramerateLimit(60);
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
}
|
||||
|
||||
window.clear();
|
||||
window.display();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Expected behavior
|
||||
|
||||
Tell us what should happen
|
||||
|
||||
## Actual behavior
|
||||
|
||||
Tell us what happens instead
|
51
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
Thanks a lot for making a contribution to SFML! 🙂
|
||||
|
||||
Before you create the pull request, we ask you to check the follow boxes. (For small changes not everything needs to ticked, but the more the better!)
|
||||
|
||||
* [ ] Has this change been discussed on [the forum](https://en.sfml-dev.org/forums/index.php#c3) or in an issue before?
|
||||
* [ ] Does the code follow the SFML [Code Style Guide](https://www.sfml-dev.org/style.php)?
|
||||
* [ ] Have you provided some example/test code for your changes?
|
||||
* [ ] If you have additional steps which need to be performed list them as tasks!
|
||||
|
||||
----
|
||||
|
||||
## Description
|
||||
|
||||
Please describe your pull request.
|
||||
|
||||
This PR is related to the issue #
|
||||
|
||||
## Tasks
|
||||
|
||||
* [ ] Tested on Linux
|
||||
* [ ] Tested on Windows
|
||||
* [ ] Tested on macOS
|
||||
* [ ] Tested on iOS
|
||||
* [ ] Tested on Android
|
||||
|
||||
## How to test this PR?
|
||||
|
||||
Describe how to best test these changes. Please provide a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve) if possible, you can use the follow template as a start:
|
||||
|
||||
```cpp
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
sf::RenderWindow window(sf::VideoMode(1280, 720), "Minimal, complete and verifiable example");
|
||||
window.setFramerateLimit(60);
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
}
|
||||
|
||||
window.clear();
|
||||
window.display();
|
||||
}
|
||||
}
|
||||
```
|
55
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{ matrix.platform.name }} ${{ matrix.config.name }}
|
||||
runs-on: ${{ matrix.platform.os }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
platform:
|
||||
- { name: Windows VS2017, os: windows-2016 }
|
||||
- { name: Windows VS2019, os: windows-latest }
|
||||
- { name: Linux GCC, os: ubuntu-latest }
|
||||
- { name: Linux Clang, os: ubuntu-latest, flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ }
|
||||
- { name: MacOS XCode, os: macos-latest }
|
||||
config:
|
||||
- { name: Shared, flags: -DBUILD_SHARED_LIBS=TRUE }
|
||||
- { name: Static, flags: -DBUILD_SHARED_LIBS=FALSE }
|
||||
|
||||
include:
|
||||
- platform: { name: MacOS XCode, os: macos-latest }
|
||||
config: { name: Frameworks, flags: -DSFML_BUILD_FRAMEWORKS=TRUE }
|
||||
- platform: { name: MacOS XCode, os: macos-latest }
|
||||
config: { name: iOS, flags: -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/cmake/toolchains/iOS.toolchain.cmake -DIOS_PLATFORM=SIMULATOR }
|
||||
- platform: { name: Android, os: ubuntu-latest }
|
||||
config: { name: x86, flags: -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_SYSTEM_NAME=Android -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$GITHUB_WORKSPACE/android-ndk-r18b -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_ANDROID_STL_TYPE=c++_shared -DCMAKE_ANDROID_API=26 }
|
||||
- platform: { name: Android, os: ubuntu-latest }
|
||||
config: { name: armeabi-v7a, flags: -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_SYSTEM_NAME=Android -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$GITHUB_WORKSPACE/android-ndk-r18b -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_ANDROID_STL_TYPE=c++_shared -DCMAKE_ANDROID_API=26 }
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Linux Dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get install libxrandr-dev libxcursor-dev libudev-dev libopenal-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev
|
||||
|
||||
|
||||
- name: Install Android Components
|
||||
if: matrix.platform.name == 'Android'
|
||||
run: |
|
||||
echo "y" | /usr/local/lib/android/sdk/tools/bin/sdkmanager --install "cmake;3.10.2.4988404" --sdk_root=ANDROID_SDK_ROOT
|
||||
sudo ln -sf /usr/local/lib/android/sdk/cmake/3.10.2.4988404/bin/cmake /usr/bin/cmake
|
||||
wget -nv https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip -P $GITHUB_WORKSPACE
|
||||
unzip -qq -d $GITHUB_WORKSPACE android-ndk-r18b-linux-x86_64.zip
|
||||
|
||||
|
||||
- name: Configure CMake
|
||||
shell: bash
|
||||
run: cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install -DSFML_BUILD_EXAMPLES=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON -DSFML_BUILD_TEST_SUITE=TRUE ${{matrix.platform.flags}} ${{matrix.config.flags}}
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: cmake --build $GITHUB_WORKSPACE/build --config Release --target install
|
138
.travis.yml
|
@ -1,10 +1,134 @@
|
|||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
addons:
|
||||
apt_packages:
|
||||
- cmake
|
||||
- libxrandr-dev
|
||||
- libxcursor-dev
|
||||
- libudev-dev
|
||||
- libopenal-dev
|
||||
- libflac-dev
|
||||
- libvorbis-dev
|
||||
- g++
|
||||
- clang
|
||||
- libgl1-mesa-dev
|
||||
|
||||
before_script:
|
||||
- sudo apt-get install libpthread-stubs0-dev libgl1-mesa-dev libx11-dev
|
||||
- sudo apt-get install libxrandr-dev libfreetype6-dev libglew1.5-dev
|
||||
- sudo apt-get install libjpeg8-dev libgpgme11-dev libsndfile1-dev libopenal-dev
|
||||
- cmake .
|
||||
- mkdir build && cd build
|
||||
- cmake .. $CMAKE_FLAGS -DCMAKE_INSTALL_PREFIX=../install -DSFML_BUILD_EXAMPLES=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON
|
||||
|
||||
script:
|
||||
- make -j4
|
||||
- cmake --build . --target install
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
||||
- name: "Linux gcc Dynamic"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc
|
||||
env:
|
||||
- CMAKE_FLAGS="-DSFML_BUILD_TEST_SUITE=TRUE"
|
||||
|
||||
- name: "Linux gcc Static"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc
|
||||
env:
|
||||
- CMAKE_FLAGS="-DBUILD_SHARED_LIBS=FALSE -DSFML_BUILD_TEST_SUITE=TRUE"
|
||||
|
||||
- name: "Linux clang Dynamic"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env:
|
||||
- CMAKE_FLAGS="-DSFML_BUILD_TEST_SUITE=TRUE"
|
||||
|
||||
- name: "Linux clang Static"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env:
|
||||
- CMAKE_FLAGS="-DBUILD_SHARED_LIBS=FALSE -DSFML_BUILD_TEST_SUITE=TRUE"
|
||||
|
||||
- name: "macOS Xcode 10 Dynamic"
|
||||
os: osx
|
||||
osx_image: xcode10
|
||||
env:
|
||||
- CMAKE_FLAGS="-DSFML_BUILD_TEST_SUITE=TRUE"
|
||||
|
||||
- name: "macOS Xcode 10 Frameworks"
|
||||
os: osx
|
||||
osx_image: xcode10
|
||||
env:
|
||||
- CMAKE_FLAGS="-DSFML_BUILD_TEST_SUITE=TRUE -DSFML_BUILD_FRAMEWORKS=TRUE"
|
||||
|
||||
- name: "macOS Xcode 10 Static"
|
||||
os: osx
|
||||
osx_image: xcode10
|
||||
env:
|
||||
- CMAKE_FLAGS="-DSFML_BUILD_TEST_SUITE=TRUE -DBUILD_SHARED_LIBS=FALSE"
|
||||
|
||||
- name: "iOS Xcode 10"
|
||||
os: osx
|
||||
osx_image: xcode10
|
||||
env:
|
||||
- CMAKE_FLAGS="-GXcode -DSFML_BUILD_TEST_SUITE=TRUE -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/iOS.toolchain.cmake -DIOS_PLATFORM=SIMULATOR"
|
||||
|
||||
- name: "Visual Studio 15 2017 Dynamic"
|
||||
os: windows
|
||||
env:
|
||||
- CMAKE_FLAGS="-DSFML_BUILD_TEST_SUITE=FALSE"
|
||||
|
||||
- name: "Visual Studio 15 2017 Static"
|
||||
os: windows
|
||||
env:
|
||||
- CMAKE_FLAGS="-DBUILD_SHARED_LIBS=FALSE -DSFML_BUILD_TEST_SUITE=TRUE"
|
||||
|
||||
- name: "Visual Studio 16 2019 Dynamic"
|
||||
os: windows
|
||||
env:
|
||||
- CMAKE_FLAGS="-DSFML_BUILD_TEST_SUITE=FALSE"
|
||||
- MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
|
||||
- VS160COMNTOOLS="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools"
|
||||
- PATH=$MSBUILD_PATH:$PATH
|
||||
install:
|
||||
- choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
|
||||
- choco install visualstudio2019-workload-nativedesktop
|
||||
|
||||
- name: "Visual Studio 16 2019 Static"
|
||||
os: windows
|
||||
env:
|
||||
- CMAKE_FLAGS="-DBUILD_SHARED_LIBS=FALSE -DSFML_BUILD_TEST_SUITE=TRUE"
|
||||
- MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
|
||||
- VS160COMNTOOLS="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools"
|
||||
- PATH=$MSBUILD_PATH:$PATH
|
||||
install:
|
||||
- choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
|
||||
- choco install visualstudio2019-workload-nativedesktop
|
||||
|
||||
- name: "Android armeabi-v7a"
|
||||
language: android
|
||||
android: &androidComponents
|
||||
components:
|
||||
- tools
|
||||
- platform-tools
|
||||
- build-tools-26.0.1
|
||||
env:
|
||||
- CMAKE_FLAGS="-DCMAKE_SYSTEM_NAME=Android -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$TRAVIS_BUILD_DIR/android-ndk-r18b -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_ANDROID_STL_TYPE=c++_shared -DCMAKE_ANDROID_API=26"
|
||||
|
||||
install: &androidInstall
|
||||
- echo y | sdkmanager "cmake;3.10.2.4988404"
|
||||
- sudo ln -sf /usr/local/android-sdk/cmake/3.10.2.4988404/bin/cmake /usr/bin/cmake
|
||||
- wget https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip
|
||||
- unzip -qq android-ndk-r18b-linux-x86_64.zip
|
||||
|
||||
- name: "Android x86"
|
||||
language: android
|
||||
android: *androidComponents
|
||||
env:
|
||||
- CMAKE_FLAGS="-DCMAKE_SYSTEM_NAME=Android -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$TRAVIS_BUILD_DIR/android-ndk-r18b -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_ANDROID_STL_TYPE=c++_shared -DCMAKE_ANDROID_API=26"
|
||||
install: *androidInstall
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
|
734
CMakeLists.txt
|
@ -1,208 +1,526 @@
|
|||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
# define a macro that helps defining an option
|
||||
macro(sfml_set_option var default type docstring)
|
||||
if(NOT DEFINED ${var})
|
||||
set(${var} ${default})
|
||||
endif()
|
||||
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
|
||||
endmacro()
|
||||
|
||||
# set a default build type if none was provided
|
||||
# this has to be done before the project() instruction!
|
||||
sfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)")
|
||||
|
||||
# project name
|
||||
project(SFML)
|
||||
|
||||
# include the configuration file
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake)
|
||||
|
||||
# setup version numbers
|
||||
set(VERSION_MAJOR 2)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_PATCH 0)
|
||||
|
||||
# add the SFML header path
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
# add an option for choosing the build type (shared or static)
|
||||
sfml_set_option(BUILD_SHARED_LIBS TRUE BOOL "TRUE to build SFML as shared libraries, FALSE to build it as static libraries")
|
||||
|
||||
# add an option for building the examples
|
||||
sfml_set_option(SFML_BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them")
|
||||
|
||||
# add an option for building the API documentation
|
||||
sfml_set_option(SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
|
||||
|
||||
# Mac OS X specific options
|
||||
if(MACOSX)
|
||||
# add an option to build frameworks instead of dylibs (release only)
|
||||
sfml_set_option(SFML_BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
|
||||
|
||||
# add an option to let the user specify a custom directory for frameworks installation (SFML, sndfile, ...)
|
||||
sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory")
|
||||
|
||||
# add an option to automatically install Xcode 4 templates
|
||||
sfml_set_option(SFML_INSTALL_XCODE4_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode 4 templates, FALSE to do nothing about it")
|
||||
endif()
|
||||
|
||||
# define SFML_STATIC if the build type is not set to 'shared'
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
add_definitions(-DSFML_STATIC)
|
||||
endif()
|
||||
|
||||
# remove SL security warnings with Visual C++
|
||||
if(COMPILER_MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
endif()
|
||||
|
||||
# define an option for choosing between static and dynamic C runtime (Windows only)
|
||||
if(WINDOWS)
|
||||
sfml_set_option(SFML_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")
|
||||
|
||||
# the following combination of flags is not valid
|
||||
if (BUILD_SHARED_LIBS AND SFML_USE_STATIC_STD_LIBS)
|
||||
message(FATAL_ERROR "BUILD_SHARED_LIBS and SFML_USE_STATIC_STD_LIBS cannot be used together")
|
||||
endif()
|
||||
|
||||
# for VC++, we can apply it globally by modifying the compiler flags
|
||||
if(COMPILER_MSVC AND SFML_USE_STATIC_STD_LIBS)
|
||||
foreach(flag
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# disable the rpath stuff
|
||||
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
||||
|
||||
# setup Mac OS X stuff
|
||||
if(MACOSX)
|
||||
# SFML_BUILD_FRAMEWORKS needs two things :
|
||||
# first, it's available only for release
|
||||
# (because cmake currently doesn't allow specifying a custom framework name so XXX-d is not possible)
|
||||
# secondly, it works only with BUILD_SHARED_LIBS enabled
|
||||
if(SFML_BUILD_FRAMEWORKS)
|
||||
# requirement #1
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
message(FATAL_ERROR "CMAKE_BUILD_TYPE should be \"Release\" when SFML_BUILD_FRAMEWORKS is TRUE")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# requirement #2
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when SFML_BUILD_FRAMEWORKS is TRUE")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LINUX)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
sfml_set_option(SFML_INSTALL_PKGCONFIG_FILES TRUE BOOL "TRUE to automatically install pkg-config files so other projects can find SFML")
|
||||
if(SFML_INSTALL_PKGCONFIG_FILES)
|
||||
foreach(sfml_module IN ITEMS all system window graphics audio network)
|
||||
CONFIGURE_FILE(
|
||||
"tools/pkg-config/sfml-${sfml_module}.pc.in"
|
||||
"tools/pkg-config/sfml-${sfml_module}.pc"
|
||||
@ONLY)
|
||||
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfml-${sfml_module}.pc"
|
||||
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig")
|
||||
endforeach()
|
||||
endif()
|
||||
else()
|
||||
if(SFML_INSTALL_PKGCONFIG_FILES)
|
||||
message(WARNING "No pkg-config files are provided for the static SFML libraries (SFML_INSTALL_PKGCONFIG_FILES will be ignored).")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# enable project folders
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
|
||||
|
||||
# add the subdirectories
|
||||
add_subdirectory(src/SFML)
|
||||
if(SFML_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
if(SFML_BUILD_DOC)
|
||||
add_subdirectory(doc)
|
||||
endif()
|
||||
|
||||
# setup the install rules
|
||||
if(NOT SFML_BUILD_FRAMEWORKS)
|
||||
install(DIRECTORY include
|
||||
DESTINATION .
|
||||
COMPONENT devel
|
||||
PATTERN ".svn" EXCLUDE)
|
||||
else()
|
||||
# find only "root" headers
|
||||
file(GLOB SFML_HEADERS RELATIVE ${PROJECT_SOURCE_DIR} "include/SFML/*")
|
||||
|
||||
# in fact we have to fool cmake to copy all the headers in subdirectories
|
||||
# to do that we have to add the "root" headers to the PUBLIC_HEADER
|
||||
# then we can run a post script to copy the remaining headers
|
||||
|
||||
# we need a dummy file in order to compile the framework
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
|
||||
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
||||
|
||||
set(SFML_SOURCES ${SFML_HEADERS})
|
||||
list(APPEND SFML_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
||||
|
||||
# create SFML.framework
|
||||
add_library(SFML ${SFML_SOURCES})
|
||||
|
||||
# edit target properties
|
||||
set_target_properties(SFML PROPERTIES
|
||||
FRAMEWORK TRUE
|
||||
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.SFML
|
||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
PUBLIC_HEADER "${SFML_HEADERS}")
|
||||
|
||||
# add the remaining headers
|
||||
add_custom_command(TARGET SFML
|
||||
POST_BUILD
|
||||
COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* SFML.framework/Versions/${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}/Headers)
|
||||
|
||||
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
|
||||
# NOTE : it's not required to link agains SFML.framework
|
||||
set_target_properties(SFML PROPERTIES
|
||||
BUILD_WITH_INSTALL_RPATH 1
|
||||
INSTALL_NAME_DIR "@executable_path/../Frameworks")
|
||||
|
||||
# install rule
|
||||
install(TARGETS SFML
|
||||
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}
|
||||
COMPONENT devel)
|
||||
endif()
|
||||
|
||||
install(FILES cmake/Modules/FindSFML.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules)
|
||||
install(FILES license.txt DESTINATION ${INSTALL_MISC_DIR})
|
||||
install(FILES readme.txt DESTINATION ${INSTALL_MISC_DIR})
|
||||
|
||||
if(WINDOWS)
|
||||
if(ARCH_32BITS)
|
||||
install(FILES extlibs/bin/x86/libsndfile-1.dll DESTINATION bin)
|
||||
install(FILES extlibs/bin/x86/openal32.dll DESTINATION bin)
|
||||
elseif(ARCH_64BITS)
|
||||
install(FILES extlibs/bin/x64/libsndfile-1.dll DESTINATION bin)
|
||||
install(FILES extlibs/bin/x64/openal32.dll DESTINATION bin)
|
||||
endif()
|
||||
elseif(MACOSX)
|
||||
install(DIRECTORY extlibs/libs-osx/Frameworks/sndfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
||||
install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
||||
|
||||
if(SFML_INSTALL_XCODE4_TEMPLATES)
|
||||
install(DIRECTORY tools/xcode/templates/SFML DESTINATION /Library/Developer/Xcode/Templates)
|
||||
endif()
|
||||
endif()
|
||||
# CMake's built-in Android support requires 3.7.0
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Android")
|
||||
cmake_minimum_required(VERSION 3.7.2)
|
||||
else()
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
endif()
|
||||
|
||||
# define a macro that helps defining an option
|
||||
macro(sfml_set_option var default type docstring)
|
||||
if(NOT DEFINED ${var})
|
||||
set(${var} ${default})
|
||||
endif()
|
||||
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
|
||||
endmacro()
|
||||
|
||||
# these options have to be set before CMake detects/configures the toolchain
|
||||
|
||||
# determine whether to create a debug or release build
|
||||
sfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)")
|
||||
|
||||
# Suppress Cygwin legacy warning
|
||||
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
|
||||
|
||||
# Suppress Mac OS X RPATH warnings and adopt new related behaviors
|
||||
cmake_policy(SET CMP0042 NEW)
|
||||
if (NOT CMAKE_VERSION VERSION_LESS 3.9)
|
||||
cmake_policy(SET CMP0068 NEW)
|
||||
endif()
|
||||
|
||||
# add some default value for some additional macOS variable
|
||||
# note that those variables are ignored on other systems
|
||||
if(NOT CMAKE_OSX_ARCHITECTURES)
|
||||
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "macOS architecture to build; 64-bit is expected" FORCE)
|
||||
endif()
|
||||
if(NOT CMAKE_OSX_SYSROOT)
|
||||
# query the path to the default SDK, will fail on non-macOS, but it's okay.
|
||||
execute_process(COMMAND xcodebuild -sdk macosx -version Path
|
||||
COMMAND head -n 1
|
||||
COMMAND tr -d '\n'
|
||||
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
|
||||
ERROR_QUIET)
|
||||
endif()
|
||||
|
||||
# project name
|
||||
project(SFML)
|
||||
|
||||
# include the configuration file
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake)
|
||||
|
||||
# we use the paths from the cmake GNUInstallDirs module as defaults
|
||||
# you can override these if you like
|
||||
# https://cmake.org/cmake/help/v3.0/module/GNUInstallDirs.html
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# setup version numbers
|
||||
set(VERSION_MAJOR 2)
|
||||
set(VERSION_MINOR 5)
|
||||
set(VERSION_PATCH 1)
|
||||
|
||||
# add an option for choosing the build type (shared or static)
|
||||
if(NOT (SFML_OS_IOS OR SFML_OS_ANDROID))
|
||||
sfml_set_option(BUILD_SHARED_LIBS TRUE BOOL "TRUE to build SFML as shared libraries, FALSE to build it as static libraries")
|
||||
else()
|
||||
if(SFML_OS_IOS)
|
||||
set(BUILD_SHARED_LIBS FALSE)
|
||||
elseif(SFML_OS_ANDROID)
|
||||
set(BUILD_SHARED_LIBS TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# add an option for building the examples
|
||||
if(NOT SFML_OS_ANDROID)
|
||||
sfml_set_option(SFML_BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them")
|
||||
else()
|
||||
set(SFML_BUILD_EXAMPLES FALSE)
|
||||
endif()
|
||||
|
||||
# add options to select which modules to build
|
||||
sfml_set_option(SFML_BUILD_WINDOW TRUE BOOL "TRUE to build SFML's Window module. This setting is ignored, if the graphics module is built.")
|
||||
sfml_set_option(SFML_BUILD_GRAPHICS TRUE BOOL "TRUE to build SFML's Graphics module.")
|
||||
sfml_set_option(SFML_BUILD_AUDIO TRUE BOOL "TRUE to build SFML's Audio module.")
|
||||
sfml_set_option(SFML_BUILD_NETWORK TRUE BOOL "TRUE to build SFML's Network module.")
|
||||
|
||||
# add an option for building the API documentation
|
||||
sfml_set_option(SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
|
||||
|
||||
# add an option for choosing the OpenGL implementation
|
||||
if(SFML_BUILD_WINDOW)
|
||||
sfml_set_option(SFML_OPENGL_ES ${OPENGL_ES} BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation")
|
||||
endif()
|
||||
|
||||
# add an option for building the test suite
|
||||
sfml_set_option(SFML_BUILD_TEST_SUITE FALSE BOOL "TRUE to build the SFML test suite, FALSE to ignore it")
|
||||
|
||||
# macOS specific options
|
||||
if(SFML_OS_MACOSX)
|
||||
# add an option to build frameworks instead of dylibs (release only)
|
||||
sfml_set_option(SFML_BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
|
||||
|
||||
# add an option to automatically install Xcode templates
|
||||
sfml_set_option(SFML_INSTALL_XCODE_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode templates, FALSE to do nothing about it. The templates are compatible with Xcode 4 and 5.")
|
||||
endif()
|
||||
|
||||
# iOS specific options
|
||||
if(SFML_OS_IOS)
|
||||
# At the moment the minimal deployement target version is 10.2 only because the externals for iOS were built with that requirement.
|
||||
sfml_set_option(SFML_IOS_DEPLOYMENT_TARGET "10.2" STRING "The minimal iOS version that will be able to run the built binaries. Cannot be lower than 10.2.")
|
||||
|
||||
sfml_set_option(SFML_CODE_SIGN_IDENTITY "iPhone Developer" STRING "The code signing identity to use when building for a real device")
|
||||
endif()
|
||||
|
||||
# Android options
|
||||
if(SFML_OS_ANDROID)
|
||||
# make sure there's the android library available
|
||||
if (CMAKE_ANDROID_API LESS 14)
|
||||
message(FATAL_ERROR "Android API level (${CMAKE_ANDROID_API}) must be equal or greater than 14.")
|
||||
endif()
|
||||
|
||||
# CMake doesn't support defining the STL to be used with Nsight Tegra, so warn the user
|
||||
if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
|
||||
message(WARNING "CMake might not properly support setting the STL. Make sure to adjust all generated library projects!")
|
||||
endif()
|
||||
|
||||
# install everything in $NDK/sources/ because this path is appended by the NDK (convenient)
|
||||
set(CMAKE_INSTALL_PREFIX ${CMAKE_ANDROID_NDK}/sources/third_party/sfml)
|
||||
|
||||
# we install libs in a subdirectory named after the ABI
|
||||
set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${CMAKE_ANDROID_ARCH_ABI}")
|
||||
# pass shared STL configuration (if any)
|
||||
if (CMAKE_ANDROID_STL_TYPE MATCHES "_shared")
|
||||
add_definitions("-DSTL_LIBRARY=${CMAKE_ANDROID_STL_TYPE}")
|
||||
# if(NOT CMAKE_ANDROID_STL_TYPE MATCHES "c\\+\\+_shared")
|
||||
# message("Android: Using ${CMAKE_ANDROID_STL_TYPE} as STL. Set CMAKE_ANDROID_STL_TYPE to c++_shared, if there are any issues.")
|
||||
# endif()
|
||||
else()
|
||||
# message(WARNING "Android: You're using a static STL (${CMAKE_ANDROID_STL_TYPE}). Set CMAKE_ANDROID_STL_TYPE to c++_shared, if there are any issues.")
|
||||
endif()
|
||||
|
||||
# let the user switch ABIs
|
||||
set(ANDROID_ABI "armeabi-v7a" CACHE STRING "Look at the NDK docs for currently supported ABIs")
|
||||
|
||||
# this is a workaround to compile sfml-activity without the stl library as a dependency
|
||||
# we save the original compilation command line to restore it later in Macro.cmake
|
||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITH_STL ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
|
||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STL "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
||||
endif()
|
||||
|
||||
# Install directories
|
||||
# For miscellaneous files
|
||||
if(SFML_OS_WINDOWS OR SFML_OS_IOS)
|
||||
set(DEFAULT_INSTALL_MISC_DIR .)
|
||||
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD)
|
||||
set(DEFAULT_INSTALL_MISC_DIR share/SFML)
|
||||
elseif(SFML_OS_MACOSX)
|
||||
set(DEFAULT_INSTALL_MISC_DIR /usr/local/share/SFML)
|
||||
elseif(SFML_OS_ANDROID)
|
||||
set(DEFAULT_INSTALL_MISC_DIR ${CMAKE_ANDROID_NDK}/sources/third_party/sfml)
|
||||
endif()
|
||||
|
||||
# force building sfml-window, if sfml-graphics module is built
|
||||
if(SFML_BUILD_GRAPHICS AND NOT SFML_BUILD_WINDOW)
|
||||
message(WARNING "You're trying to build SFML's Graphics module without the Window module. Forcing building of the Window module as a dependency.")
|
||||
set(SFML_BUILD_WINDOW TRUE)
|
||||
endif()
|
||||
|
||||
# allow not using bundled dependencies with a switch
|
||||
# (except for stb_image)
|
||||
# yes this is horrible, but GLOB_RECURSE sucks
|
||||
sfml_set_option(SFML_USE_SYSTEM_DEPS FALSE BOOL "TRUE to use system dependencies, FALSE to use the bundled ones.")
|
||||
if(SFML_USE_SYSTEM_DEPS)
|
||||
if(SFML_INSTALL_XCODE_TEMPLATES)
|
||||
message(FATAL_ERROR "XCode templates installation cannot be used with the SFML_USE_SYSTEM_DEPS option (the bundled frameworks are required.)")
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE DEP_LIBS "${CMAKE_SOURCE_DIR}/extlibs/libs*/*")
|
||||
file(GLOB_RECURSE DEP_BINS "${CMAKE_SOURCE_DIR}/extlibs/bin*/*")
|
||||
file(GLOB_RECURSE DEP_HEADERS "${CMAKE_SOURCE_DIR}/extlibs/headers/*")
|
||||
|
||||
foreach(DEP_FILE ${DEP_LIBS} ${DEP_BINS} ${DEP_HEADERS})
|
||||
get_filename_component(DEP_DIR ${DEP_FILE} PATH)
|
||||
|
||||
if(NOT DEP_DIR MATCHES "/stb_image(/|$)")
|
||||
set(CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH} ${DEP_DIR})
|
||||
endif()
|
||||
|
||||
get_filename_component(DEP_PARENT_DIR ${DEP_DIR} PATH)
|
||||
while(NOT DEP_PARENT_DIR STREQUAL "${CMAKE_SOURCE_DIR}/extlibs")
|
||||
if(NOT DEP_DIR MATCHES "/stb_image(/|$)")
|
||||
set(CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH} ${DEP_PARENT_DIR})
|
||||
endif()
|
||||
|
||||
get_filename_component(DEP_PARENT_DIR ${DEP_PARENT_DIR} PATH)
|
||||
endwhile()
|
||||
endforeach()
|
||||
|
||||
list(REMOVE_DUPLICATES CMAKE_IGNORE_PATH)
|
||||
endif()
|
||||
|
||||
# Visual C++: remove warnings regarding SL security and algorithms on pointers
|
||||
if(SFML_COMPILER_MSVC)
|
||||
# add an option to choose whether PDB debug symbols should be generated (defaults to true when possible)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.1)
|
||||
sfml_set_option(SFML_GENERATE_PDB FALSE BOOL "True to generate PDB debug symbols, FALSE otherwise. Requires CMake 3.1.")
|
||||
if(SFML_GENERATE_PDB)
|
||||
message(FATAL_ERROR "Generation of PDB files (SFML_GENERATE_PDB) requires at least CMake 3.1.0")
|
||||
endif()
|
||||
else()
|
||||
sfml_set_option(SFML_GENERATE_PDB TRUE BOOL "True to generate PDB debug symbols, FALSE otherwise. Requires CMake 3.1.")
|
||||
endif()
|
||||
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
# define SFML_OPENGL_ES if needed
|
||||
if(SFML_OPENGL_ES)
|
||||
add_definitions(-DSFML_OPENGL_ES)
|
||||
add_definitions(-DGL_GLEXT_PROTOTYPES)
|
||||
endif()
|
||||
|
||||
# define an option for choosing between static and dynamic C runtime (Windows only)
|
||||
if(SFML_OS_WINDOWS)
|
||||
sfml_set_option(SFML_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")
|
||||
|
||||
# the following combination of flags is not valid
|
||||
if (BUILD_SHARED_LIBS AND SFML_USE_STATIC_STD_LIBS)
|
||||
message(FATAL_ERROR "BUILD_SHARED_LIBS and SFML_USE_STATIC_STD_LIBS cannot be used together")
|
||||
endif()
|
||||
|
||||
# for VC++, we can apply it globally by modifying the compiler flags
|
||||
if(SFML_COMPILER_MSVC AND SFML_USE_STATIC_STD_LIBS)
|
||||
foreach(flag
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# setup Mac OS X stuff
|
||||
if(SFML_OS_MACOSX)
|
||||
# SFML_BUILD_FRAMEWORKS needs two things:
|
||||
# first, it's available only for release
|
||||
# (because cmake currently doesn't allow specifying a custom framework name so XXX-d is not possible)
|
||||
# secondly, it works only with BUILD_SHARED_LIBS enabled
|
||||
if(SFML_BUILD_FRAMEWORKS)
|
||||
# requirement #1
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
message(FATAL_ERROR "CMAKE_BUILD_TYPE should be \"Release\" when SFML_BUILD_FRAMEWORKS is TRUE")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# requirement #2
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when SFML_BUILD_FRAMEWORKS is TRUE")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# only the default architecture (i.e. 64-bit) is supported
|
||||
if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
|
||||
message(FATAL_ERROR "Only 64-bit architecture is supported")
|
||||
endif()
|
||||
|
||||
# configure Xcode templates
|
||||
set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)")
|
||||
endif()
|
||||
|
||||
# enable project folders
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
|
||||
|
||||
# add the subdirectories
|
||||
add_subdirectory(src/SFML)
|
||||
if(SFML_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
if(SFML_BUILD_DOC)
|
||||
add_subdirectory(doc)
|
||||
endif()
|
||||
if(SFML_BUILD_TEST_SUITE)
|
||||
if (SFML_OS_IOS)
|
||||
message( WARNING "Unit testing not supported on iOS")
|
||||
else()
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# on Linux and BSD-like OS, install pkg-config files by default
|
||||
set(SFML_INSTALL_PKGCONFIG_DEFAULT FALSE)
|
||||
|
||||
if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD)
|
||||
set(SFML_INSTALL_PKGCONFIG_DEFAULT TRUE)
|
||||
endif()
|
||||
|
||||
sfml_set_option(SFML_INSTALL_PKGCONFIG_FILES ${SFML_INSTALL_PKGCONFIG_DEFAULT} BOOL "TRUE to automatically install pkg-config files so other projects can find SFML")
|
||||
|
||||
if(SFML_INSTALL_PKGCONFIG_FILES)
|
||||
sfml_set_option(SFML_PKGCONFIG_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/${SFML_PKGCONFIG_DIR}" PATH "Install directory for SFML's pkg-config .pc files")
|
||||
|
||||
foreach(sfml_module IN ITEMS all system window graphics audio network)
|
||||
CONFIGURE_FILE(
|
||||
"tools/pkg-config/sfml-${sfml_module}.pc.in"
|
||||
"tools/pkg-config/sfml-${sfml_module}.pc"
|
||||
@ONLY)
|
||||
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfml-${sfml_module}.pc"
|
||||
DESTINATION "${SFML_PKGCONFIG_INSTALL_PREFIX}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# setup the install rules
|
||||
if(NOT SFML_BUILD_FRAMEWORKS)
|
||||
install(DIRECTORY include
|
||||
DESTINATION .
|
||||
COMPONENT devel
|
||||
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl")
|
||||
|
||||
if(SFML_GENERATE_PDB)
|
||||
install(DIRECTORY ${PROJECT_BINARY_DIR}/lib
|
||||
DESTINATION .
|
||||
COMPONENT devel
|
||||
FILES_MATCHING PATTERN "*.pdb")
|
||||
endif()
|
||||
else()
|
||||
# find only "root" headers
|
||||
file(GLOB SFML_HEADERS RELATIVE ${PROJECT_SOURCE_DIR} "include/SFML/*")
|
||||
|
||||
# in fact we have to fool cmake to copy all the headers in subdirectories
|
||||
# to do that we have to add the "root" headers to the PUBLIC_HEADER
|
||||
# then we can run a post script to copy the remaining headers
|
||||
|
||||
# we need a dummy file in order to compile the framework
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
|
||||
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
||||
|
||||
set(SFML_SOURCES ${SFML_HEADERS})
|
||||
list(APPEND SFML_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
||||
|
||||
# create SFML.framework
|
||||
add_library(SFML ${SFML_SOURCES})
|
||||
|
||||
# set the target flags to use the appropriate C++ standard library
|
||||
sfml_set_stdlib(SFML)
|
||||
|
||||
# edit target properties
|
||||
set_target_properties(SFML PROPERTIES
|
||||
FRAMEWORK TRUE
|
||||
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.SFML
|
||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
PUBLIC_HEADER "${SFML_HEADERS}")
|
||||
|
||||
# add the non-optional SFML headers
|
||||
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Config.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/OpenGL.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/GpuPreference.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/System.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Main.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/System
|
||||
$<TARGET_FILE_DIR:SFML>/Headers)
|
||||
|
||||
# add window module headers if enabled
|
||||
if(SFML_BUILD_WINDOW)
|
||||
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Window.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Window
|
||||
$<TARGET_FILE_DIR:SFML>/Headers)
|
||||
endif()
|
||||
|
||||
# add network module headers if enabled
|
||||
if(SFML_BUILD_NETWORK)
|
||||
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Network.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Network
|
||||
$<TARGET_FILE_DIR:SFML>/Headers)
|
||||
endif()
|
||||
|
||||
# add graphics module headers if enabled
|
||||
if(SFML_BUILD_GRAPHICS)
|
||||
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Graphics.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Graphics
|
||||
$<TARGET_FILE_DIR:SFML>/Headers)
|
||||
endif()
|
||||
|
||||
# add audio module headers if enabled
|
||||
if(SFML_BUILD_AUDIO)
|
||||
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Audio.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/SFML/Audio
|
||||
$<TARGET_FILE_DIR:SFML>/Headers)
|
||||
endif()
|
||||
|
||||
# adapt install directory to allow distributing dylibs/frameworks in user's frameworks/application bundle
|
||||
# NOTE: it's not required to link against SFML.framework
|
||||
set_target_properties(SFML PROPERTIES INSTALL_NAME_DIR "@rpath")
|
||||
if(NOT CMAKE_SKIP_BUILD_RPATH)
|
||||
if (CMAKE_VERSION VERSION_LESS 3.9)
|
||||
set_target_properties(${target} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
else()
|
||||
set_target_properties(${target} PROPERTIES BUILD_WITH_INSTALL_NAME_DIR TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# install rule
|
||||
install(TARGETS SFML
|
||||
FRAMEWORK DESTINATION "."
|
||||
COMPONENT devel)
|
||||
endif()
|
||||
|
||||
install(FILES license.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
||||
install(FILES readme.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
||||
|
||||
# install 3rd-party libraries and tools
|
||||
if(SFML_OS_WINDOWS)
|
||||
|
||||
if(NOT SFML_USE_SYSTEM_DEPS)
|
||||
# install the binaries of SFML dependencies
|
||||
if(ARCH_32BITS)
|
||||
install(DIRECTORY extlibs/bin/x86/ DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
if(SFML_COMPILER_MSVC AND SFML_MSVC_VERSION LESS 14)
|
||||
install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
elseif(SFML_COMPILER_MSVC)
|
||||
install(DIRECTORY extlibs/libs-msvc-universal/x86/ DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
else()
|
||||
install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
elseif(ARCH_64BITS)
|
||||
install(DIRECTORY extlibs/bin/x64/ DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
if(SFML_COMPILER_MSVC AND SFML_MSVC_VERSION LESS 14)
|
||||
install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
elseif(SFML_COMPILER_MSVC)
|
||||
install(DIRECTORY extlibs/libs-msvc-universal/x64/ DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
else()
|
||||
install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
elseif(SFML_OS_MACOSX)
|
||||
# install extlibs dependencies only when used
|
||||
if(SFML_BUILD_GRAPHICS)
|
||||
if(FREETYPE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/freetype.framework")
|
||||
install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SFML_BUILD_AUDIO)
|
||||
if(FLAC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/FLAC.framework")
|
||||
install(DIRECTORY extlibs/libs-osx/Frameworks/FLAC.framework DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
if(OGG_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/ogg.framework")
|
||||
install(DIRECTORY extlibs/libs-osx/Frameworks/ogg.framework DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
if(VORBIS_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbis.framework")
|
||||
install(DIRECTORY extlibs/libs-osx/Frameworks/vorbis.framework DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
if(VORBISENC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisenc.framework")
|
||||
install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisenc.framework DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
if(VORBISFILE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisfile.framework")
|
||||
install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisfile.framework DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
if(OPENAL_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/OpenAL.framework")
|
||||
install(DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# install the Xcode templates if requested
|
||||
if(SFML_INSTALL_XCODE_TEMPLATES)
|
||||
# configure the templates plist files
|
||||
foreach(TEMPLATE "SFML Compiler" "SFML App")
|
||||
configure_file(
|
||||
"tools/xcode/templates/SFML/${TEMPLATE}.xctemplate/TemplateInfo.plist.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/tools/xcode/templates/SFML/${TEMPLATE}.xctemplate/TemplateInfo.plist"
|
||||
@ONLY)
|
||||
endforeach()
|
||||
install(DIRECTORY "tools/xcode/templates/SFML" "${CMAKE_CURRENT_BINARY_DIR}/tools/xcode/templates/SFML"
|
||||
DESTINATION /Library/Developer/Xcode/Templates
|
||||
PATTERN "*.in" EXCLUDE
|
||||
PATTERN ".DS_Store" EXCLUDE)
|
||||
endif()
|
||||
|
||||
elseif(SFML_OS_IOS)
|
||||
|
||||
# fix CMake install rules broken for iOS (see http://public.kitware.com/Bug/view.php?id=12506)
|
||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/lib/\$ENV{CONFIGURATION}/" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
if(NOT SFML_USE_SYSTEM_DEPS)
|
||||
# since the iOS libraries are built as static, we must install the SFML dependencies
|
||||
# too so that the end user can easily link them to its final application
|
||||
if(SFML_BUILD_GRAPHICS)
|
||||
install(FILES extlibs/libs-ios/libfreetype.a DESTINATION lib)
|
||||
endif()
|
||||
|
||||
if(SFML_BUILD_AUDIO)
|
||||
install(FILES extlibs/libs-ios/libflac.a
|
||||
extlibs/libs-ios/libvorbis.a
|
||||
extlibs/libs-ios/libogg.a
|
||||
DESTINATION lib)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
elseif(SFML_OS_ANDROID)
|
||||
|
||||
if(NOT SFML_USE_SYSTEM_DEPS)
|
||||
# install extlibs
|
||||
install(DIRECTORY extlibs/libs-android/${CMAKE_ANDROID_ARCH_ABI} DESTINATION extlibs/lib)
|
||||
install(FILES extlibs/Android.mk DESTINATION extlibs)
|
||||
endif()
|
||||
|
||||
# install Android.mk so the NDK knows how to set up SFML
|
||||
install(FILES src/SFML/Android.mk DESTINATION .)
|
||||
|
||||
endif()
|
||||
|
||||
sfml_export_targets()
|
||||
|
|
7
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Contribution Guidelines
|
||||
|
||||
You would like to see a feature implemented or a bug fixed in SFML? Great! Contributions to SFML are highly appreciated, be it in the form of general ideas, concrete suggestions or code patches.
|
||||
|
||||
[A few guiding rules have been set up on the SFML website](https://www.sfml-dev.org/contribute.php) that you should be aware of before opening an Issue or Pull Request. They will help you focus on the important stuff and prevent you from losing (y)our time with requests that are out of SFML's scope, known issues, and so on.
|
||||
|
||||
Those rules cover the general scope defined for this project, a coding style, and a precise procedure to report bugs or suggest new features.
|
702
changelog.md
Normal file
|
@ -0,0 +1,702 @@
|
|||
# Changelog
|
||||
|
||||
## SFML 2.5.1
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.5.1
|
||||
|
||||
### General
|
||||
|
||||
* Various CMake fixes (#1414, #1416, #1436, #1439, #1467, #1470)
|
||||
* Fixed the installation of pkg-config files (#1466)
|
||||
* Fixed two conversion warnings (#1454)
|
||||
* [Android] Fixes all symbols in sfml-main are hidden (#1457, #1460)
|
||||
* [Android] Fixed some `#define` flag problem (#1458)
|
||||
* [Android] Fix deadlock in main cleanup (#1265)
|
||||
* [iOS] Modernized toolchain file (#1411)
|
||||
* [iOS] Check that `<SFML/Main.hpp>` is used (#1412)
|
||||
* [macOS] Add `-ObjC` flag to fix static linking on macOS (#1485)
|
||||
|
||||
### Window
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* [iOS] Use default supported rotations when none are specified (#1417)
|
||||
* [iOS] Fixed autocomplete window overlaps keyboard (#1473, #1482)
|
||||
* [Linux] Fixed dual monitor issue (#1226, #1238)
|
||||
* [Linux] Fixed issue where fullscreen window didn't go over task bars on top and left on in Ubuntu (#1224)
|
||||
* [Linux] Fixed the Unix clipboard implementation causing an abort due to internal data races in Xlib (#1437)
|
||||
* [macOS] Added additional system cursors (#1401, #1413, #1425)
|
||||
* [Windows] Fixed swapped colors for custom cursors (#1464, #1465, #1491)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed a bug in which a `sf::RenderTexture` would not be re-activated after being re-created (#1438)
|
||||
* Fixed `sf::RenderTextureImplFBO`'s destructor incorrectly triggering deletion of other `sf::RenderTextureImplFBO`'s active FBOs (#1440)
|
||||
* Fix `sf::RenderWindow::setActive` incorrectly trying to unbind an FBO during deactivation (#1442)
|
||||
* Fixed `sf::RenderTexture::display()` dereferencing a NULL pointer when being called before `sf::RenderTexture::create()` (#1446)
|
||||
* Fixed bug in `sf::Text` when applying an outline color/thickness (#1176)
|
||||
* Squash duplicated `sf::Font` glyphs to single chars (#1461)
|
||||
* Fixed two issues with glyph sub-pixel positioning (#1452)
|
||||
* Reduced context locking & unlocking while creating textures (#1459)
|
||||
* Fixed the error message when the wrong bitmap font size is selected (#1456, #1474, #1492)
|
||||
|
||||
### Audio
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed performance issue with reading WAV files (#1450)
|
||||
|
||||
## SFML 2.5.0
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.5.0
|
||||
|
||||
### General
|
||||
|
||||
* Replaced FindSFML.cmake with SFMLConfig.cmake (#1335)
|
||||
* Markdown'd and updated readme, changelog, contributing and license files (#1196, #1368, #1317)
|
||||
* Improve packaging support (#1173)
|
||||
* Added Tagfile generation and search (#1327)
|
||||
* Added CMake variables to select the modules to be built (#798, #800)
|
||||
* Do not install extlibs if `SFML_USE_SYSTEM_DEPS` is true (#1236, #1237)
|
||||
* Fixed various type conversion/comparison warnings (#1325)
|
||||
* [Android] Increased minimum API version to 14 (#1362)
|
||||
* [Android] Removed custom toolchain and added support for the newest NDK version and Gradle (#1350, #1393)
|
||||
* [iOS] Updated the binary libs from exlibs/libs-ios (#1207, #1209)
|
||||
* [iOS] Use a CMake toolchain file for iOS build (#1268, #1269)
|
||||
* [iOS] Install extlibs if needed (#1348)
|
||||
* [iOS] Drop 32 bit support (#1374)
|
||||
* [iOS] Force correct iOS architecture for cmake (#1373, #1377)
|
||||
* [iOS] Added iOS example (#1378)
|
||||
* [macOS] Fixed launch of cocoa examples (#1334)
|
||||
* [macOS] Improved application signing process (#1020, #1036, #1194)
|
||||
* [macOS] Improved CMake script (#1215, #1371)
|
||||
* [macOS] Use `-stdlib=libc++` (#1361)
|
||||
* [OpenBSD] Added support for OpenBSD (#1330)
|
||||
|
||||
### System
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Added protected destructor to `sf::NonCopyable` to prevent possible resource leaks (#1125, #1161)
|
||||
* Fixed crash when `sf::Clock` is constructed in a global scope (#1258)
|
||||
|
||||
### Window
|
||||
|
||||
**Features**
|
||||
|
||||
* Implemented Cursor API (#269, #784, #827)
|
||||
* Implemented Clipboard API (#715, #1204, #1221)
|
||||
* Renamed a few key codes (#1395)
|
||||
* Added joystick example (#1363)
|
||||
* [Windows] Added support for interfacing with joysticks via DirectInput when it is available (#1251, #1326)
|
||||
* [Windows] Fix discrete GPU preference symbols being exported from the wrong place (#1192, #1406)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* [Android] Return correct key code for delete/backspace (#1309, #1362)
|
||||
* [iOS] Don't need to find vorbisfile or vorbisenc (#1347)
|
||||
* [Linux] Fixed `sf::Window::getPosition()` returning incorrect position because of differences in window managers (#1228, #1266)
|
||||
* [Linux] Fix X11 key repeat handling not filtering out events from other windows (#1223, #1230, #1291)
|
||||
* [Linux] Restore fullscreen of a non-visible window (#1339)
|
||||
* [macOS] Fixed window menu not working (#1091, #1180, #1193)
|
||||
* [macOS] Fixed crash with application messing hardware detection e.g. TeamViewer (#1323)
|
||||
* [macOS] Added support for (some) Hat/POV axis (#1248)
|
||||
* [Windows] Prevent uninitialized read by zeroing memory (#1264)
|
||||
* [Windows] Fixed modifier keys handling (#1357)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Features**
|
||||
|
||||
* Implemented additional line spacing and letter spacing in `sf::Text` (#928, #1366)
|
||||
* Added `sf::VertexBuffer` class (#1308)
|
||||
* Added GPU local texture copying support, allowing performance optimizations and texture swapping (#1119, #1319, #1320)
|
||||
* Optimize performance by skipping `glTexCoordPointer()` call if not needed (#1015)
|
||||
* Generate shape outline vertices only if necessary (#925, #1356)
|
||||
* Removed dependency to libjpeg, stb_image_write now supports writing JPEG files (#1278, #1279)
|
||||
* Enable comparing `sf::Transform` and optimize resetting OpenGL back to the identity matrix (#1298)
|
||||
* Added missing `setActive()` virtual method to `sf::RenderTarget` (#1157)
|
||||
* Updated stb_image to v2.16 and stb_image_write to v1.07 (#1270)
|
||||
* Added `sf::RenderTexture` stencil and multisampling support (#1274, #1285)
|
||||
* Added example demonstrating `sf::VertexBuffer`, `sf::Shader` and `sf::Thread` usage (#1352)
|
||||
* Optimized `sf::RenderTexture` performance (#1379)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Properly free memory in `sf::Font::cleanup()` (#1119)
|
||||
* Fixed memory leak in `sf::Font` (#1216)
|
||||
* Fix OpenGL texture coordinate pointer not being updated correctly under certain conditions (#1297)
|
||||
* Fix for broken text when the font is reloaded (#1345)
|
||||
* Fix memory leak in `sf::Text` (#1233, #1360)
|
||||
* Fixed strict aliasing punning warning when generating the key of a glyph in Font.cpp (#1187, #1396)
|
||||
* Fixed OpenGL version string being parsed incorrectly on some platforms (#1249, #1390)
|
||||
* [macOS] Worked around render target bug (#1132, #1342)
|
||||
* [Windows] Replaced time-based joystick poll with a hardware event handler (#1179, #1195, #1198, #1199, #1421)
|
||||
|
||||
### Audio
|
||||
|
||||
**Features**
|
||||
|
||||
* Added loop point support to `sf::Music` (#177, #629)
|
||||
* Added support for the extensible PCM wave file format (#1296)
|
||||
* [iOS] Enable audio module (#1338)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed inconsistent seek behavior in `sf::SoundStream` (#1118)
|
||||
* Fixed stack overflow in `sf::SoundStream::fillAndPushBuffer()` (#1154)
|
||||
* Fixed seeking quirks in the FLAC reader (#966, #1162)
|
||||
* Allow polymorphism with `sf::SoundSource` (#1185)
|
||||
* Fixed WAV file writer writing wrong header values (#1280, #1281)
|
||||
* Small bugfix to argument of `alcCaptureOpenDevice()` (#1304, #1305)
|
||||
* [iOS] Find OpenAL correctly (#1263, #1376)
|
||||
* [Windows] Updated OpenAL Soft to 1.18.1 fixing crashes (#1247, #1260)
|
||||
|
||||
### Network
|
||||
|
||||
**Features**
|
||||
|
||||
* Add append/overwrite parameter to Ftp::upload (#1072, #1399)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed wrong condition for building network support (#1253)
|
||||
* Changed TCP listen backlog from 0 to SOMAXCONN (#1369, #1407)
|
||||
* Fixed socket reuse not conforming to documentation (#1346, #1408)
|
||||
|
||||
## SFML 2.4.2
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.4.2
|
||||
|
||||
### System
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* [Windows] Removed thread affinity changes in sf::Clock (#1107)
|
||||
|
||||
### Window
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed bug where TransientContextLock would hang (#1165, #1172)
|
||||
* [Linux] Fixed GLX extensions being loaded too late (#1183)
|
||||
* [Linux] Fix wrong types passed to XChangeProperty (#1168, #1171)
|
||||
* [Windows] Make context disabling via wglMakeCurrent more tolerant of broken drivers (#1186)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Optimized sf::Image::create and made it more exception safe (#1166)
|
||||
|
||||
## SFML 2.4.1
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.4.1
|
||||
|
||||
### General
|
||||
|
||||
* [kFreeBSD] Define SFML_OS_FREEBSD when compiling for kFreeBSD (#1129)
|
||||
* [Windows] Added some simple messaging when trying to build under Cygwin (#1153)
|
||||
|
||||
### Window
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed stack overflow on GlContext creation with multiple threads (#989, #1002)
|
||||
* Adjusted mouse cursor grab documentation (#1133)
|
||||
* [iOS] Fixed orientation change not rescaling window size properly (#1049, #1050)
|
||||
* [Linux] Fixed fullscreen issue (#921, #1138)
|
||||
* [Linux] Switched from XCB back to Xlib for windowing (#1138)
|
||||
* [Linux] Fixed window icon not showing up on some distros (#1087, #1088)
|
||||
* [Linux] Fixed an issue where GNOME flags window unresponsive (#1089, #1138)
|
||||
* [Linux] Fixed leak of XVisualInfo objects during GlxContext creation (#1135)
|
||||
* [Linux] Fixed possible hang when setting visibility if external window sources (#1136)
|
||||
* [macOS] Fixed inconsistency between doc and impl on macOS for the grab feature (#1133, #1148, #1150)
|
||||
* [Windows] Fixed context memory leaks (#1143, #1002)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Adjusted uniform error message (#1131)
|
||||
* Clarify documentation on Rect::contains function bounds (#1151)
|
||||
|
||||
### Network
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed a typo in comment for void unbind() (#1121)
|
||||
|
||||
## SFML 2.4.0
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.4.0
|
||||
|
||||
### General
|
||||
|
||||
* Added deprecation macro (#969)
|
||||
* Fixed issues reported by Coverity Scan static analysis (#1064)
|
||||
* Fixed some initialization issues reported by Cppcheck (#1008)
|
||||
* Changed comment chars in FindSFML.cmake to # (#1090)
|
||||
* Fixed some typos (#1098, #993, #1099, #956, #963, #979)
|
||||
* Updated/fixed string comparisons in Config.cmake (#1102)
|
||||
* Added the missing -s postfix for the RelWithDebInfo config (#1014)
|
||||
* [Android] Fixed current Android compilation issues (#1116, #1111, #1079)
|
||||
* [macOS] Update Xcode template material (#976, #968)
|
||||
* [Windows] Added support for VS 2015 (#972)
|
||||
* [Windows] Create and install PDB debug symbols alongside binaries (#1037)
|
||||
|
||||
### Deprecated API
|
||||
|
||||
* sf::RenderWindow::capture(): Use a sf::Texture and its sf::Texture::update(const Window&) function and copy its contents into an sf::Image instead.
|
||||
* sf::Shader::setParameter(): Use setUniform() instead.
|
||||
* sf::Text::getColor(): There is now fill and outline colors instead of a single global color. Use getFillColor() or getOutlineColor() instead.
|
||||
* sf::Text::setColor(): There is now fill and outline colors instead of a single global color. Use setFillColor() or setOutlineColor() instead.
|
||||
* sf::LinesStrip: Use LineStrip instead.
|
||||
* sf::TrianglesFan: Use TriangleFan instead.
|
||||
* sf::TrianglesStrip: Use TriangleStrip instead.
|
||||
|
||||
### System
|
||||
|
||||
**Features**
|
||||
|
||||
* [Android] Added sf::getNativeActivity() (#1005, #680)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Added missing <iterator> include in String.hpp (#1069, #1068)
|
||||
* Fixed encoding of UTF-16 (#997)
|
||||
* [Android] Fixed crash when trying to load a non-existing font file (#1058)
|
||||
|
||||
### Window
|
||||
|
||||
**Features**
|
||||
|
||||
* Added ability to grab cursor (#614, #394, #1107)
|
||||
* Added Multi-GPU preference (#869, #867)
|
||||
* Added support for sRGB capable framebuffers (#981, #175)
|
||||
* [Linux, Windows] Improved OpenGL context creation (#884)
|
||||
* [Linux, Windows] Added support for pbuffers on Windows and Unix (#885, #434)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Updated platform-specific handle documentation (#961)
|
||||
* [Android] Accept touch events from "multiple" devices (#954, #953)
|
||||
* [Android] Copy the selected EGL context's settings to SFML (#1039)
|
||||
* [Linux] Fixed modifiers causing sf::Keyboard::Unknown being returned (#1022, #1012)
|
||||
* [macOS] Improved memory management on macOS (#962, #790)
|
||||
* [macOS] Fixed crash when resizing a window to a zero-height/width size (#986, #984)
|
||||
* [macOS] Use the mouse button constant instead of 0 to avoid a compiler error on macOS (#1035)
|
||||
* [macOS] macOS improvement: warnings + bugfix + refactoring, the lot! (#1042)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Features**
|
||||
|
||||
* Added support for outlined text (#840)
|
||||
* Add support for geometry shaders (#886, #428)
|
||||
* Feature/blend mode reverse subtract (#945, #944)
|
||||
* Implemented support for mipmap generation (#973, #498, #123)
|
||||
* Added new API to set shader uniforms (#983, #538)
|
||||
* Rewrite RenderWindow::capture (#1001)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Exporting some Glsl utility functions due to linking issues (#1044, #1046)
|
||||
* Fixed missing initialisation of Font::m_stroker (#1059)
|
||||
* Changed primitive types to be grammatically correct (#1095, #939)
|
||||
|
||||
### Audio
|
||||
|
||||
**Features**
|
||||
|
||||
* Implemented stereo audio recording (#1010)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Added an assignment operator to SoundSource (#864)
|
||||
* [macOS] Updates OpenAL-soft for macOS to version 1.17.2 (#1057, #900, #1000)
|
||||
* Fixed a bug where vorbis can't handle large buffers (#1067)
|
||||
* Added support for 24-bit .wav files (#958, #955)
|
||||
* Fixed threading issue in sf::SoundRecorder (#1011)
|
||||
* Made WAV file reader no longer assume that data chunk goes till end of file to prevent reading trailing metadata as samples (#1018)
|
||||
* Fixed seeking in multi channel FLAC files (#1041, #1040)
|
||||
|
||||
### Network
|
||||
|
||||
**Features**
|
||||
|
||||
* Added optional argument on which address to bind (socket). (#850, #678)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed FTP directory listing blocking forever (#1086, #1025)
|
||||
|
||||
## SFML 2.3.2
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.3.2
|
||||
|
||||
### General
|
||||
|
||||
* Fixed an issue where FindSFML.cmake couldn't find older versions of SFML (#903)
|
||||
* Robust alCheck and glCheck macros (#917)
|
||||
* Fixed FindSFML.cmake to use the uppercase FLAC name (#923)
|
||||
* Added a CONTRIBUTING file so GitHub shows a message when creating a new issue (#932)
|
||||
|
||||
### Window
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* [Linux] Fixed an issue where the keypad's key weren't being detected (#910)
|
||||
* [Linux] Revert to Xlib event handling (#934)
|
||||
* [Linux] Fixed `XK_*` inconsistency in InpuImpl.cpp (#947)
|
||||
* [Linux] Fix `_NET_WM_PING` messages not being replied to properly (#947)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed clear bug on RenderTextures (#915)
|
||||
* Fixed image file extension detection (#929, #930, #931)
|
||||
* Secure function against random data return (#935, #942)
|
||||
|
||||
## SFML 2.3.1
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.3.1
|
||||
|
||||
### Window
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* [Android] Make sure a window still exists before trying to access its dimensions (#854)
|
||||
* [Android] Added Android API level checks (#856)
|
||||
* [Android] Updated the JNI/event handling code (#906)
|
||||
* [Linux] Resized events are only spawned when the window size actually changes (#878, #893)
|
||||
* [Linux] Whitelisted X SHAPE events (#879, #883)
|
||||
* [Linux] Remap Unix keyboard when user changes layout (#895, #897)
|
||||
* [Linux] Fix undefined behavior in ewmhSupported() (#892, #901)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Added support for GL_EXT_texture_edge_clamp for systems that don't expose GL_SGIS_texture_edge_clamp (#880, #882)
|
||||
|
||||
### Audio
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* [Android] Fixed audio files not loading (and possibly crashing) (#855, #887)
|
||||
|
||||
## SFML 2.3
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.3
|
||||
|
||||
### General
|
||||
|
||||
* Examples only link against sfml-main in release mode (#610, #766)
|
||||
* Replaced unsigned int with std::size_t for array indices and sizes (#739)
|
||||
* Fixed some issues with the Doxygen documentation (#750)
|
||||
* Added support for EditorConfig (#751)
|
||||
* Hide success message for CMake in quiet mode (#753)
|
||||
* Improved documentation for statuses with sf::Ftp (#763)
|
||||
* Moved stb_image into the extlibs directory (#795)
|
||||
* Changed the SOVERSION to major.minor (#812)
|
||||
* Fixed warnings about switch-statements (#863)
|
||||
* Added missing includes in the general headers (#851)
|
||||
* [Android] Updated toolchain file and dependencies (#791)
|
||||
* [Linux] Fixed missing pthread dependency (#794)
|
||||
* [macOS] Relaxed CMake installation rules regarding framework dependencies (#767)
|
||||
|
||||
### Deprecated API
|
||||
|
||||
* sf::Event::MouseWheelEvent: This event is deprecated and potentially inaccurate. Use MouseWheelScrollEvent instead.
|
||||
|
||||
### Window
|
||||
|
||||
**Features**
|
||||
|
||||
* Added new events for handling high-precision scrolling (#95, #810, #837)
|
||||
* Switched from Xlib to XCB (#200, #319, #694, #780, #813, #825)
|
||||
* Added support for OpenGL 3 core context creation (#654, #779)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed glXSwapIntervalSGI being broken for some driver implementations (#727, #779)
|
||||
* Fixed simultaneous context operations causing crashes on some AMD hardware (#778, #779)
|
||||
* Fixed joystick identification (#809, #811)
|
||||
* [iOS] Fixed various issues including stencil bits, device orientation and retina support (#748)
|
||||
* [iOS] Fixed inconsistency between sf::Touch::getPosition and touch events (#875)
|
||||
* [Linux] Fixed Alt+F4 not getting triggered in window mode (#274)
|
||||
* [Linux] Fixed Unix joystick stuff (#838)
|
||||
* [macOS] Fixed typo in JoystickImpl.cpp to prevent a crash (#762, #765)
|
||||
* [macOS] Fixed an issue in InputImpl::getSFOpenGLViewFromSFMLWindow (#782, #792)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Features**
|
||||
|
||||
* Replaced GLEW with loader generated by glLoadGen (#779)
|
||||
* Added a new constructor to sf::Color that takes an sf::Uint32 (#722)
|
||||
* Updated stb_image to v2.02 (#777)
|
||||
* Updated FreeType to v2.5.5 (#799, #804)
|
||||
* Added checks for software OpenGL (#870)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed GL_ARB_compatibility not being detected (#859)
|
||||
* Fixed pixel format selection (#862)
|
||||
* Bumped back the OpenGL version requirement to 1.1 (#858)
|
||||
|
||||
### Audio
|
||||
|
||||
**Features**
|
||||
|
||||
* Dropped libsndfile and started using Vorbis, FLAC and OGG directly (#604, #757)
|
||||
* Added a FLAC file to the sound example (#815)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed access violation error in the destructor of sf::AudioDevice (#30, #602)
|
||||
* [macOS] Fixed threading issue with sf::SoundStream and OpenAL (#541, #831)
|
||||
|
||||
### Network
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed sf::TcpSocket not handling partial sends properly (#749, #796)
|
||||
|
||||
## SFML 2.2
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.2
|
||||
|
||||
### General
|
||||
|
||||
* Support for iOS and Android platform (#410, #440)
|
||||
* Various documentation corrections (#438, #496, #497, #714)
|
||||
* Fixed support for compilers on Debian FreeBSD (#380, #578)
|
||||
* Added support for Visual Studio 2013 and proper support for the TDM builds (#482)
|
||||
* Fixed CMake problems related to FindSFML and cached variables (#637, #684)
|
||||
* Switched and enforced LF line endings (#708, #712)
|
||||
* Updated OpenAL to version 1.15.1 (d077210)
|
||||
* Made compiler and OS variable names much clearer in CMake files (9b0ed30)
|
||||
* Re-enabled RPATH feature (e157e7a)
|
||||
* Slight adjustments to the examples (#737)
|
||||
* [FreeBSD] Various configuration fixes (#577, #578)
|
||||
* [Linux] Updated FindSFML.cmake to add UDev to SFML's dependencies (#728, #729, #734, #736)
|
||||
* [macOS] Fixed incorrect symlink in freetype.framework (#519)
|
||||
* [macOS] CMake module for correct dependencies (#548)
|
||||
* [macOS] Fixed SFML target for Xcode (#595, #596)
|
||||
* [macOS] Updated implementation, mainly reverting to non-ARC (#601)
|
||||
* [macOS] Fixed memory leaks and dead store (#615)
|
||||
* [macOS] Improved event handling and performance (#617)
|
||||
* [macOS] Reduced memory usage (#672, #698)
|
||||
* [macOS] macOS 10.10 support (#691, #699)
|
||||
* [macOS] Improve flexibility of dependencies' locations (#713)
|
||||
* [Windows] Removed the hack that copied external libraries into SFML static libraries (dbf01a7)
|
||||
|
||||
### System
|
||||
|
||||
**Features**
|
||||
|
||||
* Added substring and replace functions to sf::String (#21, #355)
|
||||
* Added toUtfX to sf::String (#501)
|
||||
* Added fromUtfX functions to set the internal data to a string by converting from another string in a fixed encoding (#196)
|
||||
* Added modulo operator for sf::Time (#429, #430)
|
||||
* Added division operator for sf::Time (#453)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Ensured a high resolution for sf::sleep (#439, #475)
|
||||
* [Windows] Fixed stack unalignment by two internal functions (#412)
|
||||
|
||||
### Window
|
||||
|
||||
**Features**
|
||||
|
||||
* Added window methods to request and to check focus (#518, #525, #613, #723, #735)
|
||||
* Provide name, manufacturer ID and product ID via sf::Joystick (#152, #528)
|
||||
* [FreeBSD] Joystick support (#477)
|
||||
* [macOS] Improved integration with menus and dock actions (#11)
|
||||
* [macOS] Support for OpenGL 3.2 (#84)
|
||||
* [macOS] Improved fullscreen support (#343)
|
||||
* [macOS] Added support for retina displays (#353, #388)
|
||||
* [Windows] Removed support for Windows 9x (#469)
|
||||
* [Windows] Fixed typo in Windows keyboard implementation (#516)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* sf::Window::create() now also resets framerate limit (#371)
|
||||
* Fixed OpenGL context leak (#635, #705)
|
||||
* Fixed various joystick problems (memory leak, accelerometer detected, code refactoring) (#660, #686, #742, #743)
|
||||
* Optimized sf::Window::waitEvent a bit, no sleep if events are available at first try (ff555d6)
|
||||
* [Linux] Output error message when XOpenDisplay() fails (#508, #616)
|
||||
* [Linux] Resize window with setSize when sf::Style::Resize is set (#466)
|
||||
* [Linux] Fixed broken key repeat on window recreation (#564, #567)
|
||||
* [macOS] Fixed KeyReleased not being fired in fullscreen mode (#465)
|
||||
* [macOS] Fixed an issue where disconnecting the keyboard would cause a crash (#467)
|
||||
* [macOS] Fixed unexpected resizing behavior (#468)
|
||||
* [macOS] Improved resizing windows (#474)
|
||||
* [macOS] Fixed memory leak with sf::Window::create() (#484)
|
||||
* [macOS] Fixed menu shortcuts in fullscreen on macOS (#527)
|
||||
* [macOS] Improved cursor hiding (#703)
|
||||
* [macOS] Fixed right click not detected with trackpads (#716, #730)
|
||||
* [Windows] Fixed joystick POV values (ef1d29b)
|
||||
* [Windows] Fixed Unicode inconsistency (#635)
|
||||
* [Windows] Fixed Alt+F4 and mouse clicks issues (#437, #457)
|
||||
* [Windows] Send MouseButtonReleased event when the mouse is outside of the window (#455, #457)
|
||||
* [Windows] Fixed sf::Joystick wrong registry usage (#701, #702, #706)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Features**
|
||||
|
||||
* Provide more information about the loaded font in sf::Font (#164)
|
||||
* Implemented a more flexible blending system (#298)
|
||||
* Added strikethrough text style (#243, #362, #682)
|
||||
* Slight optimization for sf::Text::setString (#413)
|
||||
* Added subtraction operator for sf::Color (#114, #145)
|
||||
* Optimized sf::Image::flipVertically/flipHorizontally (#555)
|
||||
* Changed sf::Font measurements from int to float to allow better underline drawing (#693)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Improved text quality for small and pixelated fonts (#228)
|
||||
* Yet another fix for Intel GPUs with sf::RenderTexture (#418)
|
||||
* Removed VTab since it causes issues and doesn't have a use nowadays (#442, #445, #460, #588)
|
||||
* Fixed broken BDF and PCF font formats (#448)
|
||||
* Fixed compilation issue with newer versions of GCC for sf::Rect (#458)
|
||||
* Fixed resetGLStates() not explicitly setting the default polygon mode (#480)
|
||||
* Fixed division-by-zero in sf::RectangleShape (#499)
|
||||
* Fixed potential memory leak in sf::Font (#509)
|
||||
* Updated glext and removed glxext (#511, #583)
|
||||
* Make sure texture unit 0 is active when resetting sf::RenderTarget states (#523, #591)
|
||||
* Fixed texture rect computation in fonts (#669)
|
||||
* Improved rendering of underlined text (#593)
|
||||
* Avoided repeated output of error messages (#566)
|
||||
* Fixed text rendered with vertical offset on ascent and font size mismatch (#576)
|
||||
* Fixed rounding problem for viewports (#598)
|
||||
* Fixed sf::Shader::isAvailable() possibly breaking context management (#211, #603, #608, #603)
|
||||
* Fixed sf::Texture::getMaximumSize() possibly breaking context management (#666)
|
||||
* Fixed various sf::Text rendering issues (#692, #699)
|
||||
* The texture matrix is now reset in sf::Texture::bind(NULL) (7c4b058)
|
||||
* [Windows] Fixed DPI scaling causing strange window behavior (#679, #681, #688)
|
||||
|
||||
### Audio
|
||||
|
||||
**Features**
|
||||
|
||||
* Added support for selecting the audio capture device (#220, #470)
|
||||
* Make sf::SoundRecorder processing frequency configurable (#333)
|
||||
* Added up vector to sf::Listener (#545)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Prevented sf::SoundStream::setPlayingOffset() from restarting playing even when paused (#203, #592)
|
||||
* Fixed sf::SoundBuffer contents not being able to be updated when still attached to sounds (#354, 367, #390, #589)
|
||||
* Catch audio format error and prevent division by zero (#529)
|
||||
* Fixed sf::SoundBuffer returning wrong duration for sounds containing more than ~4.3 million samples (2ff58ed)
|
||||
* Optimized sf::Listener with a cache (d97e524)
|
||||
|
||||
### Network
|
||||
|
||||
**Features**
|
||||
|
||||
* Added support for PUT and DELETE in sf::Http (#257, #312, #607)
|
||||
* Added support for chunked HTTP transfers (#296, #337)
|
||||
* Added support for 64-bit integers in sf::Packet (#710)
|
||||
* Made sf::Ftp::sendCommand() public (2c5cab5)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Checked socket descriptor limit (#153, #628, #683)
|
||||
* Fixed sf::TcpSocket::connect()'s switching from blocking to non-blocking mode on immediate connection success (#221)
|
||||
* Fixed FTP download and upload file sizes being limited by available RAM (#565, #590)
|
||||
* Fixed C++11 compiler warnings for sf::Uint8 (#731, #732)
|
||||
|
||||
## SFML 2.1
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.1
|
||||
|
||||
### General
|
||||
|
||||
* Updated the Window and OpenGL examples (got rid of GLU and immediate mode)
|
||||
|
||||
### Window
|
||||
|
||||
**Features**
|
||||
|
||||
* Now using inotify on Linux to avoid constantly polling joystick connections (#96)
|
||||
* Add keypad return, equal and period keys support for macOS
|
||||
* Improved mouse events on macOS regarding fullscreen mode
|
||||
* Improved mouse events on macOS (#213, #277)
|
||||
* Improved reactivity of setMousePosition on macOS (#290)
|
||||
* Added support for right control key on macOS
|
||||
* Improved TextEntered for macOS (#377)
|
||||
* Improved the performances of Window::getSize() (the size is now cached)
|
||||
* Added the WM_CLASS property to SFML windows on Linux
|
||||
* Fake resize events are no longer sent when the window is moved, on Linux
|
||||
* Pressing ALT or F10 on Windows no longer steals the focus
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed MouseMove event sometimes not generated when holding left button on Windows (#225)
|
||||
* Fixed ContextSettings ignored when creating a 3.x/4.x OpenGL context on Linux (#258)
|
||||
* Fixed ContextSettings ignored on Linux when creating a window (#35)
|
||||
* Fixed windows bigger than the desktop not appearing on Windows (#215)
|
||||
* Fixed KeyRelease events sometimes not reported on Linux (#404)
|
||||
* Fixed mouse moved event on macOS when dragging the cursor (#277)
|
||||
* Fixed KeyRelease event with CMD key pressed (#381)
|
||||
* Fixed taskbar bugs on Windows (#328, #69)
|
||||
* Fixed Window::getPosition() on Linux (#346)
|
||||
* Unicode characters outside the BMP (> 0xFFFF) are now correctly handled on Windows (#366)
|
||||
|
||||
### Graphics
|
||||
|
||||
**Features**
|
||||
|
||||
* Checking errors in RenderTarget::pushGLStates() to avoid generating false error messages when user leaves unchecked OpenGL errors (#340)
|
||||
* Optimized Shader::setParameter functions, by using a cache internally (#316, #358)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed bounding rect of sf::Text ignoring whitespaces (#216)
|
||||
* Solved graphics resources not updated or corrupted when loaded in a thread (#411)
|
||||
* Fixed white pixel showing on first character of sf::Text (#414)
|
||||
* sf::Rect::contains and sf::Rect::intersects now handle rectangles with negative dimensions correctly (#219)
|
||||
* Fixed Shape::setTextureRect not working when called before setTexture
|
||||
|
||||
### Audio
|
||||
|
||||
**Features**
|
||||
|
||||
* loadFromStream functions now explicitly reset the stream (seek(0)) before starting to read (#349)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Added a workaround for a bug in the macOS implementation of OpenAL (unsupported channel count no properly detected) (#201)
|
||||
* Fixed SoundBuffer::loadFromStream reading past the end of the stream (#214)
|
||||
|
||||
### Network
|
||||
|
||||
**Features**
|
||||
|
||||
* Replaced the deprecated gethostbyname with getaddrinfo (#47)
|
||||
* Minor improvements to sf::Packet operators (now using strlen and wcslen instead of explicit loops) (#118)
|
||||
|
||||
**Bugfixes**
|
||||
|
||||
* Fixed non-blocking connection with a sf::TcpSocket on Windows
|
||||
* Fixed TCP packet data corruption in non-blocking mode (#402, #119)
|
||||
* On Unix systems, a socket disconnection no longer stops the program with signal SIGPIPE (#72)
|
||||
|
||||
## SFML 2.0
|
||||
|
||||
Also available on the website: https://www.sfml-dev.org/changelog.php#sfml-2.0
|
||||
|
||||
No changelog available. *Everything changed.*
|
||||
|
||||
## Older Releases
|
||||
|
||||
See the website for changelogs of older releases: https://www.sfml-dev.org/changelog.php
|
|
@ -1,75 +1,118 @@
|
|||
# detect the OS
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
set(WINDOWS 1)
|
||||
|
||||
# detect the architecture (note: this test won't work for cross-compilation)
|
||||
include(CheckTypeSize)
|
||||
check_type_size(void* SIZEOF_VOID_PTR)
|
||||
if("${SIZEOF_VOID_PTR}" STREQUAL "4")
|
||||
set(ARCH_32BITS 1)
|
||||
elseif("${SIZEOF_VOID_PTR}" STREQUAL "8")
|
||||
set(ARCH_64BITS 1)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported architecture")
|
||||
return()
|
||||
endif()
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set(LINUX 1)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
# FreeBSD compile path is the same as Linux
|
||||
set(LINUX 1)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set(MACOSX 1)
|
||||
|
||||
# detect OS X version. (use '/usr/bin/sw_vers -productVersion' to extract V from '10.V.x'.)
|
||||
EXEC_PROGRAM(/usr/bin/sw_vers ARGS -productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW)
|
||||
STRING(REGEX REPLACE "10\\.([0-9]).*" "\\1" MACOSX_VERSION "${MACOSX_VERSION_RAW}")
|
||||
if(${MACOSX_VERSION} LESS 5)
|
||||
message(FATAL_ERROR "Unsupported version of OS X : ${MACOSX_VERSION_RAW}")
|
||||
return()
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported operating system")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# detect the compiler and its version
|
||||
# Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true
|
||||
# even when CLANG is used, therefore the Clang test is done first
|
||||
if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
# CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change,
|
||||
# but there is no other way to detect CLang at the moment
|
||||
set(COMPILER_CLANG 1)
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE CLANG_VERSION_OUTPUT)
|
||||
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION "${CLANG_VERSION_OUTPUT}")
|
||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(COMPILER_GCC 1)
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT)
|
||||
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" GCC_VERSION "${GCC_VERSION_OUTPUT}")
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE GCC_MACHINE)
|
||||
string(STRIP "${GCC_MACHINE}" GCC_MACHINE)
|
||||
if(${GCC_MACHINE} MATCHES ".*w64.*")
|
||||
set(COMPILER_GCC_W64 1)
|
||||
endif()
|
||||
elseif(MSVC)
|
||||
set(COMPILER_MSVC 1)
|
||||
if(MSVC_VERSION EQUAL 1400)
|
||||
set(MSVC_VERSION 2005)
|
||||
elseif(MSVC_VERSION EQUAL 1500)
|
||||
set(MSVC_VERSION 2008)
|
||||
elseif(MSVC_VERSION EQUAL 1600)
|
||||
set(MSVC_VERSION 2010)
|
||||
elseif(MSVC_VERSION EQUAL 1700)
|
||||
set(MSVC_VERSION 2011)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported compiler")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# define the install directory for miscellaneous files
|
||||
if(WINDOWS)
|
||||
set(INSTALL_MISC_DIR .)
|
||||
elseif(UNIX)
|
||||
set(INSTALL_MISC_DIR share/SFML)
|
||||
endif()
|
||||
# detect the OS
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
set(SFML_OS_WINDOWS 1)
|
||||
|
||||
# don't use the OpenGL ES implementation on Windows
|
||||
set(OPENGL_ES 0)
|
||||
|
||||
# detect the architecture (note: this test won't work for cross-compilation)
|
||||
include(CheckTypeSize)
|
||||
check_type_size(void* SIZEOF_VOID_PTR)
|
||||
if(${SIZEOF_VOID_PTR} STREQUAL "4")
|
||||
set(ARCH_32BITS 1)
|
||||
elseif(${SIZEOF_VOID_PTR} STREQUAL "8")
|
||||
set(ARCH_64BITS 1)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported architecture")
|
||||
return()
|
||||
endif()
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
set(SFML_OS_UNIX 1)
|
||||
if(ANDROID)
|
||||
set(SFML_OS_ANDROID 1)
|
||||
# use the OpenGL ES implementation on Android
|
||||
set(OPENGL_ES 1)
|
||||
else()
|
||||
set(SFML_OS_LINUX 1)
|
||||
# don't use the OpenGL ES implementation on Linux
|
||||
set(OPENGL_ES 0)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "^k?FreeBSD$")
|
||||
set(SFML_OS_FREEBSD 1)
|
||||
# don't use the OpenGL ES implementation on FreeBSD
|
||||
set(OPENGL_ES 0)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "^OpenBSD$")
|
||||
set(SFML_OS_OPENBSD 1)
|
||||
# don't use the OpenGL ES implementation on OpenBSD
|
||||
set(OPENGL_ES 0)
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
|
||||
if(IOS)
|
||||
set(SFML_OS_IOS 1)
|
||||
|
||||
# use the OpenGL ES implementation on iOS
|
||||
set(OPENGL_ES 1)
|
||||
else()
|
||||
set(SFML_OS_MACOSX 1)
|
||||
|
||||
# don't use the OpenGL ES implementation on Mac OS X
|
||||
set(OPENGL_ES 0)
|
||||
|
||||
# detect OS X version. (use '/usr/bin/sw_vers -productVersion' to extract V from '10.V.x'.)
|
||||
EXEC_PROGRAM(/usr/bin/sw_vers ARGS -productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW)
|
||||
STRING(REGEX REPLACE "10\\.([0-9]+).*" "\\1" MACOSX_VERSION "${MACOSX_VERSION_RAW}")
|
||||
if(${MACOSX_VERSION} LESS 7)
|
||||
message(FATAL_ERROR "Unsupported version of OS X: ${MACOSX_VERSION_RAW}")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
set(SFML_OS_ANDROID 1)
|
||||
|
||||
# use the OpenGL ES implementation on Android
|
||||
set(OPENGL_ES 1)
|
||||
# comparing CMAKE_SYSTEM_NAME with "CYGWIN" generates a false warning depending on the CMake version
|
||||
# let's avoid it so the actual error is more visible
|
||||
elseif(${CYGWIN})
|
||||
message(FATAL_ERROR "Unfortunately SFML doesn't support Cygwin's 'hybrid' status between both Windows and Linux derivatives.\nIf you insist on using the GCC, please use a standalone build of MinGW without the Cygwin environment instead.")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported operating system or environment")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# set pkgconfig install directory
|
||||
# this could be e.g. macports on mac or msys2 on windows etc.
|
||||
set(SFML_PKGCONFIG_DIR "/${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
|
||||
if(SFML_OS_FREEBSD OR SFML_OS_OPENBSD)
|
||||
set(SFML_PKGCONFIG_DIR "/libdata/pkgconfig")
|
||||
endif()
|
||||
|
||||
# detect the compiler and its version
|
||||
# Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true
|
||||
# even when CLANG is used, therefore the Clang test is done first
|
||||
if(CMAKE_CXX_COMPILER MATCHES "clang[+][+]" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
# CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change,
|
||||
# but there is no other way to detect CLang at the moment
|
||||
set(SFML_COMPILER_CLANG 1)
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE CLANG_VERSION_OUTPUT)
|
||||
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" SFML_CLANG_VERSION "${CLANG_VERSION_OUTPUT}")
|
||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(SFML_COMPILER_GCC 1)
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT)
|
||||
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" SFML_GCC_VERSION "${GCC_VERSION_OUTPUT}")
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE GCC_COMPILER_VERSION)
|
||||
string(REGEX MATCHALL ".*(tdm[64]*-[1-9]).*" SFML_COMPILER_GCC_TDM "${GCC_COMPILER_VERSION}")
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE GCC_MACHINE)
|
||||
string(STRIP "${GCC_MACHINE}" GCC_MACHINE)
|
||||
if(GCC_MACHINE MATCHES ".*w64.*")
|
||||
set(SFML_COMPILER_GCC_W64 1)
|
||||
endif()
|
||||
elseif(MSVC)
|
||||
set(SFML_COMPILER_MSVC 1)
|
||||
if(MSVC_VERSION EQUAL 1400)
|
||||
set(SFML_MSVC_VERSION 8)
|
||||
elseif(MSVC_VERSION EQUAL 1500)
|
||||
set(SFML_MSVC_VERSION 9)
|
||||
elseif(MSVC_VERSION EQUAL 1600)
|
||||
set(SFML_MSVC_VERSION 10)
|
||||
elseif(MSVC_VERSION EQUAL 1700)
|
||||
set(SFML_MSVC_VERSION 11)
|
||||
elseif(MSVC_VERSION EQUAL 1800)
|
||||
set(SFML_MSVC_VERSION 12)
|
||||
elseif(MSVC_VERSION EQUAL 1900)
|
||||
set(SFML_MSVC_VERSION 14)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported compiler")
|
||||
return()
|
||||
endif()
|
||||
|
|
|
@ -1,256 +1,427 @@
|
|||
# some of these macros are inspired from the boost/cmake macros
|
||||
|
||||
# this macro adds external dependencies to a static target,
|
||||
# compensating for the lack of a link step when building a static library.
|
||||
# every compiler has its own way of doing it:
|
||||
# - VC++ supports it directly through the static library flags
|
||||
# - MinGW/gcc doesn't support it, but as a static library is nothing more than an archive,
|
||||
# we can simply merge the external dependencies to our generated target as a post-build step
|
||||
# - for other compilers and OSes, static build is not encouraged so we don't try to
|
||||
# pre-link dependencies, we just "link" them so that the SFML samples can compile
|
||||
# out-of-the-box (CMake forwards the dependencies automatically)
|
||||
macro(sfml_static_add_libraries target)
|
||||
if(WINDOWS AND COMPILER_GCC)
|
||||
# Windows - gcc
|
||||
foreach(lib ${ARGN})
|
||||
if(NOT ${lib} MATCHES ".*/.*")
|
||||
string(REGEX REPLACE "(.*)/bin/.*\\.exe" "\\1" STANDARD_LIBS_PATH "${CMAKE_CXX_COMPILER}")
|
||||
if(COMPILER_GCC_W64)
|
||||
set(lib "${STANDARD_LIBS_PATH}/${GCC_MACHINE}/lib/lib${lib}.a")
|
||||
else()
|
||||
set(lib "${STANDARD_LIBS_PATH}/lib/lib${lib}.a")
|
||||
endif()
|
||||
endif()
|
||||
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
|
||||
get_target_property(TARGET_FILENAME ${target} ${BUILD_TYPE}_LOCATION)
|
||||
add_custom_command(TARGET ${target}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_AR} x ${lib}
|
||||
COMMAND ${CMAKE_AR} rcs ${TARGET_FILENAME} *.o
|
||||
COMMAND del *.o /f /q
|
||||
VERBATIM)
|
||||
endforeach()
|
||||
elseif(MSVC)
|
||||
# Visual C++
|
||||
set(LIBRARIES "")
|
||||
foreach(lib ${ARGN})
|
||||
if(NOT ${lib} MATCHES ".*\\.lib")
|
||||
set(lib ${lib}.lib)
|
||||
endif()
|
||||
if(MSVC_IDE AND MSVC_VERSION LESS 2010)
|
||||
# for Visual Studio projects < 2010, we must add double quotes
|
||||
# around paths because they may contain spaces
|
||||
set(LIBRARIES "${LIBRARIES} "\\;${lib}"\\;")
|
||||
else()
|
||||
set(LIBRARIES "${LIBRARIES} \"${lib}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
set_target_properties(${target} PROPERTIES STATIC_LIBRARY_FLAGS ${LIBRARIES})
|
||||
else()
|
||||
# All other platforms
|
||||
target_link_libraries(${target} ${ARGN})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# check if a value is contained in a list
|
||||
# sets ${var} to TRUE if the value is found
|
||||
macro(sfml_list_contains var value)
|
||||
set(${var})
|
||||
foreach(value2 ${ARGN})
|
||||
if(${value} STREQUAL ${value2})
|
||||
set(${var} TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# parse a list of arguments and options
|
||||
# ex: sfml_parse_arguments(THIS "SOURCES;DEPENDS" "FLAG" FLAG SOURCES s1 s2 s3 DEPENDS d1 d2)
|
||||
# will define the following variables:
|
||||
# - THIS_SOURCES (s1 s2 s3)
|
||||
# - THIS_DEPENDS (d1 d2)
|
||||
# - THIS_FLAG TRUE
|
||||
macro(sfml_parse_arguments prefix arg_names option_names)
|
||||
foreach(arg_name ${arg_names})
|
||||
set(${prefix}_${arg_name})
|
||||
endforeach()
|
||||
foreach(option_name ${option_names})
|
||||
set(${prefix}_${option_name} FALSE)
|
||||
endforeach()
|
||||
set(current_arg_name)
|
||||
set(current_arg_list)
|
||||
foreach(arg ${ARGN})
|
||||
sfml_list_contains(is_arg_name ${arg} ${arg_names})
|
||||
if(is_arg_name)
|
||||
set(${prefix}_${current_arg_name} ${current_arg_list})
|
||||
set(current_arg_name ${arg})
|
||||
set(current_arg_list)
|
||||
else()
|
||||
sfml_list_contains(is_option ${arg} ${option_names})
|
||||
if(is_option)
|
||||
set(${prefix}_${arg} TRUE)
|
||||
else()
|
||||
set(current_arg_list ${current_arg_list} ${arg})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
set(${prefix}_${current_arg_name} ${current_arg_list})
|
||||
endmacro()
|
||||
|
||||
# add a new target which is a SFML library
|
||||
# ex: sfml_add_library(sfml-graphics
|
||||
# SOURCES sprite.cpp image.cpp ...
|
||||
# DEPENDS sfml-window sfml-system
|
||||
# EXTERNAL_LIBS opengl freetype ...)
|
||||
macro(sfml_add_library target)
|
||||
|
||||
# parse the arguments
|
||||
sfml_parse_arguments(THIS "SOURCES;DEPENDS;EXTERNAL_LIBS" "" ${ARGN})
|
||||
|
||||
# create the target
|
||||
add_library(${target} ${THIS_SOURCES})
|
||||
|
||||
# define the export symbol of the module
|
||||
string(REPLACE "-" "_" NAME_UPPER "${target}")
|
||||
string(TOUPPER "${NAME_UPPER}" NAME_UPPER)
|
||||
set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS)
|
||||
|
||||
# adjust the output file prefix/suffix to match our conventions
|
||||
if(BUILD_SHARED_LIBS)
|
||||
if(WINDOWS)
|
||||
# include the major version number in Windows shared library names (but not import library names)
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
set_target_properties(${target} PROPERTIES SUFFIX "-${VERSION_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
else()
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
endif()
|
||||
if (WINDOWS AND COMPILER_GCC)
|
||||
# on Windows/gcc get rid of "lib" prefix for shared libraries,
|
||||
# and transform the ".dll.a" suffix into ".a" for import libraries
|
||||
set_target_properties(${target} PROPERTIES PREFIX "")
|
||||
set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".a")
|
||||
endif()
|
||||
else()
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -s-d)
|
||||
set_target_properties(${target} PROPERTIES RELEASE_POSTFIX -s)
|
||||
set_target_properties(${target} PROPERTIES MINSIZEREL_POSTFIX -s)
|
||||
endif()
|
||||
|
||||
# set the version and soversion of the target (for compatible systems -- mostly Linuxes)
|
||||
set_target_properties(${target} PROPERTIES SOVERSION ${VERSION_MAJOR})
|
||||
set_target_properties(${target} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
|
||||
|
||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "SFML")
|
||||
|
||||
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
||||
if(WINDOWS AND COMPILER_GCC AND SFML_USE_STATIC_STD_LIBS)
|
||||
if(NOT GCC_VERSION VERSION_LESS "4")
|
||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# if using gcc >= 4.0 or clang >= 3.0 on a non-Windows platform, we must hide public symbols by default
|
||||
# (exported ones are explicitely marked)
|
||||
if(NOT WINDOWS AND ((COMPILER_GCC AND NOT GCC_VERSION VERSION_LESS "4") OR (COMPILER_CLANG AND NOT CLANG_VERSION VERSION_LESS "3")))
|
||||
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
|
||||
endif()
|
||||
|
||||
# link the target to its SFML dependencies
|
||||
if(THIS_DEPENDS)
|
||||
target_link_libraries(${target} ${THIS_DEPENDS})
|
||||
endif()
|
||||
|
||||
# build frameworks or dylibs
|
||||
if(MACOSX AND BUILD_SHARED_LIBS)
|
||||
if(SFML_BUILD_FRAMEWORKS)
|
||||
# adapt target to build frameworks instead of dylibs
|
||||
set_target_properties(${target} PROPERTIES
|
||||
FRAMEWORK TRUE
|
||||
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.${target}
|
||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
|
||||
endif()
|
||||
|
||||
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
|
||||
set_target_properties(${target} PROPERTIES
|
||||
BUILD_WITH_INSTALL_RPATH 1
|
||||
INSTALL_NAME_DIR "@executable_path/../Frameworks")
|
||||
endif()
|
||||
|
||||
# link the target to its external dependencies
|
||||
if(THIS_EXTERNAL_LIBS)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
# in shared build, we use the regular linker commands
|
||||
target_link_libraries(${target} ${THIS_EXTERNAL_LIBS})
|
||||
else()
|
||||
# in static build there's no link stage, but with some compilers it is possible to force
|
||||
# the generated static library to directly contain the symbols from its dependencies
|
||||
sfml_static_add_libraries(${target} ${THIS_EXTERNAL_LIBS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# add the install rule
|
||||
install(TARGETS ${target}
|
||||
RUNTIME DESTINATION bin COMPONENT bin
|
||||
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin
|
||||
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel
|
||||
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin)
|
||||
|
||||
endmacro()
|
||||
|
||||
# add a new target which is a SFML example
|
||||
# ex: sfml_add_example(ftp
|
||||
# SOURCES ftp.cpp ...
|
||||
# DEPENDS sfml-network sfml-system)
|
||||
macro(sfml_add_example target)
|
||||
|
||||
# parse the arguments
|
||||
sfml_parse_arguments(THIS "SOURCES;DEPENDS" "GUI_APP" ${ARGN})
|
||||
|
||||
# set a source group for the source files
|
||||
source_group("" FILES ${THIS_SOURCES})
|
||||
|
||||
# create the target
|
||||
if(THIS_GUI_APP AND WINDOWS)
|
||||
add_executable(${target} WIN32 ${THIS_SOURCES})
|
||||
target_link_libraries(${target} sfml-main)
|
||||
else()
|
||||
add_executable(${target} ${THIS_SOURCES})
|
||||
endif()
|
||||
|
||||
# set the debug suffix
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
|
||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "Examples")
|
||||
|
||||
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
||||
if(WINDOWS AND COMPILER_GCC AND SFML_USE_STATIC_STD_LIBS)
|
||||
if(NOT GCC_VERSION VERSION_LESS "4")
|
||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# link the target to its SFML dependencies
|
||||
if(THIS_DEPENDS)
|
||||
target_link_libraries(${target} ${THIS_DEPENDS})
|
||||
endif()
|
||||
|
||||
# add the install rule
|
||||
install(TARGETS ${target}
|
||||
RUNTIME DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples)
|
||||
|
||||
# install the example's source code
|
||||
install(FILES ${THIS_SOURCES}
|
||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||
COMPONENT examples)
|
||||
|
||||
# install the example's resources as well
|
||||
set(EXAMPLE_RESOURCES "${CMAKE_SOURCE_DIR}/examples/${target}/resources")
|
||||
if(EXISTS ${EXAMPLE_RESOURCES})
|
||||
install(DIRECTORY ${EXAMPLE_RESOURCES}
|
||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||
COMPONENT examples)
|
||||
endif()
|
||||
endmacro()
|
||||
include(CMakeParseArguments)
|
||||
|
||||
# This little macro lets you set any Xcode specific property
|
||||
macro (sfml_set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
|
||||
set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
|
||||
endmacro ()
|
||||
|
||||
# set the appropriate standard library on each platform for the given target
|
||||
# example: sfml_set_stdlib(sfml-system)
|
||||
function(sfml_set_stdlib target)
|
||||
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
||||
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
|
||||
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
|
||||
target_link_libraries(${target} PRIVATE "-static-libgcc" "-static-libstdc++")
|
||||
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
|
||||
target_link_libraries(${target} PRIVATE "-shared-libgcc" "-shared-libstdc++")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SFML_OS_MACOSX)
|
||||
if (${CMAKE_GENERATOR} MATCHES "Xcode")
|
||||
sfml_set_xcode_property(${target} CLANG_CXX_LIBRARY "libc++")
|
||||
else()
|
||||
target_compile_options(${target} PRIVATE "-stdlib=libc++")
|
||||
target_link_libraries(${target} PRIVATE "-stdlib=libc++")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(sfml_set_common_ios_properties target)
|
||||
# enable automatic reference counting on iOS
|
||||
sfml_set_xcode_property(${target} CLANG_ENABLE_OBJC_ARC YES)
|
||||
sfml_set_xcode_property(${target} IPHONEOS_DEPLOYMENT_TARGET "${SFML_IOS_DEPLOYMENT_TARGET}")
|
||||
sfml_set_xcode_property(${target} CODE_SIGN_IDENTITY "${SFML_CODE_SIGN_IDENTITY}")
|
||||
|
||||
get_target_property(target_type ${target} TYPE)
|
||||
if (target_type STREQUAL "EXECUTABLE")
|
||||
set_target_properties(${target} PROPERTIES
|
||||
MACOSX_BUNDLE TRUE # Bare executables are not usable on iOS, only bundle applications
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER "org.sfml-dev.${target}" # If missing, trying to launch an example in simulator will make Xcode < 9.3 crash
|
||||
MACOSX_BUNDLE_BUNDLE_NAME "${target}"
|
||||
MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# add a new target which is a SFML library
|
||||
# example: sfml_add_library(sfml-graphics
|
||||
# SOURCES sprite.cpp image.cpp ...
|
||||
# [STATIC]) # Always create a static library and ignore BUILD_SHARED_LIBS
|
||||
macro(sfml_add_library target)
|
||||
|
||||
# parse the arguments
|
||||
cmake_parse_arguments(THIS "STATIC" "" "SOURCES" ${ARGN})
|
||||
if (NOT "${THIS_UNPARSED_ARGUMENTS}" STREQUAL "")
|
||||
message(FATAL_ERROR "Extra unparsed arguments when calling sfml_add_library: ${THIS_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
|
||||
# create the target
|
||||
if (THIS_STATIC)
|
||||
add_library(${target} STATIC ${THIS_SOURCES})
|
||||
else()
|
||||
add_library(${target} ${THIS_SOURCES})
|
||||
endif()
|
||||
|
||||
# define the export symbol of the module
|
||||
string(REPLACE "-" "_" NAME_UPPER "${target}")
|
||||
string(TOUPPER "${NAME_UPPER}" NAME_UPPER)
|
||||
set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS)
|
||||
|
||||
# adjust the output file prefix/suffix to match our conventions
|
||||
if(BUILD_SHARED_LIBS AND NOT THIS_STATIC)
|
||||
if(SFML_OS_WINDOWS)
|
||||
# include the major version number in Windows shared library names (but not import library names)
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
set_target_properties(${target} PROPERTIES SUFFIX "-${VERSION_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
else()
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
endif()
|
||||
if (SFML_OS_WINDOWS AND SFML_COMPILER_GCC)
|
||||
# on Windows/gcc get rid of "lib" prefix for shared libraries,
|
||||
# and transform the ".dll.a" suffix into ".a" for import libraries
|
||||
set_target_properties(${target} PROPERTIES PREFIX "")
|
||||
set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".a")
|
||||
endif()
|
||||
else()
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -s-d)
|
||||
set_target_properties(${target} PROPERTIES RELEASE_POSTFIX -s)
|
||||
set_target_properties(${target} PROPERTIES MINSIZEREL_POSTFIX -s)
|
||||
set_target_properties(${target} PROPERTIES RELWITHDEBINFO_POSTFIX -s)
|
||||
endif()
|
||||
|
||||
# set the version and soversion of the target (for compatible systems -- mostly Linuxes)
|
||||
# except for Android which strips soversion suffixes
|
||||
if(NOT SFML_OS_ANDROID)
|
||||
set_target_properties(${target} PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR})
|
||||
set_target_properties(${target} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
|
||||
endif()
|
||||
|
||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "SFML")
|
||||
|
||||
# set the target flags to use the appropriate C++ standard library
|
||||
sfml_set_stdlib(${target})
|
||||
|
||||
# For Visual Studio on Windows, export debug symbols (PDB files) to lib directory
|
||||
if(SFML_GENERATE_PDB)
|
||||
# PDB files are only generated in Debug and RelWithDebInfo configurations, find out which one
|
||||
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
|
||||
set(SFML_PDB_POSTFIX "-d")
|
||||
else()
|
||||
set(SFML_PDB_POSTFIX "")
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS AND NOT THIS_STATIC)
|
||||
# DLLs export debug symbols in the linker PDB (the compiler PDB is an intermediate file)
|
||||
set_target_properties(${target} PROPERTIES
|
||||
PDB_NAME "${target}${SFML_PDB_POSTFIX}"
|
||||
PDB_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
|
||||
else()
|
||||
# Static libraries have no linker PDBs, thus the compiler PDBs are relevant
|
||||
set_target_properties(${target} PROPERTIES
|
||||
COMPILE_PDB_NAME "${target}-s${SFML_PDB_POSTFIX}"
|
||||
COMPILE_PDB_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# if using gcc >= 4.0 or clang >= 3.0 on a non-Windows platform, we must hide public symbols by default
|
||||
# (exported ones are explicitly marked)
|
||||
if(NOT SFML_OS_WINDOWS AND ((SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4") OR (SFML_COMPILER_CLANG AND NOT SFML_CLANG_VERSION VERSION_LESS "3")))
|
||||
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
|
||||
endif()
|
||||
|
||||
# build frameworks or dylibs
|
||||
if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS AND NOT THIS_STATIC)
|
||||
if(SFML_BUILD_FRAMEWORKS)
|
||||
# adapt target to build frameworks instead of dylibs
|
||||
set_target_properties(${target} PROPERTIES
|
||||
FRAMEWORK TRUE
|
||||
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.${target}
|
||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
|
||||
endif()
|
||||
|
||||
# adapt install directory to allow distributing dylibs/frameworks in user's frameworks/application bundle
|
||||
# but only if cmake rpath options aren't set
|
||||
if(NOT CMAKE_SKIP_RPATH AND NOT CMAKE_SKIP_INSTALL_RPATH AND NOT CMAKE_INSTALL_RPATH AND NOT CMAKE_INSTALL_RPATH_USE_LINK_PATH AND NOT CMAKE_INSTALL_NAME_DIR)
|
||||
set_target_properties(${target} PROPERTIES INSTALL_NAME_DIR "@rpath")
|
||||
if(NOT CMAKE_SKIP_BUILD_RPATH)
|
||||
if (CMAKE_VERSION VERSION_LESS 3.9)
|
||||
set_target_properties(${target} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
else()
|
||||
set_target_properties(${target} PROPERTIES BUILD_WITH_INSTALL_NAME_DIR TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SFML_OS_IOS)
|
||||
sfml_set_common_ios_properties(${target})
|
||||
endif()
|
||||
|
||||
# sfml-activity library is our bootstrap activity and must not depend on stlport_shared
|
||||
# (otherwise Android will fail to load it)
|
||||
if (SFML_OS_ANDROID)
|
||||
if (${target} MATCHES "sfml-activity")
|
||||
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fpermissive)
|
||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-landroid -llog")
|
||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STL})
|
||||
else()
|
||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_LIBRARY_WITH_STL})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# add the install rule
|
||||
install(TARGETS ${target} EXPORT SFMLConfigExport
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bin
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
||||
FRAMEWORK DESTINATION "." COMPONENT bin)
|
||||
|
||||
# add <project>/include as public include directory
|
||||
target_include_directories(${target}
|
||||
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/src)
|
||||
|
||||
if (SFML_BUILD_FRAMEWORKS)
|
||||
target_include_directories(${target} INTERFACE $<INSTALL_INTERFACE:SFML.framework>)
|
||||
else()
|
||||
target_include_directories(${target} INTERFACE $<INSTALL_INTERFACE:include>)
|
||||
endif()
|
||||
|
||||
# define SFML_STATIC if the build type is not set to 'shared'
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(${target} PUBLIC "SFML_STATIC")
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
||||
# add a new target which is a SFML example
|
||||
# example: sfml_add_example(ftp
|
||||
# SOURCES ftp.cpp ...
|
||||
# BUNDLE_RESOURCES MainMenu.nib ... # Files to be added in target but not installed next to the executable
|
||||
# DEPENDS sfml-network
|
||||
# RESOURCES_DIR resources) # A directory to install next to the executable and sources
|
||||
macro(sfml_add_example target)
|
||||
|
||||
# parse the arguments
|
||||
cmake_parse_arguments(THIS "GUI_APP" "RESOURCES_DIR" "SOURCES;BUNDLE_RESOURCES;DEPENDS" ${ARGN})
|
||||
|
||||
# set a source group for the source files
|
||||
source_group("" FILES ${THIS_SOURCES})
|
||||
|
||||
# check whether resources must be added in target
|
||||
set(target_input ${THIS_SOURCES})
|
||||
if(THIS_BUNDLE_RESOURCES)
|
||||
set(target_input ${target_input} ${THIS_BUNDLE_RESOURCES})
|
||||
endif()
|
||||
|
||||
# create the target
|
||||
if(THIS_GUI_APP AND SFML_OS_WINDOWS AND NOT DEFINED CMAKE_CONFIGURATION_TYPES AND ${CMAKE_BUILD_TYPE} STREQUAL "Release")
|
||||
add_executable(${target} WIN32 ${target_input})
|
||||
target_link_libraries(${target} PRIVATE sfml-main)
|
||||
elseif(THIS_GUI_APP AND SFML_OS_IOS)
|
||||
|
||||
# For iOS apps we need the launch screen storyboard,
|
||||
# and a custom info.plist to use it
|
||||
SET(LAUNCH_SCREEN "${CMAKE_SOURCE_DIR}/examples/assets/LaunchScreen.storyboard")
|
||||
SET(LOGO "${CMAKE_SOURCE_DIR}/examples/assets/logo.png")
|
||||
SET(INFO_PLIST "${CMAKE_SOURCE_DIR}/examples/assets/info.plist")
|
||||
SET(ICONS "${CMAKE_SOURCE_DIR}/examples/assets/icon.icns")
|
||||
add_executable(${target} MACOSX_BUNDLE ${target_input} ${LAUNCH_SCREEN} ${LOGO} ${ICONS})
|
||||
set(RESOURCES ${LAUNCH_SCREEN} ${LOGO} ${ICONS})
|
||||
set_target_properties(${target} PROPERTIES RESOURCE "${RESOURCES}"
|
||||
MACOSX_BUNDLE_INFO_PLIST ${INFO_PLIST}
|
||||
MACOSX_BUNDLE_ICON_FILE icon.icns)
|
||||
target_link_libraries(${target} PRIVATE sfml-main)
|
||||
else()
|
||||
add_executable(${target} ${target_input})
|
||||
endif()
|
||||
|
||||
# set the debug suffix
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
|
||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "Examples")
|
||||
|
||||
# set the target flags to use the appropriate C++ standard library
|
||||
sfml_set_stdlib(${target})
|
||||
|
||||
# set the Visual Studio startup path for debugging
|
||||
set_target_properties(${target} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# link the target to its SFML dependencies
|
||||
if(THIS_DEPENDS)
|
||||
target_link_libraries(${target} PRIVATE ${THIS_DEPENDS})
|
||||
endif()
|
||||
|
||||
if (SFML_OS_IOS)
|
||||
sfml_set_common_ios_properties(${target})
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
||||
# add a new target which is a SFML test
|
||||
# example: sfml_add_test(sfml-test
|
||||
# ftp.cpp ...
|
||||
# sfml-network)
|
||||
function(sfml_add_test target SOURCES DEPENDS)
|
||||
|
||||
# set a source group for the source files
|
||||
source_group("" FILES ${SOURCES})
|
||||
|
||||
# create the target
|
||||
add_executable(${target} ${SOURCES})
|
||||
|
||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "Tests")
|
||||
|
||||
# link the target to its SFML dependencies
|
||||
if(DEPENDS)
|
||||
target_link_libraries(${target} PRIVATE ${DEPENDS})
|
||||
endif()
|
||||
|
||||
# Add the test
|
||||
add_test(${target} ${target})
|
||||
|
||||
# If building shared libs on windows we must copy the dependencies into the folder
|
||||
if (WIN32 AND BUILD_SHARED_LIBS)
|
||||
foreach (DEPENDENCY ${DEPENDS})
|
||||
add_custom_command(TARGET ${target} PRE_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
$<TARGET_FILE:${DEPENDENCY}>
|
||||
$<TARGET_FILE_DIR:${target}>)
|
||||
endforeach()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Create an interface library for an external dependency. This virtual target can provide
|
||||
# link specifications and include directories to be used by dependees.
|
||||
# The created INTERFACE library is tagged for export to be part of the generated SFMLConfig
|
||||
# Usage: sfml_add_external(target_name
|
||||
# [INCLUDE "extlibs/include"]
|
||||
# [LINK "extlibs/libfoo/libfoo.a"])
|
||||
function(sfml_add_external)
|
||||
list(GET ARGN 0 target)
|
||||
list(REMOVE_AT ARGN 0)
|
||||
|
||||
if (TARGET ${target})
|
||||
message(FATAL_ERROR "Target '${target}' is already defined")
|
||||
endif()
|
||||
|
||||
cmake_parse_arguments(THIS "" "" "INCLUDE;LINK" ${ARGN})
|
||||
if (THIS_UNPARSED_ARGUMENTS)
|
||||
message(FATAL_ERROR "Unknown arguments when calling sfml_import_library: ${THIS_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
|
||||
add_library(${target} INTERFACE)
|
||||
|
||||
if (THIS_INCLUDE)
|
||||
foreach(include_dir IN LISTS THIS_INCLUDE)
|
||||
if (NOT include_dir)
|
||||
message(FATAL_ERROR "No path given for include dir ${THIS_INCLUDE}")
|
||||
endif()
|
||||
target_include_directories(${target} INTERFACE "$<BUILD_INTERFACE:${include_dir}>")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if (THIS_LINK)
|
||||
foreach(link_item IN LISTS THIS_LINK)
|
||||
if (NOT link_item)
|
||||
message(FATAL_ERROR "Missing item in ${THIS_LINK}")
|
||||
endif()
|
||||
target_link_libraries(${target} INTERFACE "$<BUILD_INTERFACE:${link_item}>")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
install(TARGETS ${target} EXPORT SFMLConfigExport)
|
||||
endfunction()
|
||||
|
||||
# Find the requested package and make an INTERFACE library from it
|
||||
# The created INTERFACE library is tagged for export to be part of the generated SFMLConfig
|
||||
# Usage: sfml_find_package(wanted_target_name
|
||||
# [INCLUDE "OPENGL_INCLUDE_DIR"]
|
||||
# [LINK "OPENGL_gl_LIBRARY"])
|
||||
function(sfml_find_package)
|
||||
list(GET ARGN 0 target)
|
||||
list(REMOVE_AT ARGN 0)
|
||||
|
||||
if (TARGET ${target})
|
||||
message(FATAL_ERROR "Target '${target}' is already defined")
|
||||
endif()
|
||||
|
||||
cmake_parse_arguments(THIS "" "" "INCLUDE;LINK" ${ARGN})
|
||||
if (THIS_UNPARSED_ARGUMENTS)
|
||||
message(FATAL_ERROR "Unknown arguments when calling sfml_import_library: ${THIS_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
|
||||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")
|
||||
if (SFML_OS_IOS)
|
||||
find_host_package(${target} REQUIRED)
|
||||
else()
|
||||
find_package(${target} REQUIRED)
|
||||
endif()
|
||||
|
||||
# Make sure to interpret the items in INCLUDE and LINK parameters. sfml_add_external()
|
||||
# does not interpret given items in order to also accept parameters that must not be interpreted
|
||||
set(LINK_LIST "")
|
||||
if (THIS_LINK)
|
||||
foreach(link_item IN LISTS THIS_LINK)
|
||||
list(APPEND LINK_LIST "${${link_item}}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set(INCLUDE_LIST "")
|
||||
if (THIS_INCLUDE)
|
||||
foreach(include_dir IN LISTS THIS_INCLUDE)
|
||||
list(APPEND INCLUDE_LIST "${${include_dir}}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
sfml_add_external(${target} INCLUDE ${INCLUDE_LIST} LINK ${LINK_LIST})
|
||||
endfunction()
|
||||
|
||||
# Generate a SFMLConfig.cmake file (and associated files) from the targets registered against
|
||||
# the EXPORT name "SFMLConfigExport" (EXPORT parameter of install(TARGETS))
|
||||
function(sfml_export_targets)
|
||||
# CMAKE_CURRENT_LIST_DIR or CMAKE_CURRENT_SOURCE_DIR not usable for files that are to be included like this one
|
||||
set(CURRENT_DIR "${PROJECT_SOURCE_DIR}/cmake")
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SFMLConfigVersion.cmake"
|
||||
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
set(config_name "Shared")
|
||||
else()
|
||||
set(config_name "Static")
|
||||
endif()
|
||||
set(targets_config_filename "SFML${config_name}Targets.cmake")
|
||||
|
||||
export(EXPORT SFMLConfigExport
|
||||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${targets_config_filename}")
|
||||
|
||||
if (SFML_BUILD_FRAMEWORKS)
|
||||
set(config_package_location "SFML.framework/Resources/CMake")
|
||||
else()
|
||||
set(config_package_location ${CMAKE_INSTALL_LIBDIR}/cmake/SFML)
|
||||
endif()
|
||||
configure_package_config_file("${CURRENT_DIR}/SFMLConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/SFMLConfig.cmake"
|
||||
INSTALL_DESTINATION "${config_package_location}")
|
||||
configure_package_config_file("${CURRENT_DIR}/SFMLConfigDependencies.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/SFMLConfigDependencies.cmake"
|
||||
INSTALL_DESTINATION "${config_package_location}")
|
||||
|
||||
|
||||
install(EXPORT SFMLConfigExport
|
||||
FILE ${targets_config_filename}
|
||||
DESTINATION ${config_package_location})
|
||||
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SFMLConfig.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/SFMLConfigDependencies.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/SFMLConfigVersion.cmake"
|
||||
DESTINATION ${config_package_location}
|
||||
COMPONENT devel)
|
||||
endfunction()
|
||||
|
|
14
cmake/Modules/FindEGL.cmake
Normal file
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# Try to find EGL library and include path.
|
||||
# Once done this will define
|
||||
#
|
||||
# EGL_FOUND
|
||||
# EGL_INCLUDE_PATH
|
||||
# EGL_LIBRARY
|
||||
#
|
||||
|
||||
find_path(EGL_INCLUDE_DIR EGL/egl.h)
|
||||
find_library(EGL_LIBRARY NAMES EGL)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR)
|
18
cmake/Modules/FindFLAC.cmake
Normal file
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# Try to find FLAC libraries and include paths.
|
||||
# Once done this will define
|
||||
#
|
||||
# FLAC_FOUND
|
||||
# FLAC_INCLUDE_DIR
|
||||
# FLAC_LIBRARY
|
||||
#
|
||||
|
||||
find_path(FLAC_INCLUDE_DIR FLAC/all.h)
|
||||
find_path(FLAC_INCLUDE_DIR FLAC/stream_decoder.h)
|
||||
|
||||
find_library(FLAC_LIBRARY NAMES FLAC)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(FLAC DEFAULT_MSG FLAC_LIBRARY FLAC_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(FLAC_INCLUDE_DIR FLAC_LIBRARY)
|
158
cmake/Modules/FindFreetype.cmake
Normal file
|
@ -0,0 +1,158 @@
|
|||
#.rst:
|
||||
# FindFreetype
|
||||
# ------------
|
||||
#
|
||||
# Locate FreeType library
|
||||
#
|
||||
# This module defines
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# FREETYPE_LIBRARIES, the library to link against
|
||||
# FREETYPE_FOUND, if false, do not try to link to FREETYPE
|
||||
# FREETYPE_INCLUDE_DIRS, where to find headers.
|
||||
# FREETYPE_VERSION_STRING, the version of freetype found (since CMake 2.8.8)
|
||||
# This is the concatenation of the paths:
|
||||
# FREETYPE_INCLUDE_DIR_ft2build
|
||||
# FREETYPE_INCLUDE_DIR_freetype2
|
||||
#
|
||||
#
|
||||
#
|
||||
# $FREETYPE_DIR is an environment variable that would correspond to the
|
||||
# ./configure --prefix=$FREETYPE_DIR used in building FREETYPE.
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2007-2009 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
# Created by Eric Wing.
|
||||
# Modifications by Alexander Neundorf.
|
||||
# This file has been renamed to "FindFreetype.cmake" instead of the correct
|
||||
# "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex.
|
||||
|
||||
# Ugh, FreeType seems to use some #include trickery which
|
||||
# makes this harder than it should be. It looks like they
|
||||
# put ft2build.h in a common/easier-to-find location which
|
||||
# then contains a #include to a more specific header in a
|
||||
# more specific location (#include <freetype/config/ftheader.h>).
|
||||
# Then from there, they need to set a bunch of #define's
|
||||
# so you can do something like:
|
||||
# #include FT_FREETYPE_H
|
||||
# Unfortunately, using CMake's mechanisms like include_directories()
|
||||
# wants explicit full paths and this trickery doesn't work too well.
|
||||
# I'm going to attempt to cut out the middleman and hope
|
||||
# everything still works.
|
||||
find_path(
|
||||
FREETYPE_INCLUDE_DIR_ft2build
|
||||
ft2build.h
|
||||
HINTS
|
||||
ENV FREETYPE_DIR
|
||||
PATHS
|
||||
/usr/X11R6
|
||||
/usr/local/X11R6
|
||||
/usr/local/X11
|
||||
/usr/freeware
|
||||
ENV GTKMM_BASEPATH
|
||||
[HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
|
||||
PATH_SUFFIXES
|
||||
include/freetype2
|
||||
include
|
||||
freetype2
|
||||
)
|
||||
|
||||
find_path(
|
||||
FREETYPE_INCLUDE_DIR_freetype2
|
||||
NAMES
|
||||
freetype/config/ftheader.h
|
||||
config/ftheader.h
|
||||
HINTS
|
||||
ENV FREETYPE_DIR
|
||||
PATHS
|
||||
/usr/X11R6
|
||||
/usr/local/X11R6
|
||||
/usr/local/X11
|
||||
/usr/freeware
|
||||
ENV GTKMM_BASEPATH
|
||||
[HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
|
||||
PATH_SUFFIXES
|
||||
include/freetype2
|
||||
include
|
||||
freetype2
|
||||
)
|
||||
|
||||
find_library(FREETYPE_LIBRARY
|
||||
NAMES
|
||||
freetype
|
||||
libfreetype
|
||||
freetype219
|
||||
HINTS
|
||||
ENV FREETYPE_DIR
|
||||
PATHS
|
||||
/usr/X11R6
|
||||
/usr/local/X11R6
|
||||
/usr/local/X11
|
||||
/usr/freeware
|
||||
ENV GTKMM_BASEPATH
|
||||
[HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
)
|
||||
|
||||
# set the user variables
|
||||
if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
|
||||
set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}")
|
||||
list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS)
|
||||
endif()
|
||||
set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}")
|
||||
|
||||
if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
|
||||
set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
|
||||
elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
|
||||
set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
|
||||
endif()
|
||||
|
||||
if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H)
|
||||
file(STRINGS "${FREETYPE_H}" freetype_version_str
|
||||
REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
|
||||
|
||||
unset(FREETYPE_VERSION_STRING)
|
||||
foreach(VPART MAJOR MINOR PATCH)
|
||||
foreach(VLINE ${freetype_version_str})
|
||||
if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$")
|
||||
set(FREETYPE_VERSION_PART "${CMAKE_MATCH_1}")
|
||||
if(FREETYPE_VERSION_STRING)
|
||||
set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}")
|
||||
else()
|
||||
set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}")
|
||||
endif()
|
||||
unset(FREETYPE_VERSION_PART)
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
||||
# set FREETYPE_FOUND to TRUE if all listed variables are TRUE
|
||||
if(FREETYPE_LIBRARY AND FREETYPE_INCLUDE_DIRS AND FREETYPE_VERSION_STRING)
|
||||
set(FREETYPE_FOUND TRUE)
|
||||
else()
|
||||
set(FREETYPE_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
FREETYPE_LIBRARY
|
||||
FREETYPE_INCLUDE_DIR_freetype2
|
||||
FREETYPE_INCLUDE_DIR_ft2build
|
||||
)
|
14
cmake/Modules/FindGLES.cmake
Normal file
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# Try to find GLES library and include path.
|
||||
# Once done this will define
|
||||
#
|
||||
# GLES_FOUND
|
||||
# GLES_INCLUDE_PATH
|
||||
# GLES_LIBRARY
|
||||
#
|
||||
|
||||
find_path(GLES_INCLUDE_DIR GLES/gl.h)
|
||||
find_library(GLES_LIBRARY NAMES GLESv1_CM)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(GLES DEFAULT_MSG GLES_LIBRARY GLES_INCLUDE_DIR)
|
|
@ -1,65 +0,0 @@
|
|||
#
|
||||
# Try to find GLEW library and include path.
|
||||
# Once done this will define
|
||||
#
|
||||
# GLEW_FOUND
|
||||
# GLEW_INCLUDE_PATH
|
||||
# GLEW_LIBRARY
|
||||
#
|
||||
|
||||
IF (WIN32)
|
||||
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
|
||||
$ENV{PROGRAMFILES}/GLEW/include
|
||||
${GLEW_ROOT_DIR}/include
|
||||
DOC "The directory where GL/glew.h resides")
|
||||
|
||||
IF (NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||
FIND_LIBRARY( GLEW_LIBRARY
|
||||
NAMES glew64 glew64s
|
||||
PATHS
|
||||
$ENV{PROGRAMFILES}/GLEW/lib
|
||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
|
||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
|
||||
DOC "The GLEW library (64-bit)"
|
||||
)
|
||||
ELSE(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||
FIND_LIBRARY( GLEW_LIBRARY
|
||||
NAMES glew GLEW glew32 glew32s
|
||||
PATHS
|
||||
$ENV{PROGRAMFILES}/GLEW/lib
|
||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
|
||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
|
||||
DOC "The GLEW library"
|
||||
)
|
||||
ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||
ELSE (WIN32)
|
||||
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/sw/include
|
||||
/opt/local/include
|
||||
${GLEW_ROOT_DIR}/include
|
||||
DOC "The directory where GL/glew.h resides")
|
||||
|
||||
FIND_LIBRARY( GLEW_LIBRARY
|
||||
NAMES GLEW glew
|
||||
PATHS
|
||||
/usr/lib64
|
||||
/usr/lib
|
||||
/usr/local/lib64
|
||||
/usr/local/lib
|
||||
/sw/lib
|
||||
/opt/local/lib
|
||||
${GLEW_ROOT_DIR}/lib
|
||||
DOC "The GLEW library")
|
||||
ENDIF (WIN32)
|
||||
|
||||
SET(GLEW_FOUND "NO")
|
||||
IF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
|
||||
SET(GLEW_LIBRARIES ${GLEW_LIBRARY})
|
||||
SET(GLEW_FOUND "YES")
|
||||
ENDIF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
|
||||
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_PATH)
|
|
@ -1,209 +0,0 @@
|
|||
# This script locates the SFML library
|
||||
# ------------------------------------
|
||||
#
|
||||
# Usage
|
||||
# -----
|
||||
#
|
||||
# When you try to locate the SFML libraries, you must specify which modules you want to use (system, window, graphics, network, audio, main).
|
||||
# If none is given, the SFML_LIBRARIES variable will be empty and you'll end up linking to nothing.
|
||||
# example:
|
||||
# find_package(SFML COMPONENTS graphics window system) // find the graphics, window and system modules
|
||||
#
|
||||
# You can enforce a specific version, either MAJOR.MINOR or only MAJOR.
|
||||
# If nothing is specified, the version won't be checked (ie. any version will be accepted).
|
||||
# example:
|
||||
# find_package(SFML COMPONENTS ...) // no specific version required
|
||||
# find_package(SFML 2 COMPONENTS ...) // any 2.x version
|
||||
# find_package(SFML 2.4 COMPONENTS ...) // version 2.4 or greater
|
||||
#
|
||||
# By default, the dynamic libraries of SFML will be found. To find the static ones instead,
|
||||
# you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...).
|
||||
# In case of static linking, the SFML_STATIC macro will also be defined by this script.
|
||||
# example:
|
||||
# set(SFML_STATIC_LIBRARIES TRUE)
|
||||
# find_package(SFML 2 COMPONENTS network system)
|
||||
#
|
||||
# On Mac OS X if SFML_STATIC_LIBRARIES is not set to TRUE then by default CMake will search for frameworks unless
|
||||
# CMAKE_FIND_FRAMEWORK is set to "NEVER" for example. Please refer to CMake documentation for more details.
|
||||
# Moreover, keep in mind that SFML frameworks are only available as release libraries unlike dylibs which
|
||||
# are available for both release and debug modes.
|
||||
#
|
||||
# If SFML is not installed in a standard path, you can use the SFML_ROOT CMake (or environment) variable
|
||||
# to tell CMake where SFML is.
|
||||
#
|
||||
# Output
|
||||
# ------
|
||||
#
|
||||
# This script defines the following variables:
|
||||
# - For each specified module XXX (system, window, graphics, network, audio, main):
|
||||
# - SFML_XXX_LIBRARY_DEBUG: the name of the debug library of the xxx module (set to SFML_XXX_LIBRARY_RELEASE is no debug version is found)
|
||||
# - SFML_XXX_LIBRARY_RELEASE: the name of the release library of the xxx module (set to SFML_XXX_LIBRARY_DEBUG is no release version is found)
|
||||
# - SFML_XXX_LIBRARY: the name of the library to link to for the xxx module (includes both debug and optimized names if necessary)
|
||||
# - SFML_XXX_FOUND: true if either the debug or release library of the xxx module is found
|
||||
# - SFML_LIBRARIES: the list of all libraries corresponding to the required modules
|
||||
# - SFML_FOUND: true if all the required modules are found
|
||||
# - SFML_INCLUDE_DIR: the path where SFML headers are located (the directory containing the SFML/Config.hpp file)
|
||||
#
|
||||
# example:
|
||||
# find_package(SFML 2 COMPONENTS system window graphics audio REQUIRED)
|
||||
# include_directories(${SFML_INCLUDE_DIR})
|
||||
# add_executable(myapp ...)
|
||||
# target_link_libraries(myapp ${SFML_LIBRARIES})
|
||||
|
||||
# define the SFML_STATIC macro if static build was chosen
|
||||
if(SFML_STATIC_LIBRARIES)
|
||||
add_definitions(-DSFML_STATIC)
|
||||
endif()
|
||||
|
||||
# deduce the libraries suffix from the options
|
||||
set(FIND_SFML_LIB_SUFFIX "")
|
||||
if(SFML_STATIC_LIBRARIES)
|
||||
set(FIND_SFML_LIB_SUFFIX "${FIND_SFML_LIB_SUFFIX}-s")
|
||||
endif()
|
||||
|
||||
# find the SFML include directory
|
||||
find_path(SFML_INCLUDE_DIR SFML/Config.hpp
|
||||
PATH_SUFFIXES include
|
||||
PATHS
|
||||
${SFML_ROOT}
|
||||
$ENV{SFML_ROOT}
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local/
|
||||
/usr/
|
||||
/sw # Fink
|
||||
/opt/local/ # DarwinPorts
|
||||
/opt/csw/ # Blastwave
|
||||
/opt/)
|
||||
|
||||
# check the version number
|
||||
set(SFML_VERSION_OK TRUE)
|
||||
if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR)
|
||||
# extract the major and minor version numbers from SFML/Config.hpp
|
||||
# we have to handle framework a little bit differently :
|
||||
if("${SFML_INCLUDE_DIR}" MATCHES "SFML.framework")
|
||||
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/Headers/Config.hpp")
|
||||
else()
|
||||
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/SFML/Config.hpp")
|
||||
endif()
|
||||
FILE(READ "${SFML_CONFIG_HPP_INPUT}" SFML_CONFIG_HPP_CONTENTS)
|
||||
STRING(REGEX MATCH ".*#define SFML_VERSION_MAJOR ([0-9]+).*#define SFML_VERSION_MINOR ([0-9]+).*" SFML_CONFIG_HPP_CONTENTS "${SFML_CONFIG_HPP_CONTENTS}")
|
||||
STRING(REGEX REPLACE ".*#define SFML_VERSION_MAJOR ([0-9]+).*" "\\1" SFML_VERSION_MAJOR "${SFML_CONFIG_HPP_CONTENTS}")
|
||||
STRING(REGEX REPLACE ".*#define SFML_VERSION_MINOR ([0-9]+).*" "\\1" SFML_VERSION_MINOR "${SFML_CONFIG_HPP_CONTENTS}")
|
||||
math(EXPR SFML_REQUESTED_VERSION "${SFML_FIND_VERSION_MAJOR} * 10 + ${SFML_FIND_VERSION_MINOR}")
|
||||
|
||||
# if we could extract them, compare with the requested version number
|
||||
if (SFML_VERSION_MAJOR)
|
||||
# transform version numbers to an integer
|
||||
math(EXPR SFML_VERSION "${SFML_VERSION_MAJOR} * 10 + ${SFML_VERSION_MINOR}")
|
||||
|
||||
# compare them
|
||||
if(SFML_VERSION LESS SFML_REQUESTED_VERSION)
|
||||
set(SFML_VERSION_OK FALSE)
|
||||
endif()
|
||||
else()
|
||||
# SFML version is < 2.0
|
||||
if (SFML_REQUESTED_VERSION GREATER 19)
|
||||
set(SFML_VERSION_OK FALSE)
|
||||
set(SFML_VERSION_MAJOR 1)
|
||||
set(SFML_VERSION_MINOR x)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# find the requested modules
|
||||
set(SFML_FOUND TRUE) # will be set to false if one of the required modules is not found
|
||||
set(FIND_SFML_LIB_PATHS
|
||||
${SFML_ROOT}
|
||||
$ENV{SFML_ROOT}
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt)
|
||||
foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS})
|
||||
string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER)
|
||||
string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER)
|
||||
set(FIND_SFML_COMPONENT_NAME sfml-${FIND_SFML_COMPONENT_LOWER}${FIND_SFML_LIB_SUFFIX})
|
||||
|
||||
# no suffix for sfml-main, it is always a static library
|
||||
if(FIND_SFML_COMPONENT_LOWER STREQUAL "main")
|
||||
set(FIND_SFML_COMPONENT_NAME sfml-${FIND_SFML_COMPONENT_LOWER})
|
||||
endif()
|
||||
|
||||
# debug library
|
||||
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG
|
||||
NAMES ${FIND_SFML_COMPONENT_NAME}-d
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS ${FIND_SFML_LIB_PATHS})
|
||||
|
||||
# release library
|
||||
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE
|
||||
NAMES ${FIND_SFML_COMPONENT_NAME}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS ${FIND_SFML_LIB_PATHS})
|
||||
|
||||
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG OR SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
||||
# library found
|
||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND TRUE)
|
||||
|
||||
# if both are found, set SFML_XXX_LIBRARY to contain both
|
||||
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY debug ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}
|
||||
optimized ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
||||
endif()
|
||||
|
||||
# if only one debug/release variant is found, set the other to be equal to the found one
|
||||
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
||||
# debug and not release
|
||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG})
|
||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG})
|
||||
endif()
|
||||
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG)
|
||||
# release and not debug
|
||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
||||
endif()
|
||||
else()
|
||||
# library not found
|
||||
set(SFML_FOUND FALSE)
|
||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND FALSE)
|
||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY "")
|
||||
set(FIND_SFML_MISSING "${FIND_SFML_MISSING} SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY")
|
||||
endif()
|
||||
|
||||
# mark as advanced
|
||||
MARK_AS_ADVANCED(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY
|
||||
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE
|
||||
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG)
|
||||
|
||||
# add to the global list of libraries
|
||||
set(SFML_LIBRARIES ${SFML_LIBRARIES} "${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY}")
|
||||
endforeach()
|
||||
|
||||
# handle errors
|
||||
if(NOT SFML_VERSION_OK)
|
||||
# SFML version not ok
|
||||
set(FIND_SFML_ERROR "SFML found but version too low (requested: ${SFML_FIND_VERSION}, found: ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR})")
|
||||
set(SFML_FOUND FALSE)
|
||||
elseif(NOT SFML_FOUND)
|
||||
# include directory or library not found
|
||||
set(FIND_SFML_ERROR "Could NOT find SFML (missing: ${FIND_SFML_MISSING})")
|
||||
endif()
|
||||
if (NOT SFML_FOUND)
|
||||
if(SFML_FIND_REQUIRED)
|
||||
# fatal error
|
||||
message(FATAL_ERROR ${FIND_SFML_ERROR})
|
||||
elseif(NOT SFML_FIND_QUIETLY)
|
||||
# error but continue
|
||||
message("${FIND_SFML_ERROR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# handle success
|
||||
if(SFML_FOUND)
|
||||
message(STATUS "Found SFML ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR} in ${SFML_INCLUDE_DIR}")
|
||||
endif()
|
|
@ -1,28 +0,0 @@
|
|||
# - Find sndfile
|
||||
# Find the native sndfile includes and libraries
|
||||
#
|
||||
# SNDFILE_INCLUDE_DIR - where to find sndfile.h, etc.
|
||||
# SNDFILE_LIBRARIES - List of libraries when using libsndfile.
|
||||
# SNDFILE_FOUND - True if libsndfile found.
|
||||
|
||||
if(SNDFILE_INCLUDE_DIR)
|
||||
# Already in cache, be silent
|
||||
set(SNDFILE_FIND_QUIETLY TRUE)
|
||||
endif(SNDFILE_INCLUDE_DIR)
|
||||
|
||||
find_path(SNDFILE_INCLUDE_DIR sndfile.h)
|
||||
|
||||
find_library(SNDFILE_LIBRARY NAMES sndfile sndfile-1)
|
||||
|
||||
# Handle the QUIETLY and REQUIRED arguments and set SNDFILE_FOUND to TRUE if
|
||||
# all listed variables are TRUE.
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(SNDFILE DEFAULT_MSG SNDFILE_LIBRARY SNDFILE_INCLUDE_DIR)
|
||||
|
||||
if(SNDFILE_FOUND)
|
||||
set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY})
|
||||
else(SNDFILE_FOUND)
|
||||
set(SNDFILE_LIBRARIES)
|
||||
endif(SNDFILE_FOUND)
|
||||
|
||||
mark_as_advanced(SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY)
|
53
cmake/Modules/FindUDev.cmake
Normal file
|
@ -0,0 +1,53 @@
|
|||
# Configure libudev environment
|
||||
#
|
||||
# UDEV_FOUND - system has a libudev
|
||||
# UDEV_INCLUDE_DIR - where to find header files
|
||||
# UDEV_LIBRARIES - the libraries to link against udev
|
||||
# UDEV_STABLE - it's true when is the version greater or equals to 143 - version when the libudev was stabilized in its API
|
||||
#
|
||||
# copyright (c) 2011 Petr Vanek <petr@scribus.info>
|
||||
# Redistribution and use of this file is allowed according to the terms of the BSD license.
|
||||
#
|
||||
|
||||
FIND_PATH(
|
||||
UDEV_INCLUDE_DIR
|
||||
libudev.h
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
${UDEV_PATH_INCLUDES}
|
||||
)
|
||||
|
||||
FIND_LIBRARY(
|
||||
UDEV_LIBRARIES
|
||||
NAMES udev libudev
|
||||
PATHS ${ADDITIONAL_LIBRARY_PATHS}
|
||||
${UDEV_PATH_LIB}
|
||||
)
|
||||
|
||||
IF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR)
|
||||
SET(UDEV_FOUND "YES")
|
||||
execute_process(COMMAND pkg-config --atleast-version=143 libudev RESULT_VARIABLE UDEV_STABLE)
|
||||
# retvale is 0 of the condition is "true" so we need to negate the value...
|
||||
if (UDEV_STABLE)
|
||||
set(UDEV_STABLE 0)
|
||||
else (UDEV_STABLE)
|
||||
set(UDEV_STABLE 1)
|
||||
endif (UDEV_STABLE)
|
||||
message(STATUS "libudev stable: ${UDEV_STABLE}")
|
||||
ENDIF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR)
|
||||
|
||||
IF (UDEV_FOUND)
|
||||
MESSAGE(STATUS "Found UDev: ${UDEV_LIBRARIES}")
|
||||
MESSAGE(STATUS " include: ${UDEV_INCLUDE_DIR}")
|
||||
ELSE (UDEV_FOUND)
|
||||
MESSAGE(STATUS "UDev not found.")
|
||||
MESSAGE(STATUS "UDev: You can specify includes: -DUDEV_PATH_INCLUDES=/opt/udev/include")
|
||||
MESSAGE(STATUS " currently found includes: ${UDEV_INCLUDE_DIR}")
|
||||
MESSAGE(STATUS "UDev: You can specify libs: -DUDEV_PATH_LIB=/opt/udev/lib")
|
||||
MESSAGE(STATUS " currently found libs: ${UDEV_LIBRARIES}")
|
||||
IF (UDev_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR "Could not find UDev library")
|
||||
ENDIF (UDev_FIND_REQUIRED)
|
||||
ENDIF (UDEV_FOUND)
|
||||
|
||||
mark_as_advanced(UDEV_INCLUDE_DIR UDEV_LIBRARIES)
|
29
cmake/Modules/FindVORBIS.cmake
Normal file
|
@ -0,0 +1,29 @@
|
|||
#
|
||||
# Try to find Ogg/Vorbis libraries and include paths.
|
||||
# Once done this will define
|
||||
#
|
||||
# VORBIS_FOUND
|
||||
# VORBIS_INCLUDE_DIRS
|
||||
# VORBIS_LIBRARIES
|
||||
#
|
||||
|
||||
find_path(OGG_INCLUDE_DIR ogg/ogg.h)
|
||||
find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h)
|
||||
|
||||
find_library(OGG_LIBRARY NAMES ogg)
|
||||
find_library(VORBIS_LIBRARY NAMES vorbis)
|
||||
if (NOT SFML_OS_IOS)
|
||||
find_library(VORBISFILE_LIBRARY NAMES vorbisfile)
|
||||
find_library(VORBISENC_LIBRARY NAMES vorbisenc)
|
||||
set(VORBIS_LIBRARIES ${VORBISENC_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY})
|
||||
else()
|
||||
set(VORBIS_LIBRARIES ${VORBIS_LIBRARY} ${OGG_LIBRARY})
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(VORBIS DEFAULT_MSG VORBIS_LIBRARIES VORBIS_INCLUDE_DIR OGG_INCLUDE_DIR)
|
||||
|
||||
set(VORBIS_INCLUDE_DIRS ${OGG_INCLUDE_DIR} ${VORBIS_INCLUDE_DIR})
|
||||
|
||||
mark_as_advanced(OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY VORBISENC_LIBRARY)
|
148
cmake/SFMLConfig.cmake.in
Normal file
|
@ -0,0 +1,148 @@
|
|||
# This script provides the SFML libraries as imported targets
|
||||
# ------------------------------------
|
||||
#
|
||||
# Usage
|
||||
# -----
|
||||
#
|
||||
# When you try to locate the SFML libraries, you must specify which modules you want to use (system, window, graphics, network, audio, main).
|
||||
# If none is given, no imported target will be created and you won't be able to link to SFML libraries.
|
||||
# example:
|
||||
# find_package(SFML COMPONENTS graphics window system) # find the graphics, window and system modules
|
||||
#
|
||||
# You can enforce a specific version, either MAJOR.MINOR or only MAJOR.
|
||||
# If nothing is specified, the version won't be checked (i.e. any version will be accepted).
|
||||
# example:
|
||||
# find_package(SFML COMPONENTS ...) # no specific version required
|
||||
# find_package(SFML 2 COMPONENTS ...) # any 2.x version
|
||||
# find_package(SFML 2.4 COMPONENTS ...) # version 2.4 or greater
|
||||
#
|
||||
# By default, the dynamic libraries of SFML will be found. To find the static ones instead,
|
||||
# you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...).
|
||||
# You don't need to deal with SFML's dependencies when linking your targets against SFML libraries,
|
||||
# they will all be configured automatically, even if you use SFML static libraries.
|
||||
# example:
|
||||
# set(SFML_STATIC_LIBRARIES TRUE)
|
||||
# find_package(SFML 2 COMPONENTS network system)
|
||||
#
|
||||
# On macOS by default CMake will search for frameworks. If you want to use static libraries and have installed
|
||||
# both SFML frameworks and SFML static libraries, your must set CMAKE_FIND_FRAMEWORK to "NEVER" or "LAST"
|
||||
# in addition to setting SFML_STATIC_LIBRARIES to TRUE. Otherwise CMake will check the frameworks bundle config and
|
||||
# fail after finding out that it does not provide static libraries. Please refer to CMake documentation for more details.
|
||||
#
|
||||
# Additionally, keep in mind that SFML frameworks are only available as release libraries unlike dylibs which
|
||||
# are available for both release and debug modes.
|
||||
#
|
||||
# If SFML is not installed in a standard path, you can use the SFML_DIR CMake variable
|
||||
# to tell CMake where SFML's config file is located (PREFIX/lib/cmake/SFML for a library-based installation,
|
||||
# and PREFIX/SFML.framework/Resources/CMake on macOS for a framework-based installation).
|
||||
#
|
||||
# Output
|
||||
# ------
|
||||
#
|
||||
# This script defines the following variables:
|
||||
# - For each specified module XXX (system, window, graphics, network, audio, main):
|
||||
# - SFML_XXX_FOUND: true if either the debug or release library of the xxx module is found
|
||||
# - SFML_FOUND: true if all the required modules are found
|
||||
#
|
||||
# And the following targets:
|
||||
# - For each specified module XXX (system, window, graphics, network, audio, main):
|
||||
# - sfml-XXX
|
||||
# The SFML targets are the same for both Debug and Release build configurations and will automatically provide
|
||||
# correct settings based on your currently active build configuration. The SFML targets name also do not change
|
||||
# when using dynamic or static SFML libraries.
|
||||
#
|
||||
# When linking against a SFML target, you do not need to specify indirect dependencies. For example, linking
|
||||
# against sfml-graphics will also automatically link against sfml-window and sfml-system.
|
||||
#
|
||||
# example:
|
||||
# find_package(SFML 2 COMPONENTS graphics audio REQUIRED)
|
||||
# add_executable(myapp ...)
|
||||
# target_link_libraries(myapp sfml-graphics sfml-audio)
|
||||
|
||||
if (NOT SFML_FIND_COMPONENTS)
|
||||
message(FATAL_ERROR "find_package(SFML) called with no component")
|
||||
endif()
|
||||
|
||||
set(FIND_SFML_PATHS
|
||||
"${CMAKE_CURRENT_LIST_DIR}/../.."
|
||||
${SFML_ROOT}
|
||||
$ENV{SFML_ROOT}
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt)
|
||||
|
||||
find_path(SFML_DOC_DIR SFML.tag
|
||||
PATH_SUFFIXES SFML/doc share/doc/SFML
|
||||
PATHS ${FIND_SFML_PATHS})
|
||||
|
||||
|
||||
# Update requested components (eg. request window component if graphics component was requested)
|
||||
set(FIND_SFML_SYSTEM_DEPENDENCIES "")
|
||||
set(FIND_SFML_MAIN_DEPENDENCIES "")
|
||||
set(FIND_SFML_AUDIO_DEPENDENCIES system)
|
||||
set(FIND_SFML_NETWORK_DEPENDENCIES system)
|
||||
set(FIND_SFML_WINDOW_DEPENDENCIES system)
|
||||
set(FIND_SFML_GRAPHICS_DEPENDENCIES window system)
|
||||
set(FIND_SFML_ADDITIONAL_COMPONENTS "")
|
||||
foreach(component ${SFML_FIND_COMPONENTS})
|
||||
string(TOUPPER "${component}" UPPER_COMPONENT)
|
||||
list(APPEND FIND_SFML_ADDITIONAL_COMPONENTS ${FIND_SFML_${UPPER_COMPONENT}_DEPENDENCIES})
|
||||
endforeach()
|
||||
list(APPEND SFML_FIND_COMPONENTS ${FIND_SFML_ADDITIONAL_COMPONENTS})
|
||||
list(REMOVE_DUPLICATES SFML_FIND_COMPONENTS)
|
||||
|
||||
# Choose which target definitions must be imported
|
||||
if (SFML_STATIC_LIBRARIES)
|
||||
set(SFML_IS_FRAMEWORK_INSTALL "@SFML_BUILD_FRAMEWORKS@")
|
||||
if (SFML_IS_FRAMEWORK_INSTALL)
|
||||
message(WARNING "Static frameworks are not supported by SFML. Clear SFML_DIR cache entry, \
|
||||
and either change SFML_STATIC_LIBRARIES or CMAKE_FIND_FRAMEWORK before calling find_package(SFML)")
|
||||
endif()
|
||||
set(config_name "Static")
|
||||
else()
|
||||
set(config_name "Shared")
|
||||
endif()
|
||||
set(targets_config_file "${CMAKE_CURRENT_LIST_DIR}/SFML${config_name}Targets.cmake")
|
||||
|
||||
# Generate imported targets for SFML and its dependencies
|
||||
if (EXISTS "${targets_config_file}")
|
||||
# Set SFML_FOUND to TRUE by default, may be overwritten by one of the includes below
|
||||
set(SFML_FOUND TRUE)
|
||||
include("${targets_config_file}")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/SFMLConfigDependencies.cmake")
|
||||
|
||||
if (SFML_FOUND)
|
||||
foreach (component ${SFML_FIND_COMPONENTS})
|
||||
string(TOUPPER "${component}" UPPER_COMPONENT)
|
||||
if (TARGET sfml-${component})
|
||||
set(SFML_${UPPER_COMPONENT}_FOUND TRUE)
|
||||
else()
|
||||
set(FIND_SFML_ERROR "Found SFML but requested component '${component}' is missing in the config defined in ${SFML_DIR}.")
|
||||
set(SFML_${UPPER_COMPONENT}_FOUND FALSE)
|
||||
set(SFML_FOUND FALSE)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
else()
|
||||
set(FIND_SFML_ERROR "Requested SFML configuration (${config_name}) was not found")
|
||||
set(SFML_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
if (NOT SFML_FOUND)
|
||||
if(SFML_FIND_REQUIRED)
|
||||
# fatal error
|
||||
message(FATAL_ERROR "${FIND_SFML_ERROR}")
|
||||
elseif(NOT SFML_FIND_QUIETLY)
|
||||
# error but continue
|
||||
message(STATUS "${FIND_SFML_ERROR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SFML_FOUND AND NOT SFML_FIND_QUIETLY)
|
||||
message(STATUS "Found SFML @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ in ${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
87
cmake/SFMLConfigDependencies.cmake.in
Normal file
|
@ -0,0 +1,87 @@
|
|||
|
||||
if (CMAKE_VERSION VERSION_LESS 3.5.2)
|
||||
include(CMakeParseArguments)
|
||||
endif()
|
||||
|
||||
# in case of static linking, we must also define the list of all the dependencies of SFML libraries
|
||||
if(SFML_STATIC_LIBRARIES)
|
||||
# detect the OS
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
set(FIND_SFML_OS_WINDOWS 1)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set(FIND_SFML_OS_LINUX 1)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
set(FIND_SFML_OS_FREEBSD 1)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
if (DEFINED IOS)
|
||||
set(FIND_SFML_OS_IOS 1)
|
||||
else()
|
||||
set(FIND_SFML_OS_MACOSX 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# start with an empty list
|
||||
set(FIND_SFML_DEPENDENCIES_NOTFOUND)
|
||||
|
||||
# macro that searches for a 3rd-party library
|
||||
function(sfml_bind_dependency)
|
||||
cmake_parse_arguments(THIS "" "TARGET;FRIENDLY_NAME" "SEARCH_NAMES" ${ARGN})
|
||||
if (THIS_UNPARSED_ARGUMENTS)
|
||||
message(FATAL_ERROR "Unknown arguments when calling sfml_bind_dependency: ${THIS_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
|
||||
# No lookup in environment variables (PATH on Windows), as they may contain wrong library versions
|
||||
find_library(${THIS_FRIENDLY_NAME}_LIB NAMES ${THIS_SEARCH_NAMES}
|
||||
PATHS ${FIND_SFML_PATHS} PATH_SUFFIXES lib NO_SYSTEM_ENVIRONMENT_PATH)
|
||||
mark_as_advanced(${THIS_FRIENDLY_NAME}_LIB)
|
||||
if(${THIS_FRIENDLY_NAME}_LIB)
|
||||
set_property(TARGET ${THIS_TARGET} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${THIS_FRIENDLY_NAME}_LIB}")
|
||||
else()
|
||||
set(FIND_SFML_DEPENDENCIES_NOTFOUND "${FIND_SFML_DEPENDENCIES_NOTFOUND} ${THIS_FRIENDLY_NAME}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# sfml-window
|
||||
list(FIND SFML_FIND_COMPONENTS "window" FIND_SFML_WINDOW_COMPONENT_INDEX)
|
||||
if(FIND_SFML_WINDOW_COMPONENT_INDEX GREATER -1)
|
||||
if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
|
||||
sfml_bind_dependency(TARGET X11 FRIENDLY_NAME "X11" SEARCH_NAMES "X11")
|
||||
sfml_bind_dependency(TARGET X11 FRIENDLY_NAME "Xrandr" SEARCH_NAMES "Xrandr")
|
||||
sfml_bind_dependency(TARGET X11 FRIENDLY_NAME "Xcursor" SEARCH_NAMES "Xcursor")
|
||||
endif()
|
||||
|
||||
if(FIND_SFML_OS_LINUX)
|
||||
sfml_bind_dependency(TARGET UDev FRIENDLY_NAME "UDev" SEARCH_NAMES "udev" "libudev")
|
||||
endif()
|
||||
|
||||
if (FIND_SFML_OS_WINDOWS)
|
||||
set_property(TARGET OpenGL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "OpenGL32")
|
||||
elseif(NOT FIND_SFML_OS_IOS)
|
||||
sfml_bind_dependency(TARGET OpenGL FRIENDLY_NAME "OpenGL" SEARCH_NAMES "OpenGL" "GL")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# sfml-graphics
|
||||
list(FIND SFML_FIND_COMPONENTS "graphics" FIND_SFML_GRAPHICS_COMPONENT_INDEX)
|
||||
if(FIND_SFML_GRAPHICS_COMPONENT_INDEX GREATER -1)
|
||||
sfml_bind_dependency(TARGET Freetype FRIENDLY_NAME "FreeType" SEARCH_NAMES "freetype")
|
||||
endif()
|
||||
|
||||
# sfml-audio
|
||||
list(FIND SFML_FIND_COMPONENTS "audio" FIND_SFML_AUDIO_COMPONENT_INDEX)
|
||||
if(FIND_SFML_AUDIO_COMPONENT_INDEX GREATER -1)
|
||||
sfml_bind_dependency(TARGET OpenAL FRIENDLY_NAME "OpenAL" SEARCH_NAMES "OpenAL" "openal" "openal32")
|
||||
if (NOT FIND_SFML_OS_IOS)
|
||||
sfml_bind_dependency(TARGET VORBIS FRIENDLY_NAME "VorbisFile" SEARCH_NAMES "vorbisfile")
|
||||
sfml_bind_dependency(TARGET VORBIS FRIENDLY_NAME "VorbisEnc" SEARCH_NAMES "vorbisenc")
|
||||
endif()
|
||||
sfml_bind_dependency(TARGET VORBIS FRIENDLY_NAME "Vorbis" SEARCH_NAMES "vorbis")
|
||||
sfml_bind_dependency(TARGET VORBIS FRIENDLY_NAME "Ogg" SEARCH_NAMES "ogg")
|
||||
sfml_bind_dependency(TARGET FLAC FRIENDLY_NAME "FLAC" SEARCH_NAMES "FLAC")
|
||||
endif()
|
||||
|
||||
if (FIND_SFML_DEPENDENCIES_NOTFOUND)
|
||||
set(FIND_SFML_ERROR "SFML found but some of its dependencies are missing (${FIND_SFML_DEPENDENCIES_NOTFOUND})")
|
||||
set(SFML_FOUND FALSE)
|
||||
endif()
|
||||
endif()
|
188
cmake/toolchains/iOS.toolchain.cmake
Normal file
|
@ -0,0 +1,188 @@
|
|||
# Copyright (c) 2016, Bogdan Cristea <cristeab@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake
|
||||
# files which are included with CMake 2.8.4
|
||||
# It has been altered for iOS development
|
||||
|
||||
# Options:
|
||||
#
|
||||
# IOS_PLATFORM = OS (default) or SIMULATOR
|
||||
# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
|
||||
# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
|
||||
# SIMULATOR - used to build for the Simulator platforms, which have an x86_64 arch.
|
||||
#
|
||||
# IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
|
||||
# By default this location is automatcially chosen based on the IOS_PLATFORM value above.
|
||||
# If set manually, it will override the default location and force the user of a particular Developer Platform
|
||||
#
|
||||
# IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
|
||||
# By default this location is automatcially chosen based on the IOS_DEVELOPER_ROOT value.
|
||||
# In this case it will always be the most up-to-date SDK found in the IOS_DEVELOPER_ROOT path.
|
||||
# If set manually, this will force the use of a specific SDK version
|
||||
|
||||
# Macros:
|
||||
#
|
||||
# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE)
|
||||
# A convenience macro for setting xcode specific properties on targets
|
||||
# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1")
|
||||
#
|
||||
# find_host_package (PROGRAM ARGS)
|
||||
# A macro used to find executable programs on the host system, not within the iOS environment.
|
||||
# Thanks to the android-cmake project for providing the command
|
||||
|
||||
# Standard settings
|
||||
set (CMAKE_SYSTEM_NAME Darwin)
|
||||
set (CMAKE_SYSTEM_VERSION 1)
|
||||
set (UNIX True)
|
||||
set (APPLE True)
|
||||
set (IOS True)
|
||||
|
||||
# Required as of cmake 2.8.10
|
||||
set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
|
||||
|
||||
# Determine the cmake host system version so we know where to find the iOS SDKs
|
||||
find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
|
||||
if (CMAKE_UNAME)
|
||||
exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
|
||||
string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
|
||||
endif (CMAKE_UNAME)
|
||||
|
||||
set(CMAKE_C_COMPILER /usr/bin/clang CACHE FILEPATH "" FORCE)
|
||||
set(CMAKE_CXX_COMPILER /usr/bin/clang++ CACHE FILEPATH "" FORCE)
|
||||
set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
|
||||
|
||||
# Skip the platform compiler checks for cross compiling
|
||||
set (CMAKE_CXX_COMPILER_WORKS TRUE)
|
||||
set (CMAKE_C_COMPILER_WORKS TRUE)
|
||||
|
||||
# All iOS/Darwin specific settings - some may be redundant
|
||||
set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
|
||||
set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
|
||||
set (CMAKE_SHARED_MODULE_PREFIX "lib")
|
||||
set (CMAKE_SHARED_MODULE_SUFFIX ".so")
|
||||
set (CMAKE_MODULE_EXISTS 1)
|
||||
set (CMAKE_DL_LIBS "")
|
||||
|
||||
set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
|
||||
set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
|
||||
set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
|
||||
set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
|
||||
|
||||
# Hidden visibilty is required for cxx on iOS
|
||||
set (CMAKE_C_FLAGS_INIT "")
|
||||
set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden")
|
||||
|
||||
set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
|
||||
set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
|
||||
|
||||
set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
|
||||
set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
|
||||
set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
|
||||
set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
|
||||
set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
|
||||
set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
|
||||
|
||||
# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
|
||||
# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
|
||||
# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
|
||||
# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
|
||||
if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
|
||||
find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
|
||||
endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
|
||||
|
||||
# Setup iOS platform unless specified manually with IOS_PLATFORM
|
||||
if (NOT DEFINED IOS_PLATFORM)
|
||||
set (IOS_PLATFORM "OS")
|
||||
endif (NOT DEFINED IOS_PLATFORM)
|
||||
set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform: OS or SIMULATOR")
|
||||
|
||||
# Check the platform selection and setup for developer root
|
||||
if (IOS_PLATFORM STREQUAL OS)
|
||||
set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
|
||||
|
||||
# This causes the installers to properly locate the output libraries
|
||||
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
|
||||
elseif (IOS_PLATFORM STREQUAL SIMULATOR)
|
||||
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
|
||||
|
||||
# This causes the installers to properly locate the output libraries
|
||||
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
|
||||
else ()
|
||||
message (FATAL_ERROR "Unsupported IOS_PLATFORM value '${IOS_PLATFORM}' selected. Please choose OS or SIMULATOR")
|
||||
endif ()
|
||||
|
||||
# Setup iOS developer location unless specified manually with IOS_DEVELOPER_ROOT
|
||||
exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE XCODE_DEVELOPER_DIR)
|
||||
set (IOS_DEVELOPER_ROOT "${XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer" CACHE PATH "Location of iOS Platform")
|
||||
|
||||
# Find and use the most recent iOS sdk unless specified manually with IOS_SDK_ROOT
|
||||
if (NOT DEFINED IOS_SDK_ROOT)
|
||||
file (GLOB _IOS_SDKS "${IOS_DEVELOPER_ROOT}/SDKs/*")
|
||||
if (_IOS_SDKS)
|
||||
list (SORT _IOS_SDKS)
|
||||
list (REVERSE _IOS_SDKS)
|
||||
list (GET _IOS_SDKS 0 IOS_SDK_ROOT)
|
||||
else (_IOS_SDKS)
|
||||
message (FATAL_ERROR "No iOS SDK's found in default search path ${IOS_DEVELOPER_ROOT}. Manually set IOS_SDK_ROOT or install the iOS SDK.")
|
||||
endif (_IOS_SDKS)
|
||||
message (STATUS "Toolchain using default iOS SDK: ${IOS_SDK_ROOT}")
|
||||
endif (NOT DEFINED IOS_SDK_ROOT)
|
||||
set (IOS_SDK_ROOT ${IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
|
||||
|
||||
# Set the sysroot default to the most recent SDK
|
||||
set (CMAKE_OSX_SYSROOT ${IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
|
||||
|
||||
# set the architecture for iOS
|
||||
if (${IOS_PLATFORM} STREQUAL OS)
|
||||
set (OSX_UNIVERSAL true)
|
||||
set (IOS_ARCH arm64)
|
||||
elseif (${IOS_PLATFORM} STREQUAL SIMULATOR)
|
||||
set (IOS_ARCH x86_64)
|
||||
endif (${IOS_PLATFORM} STREQUAL OS)
|
||||
|
||||
set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS" FORCE)
|
||||
|
||||
# Set the find root to the iOS developer roots and to user defined paths
|
||||
set (CMAKE_FIND_ROOT_PATH ${IOS_DEVELOPER_ROOT} ${IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE STRING "iOS find search path root")
|
||||
|
||||
# default to searching for frameworks first
|
||||
set (CMAKE_FIND_FRAMEWORK FIRST)
|
||||
|
||||
# set up the default search directories for frameworks
|
||||
set (CMAKE_SYSTEM_FRAMEWORK_PATH
|
||||
${IOS_SDK_ROOT}/System/Library/Frameworks
|
||||
${IOS_SDK_ROOT}/System/Library/PrivateFrameworks
|
||||
${IOS_SDK_ROOT}/Developer/Library/Frameworks
|
||||
)
|
||||
|
||||
# only search the iOS sdks, not the remainder of the host filesystem
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
|
||||
# This macro lets you find executable programs on the host system
|
||||
macro (find_host_package)
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
|
||||
set (IOS FALSE)
|
||||
|
||||
find_package(${ARGN})
|
||||
|
||||
set (IOS TRUE)
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
endmacro (find_host_package)
|
|
@ -1,15 +1,15 @@
|
|||
|
||||
# find doxygen
|
||||
if(MACOSX)
|
||||
if(SFML_OS_MACOSX)
|
||||
# Add some path to search doxygen in more directories.
|
||||
set(ADDITIONAL_PATHS
|
||||
/Developer/Applications/Doxygen.app/Contents/Resources
|
||||
/Developer/Applications/Doxygen.app/Contents/MacOS
|
||||
$ENV{HOME}/Applications/Doxygen.app/Contents/Resources
|
||||
$ENV{HOME}/Applications/Doxygen.app/Contents/MacOS
|
||||
$ENV{HOME}/Applications/Developer/Doxygen.app/Contents/Resources
|
||||
set(ADDITIONAL_PATHS
|
||||
/Developer/Applications/Doxygen.app/Contents/Resources
|
||||
/Developer/Applications/Doxygen.app/Contents/MacOS
|
||||
$ENV{HOME}/Applications/Doxygen.app/Contents/Resources
|
||||
$ENV{HOME}/Applications/Doxygen.app/Contents/MacOS
|
||||
$ENV{HOME}/Applications/Developer/Doxygen.app/Contents/Resources
|
||||
$ENV{HOME}/Applications/Developer/Doxygen.app/Contents/MacOS)
|
||||
|
||||
|
||||
set(CMAKE_PROGRAM_PATH ${CMAKE_PROGRAM_PATH} ${ADDITIONAL_PATHS})
|
||||
endif()
|
||||
|
||||
|
@ -20,11 +20,11 @@ set(DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR})
|
|||
set(DOXYGEN_OUTPUT_DIR ${PROJECT_BINARY_DIR}/doc)
|
||||
|
||||
# see if we can generate the CHM documentation
|
||||
if(WINDOWS)
|
||||
if(SFML_OS_WINDOWS)
|
||||
# if HHC is found, we can generate the CHM (compressed HTML) output
|
||||
find_program(DOXYGEN_HHC_PROGRAM
|
||||
NAMES hhc.exe
|
||||
PATHS "c:/Program Files/HTML Help Workshop"
|
||||
PATHS "C:/Program Files/HTML Help Workshop" "C:/Program Files (x86)/HTML Help Workshop"
|
||||
DOC "HTML Help Compiler program")
|
||||
if(DOXYGEN_HHC_PROGRAM)
|
||||
set(DOXYGEN_GENERATE_HTMLHELP YES)
|
||||
|
@ -39,6 +39,7 @@ endif()
|
|||
# configure the source Doxyfile by copying it and replacing all @variables@
|
||||
set(DOXYGEN_CONFIGURED_INPUT ${DOXYGEN_OUTPUT_DIR}/doxyfile)
|
||||
configure_file(${DOXYGEN_INPUT_DIR}/doc/doxyfile.in ${DOXYGEN_CONFIGURED_INPUT} @ONLY)
|
||||
configure_file(${DOXYGEN_INPUT_DIR}/doc/header.html.in ${DOXYGEN_OUTPUT_DIR}/header.html @ONLY)
|
||||
|
||||
# copy the files needed by the documentation
|
||||
configure_file(${DOXYGEN_INPUT_DIR}/doc/doxygen.css ${DOXYGEN_OUTPUT_DIR}/html/doxygen.css COPYONLY)
|
||||
|
@ -51,11 +52,14 @@ add_custom_target(doc ALL
|
|||
WORKING_DIRECTORY ${DOXYGEN_INPUT_DIR})
|
||||
|
||||
# setup install rules
|
||||
install(FILES ${DOXYGEN_OUTPUT_DIR}/SFML.tag
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||
COMPONENT doc)
|
||||
install(DIRECTORY ${DOXYGEN_OUTPUT_DIR}/html
|
||||
DESTINATION ${INSTALL_MISC_DIR}/doc
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||
COMPONENT doc)
|
||||
if(DOXYGEN_HHC_PROGRAM)
|
||||
install(FILES ${DOXYGEN_OUTPUT_DIR}/sfml.chm
|
||||
DESTINATION ${INSTALL_MISC_DIR}/doc
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||
COMPONENT doc)
|
||||
endif()
|
||||
|
|
2742
doc/doxyfile.in
1398
doc/doxygen.css
|
@ -1,9 +1,10 @@
|
|||
</div>
|
||||
<div id="footer-container">
|
||||
<div id="footer">
|
||||
Copyright © Laurent Gomila ::
|
||||
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> ::
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</div>
|
||||
<div id="footer-container">
|
||||
<div id="footer">
|
||||
SFML is licensed under the terms and conditions of the <a href="https://www.sfml-dev.org/license.php">zlib/png license</a>.<br>
|
||||
Copyright © Laurent Gomila ::
|
||||
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> ::
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,15 +1,18 @@
|
|||
<!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>
|
||||
<title>SFML - Simple and Fast Multimedia Library</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
|
||||
<!--<link rel='stylesheet' type='text/css' href="http://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
||||
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="banner-container">
|
||||
<div id="banner">
|
||||
<span id="sfml">SFML</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="content">
|
||||
<!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>
|
||||
<title>SFML - Simple and Fast Multimedia Library</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;"/>
|
||||
<meta charset="utf-8"/>
|
||||
<!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
||||
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
|
||||
<script type="text/javascript" src="jquery.js"></script>
|
||||
<script type="text/javascript" src="dynsections.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="banner-container">
|
||||
<div id="banner">
|
||||
<span id="sfml">SFML @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="content">
|
142
doc/mainpage.hpp
|
@ -1,71 +1,71 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \mainpage
|
||||
///
|
||||
/// \section welcome Welcome
|
||||
/// Welcome to the official SFML documentation. Here you will find a detailed
|
||||
/// view of all the SFML <a href="./annotated.php">classes</a> and functions. <br/>
|
||||
/// If you are looking for tutorials, you can visit the official website
|
||||
/// at <a href="http://www.sfml-dev.org/">www.sfml-dev.org</a>.
|
||||
///
|
||||
/// \section example Short example
|
||||
/// Here is a short example, to show you how simple it is to use SFML :
|
||||
///
|
||||
/// \code
|
||||
///
|
||||
/// #include <SFML/Audio.hpp>
|
||||
/// #include <SFML/Graphics.hpp>
|
||||
///
|
||||
/// int main()
|
||||
/// {
|
||||
/// // Create the main window
|
||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
||||
///
|
||||
/// // Load a sprite to display
|
||||
/// sf::Texture texture;
|
||||
/// if (!texture.loadFromFile("cute_image.jpg"))
|
||||
/// return EXIT_FAILURE;
|
||||
/// sf::Sprite sprite(texture);
|
||||
///
|
||||
/// // Create a graphical text to display
|
||||
/// sf::Font font;
|
||||
/// if (!font.loadFromFile("arial.ttf"))
|
||||
/// return EXIT_FAILURE;
|
||||
/// sf::Text text("Hello SFML", font, 50);
|
||||
///
|
||||
/// // Load a music to play
|
||||
/// sf::Music music;
|
||||
/// if (!music.openFromFile("nice_music.ogg"))
|
||||
/// return EXIT_FAILURE;
|
||||
///
|
||||
/// // Play the music
|
||||
/// music.play();
|
||||
///
|
||||
/// // Start the game loop
|
||||
/// while (window.isOpen())
|
||||
/// {
|
||||
/// // Process events
|
||||
/// sf::Event event;
|
||||
/// while (window.pollEvent(event))
|
||||
/// {
|
||||
/// // Close window : exit
|
||||
/// if (event.type == sf::Event::Closed)
|
||||
/// window.close();
|
||||
/// }
|
||||
///
|
||||
/// // Clear screen
|
||||
/// window.clear();
|
||||
///
|
||||
/// // Draw the sprite
|
||||
/// window.draw(sprite);
|
||||
///
|
||||
/// // Draw the string
|
||||
/// window.draw(text);
|
||||
///
|
||||
/// // Update the window
|
||||
/// window.display();
|
||||
/// }
|
||||
///
|
||||
/// return EXIT_SUCCESS;
|
||||
/// }
|
||||
/// \endcode
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \mainpage
|
||||
///
|
||||
/// \section welcome Welcome
|
||||
/// Welcome to the official SFML documentation. Here you will find a detailed
|
||||
/// view of all the SFML classes and functions. <br/>
|
||||
/// If you are looking for tutorials, you can visit the official website
|
||||
/// at <a href="https://www.sfml-dev.org/">www.sfml-dev.org</a>.
|
||||
///
|
||||
/// \section example Short example
|
||||
/// Here is a short example, to show you how simple it is to use SFML:
|
||||
///
|
||||
/// \code
|
||||
///
|
||||
/// #include <SFML/Audio.hpp>
|
||||
/// #include <SFML/Graphics.hpp>
|
||||
///
|
||||
/// int main()
|
||||
/// {
|
||||
/// // Create the main window
|
||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
||||
///
|
||||
/// // Load a sprite to display
|
||||
/// sf::Texture texture;
|
||||
/// if (!texture.loadFromFile("cute_image.jpg"))
|
||||
/// return EXIT_FAILURE;
|
||||
/// sf::Sprite sprite(texture);
|
||||
///
|
||||
/// // Create a graphical text to display
|
||||
/// sf::Font font;
|
||||
/// if (!font.loadFromFile("arial.ttf"))
|
||||
/// return EXIT_FAILURE;
|
||||
/// sf::Text text("Hello SFML", font, 50);
|
||||
///
|
||||
/// // Load a music to play
|
||||
/// sf::Music music;
|
||||
/// if (!music.openFromFile("nice_music.ogg"))
|
||||
/// return EXIT_FAILURE;
|
||||
///
|
||||
/// // Play the music
|
||||
/// music.play();
|
||||
///
|
||||
/// // Start the game loop
|
||||
/// while (window.isOpen())
|
||||
/// {
|
||||
/// // Process events
|
||||
/// sf::Event event;
|
||||
/// while (window.pollEvent(event))
|
||||
/// {
|
||||
/// // Close window: exit
|
||||
/// if (event.type == sf::Event::Closed)
|
||||
/// window.close();
|
||||
/// }
|
||||
///
|
||||
/// // Clear screen
|
||||
/// window.clear();
|
||||
///
|
||||
/// // Draw the sprite
|
||||
/// window.draw(sprite);
|
||||
///
|
||||
/// // Draw the string
|
||||
/// window.draw(text);
|
||||
///
|
||||
/// // Update the window
|
||||
/// window.display();
|
||||
/// }
|
||||
///
|
||||
/// return EXIT_SUCCESS;
|
||||
/// }
|
||||
/// \endcode
|
||||
////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -1,18 +1,41 @@
|
|||
|
||||
# add the examples subdirectories
|
||||
add_subdirectory(ftp)
|
||||
add_subdirectory(opengl)
|
||||
add_subdirectory(pong)
|
||||
add_subdirectory(shader)
|
||||
add_subdirectory(sockets)
|
||||
add_subdirectory(sound)
|
||||
add_subdirectory(sound_capture)
|
||||
add_subdirectory(voip)
|
||||
add_subdirectory(window)
|
||||
if(WINDOWS)
|
||||
add_subdirectory(win32)
|
||||
elseif(LINUX)
|
||||
add_subdirectory(X11)
|
||||
elseif(MACOSX)
|
||||
add_subdirectory(cocoa)
|
||||
endif()
|
||||
# CLI based examples
|
||||
if (NOT SFML_OS_IOS)
|
||||
if(SFML_BUILD_NETWORK)
|
||||
add_subdirectory(ftp)
|
||||
add_subdirectory(sockets)
|
||||
endif()
|
||||
if(SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO)
|
||||
add_subdirectory(voip)
|
||||
endif()
|
||||
if(SFML_BUILD_AUDIO)
|
||||
add_subdirectory(sound)
|
||||
add_subdirectory(sound_capture)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# GUI based examples
|
||||
if(SFML_BUILD_WINDOW)
|
||||
add_subdirectory(window)
|
||||
endif()
|
||||
|
||||
if(SFML_BUILD_GRAPHICS)
|
||||
add_subdirectory(opengl)
|
||||
|
||||
if (NOT SFML_OS_IOS)
|
||||
add_subdirectory(joystick)
|
||||
add_subdirectory(shader)
|
||||
add_subdirectory(island)
|
||||
add_subdirectory(vulkan)
|
||||
endif()
|
||||
|
||||
if(SFML_OS_WINDOWS)
|
||||
add_subdirectory(win32)
|
||||
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
||||
add_subdirectory(X11)
|
||||
elseif(SFML_OS_MACOSX)
|
||||
add_subdirectory(cocoa)
|
||||
endif()
|
||||
endif()
|
||||
if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO)
|
||||
add_subdirectory(pong)
|
||||
endif()
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/X11)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/X11.cpp)
|
||||
|
||||
# find OpenGL, GLU and X11
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
find_package(X11 REQUIRED)
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
|
||||
# define the X11 target
|
||||
sfml_add_example(X11 GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-window sfml-system ${OPENGL_LIBRARIES} ${X11_LIBRARIES})
|
||||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/X11)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/X11.cpp)
|
||||
|
||||
# define the X11 target
|
||||
sfml_add_example(X11Example GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-window X11)
|
||||
|
|
|
@ -1,199 +1,247 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window.hpp>
|
||||
#include <X11/Xlib.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Initialize OpenGL states into the specified view
|
||||
///
|
||||
/// \param Window Target window to initialize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void initialize(sf::Window& window)
|
||||
{
|
||||
// Activate the window
|
||||
window.setActive();
|
||||
|
||||
// Setup OpenGL states
|
||||
// Set color and depth clear value
|
||||
glClearDepth(1.f);
|
||||
glClearColor(0.f, 0.5f, 0.5f, 0.f);
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
// Setup a perspective projection
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(90.f, 1.f, 1.f, 500.f);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Draw the OpenGL scene (a rotating cube) into
|
||||
/// the specified view
|
||||
///
|
||||
/// \param window Target window for rendering
|
||||
/// \param elapsedTime Time elapsed since the last draw
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void draw(sf::Window& window, float elapsedTime)
|
||||
{
|
||||
// Activate the window
|
||||
window.setActive();
|
||||
|
||||
// Clear color and depth buffers
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Apply some transformations
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.f, 0.f, -200.f);
|
||||
glRotatef(elapsedTime * 0.05f, 1.f, 0.f, 0.f);
|
||||
glRotatef(elapsedTime * 0.03f, 0.f, 1.f, 0.f);
|
||||
glRotatef(elapsedTime * 0.09f, 0.f, 0.f, 1.f);
|
||||
|
||||
// Draw a cube
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glColor3f(1.f, 1.f, 0.f);
|
||||
glVertex3f(-50.f, -50.f, -50.f);
|
||||
glVertex3f(-50.f, 50.f, -50.f);
|
||||
glVertex3f( 50.f, 50.f, -50.f);
|
||||
glVertex3f( 50.f, -50.f, -50.f);
|
||||
|
||||
glColor3f(1.f, 1.f, 0.f);
|
||||
glVertex3f(-50.f, -50.f, 50.f);
|
||||
glVertex3f(-50.f, 50.f, 50.f);
|
||||
glVertex3f( 50.f, 50.f, 50.f);
|
||||
glVertex3f( 50.f, -50.f, 50.f);
|
||||
|
||||
glColor3f(0.f, 1.f, 1.f);
|
||||
glVertex3f(-50.f, -50.f, -50.f);
|
||||
glVertex3f(-50.f, 50.f, -50.f);
|
||||
glVertex3f(-50.f, 50.f, 50.f);
|
||||
glVertex3f(-50.f, -50.f, 50.f);
|
||||
|
||||
glColor3f(0.f, 1.f, 1.f);
|
||||
glVertex3f(50.f, -50.f, -50.f);
|
||||
glVertex3f(50.f, 50.f, -50.f);
|
||||
glVertex3f(50.f, 50.f, 50.f);
|
||||
glVertex3f(50.f, -50.f, 50.f);
|
||||
|
||||
glColor3f(1.f, 0.f, 1.f);
|
||||
glVertex3f(-50.f, -50.f, 50.f);
|
||||
glVertex3f(-50.f, -50.f, -50.f);
|
||||
glVertex3f( 50.f, -50.f, -50.f);
|
||||
glVertex3f( 50.f, -50.f, 50.f);
|
||||
|
||||
glColor3f(1.f, 0.f, 1.f);
|
||||
glVertex3f(-50.f, 50.f, 50.f);
|
||||
glVertex3f(-50.f, 50.f, -50.f);
|
||||
glVertex3f( 50.f, 50.f, -50.f);
|
||||
glVertex3f( 50.f, 50.f, 50.f);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Error code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Open a connection with the X server
|
||||
Display* display = XOpenDisplay(NULL);
|
||||
if (!display)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Get the default screen
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
// Let's create the main window
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.background_pixel = BlackPixel(display, screen);
|
||||
attributes.event_mask = KeyPressMask;
|
||||
Window window = XCreateWindow(display, RootWindow(display, screen),
|
||||
0, 0, 650, 330, 0,
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(display, screen),
|
||||
CWBackPixel | CWEventMask, &attributes);
|
||||
if (!window)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Set the window's name
|
||||
XStoreName(display, window , "SFML Window");
|
||||
|
||||
// Let's create the windows which will serve as containers for our SFML views
|
||||
Window view1 = XCreateWindow(display, window,
|
||||
10, 10, 310, 310, 0,
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(display, screen),
|
||||
0, NULL);
|
||||
Window view2 = XCreateWindow(display, window,
|
||||
330, 10, 310, 310, 0,
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(display, screen),
|
||||
0, NULL);
|
||||
|
||||
// Show our windows
|
||||
XMapWindow(display, window);
|
||||
XFlush(display);
|
||||
|
||||
// Create our SFML views
|
||||
sf::Window SFMLView1(view1);
|
||||
sf::Window SFMLView2(view2);
|
||||
|
||||
// Create a clock for measuring elapsed time
|
||||
sf::Clock clock;
|
||||
|
||||
// Initialize our views
|
||||
initialize(SFMLView1);
|
||||
initialize(SFMLView2);
|
||||
|
||||
// Start the event loop
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
while (XPending(display))
|
||||
{
|
||||
// Get the next pending event
|
||||
XEvent event;
|
||||
XNextEvent(display, &event);
|
||||
|
||||
// Process it
|
||||
switch (event.type)
|
||||
{
|
||||
// Any key is pressed : quit
|
||||
case KeyPress :
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw something into our views
|
||||
draw(SFMLView1, clock.getElapsedTime().asSeconds());
|
||||
draw(SFMLView2, clock.getElapsedTime().asSeconds() * 0.3f);
|
||||
|
||||
// Display the views on screen
|
||||
SFMLView1.display();
|
||||
SFMLView2.display();
|
||||
}
|
||||
|
||||
// Close the display
|
||||
XCloseDisplay(display);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "gl.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Initialize OpenGL states into the specified view
|
||||
///
|
||||
/// \param Window Target window to initialize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void initialize(sf::Window& window)
|
||||
{
|
||||
// Activate the window
|
||||
window.setActive();
|
||||
|
||||
// Setup OpenGL states
|
||||
// Set color and depth clear value
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glClearDepthf(1.f);
|
||||
#else
|
||||
glClearDepth(1.f);
|
||||
#endif
|
||||
|
||||
glClearColor(0.f, 0.5f, 0.5f, 0.f);
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
// Setup a perspective projection
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
static const float pi = 3.141592654f;
|
||||
float extent = std::tan(90.0f * pi / 360.0f);
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glFrustumf(-extent, extent, -extent, extent, 1.0f, 500.0f);
|
||||
#else
|
||||
glFrustum(-extent, extent, -extent, extent, 1.0f, 500.0f);
|
||||
#endif
|
||||
|
||||
// Enable position and texture coordinates vertex components
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Draw the OpenGL scene (a rotating cube) into
|
||||
/// the specified view
|
||||
///
|
||||
/// \param window Target window for rendering
|
||||
/// \param elapsedTime Time elapsed since the last draw
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void draw(sf::Window& window, float elapsedTime)
|
||||
{
|
||||
// Activate the window
|
||||
window.setActive();
|
||||
|
||||
// Clear color and depth buffers
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Apply some transformations
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.f, 0.f, -200.f);
|
||||
glRotatef(elapsedTime * 10.f, 1.f, 0.f, 0.f);
|
||||
glRotatef(elapsedTime * 6.f, 0.f, 1.f, 0.f);
|
||||
glRotatef(elapsedTime * 18.f, 0.f, 0.f, 1.f);
|
||||
|
||||
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
||||
static const GLfloat cube[] =
|
||||
{
|
||||
// positions // colors
|
||||
-50, -50, -50, 1, 1, 0,
|
||||
-50, 50, -50, 1, 1, 0,
|
||||
-50, -50, 50, 1, 1, 0,
|
||||
-50, -50, 50, 1, 1, 0,
|
||||
-50, 50, -50, 1, 1, 0,
|
||||
-50, 50, 50, 1, 1, 0,
|
||||
|
||||
50, -50, -50, 1, 1, 0,
|
||||
50, 50, -50, 1, 1, 0,
|
||||
50, -50, 50, 1, 1, 0,
|
||||
50, -50, 50, 1, 1, 0,
|
||||
50, 50, -50, 1, 1, 0,
|
||||
50, 50, 50, 1, 1, 0,
|
||||
|
||||
-50, -50, -50, 1, 0, 1,
|
||||
50, -50, -50, 1, 0, 1,
|
||||
-50, -50, 50, 1, 0, 1,
|
||||
-50, -50, 50, 1, 0, 1,
|
||||
50, -50, -50, 1, 0, 1,
|
||||
50, -50, 50, 1, 0, 1,
|
||||
|
||||
-50, 50, -50, 1, 0, 1,
|
||||
50, 50, -50, 1, 0, 1,
|
||||
-50, 50, 50, 1, 0, 1,
|
||||
-50, 50, 50, 1, 0, 1,
|
||||
50, 50, -50, 1, 0, 1,
|
||||
50, 50, 50, 1, 0, 1,
|
||||
|
||||
-50, -50, -50, 0, 1, 1,
|
||||
50, -50, -50, 0, 1, 1,
|
||||
-50, 50, -50, 0, 1, 1,
|
||||
-50, 50, -50, 0, 1, 1,
|
||||
50, -50, -50, 0, 1, 1,
|
||||
50, 50, -50, 0, 1, 1,
|
||||
|
||||
-50, -50, 50, 0, 1, 1,
|
||||
50, -50, 50, 0, 1, 1,
|
||||
-50, 50, 50, 0, 1, 1,
|
||||
-50, 50, 50, 0, 1, 1,
|
||||
50, -50, 50, 0, 1, 1,
|
||||
50, 50, 50, 0, 1, 1
|
||||
};
|
||||
|
||||
// Draw the cube
|
||||
glVertexPointer(3, GL_FLOAT, 6 * sizeof(GLfloat), cube);
|
||||
glColorPointer(3, GL_FLOAT, 6 * sizeof(GLfloat), cube + 3);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Error code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Open a connection with the X server
|
||||
Display* display = XOpenDisplay(NULL);
|
||||
if (!display)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Get the default screen
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
// Let's create the main window
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.background_pixel = BlackPixel(display, screen);
|
||||
attributes.event_mask = KeyPressMask;
|
||||
Window window = XCreateWindow(display, RootWindow(display, screen),
|
||||
0, 0, 650, 330, 0,
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(display, screen),
|
||||
CWBackPixel | CWEventMask, &attributes);
|
||||
if (!window)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Set the window's name
|
||||
XStoreName(display, window , "SFML Window");
|
||||
|
||||
// Let's create the windows which will serve as containers for our SFML views
|
||||
Window view1 = XCreateWindow(display, window,
|
||||
10, 10, 310, 310, 0,
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(display, screen),
|
||||
0, NULL);
|
||||
Window view2 = XCreateWindow(display, window,
|
||||
330, 10, 310, 310, 0,
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(display, screen),
|
||||
0, NULL);
|
||||
|
||||
// Show our windows
|
||||
XMapWindow(display, window);
|
||||
XFlush(display);
|
||||
|
||||
// Create our SFML views
|
||||
sf::Window sfmlView1(view1);
|
||||
sf::Window sfmlView2(view2);
|
||||
|
||||
// Create a clock for measuring elapsed time
|
||||
sf::Clock clock;
|
||||
|
||||
// Load OpenGL or OpenGL ES entry points using glad
|
||||
sfmlView1.setActive();
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
gladLoadGLES1(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#else
|
||||
gladLoadGL(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#endif
|
||||
|
||||
// Initialize our views
|
||||
initialize(sfmlView1);
|
||||
initialize(sfmlView2);
|
||||
|
||||
// Start the event loop
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
while (XPending(display))
|
||||
{
|
||||
// Get the next pending event
|
||||
XEvent event;
|
||||
XNextEvent(display, &event);
|
||||
|
||||
// Process it
|
||||
switch (event.type)
|
||||
{
|
||||
// Any key is pressed: quit
|
||||
case KeyPress:
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw something into our views
|
||||
draw(sfmlView1, clock.getElapsedTime().asSeconds());
|
||||
draw(sfmlView2, clock.getElapsedTime().asSeconds() * 0.3f);
|
||||
|
||||
// Display the views on screen
|
||||
sfmlView1.display();
|
||||
sfmlView2.display();
|
||||
}
|
||||
|
||||
// Close our SFML views before destroying the underlying window
|
||||
sfmlView1.close();
|
||||
sfmlView2.close();
|
||||
|
||||
// Destroy the window
|
||||
XDestroyWindow(display, window);
|
||||
|
||||
// Close the display
|
||||
XCloseDisplay(display);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
7837
examples/X11/gl.h
Normal file
8
examples/android/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
local.properties
|
||||
.idea
|
||||
.gradle
|
||||
build
|
||||
android.iml
|
||||
app/build
|
||||
app/.externalNativeBuild
|
||||
app/src/main/obj
|
123
examples/android/app/app.iml
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="native-android-gradle" name="Native-Android-Gradle">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<afterSyncTasks>
|
||||
<task>generateDebugSources</task>
|
||||
</afterSyncTasks>
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/cpp" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes-jar" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndkBuild" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 27 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
39
examples/android/app/build.gradle
Normal file
|
@ -0,0 +1,39 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
defaultConfig {
|
||||
applicationId "org.sfmldev.android"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 19
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
// cppFlags "-std=c++14 -frtti -fexceptions"
|
||||
}
|
||||
|
||||
}
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a'
|
||||
}
|
||||
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
path "src/main/jni/Android.mk"
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
21
examples/android/app/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
34
examples/android/app/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.sfmldev.android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-feature android:glEsVersion="0x00010001" />
|
||||
|
||||
<uses-sdk android:minSdkVersion="14"
|
||||
android:targetSdkVersion="19" />
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/sfml_logo"
|
||||
android:hasCode="false"
|
||||
android:allowBackup="true">
|
||||
|
||||
<activity android:name="android.app.NativeActivity"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/sfml_logo"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize">
|
||||
|
||||
<meta-data android:name="android.app.lib_name" android:value="sfml-activity-d" />
|
||||
<meta-data android:name="sfml.app.lib_name" android:value="sfml-example" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
BIN
examples/android/app/src/main/assets/canary.wav
Normal file
BIN
examples/android/app/src/main/assets/image.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
examples/android/app/src/main/assets/orchestral.ogg
Normal file
BIN
examples/android/app/src/main/assets/sansation.ttf
Normal file
20
examples/android/app/src/main/jni/Android.mk
Normal file
|
@ -0,0 +1,20 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := sfml-example
|
||||
|
||||
LOCAL_SRC_FILES := main.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := sfml-system-d
|
||||
LOCAL_SHARED_LIBRARIES += sfml-window-d
|
||||
LOCAL_SHARED_LIBRARIES += sfml-graphics-d
|
||||
LOCAL_SHARED_LIBRARIES += sfml-audio-d
|
||||
LOCAL_SHARED_LIBRARIES += sfml-network-d
|
||||
LOCAL_SHARED_LIBRARIES += sfml-activity-d
|
||||
LOCAL_SHARED_LIBRARIES += openal
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := sfml-main-d
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
$(call import-module,third_party/sfml)
|
8
examples/android/app/src/main/jni/Application.mk
Normal file
|
@ -0,0 +1,8 @@
|
|||
NDK_TOOLCHAIN_VERSION := 4.9
|
||||
APP_PLATFORM := android-14
|
||||
# APP_STL has to match CMAKE_ANDROID_STL_TYPE
|
||||
APP_STL := c++_static
|
||||
APP_ABI := armeabi-v7a
|
||||
APP_MODULES := sfml-activity-d sfml-example
|
||||
APP_OPTIM := debug
|
||||
APP_CFLAG := -g -ggdb -O0
|
176
examples/android/app/src/main/jni/main.cpp
Normal file
|
@ -0,0 +1,176 @@
|
|||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/Network.hpp>
|
||||
|
||||
// Do we want to showcase direct JNI/NDK interaction?
|
||||
// Undefine this to get real cross-platform code.
|
||||
// Uncomment this to try JNI access; this seems to be broken in latest NDKs
|
||||
//#define USE_JNI
|
||||
|
||||
#if defined(USE_JNI)
|
||||
// These headers are only needed for direct NDK/JDK interaction
|
||||
#include <jni.h>
|
||||
#include <android/native_activity.h>
|
||||
|
||||
// Since we want to get the native activity from SFML, we'll have to use an
|
||||
// extra header here:
|
||||
#include <SFML/System/NativeActivity.hpp>
|
||||
|
||||
// NDK/JNI sub example - call Java code from native code
|
||||
int vibrate(sf::Time duration)
|
||||
{
|
||||
// First we'll need the native activity handle
|
||||
ANativeActivity *activity = sf::getNativeActivity();
|
||||
|
||||
// Retrieve the JVM and JNI environment
|
||||
JavaVM* vm = activity->vm;
|
||||
JNIEnv* env = activity->env;
|
||||
|
||||
// First, attach this thread to the main thread
|
||||
JavaVMAttachArgs attachargs;
|
||||
attachargs.version = JNI_VERSION_1_6;
|
||||
attachargs.name = "NativeThread";
|
||||
attachargs.group = NULL;
|
||||
jint res = vm->AttachCurrentThread(&env, &attachargs);
|
||||
|
||||
if (res == JNI_ERR)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Retrieve class information
|
||||
jclass natact = env->FindClass("android/app/NativeActivity");
|
||||
jclass context = env->FindClass("android/content/Context");
|
||||
|
||||
// Get the value of a constant
|
||||
jfieldID fid = env->GetStaticFieldID(context, "VIBRATOR_SERVICE", "Ljava/lang/String;");
|
||||
jobject svcstr = env->GetStaticObjectField(context, fid);
|
||||
|
||||
// Get the method 'getSystemService' and call it
|
||||
jmethodID getss = env->GetMethodID(natact, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
|
||||
jobject vib_obj = env->CallObjectMethod(activity->clazz, getss, svcstr);
|
||||
|
||||
// Get the object's class and retrieve the member name
|
||||
jclass vib_cls = env->GetObjectClass(vib_obj);
|
||||
jmethodID vibrate = env->GetMethodID(vib_cls, "vibrate", "(J)V");
|
||||
|
||||
// Determine the timeframe
|
||||
jlong length = duration.asMilliseconds();
|
||||
|
||||
// Bzzz!
|
||||
env->CallVoidMethod(vib_obj, vibrate, length);
|
||||
|
||||
// Free references
|
||||
env->DeleteLocalRef(vib_obj);
|
||||
env->DeleteLocalRef(vib_cls);
|
||||
env->DeleteLocalRef(svcstr);
|
||||
env->DeleteLocalRef(context);
|
||||
env->DeleteLocalRef(natact);
|
||||
|
||||
// Detach thread again
|
||||
vm->DetachCurrentThread();
|
||||
}
|
||||
#endif
|
||||
|
||||
// This is the actual Android example. You don't have to write any platform
|
||||
// specific code, unless you want to use things not directly exposed.
|
||||
// ('vibrate()' in this example; undefine 'USE_JNI' above to disable it)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
sf::VideoMode screen(sf::VideoMode::getDesktopMode());
|
||||
|
||||
sf::RenderWindow window(screen, "");
|
||||
window.setFramerateLimit(30);
|
||||
|
||||
sf::Texture texture;
|
||||
if(!texture.loadFromFile("image.png"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
sf::Sprite image(texture);
|
||||
image.setPosition(screen.width / 2, screen.height / 2);
|
||||
image.setOrigin(texture.getSize().x/2, texture.getSize().y/2);
|
||||
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
sf::Text text("Tap anywhere to move the logo.", font, 64);
|
||||
text.setFillColor(sf::Color::Black);
|
||||
text.setPosition(10, 10);
|
||||
|
||||
// Loading canary.wav fails for me for now; haven't had time to test why
|
||||
|
||||
/*sf::Music music;
|
||||
if(!music.openFromFile("canary.wav"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
music.play();*/
|
||||
|
||||
sf::View view = window.getDefaultView();
|
||||
|
||||
sf::Color background = sf::Color::White;
|
||||
|
||||
// We shouldn't try drawing to the screen while in background
|
||||
// so we'll have to track that. You can do minor background
|
||||
// work, but keep battery life in mind.
|
||||
bool active = true;
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
sf::Event event;
|
||||
|
||||
while (active ? window.pollEvent(event) : window.waitEvent(event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case sf::Event::Closed:
|
||||
window.close();
|
||||
break;
|
||||
case sf::Event::KeyPressed:
|
||||
if (event.key.code == sf::Keyboard::Escape)
|
||||
window.close();
|
||||
break;
|
||||
case sf::Event::Resized:
|
||||
view.setSize(event.size.width, event.size.height);
|
||||
view.setCenter(event.size.width/2, event.size.height/2);
|
||||
window.setView(view);
|
||||
break;
|
||||
case sf::Event::LostFocus:
|
||||
background = sf::Color::Black;
|
||||
break;
|
||||
case sf::Event::GainedFocus:
|
||||
background = sf::Color::White;
|
||||
break;
|
||||
|
||||
// On Android MouseLeft/MouseEntered are (for now) triggered,
|
||||
// whenever the app loses or gains focus.
|
||||
case sf::Event::MouseLeft:
|
||||
active = false;
|
||||
break;
|
||||
case sf::Event::MouseEntered:
|
||||
active = true;
|
||||
break;
|
||||
case sf::Event::TouchBegan:
|
||||
if (event.touch.finger == 0)
|
||||
{
|
||||
image.setPosition(event.touch.x, event.touch.y);
|
||||
#if defined(USE_JNI)
|
||||
vibrate(sf::milliseconds(10));
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (active)
|
||||
{
|
||||
window.clear(background);
|
||||
window.draw(image);
|
||||
window.draw(text);
|
||||
window.display();
|
||||
}
|
||||
else {
|
||||
sf::sleep(sf::milliseconds(100));
|
||||
}
|
||||
}
|
||||
}
|
BIN
examples/android/app/src/main/res/drawable-hdpi/sfml_logo.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
examples/android/app/src/main/res/drawable-ldpi/sfml_logo.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
examples/android/app/src/main/res/drawable-mdpi/sfml_logo.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
examples/android/app/src/main/res/drawable-xhdpi/sfml_logo.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
examples/android/app/src/main/res/drawable-xxhdpi/sfml_logo.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
4
examples/android/app/src/main/res/values/strings.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">SFML</string>
|
||||
</resources>
|
23
examples/android/build.gradle
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.0'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
17
examples/android/gradle.properties
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
1
examples/android/settings.gradle
Normal file
|
@ -0,0 +1 @@
|
|||
include ':app'
|
38
examples/assets/LaunchScreen.storyboard
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<device id="ipad9_7" orientation="landscape">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="logo.png" translatesAutoresizingMaskIntoConstraints="NO" id="HXY-06-8aG">
|
||||
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="52" y="374.66266866566718"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="logo.png" width="512" height="512"/>
|
||||
</resources>
|
||||
</document>
|
BIN
examples/assets/icon.icns
Normal file
36
examples/assets/info.plist
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>icon.icns</string>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.sfml-dev.$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleLongVersionString</key>
|
||||
<string>2.5.1</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string></string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string></string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
BIN
examples/assets/logo.png
Normal file
After Width: | Height: | Size: 30 KiB |
|
@ -1,15 +1,42 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/cocoa)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/CocoaAppDelegate.h
|
||||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/cocoa)
|
||||
|
||||
# Usage: compile_xib(INPUT path/to/file.xib OUTPUT path/to/file.nib)
|
||||
function(compile_xib)
|
||||
cmake_parse_arguments(THIS "" "INPUT;OUTPUT" "" ${ARGN})
|
||||
if (NOT THIS_INPUT)
|
||||
message(FATAL_ERROR "Missing required argument INPUT in call to compile_xib()")
|
||||
endif()
|
||||
|
||||
if (NOT THIS_OUTPUT)
|
||||
message(FATAL_ERROR "Missing required argument OUTPUT in call to compile_xib()")
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED IBTOOL)
|
||||
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
|
||||
endif()
|
||||
if(NOT IBTOOL)
|
||||
message(FATAL_ERROR "ibtool is required to compile .xib files but wasn't found.")
|
||||
endif()
|
||||
|
||||
# Default args taken from Xcode 9 when it generates a nib from a xib
|
||||
set(DEFAULT_ARGS --errors --warnings --notices --module cocoa --auto-activate-custom-fonts --target-device mac --output-format human-readable-text)
|
||||
|
||||
add_custom_command(OUTPUT "${THIS_OUTPUT}"
|
||||
COMMAND "${IBTOOL}" ${DEFAULT_ARGS} "${THIS_INPUT}" --compile "${THIS_OUTPUT}"
|
||||
DEPENDS "${THIS_INPUT}"
|
||||
COMMENT "Generating ${THIS_OUTPUT}"
|
||||
VERBATIM)
|
||||
endfunction()
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/CocoaAppDelegate.h
|
||||
${SRCROOT}/CocoaAppDelegate.mm
|
||||
${SRCROOT}/NSString+stdstring.h
|
||||
${SRCROOT}/NSString+stdstring.mm
|
||||
${SRCROOT}/main.m)
|
||||
|
||||
# all XIB files
|
||||
set(XIBS MainMenu)
|
||||
compile_xib(INPUT "${SRCROOT}/MainMenu.xib" OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/MainMenu.nib")
|
||||
|
||||
# all resource files
|
||||
set(RESOURCES ${SRCROOT}/resources/logo.png
|
||||
|
@ -18,50 +45,17 @@ set(RESOURCES ${SRCROOT}/resources/logo.png
|
|||
${SRCROOT}/resources/blue.png
|
||||
${SRCROOT}/resources/green.png
|
||||
${SRCROOT}/resources/red.png
|
||||
${SRCROOT}/resources/Credits.rtf)
|
||||
|
||||
# define the cocoa target and customize it
|
||||
add_executable(cocoa MACOSX_BUNDLE ${SRC} ${RESOURCES})
|
||||
${SRCROOT}/resources/Credits.rtf
|
||||
${CMAKE_CURRENT_BINARY_DIR}/MainMenu.nib)
|
||||
set_source_files_properties(${RESOURCES} PROPERTIES
|
||||
MACOSX_PACKAGE_LOCATION Resources)
|
||||
|
||||
# define the cocoa target and customize it
|
||||
sfml_add_example(cocoa
|
||||
SOURCES ${SRC}
|
||||
BUNDLE_RESOURCES ${RESOURCES}
|
||||
DEPENDS sfml-system sfml-window sfml-graphics)
|
||||
set_target_properties(cocoa PROPERTIES
|
||||
MACOSX_BUNDLE TRUE
|
||||
MACOSX_BUNDLE_INFO_PLIST ${SRCROOT}/resources/Cocoa-Info.plist)
|
||||
target_link_libraries(cocoa "-framework Cocoa -framework Foundation"
|
||||
sfml-system sfml-window sfml-graphics)
|
||||
|
||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||
set_target_properties(cocoa PROPERTIES FOLDER "Examples")
|
||||
|
||||
# compile XIB files
|
||||
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
|
||||
if(${IBTOOL} STREQUAL "IBTOOL-NOTFOUND")
|
||||
message(FATAL_ERROR "ibtool is required to compile .xib files but wasn't found.")
|
||||
endif()
|
||||
set(RESOURCE_PATH "cocoa.app/Contents/Resources")
|
||||
set(XIB_OUTPUT_PATH "${RESOURCE_PATH}/")
|
||||
set(XIB_INPUT_PATH "${SRCROOT}/")
|
||||
foreach(XIB ${XIBS})
|
||||
add_custom_command(TARGET cocoa
|
||||
POST_BUILD
|
||||
COMMAND ${IBTOOL} --errors
|
||||
--output-format human-readable-text
|
||||
--compile ${XIB_OUTPUT_PATH}/${XIB}.nib
|
||||
${XIB_INPUT_PATH}/${XIB}.xib
|
||||
COMMENT "Compiling ${XIB}.xib")
|
||||
# deactivated options : --warnings --notices
|
||||
endforeach()
|
||||
|
||||
# add install rule
|
||||
install(TARGETS cocoa
|
||||
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/cocoa
|
||||
COMPONENT examples)
|
||||
|
||||
#
|
||||
# define the cocoa target
|
||||
# sfml_add_example is not compatible with application bundles !
|
||||
#
|
||||
#sfml_add_example(cocoa
|
||||
# SOURCES ${SRC}
|
||||
# DEPENDS sfml-system sfml-window sfml-graphics)
|
||||
#
|
||||
|
||||
target_link_libraries(cocoa PRIVATE "-framework Cocoa" "-framework Foundation" sfml-graphics)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2020 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent@sfml-dev.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.
|
||||
|
@ -27,39 +27,36 @@
|
|||
#import <SFML/Graphics.hpp>
|
||||
|
||||
/*
|
||||
* NB : We need pointers for C++ objects fields in Obj-C interface !
|
||||
* The recomanded way is to use PIMP idiom.
|
||||
* NB: We need pointers for C++ objects fields in Obj-C interface !
|
||||
* The recommended way is to use PIMPL idiom.
|
||||
*
|
||||
* It's elegant. Moreover, we do no constrain
|
||||
* other file including this one to be Obj-C++.
|
||||
* It's elegant. Moreover, we do no constrain
|
||||
* other file including this one to be Obj-C++.
|
||||
*/
|
||||
|
||||
struct SFMLmainWindow;
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||
@interface CocoaAppDelegate : NSObject <NSApplicationDelegate> {
|
||||
#else
|
||||
@interface CocoaAppDelegate : NSObject {
|
||||
#endif
|
||||
@interface CocoaAppDelegate : NSObject <NSApplicationDelegate>
|
||||
{
|
||||
@private
|
||||
NSWindow *m_window;
|
||||
NSView *m_sfmlView;
|
||||
NSTextField *m_textField;
|
||||
SFMLmainWindow *m_mainWindow;
|
||||
NSTimer *m_renderTimer;
|
||||
BOOL m_visible;
|
||||
BOOL m_initialized;
|
||||
NSWindow* m_window;
|
||||
NSView* m_sfmlView;
|
||||
NSTextField* m_textField;
|
||||
SFMLmainWindow* m_mainWindow;
|
||||
NSTimer* m_renderTimer;
|
||||
BOOL m_visible;
|
||||
BOOL m_initialized;
|
||||
}
|
||||
|
||||
@property (retain) IBOutlet NSWindow *window;
|
||||
@property (assign) IBOutlet NSView *sfmlView;
|
||||
@property (assign) IBOutlet NSTextField *textField;
|
||||
@property (retain) IBOutlet NSWindow* window;
|
||||
@property (assign) IBOutlet NSView* sfmlView;
|
||||
@property (assign) IBOutlet NSTextField* textField;
|
||||
|
||||
-(IBAction)colorChanged:(NSPopUpButton *)sender;
|
||||
-(IBAction)rotationChanged:(NSSlider *)sender;
|
||||
-(IBAction)visibleChanged:(NSButton *)sender;
|
||||
-(IBAction)textChanged:(NSTextField *)sender;
|
||||
-(IBAction)updateText:(NSButton *)sender;
|
||||
-(IBAction)colorChanged:(NSPopUpButton*)sender;
|
||||
-(IBAction)rotationChanged:(NSSlider*)sender;
|
||||
-(IBAction)visibleChanged:(NSButton*)sender;
|
||||
-(IBAction)textChanged:(NSTextField*)sender;
|
||||
-(IBAction)updateText:(NSButton*)sender;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -69,6 +66,6 @@ struct SFMLmainWindow;
|
|||
*/
|
||||
@interface SilentWindow : NSWindow
|
||||
|
||||
-(void)keyDown:(NSEvent *)theEvent;
|
||||
-(void)keyDown:(NSEvent*)theEvent;
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2020 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent@sfml-dev.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.
|
||||
|
@ -34,35 +34,33 @@
|
|||
// Our PIMPL
|
||||
struct SFMLmainWindow
|
||||
{
|
||||
SFMLmainWindow(sf::WindowHandle win)
|
||||
: renderWindow(win)
|
||||
, background(sf::Color::Blue)
|
||||
SFMLmainWindow(sf::WindowHandle win) :
|
||||
renderWindow(win),
|
||||
background(sf::Color::Blue)
|
||||
{
|
||||
std::string resPath = [[[NSBundle mainBundle] resourcePath] tostdstring];
|
||||
if (!logo.loadFromFile(resPath + "/logo.png")) {
|
||||
if (!logo.loadFromFile(resPath + "/logo.png"))
|
||||
NSLog(@"Couldn't load the logo image");
|
||||
}
|
||||
|
||||
|
||||
logo.setSmooth(true);
|
||||
|
||||
|
||||
sprite.setTexture(logo, true);
|
||||
sf::FloatRect rect = sprite.getLocalBounds();
|
||||
sf::Vector2f size(rect.width, rect.height);
|
||||
sprite.setOrigin(size / 2.f);
|
||||
sprite.scale(0.3, 0.3);
|
||||
|
||||
|
||||
unsigned int ww = renderWindow.getSize().x;
|
||||
unsigned int wh = renderWindow.getSize().y;
|
||||
sprite.setPosition(sf::Vector2f(ww, wh) / 2.f);
|
||||
|
||||
if (!font.loadFromFile(resPath + "/sansation.ttf")) {
|
||||
if (!font.loadFromFile(resPath + "/sansation.ttf"))
|
||||
NSLog(@"Couldn't load the font");
|
||||
}
|
||||
|
||||
text.setColor(sf::Color::White);
|
||||
|
||||
text.setFillColor(sf::Color::White);
|
||||
text.setFont(font);
|
||||
}
|
||||
|
||||
|
||||
sf::RenderWindow renderWindow;
|
||||
sf::Font font;
|
||||
sf::Text text;
|
||||
|
@ -74,13 +72,13 @@ struct SFMLmainWindow
|
|||
// Private stuff
|
||||
@interface CocoaAppDelegate ()
|
||||
|
||||
@property (assign) SFMLmainWindow *mainWindow;
|
||||
@property (retain) NSTimer *renderTimer;
|
||||
@property (assign) BOOL visible;
|
||||
@property (assign) SFMLmainWindow* mainWindow;
|
||||
@property (retain) NSTimer* renderTimer;
|
||||
@property (assign) BOOL visible;
|
||||
|
||||
@property (assign) BOOL initialized;
|
||||
@property (assign) BOOL initialized;
|
||||
|
||||
-(void)renderMainWindow:(NSTimer *)aTimer;
|
||||
-(void)renderMainWindow:(NSTimer*)aTimer;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -98,28 +96,31 @@ struct SFMLmainWindow
|
|||
|
||||
@synthesize initialized = m_initialized;
|
||||
|
||||
- (id)init {
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
if (self)
|
||||
self.initialized = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
-(void)applicationDidFinishLaunching:(NSNotification*)aNotification
|
||||
{
|
||||
(void)aNotification;
|
||||
|
||||
if (!self.initialized)
|
||||
{
|
||||
// Init the SFML render area.
|
||||
self.mainWindow = new SFMLmainWindow(self.sfmlView);
|
||||
self.mainWindow->text.setString([self.textField.stringValue tostdwstring]);
|
||||
self.visible = YES;
|
||||
|
||||
|
||||
// Launch the timer to periodically display our stuff into the Cocoa view.
|
||||
self.renderTimer = [NSTimer timerWithTimeInterval:1.f/60.f
|
||||
target:self
|
||||
selector:@selector(renderMainWindow:)
|
||||
userInfo:nil
|
||||
userInfo:nil
|
||||
repeats:YES];
|
||||
[[NSRunLoop mainRunLoop] addTimer:self.renderTimer
|
||||
forMode:NSDefaultRunLoopMode];
|
||||
|
@ -133,7 +134,7 @@ struct SFMLmainWindow
|
|||
* while the second mode allows timer firing while he is using a slider
|
||||
* or a menu.
|
||||
*/
|
||||
|
||||
|
||||
self.initialized = YES;
|
||||
}
|
||||
}
|
||||
|
@ -142,67 +143,58 @@ struct SFMLmainWindow
|
|||
{
|
||||
[self.renderTimer invalidate];
|
||||
self.mainWindow->renderWindow.close();
|
||||
|
||||
|
||||
self.window = nil;
|
||||
self.sfmlView = nil;
|
||||
self.textField = nil;
|
||||
|
||||
delete (SFMLmainWindow *) self.mainWindow;
|
||||
|
||||
delete (SFMLmainWindow*) self.mainWindow;
|
||||
self.mainWindow = 0;
|
||||
self.renderTimer = nil;
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(void)renderMainWindow:(NSTimer *)aTimer
|
||||
-(void)renderMainWindow:(NSTimer*)aTimer
|
||||
{
|
||||
(void)aTimer;
|
||||
|
||||
// Scaling
|
||||
/* /!\ we do this at 60fps so choose low scaling factor! /!\ */
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||
{
|
||||
self.mainWindow->sprite.scale(1.01f, 1.01f);
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||
{
|
||||
self.mainWindow->sprite.scale(0.99f, 0.99f);
|
||||
}
|
||||
|
||||
|
||||
// Clear the window, display some stuff and display it into our view.
|
||||
|
||||
|
||||
self.mainWindow->renderWindow.clear(self.mainWindow->background);
|
||||
|
||||
|
||||
if (self.visible)
|
||||
{
|
||||
self.mainWindow->renderWindow.draw(self.mainWindow->sprite);
|
||||
}
|
||||
|
||||
|
||||
self.mainWindow->renderWindow.draw(self.mainWindow->text);
|
||||
|
||||
|
||||
self.mainWindow->renderWindow.display();
|
||||
}
|
||||
|
||||
-(IBAction)colorChanged:(NSPopUpButton *)sender
|
||||
-(IBAction)colorChanged:(NSPopUpButton*)sender
|
||||
{
|
||||
if (self.initialized)
|
||||
{
|
||||
// Convert title to color
|
||||
NSString *color = [[sender selectedItem] title];
|
||||
NSString* color = [[sender selectedItem] title];
|
||||
if ([color isEqualToString:BLUE])
|
||||
{
|
||||
self.mainWindow->background = sf::Color::Blue;
|
||||
}
|
||||
else if ([color isEqualToString:GREEN])
|
||||
{
|
||||
self.mainWindow->background = sf::Color::Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.mainWindow->background = sf::Color::Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction)rotationChanged:(NSSlider *)sender
|
||||
-(IBAction)rotationChanged:(NSSlider*)sender
|
||||
{
|
||||
if (self.initialized)
|
||||
{
|
||||
|
@ -211,21 +203,23 @@ struct SFMLmainWindow
|
|||
}
|
||||
}
|
||||
|
||||
-(IBAction)visibleChanged:(NSButton *)sender
|
||||
-(IBAction)visibleChanged:(NSButton*)sender
|
||||
{
|
||||
if (self.initialized)
|
||||
self.visible = [sender state] == NSOnState;
|
||||
}
|
||||
|
||||
-(IBAction)textChanged:(NSTextField *)sender
|
||||
-(IBAction)textChanged:(NSTextField*)sender
|
||||
{
|
||||
if (self.initialized)
|
||||
self.mainWindow->text.setString([[sender stringValue] tostdwstring]);
|
||||
}
|
||||
|
||||
- (IBAction)updateText:(NSButton *)sender
|
||||
- (IBAction)updateText:(NSButton*)sender
|
||||
{
|
||||
// Simply simulate textChanged :
|
||||
(void)sender;
|
||||
|
||||
// Simply simulate textChanged:
|
||||
[self textChanged:self.textField];
|
||||
}
|
||||
|
||||
|
@ -233,8 +227,9 @@ struct SFMLmainWindow
|
|||
|
||||
@implementation SilentWindow
|
||||
|
||||
-(void)keyDown:(NSEvent *)theEvent
|
||||
-(void)keyDown:(NSEvent*)theEvent
|
||||
{
|
||||
(void)theEvent;
|
||||
// Do nothing except preventing this alert.
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2020 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent@sfml-dev.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.
|
||||
|
@ -28,9 +28,9 @@
|
|||
|
||||
@interface NSString (NSString_stdstring)
|
||||
|
||||
+(id)stringWithstdstring:(std::string const &)string;
|
||||
+(id)stringWithstdstring:(const std::string&)string;
|
||||
|
||||
+(id)stringWithstdwstring:(std::wstring const &)string;
|
||||
+(id)stringWithstdwstring:(const std::wstring&)string;
|
||||
|
||||
-(std::string)tostdstring;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2020 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent@sfml-dev.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.
|
||||
|
@ -28,51 +28,46 @@
|
|||
|
||||
@implementation NSString (NSString_stdstring)
|
||||
|
||||
+(id)stringWithstdstring:(std::string const &)string
|
||||
+(id)stringWithstdstring:(const std::string&)string
|
||||
{
|
||||
std::string utf8;
|
||||
utf8.reserve(string.size() + 1);
|
||||
|
||||
|
||||
sf::Utf8::fromAnsi(string.begin(), string.end(), std::back_inserter(utf8));
|
||||
|
||||
NSString *str = [NSString stringWithCString:utf8.c_str()
|
||||
|
||||
NSString* str = [NSString stringWithCString:utf8.c_str()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
return str;
|
||||
}
|
||||
|
||||
+(id)stringWithstdwstring:(const std::wstring&)string
|
||||
{
|
||||
char* data = (char*)string.data();
|
||||
unsigned size = string.size() * sizeof(wchar_t);
|
||||
|
||||
NSString* str = [[[NSString alloc] initWithBytes:data length:size
|
||||
encoding:NSUTF32LittleEndianStringEncoding] autorelease];
|
||||
return str;
|
||||
}
|
||||
|
||||
-(std::string)tostdstring
|
||||
{
|
||||
// Not sure about the encoding to use. Using [self UTF8String] doesn't
|
||||
// work for characters like é or à.
|
||||
const char *cstr = [self cStringUsingEncoding:NSISOLatin1StringEncoding];
|
||||
|
||||
if (cstr != NULL)
|
||||
{
|
||||
std::string str(cstr);
|
||||
return str;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
+(id)stringWithstdwstring:(std::wstring const &)string
|
||||
{
|
||||
char* data = (char *)string.data();
|
||||
unsigned size = string.size() * sizeof(wchar_t);
|
||||
|
||||
NSString *str = [[[NSString alloc] initWithBytes:data length:size
|
||||
encoding:NSUTF32LittleEndianStringEncoding] autorelease];
|
||||
return str;
|
||||
if (cstr != NULL)
|
||||
return std::string(cstr);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
-(std::wstring)tostdwstring
|
||||
{
|
||||
// According to wikipedia, Mac OS X is Little Endian on x86 and x86-64
|
||||
// http://en.wikipedia.org/wiki/Endianness
|
||||
// According to Wikipedia, Mac OS X is Little Endian on x86 and x86-64
|
||||
// https://en.wikipedia.org/wiki/Endianness
|
||||
NSData* asData = [self dataUsingEncoding:NSUTF32LittleEndianStringEncoding];
|
||||
return std::wstring((wchar_t *)[asData bytes], [asData length] / sizeof(wchar_t));
|
||||
return std::wstring((wchar_t*)[asData bytes], [asData length] / sizeof(wchar_t));
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2020 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent@sfml-dev.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.
|
||||
|
|
|
@ -6,10 +6,10 @@ This is a small example of the integration of SFML in a Cocoa application.
|
|||
Features
|
||||
--------
|
||||
|
||||
* This example shows how basic UI elements can interact with SFML
|
||||
render areas such as sf::RenderWindow (you can use sf::Window and
|
||||
* This example shows how basic UI elements can interact with SFML
|
||||
render areas such as sf::RenderWindow (you can use sf::Window and
|
||||
OpenGL code too, of course).
|
||||
* It also provides tools for converting NSString to and from
|
||||
* It also provides tools for converting NSString to and from
|
||||
std::[w]string in an Objective-C Category of NSString.
|
||||
* Moreover, it shows how you can prevent annoying the system alerts
|
||||
produced when the SFML view has focus and the user press a key
|
||||
|
|
|
@ -25,10 +25,12 @@
|
|||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2007-2012 Marco Antognini and Laurent Gomila. Shared under zlib/libpng License.</string>
|
||||
<string>Copyright © 2007-2020 Marco Antognini and Laurent Gomila. Shared under zlib/libpng License.</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
\paperw11900\paperh16840\vieww9600\viewh8400\viewkind0
|
||||
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\qj
|
||||
|
||||
\f0\fs24 \cf0 See {\field{\*\fldinst{HYPERLINK "http://sfml-dev.org"}}{\fldrslt http://sfml-dev.org}} for more information}
|
||||
\f0\fs24 \cf0 See {\field{\*\fldinst{HYPERLINK "https://sfml-dev.org"}}{\fldrslt https://sfml-dev.org}} for more information}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/ftp)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/Ftp.cpp)
|
||||
|
||||
# define the ftp target
|
||||
sfml_add_example(ftp
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-network sfml-system)
|
||||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/ftp)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/Ftp.cpp)
|
||||
|
||||
# define the ftp target
|
||||
sfml_add_example(ftp
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-network)
|
||||
|
|
|
@ -1,206 +1,206 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Print a FTP response into a standard output stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& response)
|
||||
{
|
||||
return stream << response.getStatus() << response.getMessage();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Choose the server address
|
||||
sf::IpAddress address;
|
||||
do
|
||||
{
|
||||
std::cout << "Enter the FTP server address : ";
|
||||
std::cin >> address;
|
||||
}
|
||||
while (address == sf::IpAddress::None);
|
||||
|
||||
// Connect to the server
|
||||
sf::Ftp server;
|
||||
sf::Ftp::Response connectResponse = server.connect(address);
|
||||
std::cout << connectResponse << std::endl;
|
||||
if (!connectResponse.isOk())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Ask for user name and password
|
||||
std::string user, password;
|
||||
std::cout << "User name : ";
|
||||
std::cin >> user;
|
||||
std::cout << "Password : ";
|
||||
std::cin >> password;
|
||||
|
||||
// Login to the server
|
||||
sf::Ftp::Response loginResponse = server.login(user, password);
|
||||
std::cout << loginResponse << std::endl;
|
||||
if (!loginResponse.isOk())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Main menu
|
||||
int choice = 0;
|
||||
do
|
||||
{
|
||||
// Main FTP menu
|
||||
std::cout << std::endl;
|
||||
std::cout << "Choose an action:" << std::endl;
|
||||
std::cout << "1. Print working directory" << std::endl;
|
||||
std::cout << "2. Print contents of working directory" << std::endl;
|
||||
std::cout << "3. Change directory" << std::endl;
|
||||
std::cout << "4. Create directory" << std::endl;
|
||||
std::cout << "5. Delete directory" << std::endl;
|
||||
std::cout << "6. Rename file" << std::endl;
|
||||
std::cout << "7. Remove file" << std::endl;
|
||||
std::cout << "8. Download file" << std::endl;
|
||||
std::cout << "9. Upload file" << std::endl;
|
||||
std::cout << "0. Disconnect" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Your choice: ";
|
||||
std::cin >> choice;
|
||||
std::cout << std::endl;
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
default :
|
||||
{
|
||||
// Wrong choice
|
||||
std::cout << "Invalid choice!" << std::endl;
|
||||
std::cin.clear();
|
||||
std::cin.ignore(10000, '\n');
|
||||
break;
|
||||
}
|
||||
|
||||
case 1 :
|
||||
{
|
||||
// Print the current server directory
|
||||
sf::Ftp::DirectoryResponse response = server.getWorkingDirectory();
|
||||
std::cout << response << std::endl;
|
||||
std::cout << "Current directory is " << response.getDirectory() << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2 :
|
||||
{
|
||||
// Print the contents of the current server directory
|
||||
sf::Ftp::ListingResponse response = server.getDirectoryListing();
|
||||
std::cout << response << std::endl;
|
||||
const std::vector<std::string>& names = response.getListing();
|
||||
for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
|
||||
std::cout << *it << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 3 :
|
||||
{
|
||||
// Change the current directory
|
||||
std::string directory;
|
||||
std::cout << "Choose a directory: ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.changeDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 4 :
|
||||
{
|
||||
// Create a new directory
|
||||
std::string directory;
|
||||
std::cout << "Name of the directory to create: ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.createDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 5 :
|
||||
{
|
||||
// Remove an existing directory
|
||||
std::string directory;
|
||||
std::cout << "Name of the directory to remove: ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.deleteDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 6 :
|
||||
{
|
||||
// Rename a file
|
||||
std::string source, destination;
|
||||
std::cout << "Name of the file to rename: ";
|
||||
std::cin >> source;
|
||||
std::cout << "New name: ";
|
||||
std::cin >> destination;
|
||||
std::cout << server.renameFile(source, destination) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 7 :
|
||||
{
|
||||
// Remove an existing directory
|
||||
std::string filename;
|
||||
std::cout << "Name of the file to remove: ";
|
||||
std::cin >> filename;
|
||||
std::cout << server.deleteFile(filename) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 8 :
|
||||
{
|
||||
// Download a file from server
|
||||
std::string filename, directory;
|
||||
std::cout << "Filename of the file to download (relative to current directory): ";
|
||||
std::cin >> filename;
|
||||
std::cout << "Directory to download the file to: ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.download(filename, directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 9 :
|
||||
{
|
||||
// Upload a file to server
|
||||
std::string filename, directory;
|
||||
std::cout << "Path of the file to upload (absolute or relative to working directory): ";
|
||||
std::cin >> filename;
|
||||
std::cout << "Directory to upload the file to (relative to current directory): ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.upload(filename, directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 0 :
|
||||
{
|
||||
// Disconnect
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} while (choice != 0);
|
||||
|
||||
// Disconnect from the server
|
||||
std::cout << "Disconnecting from server..." << std::endl;
|
||||
std::cout << server.disconnect() << std::endl;
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
std::cout << "Press enter to exit..." << std::endl;
|
||||
std::cin.ignore(10000, '\n');
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Print a FTP response into a standard output stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& response)
|
||||
{
|
||||
return stream << response.getStatus() << response.getMessage();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Choose the server address
|
||||
sf::IpAddress address;
|
||||
do
|
||||
{
|
||||
std::cout << "Enter the FTP server address: ";
|
||||
std::cin >> address;
|
||||
}
|
||||
while (address == sf::IpAddress::None);
|
||||
|
||||
// Connect to the server
|
||||
sf::Ftp server;
|
||||
sf::Ftp::Response connectResponse = server.connect(address);
|
||||
std::cout << connectResponse << std::endl;
|
||||
if (!connectResponse.isOk())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Ask for user name and password
|
||||
std::string user, password;
|
||||
std::cout << "User name: ";
|
||||
std::cin >> user;
|
||||
std::cout << "Password: ";
|
||||
std::cin >> password;
|
||||
|
||||
// Login to the server
|
||||
sf::Ftp::Response loginResponse = server.login(user, password);
|
||||
std::cout << loginResponse << std::endl;
|
||||
if (!loginResponse.isOk())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Main menu
|
||||
int choice = 0;
|
||||
do
|
||||
{
|
||||
// Main FTP menu
|
||||
std::cout << std::endl;
|
||||
std::cout << "Choose an action:" << std::endl;
|
||||
std::cout << "1. Print working directory" << std::endl;
|
||||
std::cout << "2. Print contents of working directory" << std::endl;
|
||||
std::cout << "3. Change directory" << std::endl;
|
||||
std::cout << "4. Create directory" << std::endl;
|
||||
std::cout << "5. Delete directory" << std::endl;
|
||||
std::cout << "6. Rename file" << std::endl;
|
||||
std::cout << "7. Remove file" << std::endl;
|
||||
std::cout << "8. Download file" << std::endl;
|
||||
std::cout << "9. Upload file" << std::endl;
|
||||
std::cout << "0. Disconnect" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Your choice: ";
|
||||
std::cin >> choice;
|
||||
std::cout << std::endl;
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
default:
|
||||
{
|
||||
// Wrong choice
|
||||
std::cout << "Invalid choice!" << std::endl;
|
||||
std::cin.clear();
|
||||
std::cin.ignore(10000, '\n');
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
// Print the current server directory
|
||||
sf::Ftp::DirectoryResponse response = server.getWorkingDirectory();
|
||||
std::cout << response << std::endl;
|
||||
std::cout << "Current directory is " << response.getDirectory() << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
// Print the contents of the current server directory
|
||||
sf::Ftp::ListingResponse response = server.getDirectoryListing();
|
||||
std::cout << response << std::endl;
|
||||
const std::vector<std::string>& names = response.getListing();
|
||||
for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
|
||||
std::cout << *it << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
// Change the current directory
|
||||
std::string directory;
|
||||
std::cout << "Choose a directory: ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.changeDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
// Create a new directory
|
||||
std::string directory;
|
||||
std::cout << "Name of the directory to create: ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.createDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{
|
||||
// Remove an existing directory
|
||||
std::string directory;
|
||||
std::cout << "Name of the directory to remove: ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.deleteDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 6:
|
||||
{
|
||||
// Rename a file
|
||||
std::string source, destination;
|
||||
std::cout << "Name of the file to rename: ";
|
||||
std::cin >> source;
|
||||
std::cout << "New name: ";
|
||||
std::cin >> destination;
|
||||
std::cout << server.renameFile(source, destination) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 7:
|
||||
{
|
||||
// Remove an existing directory
|
||||
std::string filename;
|
||||
std::cout << "Name of the file to remove: ";
|
||||
std::cin >> filename;
|
||||
std::cout << server.deleteFile(filename) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 8:
|
||||
{
|
||||
// Download a file from server
|
||||
std::string filename, directory;
|
||||
std::cout << "Filename of the file to download (relative to current directory): ";
|
||||
std::cin >> filename;
|
||||
std::cout << "Directory to download the file to: ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.download(filename, directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 9:
|
||||
{
|
||||
// Upload a file to server
|
||||
std::string filename, directory;
|
||||
std::cout << "Path of the file to upload (absolute or relative to working directory): ";
|
||||
std::cin >> filename;
|
||||
std::cout << "Directory to upload the file to (relative to current directory): ";
|
||||
std::cin >> directory;
|
||||
std::cout << server.upload(filename, directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 0:
|
||||
{
|
||||
// Disconnect
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} while (choice != 0);
|
||||
|
||||
// Disconnect from the server
|
||||
std::cout << "Disconnecting from server..." << std::endl;
|
||||
std::cout << server.disconnect() << std::endl;
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
std::cout << "Press enter to exit..." << std::endl;
|
||||
std::cin.ignore(10000, '\n');
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
11
examples/island/CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/island)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/Island.cpp)
|
||||
|
||||
# define the island target
|
||||
sfml_add_example(island GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-graphics
|
||||
RESOURCES_DIR resources)
|
590
examples/island/Island.cpp
Normal file
|
@ -0,0 +1,590 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#define STB_PERLIN_IMPLEMENTATION
|
||||
#include "stb_perlin.h"
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// Width and height of the application window
|
||||
const unsigned int windowWidth = 800;
|
||||
const unsigned int windowHeight = 600;
|
||||
|
||||
// Resolution of the generated terrain
|
||||
const unsigned int resolutionX = 800;
|
||||
const unsigned int resolutionY = 600;
|
||||
|
||||
// Thread pool parameters
|
||||
const unsigned int threadCount = 4;
|
||||
const unsigned int blockCount = 32;
|
||||
|
||||
struct WorkItem
|
||||
{
|
||||
sf::Vertex* targetBuffer;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
std::deque<WorkItem> workQueue;
|
||||
std::vector<sf::Thread*> threads;
|
||||
int pendingWorkCount = 0;
|
||||
bool workPending = true;
|
||||
bool bufferUploadPending = false;
|
||||
sf::Mutex workQueueMutex;
|
||||
|
||||
struct Setting
|
||||
{
|
||||
const char* name;
|
||||
float* value;
|
||||
};
|
||||
|
||||
// Terrain noise parameters
|
||||
const int perlinOctaves = 3;
|
||||
|
||||
float perlinFrequency = 7.0f;
|
||||
float perlinFrequencyBase = 4.0f;
|
||||
|
||||
// Terrain generation parameters
|
||||
float heightBase = 0.0f;
|
||||
float edgeFactor = 0.9f;
|
||||
float edgeDropoffExponent = 1.5f;
|
||||
|
||||
float snowcapHeight = 0.6f;
|
||||
|
||||
// Terrain lighting parameters
|
||||
float heightFactor = windowHeight / 2.0f;
|
||||
float heightFlatten = 3.0f;
|
||||
float lightFactor = 0.7f;
|
||||
}
|
||||
|
||||
|
||||
// Forward declarations of the functions we define further down
|
||||
void threadFunction();
|
||||
void generateTerrain(sf::Vertex* vertexBuffer);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Create the window of the application
|
||||
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "SFML Island",
|
||||
sf::Style::Titlebar | sf::Style::Close);
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Create all of our graphics resources
|
||||
sf::Text hudText;
|
||||
sf::Text statusText;
|
||||
sf::Shader terrainShader;
|
||||
sf::RenderStates terrainStates(&terrainShader);
|
||||
sf::VertexBuffer terrain(sf::Triangles, sf::VertexBuffer::Static);
|
||||
|
||||
// Set up our text drawables
|
||||
statusText.setFont(font);
|
||||
statusText.setCharacterSize(28);
|
||||
statusText.setFillColor(sf::Color::White);
|
||||
statusText.setOutlineColor(sf::Color::Black);
|
||||
statusText.setOutlineThickness(2.0f);
|
||||
|
||||
hudText.setFont(font);
|
||||
hudText.setCharacterSize(14);
|
||||
hudText.setFillColor(sf::Color::White);
|
||||
hudText.setOutlineColor(sf::Color::Black);
|
||||
hudText.setOutlineThickness(2.0f);
|
||||
hudText.setPosition(5.0f, 5.0f);
|
||||
|
||||
// Staging buffer for our terrain data that we will upload to our VertexBuffer
|
||||
std::vector<sf::Vertex> terrainStagingBuffer;
|
||||
|
||||
// Check whether the prerequisites are suppprted
|
||||
bool prerequisitesSupported = sf::VertexBuffer::isAvailable() && sf::Shader::isAvailable();
|
||||
|
||||
// Set up our graphics resources and set the status text accordingly
|
||||
if (!prerequisitesSupported)
|
||||
{
|
||||
statusText.setString("Shaders and/or Vertex Buffers Unsupported");
|
||||
}
|
||||
else if (!terrainShader.loadFromFile("resources/terrain.vert", "resources/terrain.frag"))
|
||||
{
|
||||
prerequisitesSupported = false;
|
||||
|
||||
statusText.setString("Failed to load shader program");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Start up our thread pool
|
||||
for (unsigned int i = 0; i < threadCount; i++)
|
||||
{
|
||||
threads.push_back(new sf::Thread(threadFunction));
|
||||
threads.back()->launch();
|
||||
}
|
||||
|
||||
// Create our VertexBuffer with enough space to hold all the terrain geometry
|
||||
terrain.create(resolutionX * resolutionY * 6);
|
||||
|
||||
// Resize the staging buffer to be able to hold all the terrain geometry
|
||||
terrainStagingBuffer.resize(resolutionX * resolutionY * 6);
|
||||
|
||||
// Generate the initial terrain
|
||||
generateTerrain(&terrainStagingBuffer[0]);
|
||||
|
||||
statusText.setString("Generating Terrain...");
|
||||
}
|
||||
|
||||
// Center the status text
|
||||
statusText.setPosition((windowWidth - statusText.getLocalBounds().width) / 2.f, (windowHeight - statusText.getLocalBounds().height) / 2.f);
|
||||
|
||||
// Set up an array of pointers to our settings for arrow navigation
|
||||
Setting settings[] =
|
||||
{
|
||||
{"perlinFrequency", &perlinFrequency},
|
||||
{"perlinFrequencyBase", &perlinFrequencyBase},
|
||||
{"heightBase", &heightBase},
|
||||
{"edgeFactor", &edgeFactor},
|
||||
{"edgeDropoffExponent", &edgeDropoffExponent},
|
||||
{"snowcapHeight", &snowcapHeight},
|
||||
{"heightFactor", &heightFactor},
|
||||
{"heightFlatten", &heightFlatten},
|
||||
{"lightFactor", &lightFactor}
|
||||
};
|
||||
|
||||
const int settingCount = 9;
|
||||
int currentSetting = 0;
|
||||
|
||||
std::ostringstream osstr;
|
||||
sf::Clock clock;
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
// Handle events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
// Window closed or escape key pressed: exit
|
||||
if ((event.type == sf::Event::Closed) ||
|
||||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
|
||||
{
|
||||
window.close();
|
||||
break;
|
||||
}
|
||||
|
||||
// Arrow key pressed:
|
||||
if (prerequisitesSupported && (event.type == sf::Event::KeyPressed))
|
||||
{
|
||||
switch (event.key.code)
|
||||
{
|
||||
case sf::Keyboard::Return: generateTerrain(&terrainStagingBuffer[0]); break;
|
||||
case sf::Keyboard::Down: currentSetting = (currentSetting + 1) % settingCount; break;
|
||||
case sf::Keyboard::Up: currentSetting = (currentSetting + settingCount - 1) % settingCount; break;
|
||||
case sf::Keyboard::Left: *(settings[currentSetting].value) -= 0.1f; break;
|
||||
case sf::Keyboard::Right: *(settings[currentSetting].value) += 0.1f; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear, draw graphics objects and display
|
||||
window.clear();
|
||||
|
||||
window.draw(statusText);
|
||||
|
||||
if (prerequisitesSupported)
|
||||
{
|
||||
{
|
||||
sf::Lock lock(workQueueMutex);
|
||||
|
||||
// Don't bother updating/drawing the VertexBuffer while terrain is being regenerated
|
||||
if (!pendingWorkCount)
|
||||
{
|
||||
// If there is new data pending to be uploaded to the VertexBuffer, do it now
|
||||
if (bufferUploadPending)
|
||||
{
|
||||
terrain.update(&terrainStagingBuffer[0]);
|
||||
bufferUploadPending = false;
|
||||
}
|
||||
|
||||
terrainShader.setUniform("lightFactor", lightFactor);
|
||||
window.draw(terrain, terrainStates);
|
||||
}
|
||||
}
|
||||
|
||||
// Update and draw the HUD text
|
||||
osstr.str("");
|
||||
osstr << "Frame: " << clock.restart().asMilliseconds() << "ms\n"
|
||||
<< "perlinOctaves: " << perlinOctaves << "\n\n"
|
||||
<< "Use the arrow keys to change the values.\nUse the return key to regenerate the terrain.\n\n";
|
||||
|
||||
for (int i = 0; i < settingCount; ++i)
|
||||
osstr << ((i == currentSetting) ? ">> " : " ") << settings[i].name << ": " << *(settings[i].value) << "\n";
|
||||
|
||||
hudText.setString(osstr.str());
|
||||
|
||||
window.draw(hudText);
|
||||
}
|
||||
|
||||
// Display things on screen
|
||||
window.display();
|
||||
}
|
||||
|
||||
// Shut down our thread pool
|
||||
{
|
||||
sf::Lock lock(workQueueMutex);
|
||||
workPending = false;
|
||||
}
|
||||
|
||||
while (!threads.empty())
|
||||
{
|
||||
threads.back()->wait();
|
||||
delete threads.back();
|
||||
threads.pop_back();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the terrain elevation at the given coordinates.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getElevation(float x, float y)
|
||||
{
|
||||
x = x / resolutionX - 0.5f;
|
||||
y = y / resolutionY - 0.5f;
|
||||
|
||||
float elevation = 0.0f;
|
||||
|
||||
for (int i = 0; i < perlinOctaves; i++)
|
||||
{
|
||||
elevation += stb_perlin_noise3(
|
||||
x * perlinFrequency * std::pow(perlinFrequencyBase, i),
|
||||
y * perlinFrequency * std::pow(perlinFrequencyBase, i),
|
||||
0, 0, 0, 0
|
||||
) * std::pow(perlinFrequencyBase, -i);
|
||||
}
|
||||
|
||||
elevation = (elevation + 1.f) / 2.f;
|
||||
|
||||
float distance = 2.0f * std::sqrt(x * x + y * y);
|
||||
elevation = (elevation + heightBase) * (1.0f - edgeFactor * std::pow(distance, edgeDropoffExponent));
|
||||
elevation = std::min(std::max(elevation, 0.0f), 1.0f);
|
||||
|
||||
return elevation;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the terrain moisture at the given coordinates.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getMoisture(float x, float y)
|
||||
{
|
||||
x = x / resolutionX - 0.5f;
|
||||
y = y / resolutionY - 0.5f;
|
||||
|
||||
float moisture = stb_perlin_noise3(
|
||||
x * 4.f + 0.5f,
|
||||
y * 4.f + 0.5f,
|
||||
0, 0, 0, 0
|
||||
);
|
||||
|
||||
return (moisture + 1.f) / 2.f;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the lowlands terrain color for the given moisture.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Color getLowlandsTerrainColor(float moisture)
|
||||
{
|
||||
sf::Color color =
|
||||
moisture < 0.27f ? sf::Color(240, 240, 180) :
|
||||
moisture < 0.3f ? sf::Color(240 - 240 * (moisture - 0.27f) / 0.03f, 240 - 40 * (moisture - 0.27f) / 0.03f, 180 - 180 * (moisture - 0.27f) / 0.03f) :
|
||||
moisture < 0.4f ? sf::Color(0, 200, 0) :
|
||||
moisture < 0.48f ? sf::Color(0, 200 - 40 * (moisture - 0.4f) / 0.08f, 0) :
|
||||
moisture < 0.6f ? sf::Color(0, 160, 0) :
|
||||
moisture < 0.7f ? sf::Color(34 * (moisture - 0.6f) / 0.1f, 160 - 60 * (moisture - 0.6f) / 0.1f, 34 * (moisture - 0.6f) / 0.1f) :
|
||||
sf::Color(34, 100, 34);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the highlands terrain color for the given elevation
|
||||
/// and moisture.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Color getHighlandsTerrainColor(float elevation, float moisture)
|
||||
{
|
||||
sf::Color lowlandsColor = getLowlandsTerrainColor(moisture);
|
||||
|
||||
sf::Color color =
|
||||
moisture < 0.6f ? sf::Color(112, 128, 144) :
|
||||
sf::Color(112 + 110 * (moisture - 0.6f) / 0.4f, 128 + 56 * (moisture - 0.6f) / 0.4f, 144 - 9 * (moisture - 0.6f) / 0.4f);
|
||||
|
||||
float factor = std::min((elevation - 0.4f) / 0.1f, 1.f);
|
||||
|
||||
color.r = lowlandsColor.r * (1.f - factor) + color.r * factor;
|
||||
color.g = lowlandsColor.g * (1.f - factor) + color.g * factor;
|
||||
color.b = lowlandsColor.b * (1.f - factor) + color.b * factor;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the snowcap terrain color for the given elevation
|
||||
/// and moisture.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Color getSnowcapTerrainColor(float elevation, float moisture)
|
||||
{
|
||||
sf::Color highlandsColor = getHighlandsTerrainColor(elevation, moisture);
|
||||
|
||||
sf::Color color = sf::Color::White;
|
||||
|
||||
float factor = std::min((elevation - snowcapHeight) / 0.05f, 1.f);
|
||||
|
||||
color.r = highlandsColor.r * (1.f - factor) + color.r * factor;
|
||||
color.g = highlandsColor.g * (1.f - factor) + color.g * factor;
|
||||
color.b = highlandsColor.b * (1.f - factor) + color.b * factor;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the terrain color for the given elevation and
|
||||
/// moisture.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Color getTerrainColor(float elevation, float moisture)
|
||||
{
|
||||
sf::Color color =
|
||||
elevation < 0.11f ? sf::Color(0, 0, elevation / 0.11f * 74.f + 181.0f) :
|
||||
elevation < 0.14f ? sf::Color(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f, std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f, 255) :
|
||||
elevation < 0.16f ? sf::Color((elevation - 0.14f) * 128.f / 0.02f + 48.f, (elevation - 0.14f) * 128.f / 0.02f + 48.f, 127.0f + (0.16f - elevation) * 128.f / 0.02f) :
|
||||
elevation < 0.17f ? sf::Color(240, 230, 140) :
|
||||
elevation < 0.4f ? getLowlandsTerrainColor(moisture) :
|
||||
elevation < snowcapHeight ? getHighlandsTerrainColor(elevation, moisture) :
|
||||
getSnowcapTerrainColor(elevation, moisture);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Compute a compressed representation of the surface
|
||||
/// normal based on the given coordinates, and the elevation
|
||||
/// of the 4 adjacent neighbours.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Vector2f computeNormal(int x, int y, float left, float right, float bottom, float top)
|
||||
{
|
||||
sf::Vector3f deltaX(1, 0, (std::pow(right, heightFlatten) - std::pow(left, heightFlatten)) * heightFactor);
|
||||
sf::Vector3f deltaY(0, 1, (std::pow(top, heightFlatten) - std::pow(bottom, heightFlatten)) * heightFactor);
|
||||
|
||||
sf::Vector3f crossProduct(
|
||||
deltaX.y * deltaY.z - deltaX.z * deltaY.y,
|
||||
deltaX.z * deltaY.x - deltaX.x * deltaY.z,
|
||||
deltaX.x * deltaY.y - deltaX.y * deltaY.x
|
||||
);
|
||||
|
||||
// Scale cross product to make z component 1.0f so we can drop it
|
||||
crossProduct /= crossProduct.z;
|
||||
|
||||
// Return "compressed" normal
|
||||
return sf::Vector2f(crossProduct.x, crossProduct.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Process a terrain generation work item. Use the vector
|
||||
/// of vertices as scratch memory and upload the data to
|
||||
/// the vertex buffer when done.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem)
|
||||
{
|
||||
unsigned int rowBlockSize = (resolutionY / blockCount) + 1;
|
||||
unsigned int rowStart = rowBlockSize * workItem.index;
|
||||
|
||||
if (rowStart >= resolutionY)
|
||||
return;
|
||||
|
||||
unsigned int rowEnd = std::min(rowStart + rowBlockSize, resolutionY);
|
||||
unsigned int rowCount = rowEnd - rowStart;
|
||||
|
||||
const float scalingFactorX = static_cast<float>(windowWidth) / static_cast<float>(resolutionX);
|
||||
const float scalingFactorY = static_cast<float>(windowHeight) / static_cast<float>(resolutionY);
|
||||
|
||||
for (unsigned int y = rowStart; y < rowEnd; y++)
|
||||
{
|
||||
for (int x = 0; x < resolutionX; x++)
|
||||
{
|
||||
int arrayIndexBase = ((y - rowStart) * resolutionX + x) * 6;
|
||||
|
||||
// Top left corner (first triangle)
|
||||
if (x > 0)
|
||||
{
|
||||
vertices[arrayIndexBase + 0] = vertices[arrayIndexBase - 6 + 5];
|
||||
}
|
||||
else if (y > rowStart)
|
||||
{
|
||||
vertices[arrayIndexBase + 0] = vertices[arrayIndexBase - resolutionX * 6 + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
vertices[arrayIndexBase + 0].position = sf::Vector2f(x * scalingFactorX, y * scalingFactorY);
|
||||
vertices[arrayIndexBase + 0].color = getTerrainColor(getElevation(x, y), getMoisture(x, y));
|
||||
vertices[arrayIndexBase + 0].texCoords = computeNormal(x, y, getElevation(x - 1, y), getElevation(x + 1, y), getElevation(x, y + 1), getElevation(x, y - 1));
|
||||
}
|
||||
|
||||
// Bottom left corner (first triangle)
|
||||
if (x > 0)
|
||||
{
|
||||
vertices[arrayIndexBase + 1] = vertices[arrayIndexBase - 6 + 2];
|
||||
}
|
||||
else
|
||||
{
|
||||
vertices[arrayIndexBase + 1].position = sf::Vector2f(x * scalingFactorX, (y + 1) * scalingFactorY);
|
||||
vertices[arrayIndexBase + 1].color = getTerrainColor(getElevation(x, y + 1), getMoisture(x, y + 1));
|
||||
vertices[arrayIndexBase + 1].texCoords = computeNormal(x, y + 1, getElevation(x - 1, y + 1), getElevation(x + 1, y + 1), getElevation(x, y + 2), getElevation(x, y));
|
||||
}
|
||||
|
||||
// Bottom right corner (first triangle)
|
||||
vertices[arrayIndexBase + 2].position = sf::Vector2f((x + 1) * scalingFactorX, (y + 1) * scalingFactorY);
|
||||
vertices[arrayIndexBase + 2].color = getTerrainColor(getElevation(x + 1, y + 1), getMoisture(x + 1, y + 1));
|
||||
vertices[arrayIndexBase + 2].texCoords = computeNormal(x + 1, y + 1, getElevation(x, y + 1), getElevation(x + 2, y + 1), getElevation(x + 1, y + 2), getElevation(x + 1, y));
|
||||
|
||||
// Top left corner (second triangle)
|
||||
vertices[arrayIndexBase + 3] = vertices[arrayIndexBase + 0];
|
||||
|
||||
// Bottom right corner (second triangle)
|
||||
vertices[arrayIndexBase + 4] = vertices[arrayIndexBase + 2];
|
||||
|
||||
// Top right corner (second triangle)
|
||||
if (y > rowStart)
|
||||
{
|
||||
vertices[arrayIndexBase + 5] = vertices[arrayIndexBase - resolutionX * 6 + 2];
|
||||
}
|
||||
else
|
||||
{
|
||||
vertices[arrayIndexBase + 5].position = sf::Vector2f((x + 1) * scalingFactorX, y * scalingFactorY);
|
||||
vertices[arrayIndexBase + 5].color = getTerrainColor(getElevation(x + 1, y), getMoisture(x + 1, y));
|
||||
vertices[arrayIndexBase + 5].texCoords = computeNormal(x + 1, y, getElevation(x, y), getElevation(x + 2, y), getElevation(x + 1, y + 1), getElevation(x + 1, y - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the resulting geometry from our thread-local buffer into the target buffer
|
||||
std::memcpy(workItem.targetBuffer + (resolutionX * rowStart * 6), &vertices[0], sizeof(sf::Vertex) * resolutionX * rowCount * 6);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Worker thread entry point. We use a thread pool to avoid
|
||||
/// the heavy cost of constantly recreating and starting
|
||||
/// new threads whenever we need to regenerate the terrain.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void threadFunction()
|
||||
{
|
||||
unsigned int rowBlockSize = (resolutionY / blockCount) + 1;
|
||||
|
||||
std::vector<sf::Vertex> vertices(resolutionX * rowBlockSize * 6);
|
||||
|
||||
WorkItem workItem = {0, 0};
|
||||
|
||||
// Loop until the application exits
|
||||
for (;;)
|
||||
{
|
||||
workItem.targetBuffer = 0;
|
||||
|
||||
// Check if there are new work items in the queue
|
||||
{
|
||||
sf::Lock lock(workQueueMutex);
|
||||
|
||||
if (!workPending)
|
||||
return;
|
||||
|
||||
if (!workQueue.empty())
|
||||
{
|
||||
workItem = workQueue.front();
|
||||
workQueue.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't receive a new work item, keep looping
|
||||
if (!workItem.targetBuffer)
|
||||
{
|
||||
sf::sleep(sf::milliseconds(10));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
processWorkItem(vertices, workItem);
|
||||
|
||||
{
|
||||
sf::Lock lock(workQueueMutex);
|
||||
|
||||
--pendingWorkCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Terrain generation entry point. This queues up the
|
||||
/// generation work items which the worker threads dequeue
|
||||
/// and process.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void generateTerrain(sf::Vertex* buffer)
|
||||
{
|
||||
bufferUploadPending = true;
|
||||
|
||||
// Make sure the work queue is empty before queuing new work
|
||||
for (;;)
|
||||
{
|
||||
{
|
||||
sf::Lock lock(workQueueMutex);
|
||||
|
||||
if (workQueue.empty())
|
||||
break;
|
||||
}
|
||||
|
||||
sf::sleep(sf::milliseconds(10));
|
||||
}
|
||||
|
||||
// Queue all the new work items
|
||||
{
|
||||
sf::Lock lock(workQueueMutex);
|
||||
|
||||
for (unsigned int i = 0; i < blockCount; i++)
|
||||
{
|
||||
WorkItem workItem = {buffer, i};
|
||||
workQueue.push_back(workItem);
|
||||
}
|
||||
|
||||
pendingWorkCount = blockCount;
|
||||
}
|
||||
}
|
BIN
examples/island/resources/sansation.ttf
Normal file
11
examples/island/resources/terrain.frag
Normal file
|
@ -0,0 +1,11 @@
|
|||
varying vec3 normal;
|
||||
uniform float lightFactor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightPosition = vec3(-1.0, 1.0, 1.0);
|
||||
vec3 eyePosition = vec3(0.0, 0.0, 1.0);
|
||||
vec3 halfVector = normalize(lightPosition + eyePosition);
|
||||
float intensity = lightFactor + (1.0 - lightFactor) * dot(normalize(normal), normalize(halfVector));
|
||||
gl_FragColor = gl_Color * vec4(intensity, intensity, intensity, 1.0);
|
||||
}
|
8
examples/island/resources/terrain.vert
Normal file
|
@ -0,0 +1,8 @@
|
|||
varying vec3 normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
gl_FrontColor = gl_Color;
|
||||
normal = vec3(gl_MultiTexCoord0.xy, 1.0);
|
||||
}
|
316
examples/island/stb_perlin.h
Normal file
|
@ -0,0 +1,316 @@
|
|||
// stb_perlin.h - v0.3 - perlin noise
|
||||
// public domain single-file C implementation by Sean Barrett
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file.
|
||||
//
|
||||
//
|
||||
// to create the implementation,
|
||||
// #define STB_PERLIN_IMPLEMENTATION
|
||||
// in *one* C/CPP file that includes this file.
|
||||
//
|
||||
//
|
||||
// Documentation:
|
||||
//
|
||||
// float stb_perlin_noise3( float x,
|
||||
// float y,
|
||||
// float z,
|
||||
// int x_wrap=0,
|
||||
// int y_wrap=0,
|
||||
// int z_wrap=0)
|
||||
//
|
||||
// This function computes a random value at the coordinate (x,y,z).
|
||||
// Adjacent random values are continuous but the noise fluctuates
|
||||
// its randomness with period 1, i.e. takes on wholly unrelated values
|
||||
// at integer points. Specifically, this implements Ken Perlin's
|
||||
// revised noise function from 2002.
|
||||
//
|
||||
// The "wrap" parameters can be used to create wraparound noise that
|
||||
// wraps at powers of two. The numbers MUST be powers of two. Specify
|
||||
// 0 to mean "don't care". (The noise always wraps every 256 due
|
||||
// details of the implementation, even if you ask for larger or no
|
||||
// wrapping.)
|
||||
//
|
||||
// Fractal Noise:
|
||||
//
|
||||
// Three common fractal noise functions are included, which produce
|
||||
// a wide variety of nice effects depending on the parameters
|
||||
// provided. Note that each function will call stb_perlin_noise3
|
||||
// 'octaves' times, so this parameter will affect runtime.
|
||||
//
|
||||
// float stb_perlin_ridge_noise3(float x, float y, float z,
|
||||
// float lacunarity, float gain, float offset, int octaves,
|
||||
// int x_wrap, int y_wrap, int z_wrap);
|
||||
//
|
||||
// float stb_perlin_fbm_noise3(float x, float y, float z,
|
||||
// float lacunarity, float gain, int octaves,
|
||||
// int x_wrap, int y_wrap, int z_wrap);
|
||||
//
|
||||
// float stb_perlin_turbulence_noise3(float x, float y, float z,
|
||||
// float lacunarity, float gain,int octaves,
|
||||
// int x_wrap, int y_wrap, int z_wrap);
|
||||
//
|
||||
// Typical values to start playing with:
|
||||
// octaves = 6 -- number of "octaves" of noise3() to sum
|
||||
// lacunarity = ~ 2.0 -- spacing between successive octaves (use exactly 2.0 for wrapping output)
|
||||
// gain = 0.5 -- relative weighting applied to each successive octave
|
||||
// offset = 1.0? -- used to invert the ridges, may need to be larger, not sure
|
||||
//
|
||||
//
|
||||
// Contributors:
|
||||
// Jack Mott - additional noise functions
|
||||
//
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap);
|
||||
extern float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float gain, float offset, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
||||
extern float stb_perlin_fbm_noise3(float x, float y, float z,float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
||||
extern float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef STB_PERLIN_IMPLEMENTATION
|
||||
|
||||
// not same permutation table as Perlin's reference to avoid copyright issues;
|
||||
// Perlin's table can be found at http://mrl.nyu.edu/~perlin/noise/
|
||||
// @OPTIMIZE: should this be unsigned char instead of int for cache?
|
||||
static unsigned char stb__perlin_randtab[512] =
|
||||
{
|
||||
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
||||
152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72,
|
||||
175, 63, 77, 90, 181, 16, 96, 111, 133, 104, 75, 162, 93, 56, 66, 240,
|
||||
8, 50, 84, 229, 49, 210, 173, 239, 141, 1, 87, 18, 2, 198, 143, 57,
|
||||
225, 160, 58, 217, 168, 206, 245, 204, 199, 6, 73, 60, 20, 230, 211, 233,
|
||||
94, 200, 88, 9, 74, 155, 33, 15, 219, 130, 226, 202, 83, 236, 42, 172,
|
||||
165, 218, 55, 222, 46, 107, 98, 154, 109, 67, 196, 178, 127, 158, 13, 243,
|
||||
65, 79, 166, 248, 25, 224, 115, 80, 68, 51, 184, 128, 232, 208, 151, 122,
|
||||
26, 212, 105, 43, 179, 213, 235, 148, 146, 89, 14, 195, 28, 78, 112, 76,
|
||||
250, 47, 24, 251, 140, 108, 186, 190, 228, 170, 183, 139, 39, 188, 244, 246,
|
||||
132, 48, 119, 144, 180, 138, 134, 193, 82, 182, 120, 121, 86, 220, 209, 3,
|
||||
91, 241, 149, 85, 205, 150, 113, 216, 31, 100, 41, 164, 177, 214, 153, 231,
|
||||
38, 71, 185, 174, 97, 201, 29, 95, 7, 92, 54, 254, 191, 118, 34, 221,
|
||||
131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62,
|
||||
27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135,
|
||||
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
||||
|
||||
// and a second copy so we don't need an extra mask or static initializer
|
||||
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
||||
152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72,
|
||||
175, 63, 77, 90, 181, 16, 96, 111, 133, 104, 75, 162, 93, 56, 66, 240,
|
||||
8, 50, 84, 229, 49, 210, 173, 239, 141, 1, 87, 18, 2, 198, 143, 57,
|
||||
225, 160, 58, 217, 168, 206, 245, 204, 199, 6, 73, 60, 20, 230, 211, 233,
|
||||
94, 200, 88, 9, 74, 155, 33, 15, 219, 130, 226, 202, 83, 236, 42, 172,
|
||||
165, 218, 55, 222, 46, 107, 98, 154, 109, 67, 196, 178, 127, 158, 13, 243,
|
||||
65, 79, 166, 248, 25, 224, 115, 80, 68, 51, 184, 128, 232, 208, 151, 122,
|
||||
26, 212, 105, 43, 179, 213, 235, 148, 146, 89, 14, 195, 28, 78, 112, 76,
|
||||
250, 47, 24, 251, 140, 108, 186, 190, 228, 170, 183, 139, 39, 188, 244, 246,
|
||||
132, 48, 119, 144, 180, 138, 134, 193, 82, 182, 120, 121, 86, 220, 209, 3,
|
||||
91, 241, 149, 85, 205, 150, 113, 216, 31, 100, 41, 164, 177, 214, 153, 231,
|
||||
38, 71, 185, 174, 97, 201, 29, 95, 7, 92, 54, 254, 191, 118, 34, 221,
|
||||
131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62,
|
||||
27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135,
|
||||
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
||||
};
|
||||
|
||||
static float stb__perlin_lerp(float a, float b, float t)
|
||||
{
|
||||
return a + (b-a) * t;
|
||||
}
|
||||
|
||||
static int stb__perlin_fastfloor(float a)
|
||||
{
|
||||
int ai = (int) a;
|
||||
return (a < ai) ? ai-1 : ai;
|
||||
}
|
||||
|
||||
// different grad function from Perlin's, but easy to modify to match reference
|
||||
static float stb__perlin_grad(int hash, float x, float y, float z)
|
||||
{
|
||||
static float basis[12][4] =
|
||||
{
|
||||
{ 1, 1, 0 },
|
||||
{ -1, 1, 0 },
|
||||
{ 1,-1, 0 },
|
||||
{ -1,-1, 0 },
|
||||
{ 1, 0, 1 },
|
||||
{ -1, 0, 1 },
|
||||
{ 1, 0,-1 },
|
||||
{ -1, 0,-1 },
|
||||
{ 0, 1, 1 },
|
||||
{ 0,-1, 1 },
|
||||
{ 0, 1,-1 },
|
||||
{ 0,-1,-1 },
|
||||
};
|
||||
|
||||
// perlin's gradient has 12 cases so some get used 1/16th of the time
|
||||
// and some 2/16ths. We reduce bias by changing those fractions
|
||||
// to 5/64ths and 6/64ths, and the same 4 cases get the extra weight.
|
||||
static unsigned char indices[64] =
|
||||
{
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
0,9,1,11,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
};
|
||||
|
||||
// if you use reference permutation table, change 63 below to 15 to match reference
|
||||
// (this is why the ordering of the table above is funky)
|
||||
float *grad = basis[indices[hash & 63]];
|
||||
return grad[0]*x + grad[1]*y + grad[2]*z;
|
||||
}
|
||||
|
||||
float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap)
|
||||
{
|
||||
float u,v,w;
|
||||
float n000,n001,n010,n011,n100,n101,n110,n111;
|
||||
float n00,n01,n10,n11;
|
||||
float n0,n1;
|
||||
|
||||
unsigned int x_mask = (x_wrap-1) & 255;
|
||||
unsigned int y_mask = (y_wrap-1) & 255;
|
||||
unsigned int z_mask = (z_wrap-1) & 255;
|
||||
int px = stb__perlin_fastfloor(x);
|
||||
int py = stb__perlin_fastfloor(y);
|
||||
int pz = stb__perlin_fastfloor(z);
|
||||
int x0 = px & x_mask, x1 = (px+1) & x_mask;
|
||||
int y0 = py & y_mask, y1 = (py+1) & y_mask;
|
||||
int z0 = pz & z_mask, z1 = (pz+1) & z_mask;
|
||||
int r0,r1, r00,r01,r10,r11;
|
||||
|
||||
#define stb__perlin_ease(a) (((a*6-15)*a + 10) * a * a * a)
|
||||
|
||||
x -= px; u = stb__perlin_ease(x);
|
||||
y -= py; v = stb__perlin_ease(y);
|
||||
z -= pz; w = stb__perlin_ease(z);
|
||||
|
||||
r0 = stb__perlin_randtab[x0];
|
||||
r1 = stb__perlin_randtab[x1];
|
||||
|
||||
r00 = stb__perlin_randtab[r0+y0];
|
||||
r01 = stb__perlin_randtab[r0+y1];
|
||||
r10 = stb__perlin_randtab[r1+y0];
|
||||
r11 = stb__perlin_randtab[r1+y1];
|
||||
|
||||
n000 = stb__perlin_grad(stb__perlin_randtab[r00+z0], x , y , z );
|
||||
n001 = stb__perlin_grad(stb__perlin_randtab[r00+z1], x , y , z-1 );
|
||||
n010 = stb__perlin_grad(stb__perlin_randtab[r01+z0], x , y-1, z );
|
||||
n011 = stb__perlin_grad(stb__perlin_randtab[r01+z1], x , y-1, z-1 );
|
||||
n100 = stb__perlin_grad(stb__perlin_randtab[r10+z0], x-1, y , z );
|
||||
n101 = stb__perlin_grad(stb__perlin_randtab[r10+z1], x-1, y , z-1 );
|
||||
n110 = stb__perlin_grad(stb__perlin_randtab[r11+z0], x-1, y-1, z );
|
||||
n111 = stb__perlin_grad(stb__perlin_randtab[r11+z1], x-1, y-1, z-1 );
|
||||
|
||||
n00 = stb__perlin_lerp(n000,n001,w);
|
||||
n01 = stb__perlin_lerp(n010,n011,w);
|
||||
n10 = stb__perlin_lerp(n100,n101,w);
|
||||
n11 = stb__perlin_lerp(n110,n111,w);
|
||||
|
||||
n0 = stb__perlin_lerp(n00,n01,v);
|
||||
n1 = stb__perlin_lerp(n10,n11,v);
|
||||
|
||||
return stb__perlin_lerp(n0,n1,u);
|
||||
}
|
||||
|
||||
float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float gain, float offset, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
||||
{
|
||||
int i;
|
||||
float frequency = 1.0f;
|
||||
float prev = 1.0f;
|
||||
float amplitude = 0.5f;
|
||||
float sum = 0.0f;
|
||||
|
||||
for (i = 0; i < octaves; i++) {
|
||||
float r = (float)(stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap));
|
||||
r = r<0 ? -r : r; // fabs()
|
||||
r = offset - r;
|
||||
r = r*r;
|
||||
sum += r*amplitude*prev;
|
||||
prev = r;
|
||||
frequency *= lacunarity;
|
||||
amplitude *= gain;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
float stb_perlin_fbm_noise3(float x, float y, float z,float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
||||
{
|
||||
int i;
|
||||
float frequency = 1.0f;
|
||||
float amplitude = 1.0f;
|
||||
float sum = 0.0f;
|
||||
|
||||
for (i = 0; i < octaves; i++) {
|
||||
sum += stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap)*amplitude;
|
||||
frequency *= lacunarity;
|
||||
amplitude *= gain;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
||||
{
|
||||
int i;
|
||||
float frequency = 1.0f;
|
||||
float amplitude = 1.0f;
|
||||
float sum = 0.0f;
|
||||
|
||||
for (i = 0; i < octaves; i++) {
|
||||
float r = stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap)*amplitude;
|
||||
r = r<0 ? -r : r; // fabs()
|
||||
sum += r;
|
||||
frequency *= lacunarity;
|
||||
amplitude *= gain;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
#endif // STB_PERLIN_IMPLEMENTATION
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
11
examples/joystick/CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/joystick)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/Joystick.cpp)
|
||||
|
||||
# define the joystick target
|
||||
sfml_add_example(joystick GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-graphics
|
||||
RESOURCES_DIR resources)
|
238
examples/joystick/Joystick.cpp
Normal file
|
@ -0,0 +1,238 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
struct JoystickObject
|
||||
{
|
||||
sf::Text label;
|
||||
sf::Text value;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, JoystickObject> Texts;
|
||||
Texts texts;
|
||||
std::ostringstream sstr;
|
||||
float threshold = 0.1f;
|
||||
|
||||
// Axes labels in as C strings
|
||||
const char* axislabels[] = {"X", "Y", "Z", "R", "U", "V", "PovX", "PovY"};
|
||||
|
||||
// Helper to set text entries to a specified value
|
||||
template<typename T>
|
||||
void set(const char* label, const T& value)
|
||||
{
|
||||
sstr.str("");
|
||||
sstr << value;
|
||||
texts[label].value.setString(sstr.str());
|
||||
}
|
||||
|
||||
// Update joystick identification
|
||||
void updateIdentification(unsigned int index)
|
||||
{
|
||||
sstr.str("");
|
||||
sstr << "Joystick " << index << ":";
|
||||
texts["ID"].label.setString(sstr.str());
|
||||
texts["ID"].value.setString(sf::Joystick::getIdentification(index).name);
|
||||
}
|
||||
|
||||
// Update joystick axes
|
||||
void updateAxes(unsigned int index)
|
||||
{
|
||||
for (unsigned int j = 0; j < sf::Joystick::AxisCount; ++j)
|
||||
{
|
||||
if (sf::Joystick::hasAxis(index, static_cast<sf::Joystick::Axis>(j)))
|
||||
set(axislabels[j], sf::Joystick::getAxisPosition(index, static_cast<sf::Joystick::Axis>(j)));
|
||||
}
|
||||
}
|
||||
|
||||
// Update joystick buttons
|
||||
void updateButtons(unsigned int index)
|
||||
{
|
||||
for (unsigned int j = 0; j < sf::Joystick::getButtonCount(index); ++j)
|
||||
{
|
||||
sstr.str("");
|
||||
sstr << "Button " << j;
|
||||
|
||||
set(sstr.str().c_str(), sf::Joystick::isButtonPressed(index, j));
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to update displayed joystick values
|
||||
void updateValues(unsigned int index)
|
||||
{
|
||||
if (sf::Joystick::isConnected(index)) {
|
||||
// Update the label-value sf::Text objects based on the current joystick state
|
||||
updateIdentification(index);
|
||||
updateAxes(index);
|
||||
updateButtons(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Create the window of the application
|
||||
sf::RenderWindow window(sf::VideoMode(400, 680), "Joystick", sf::Style::Close);
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
// Load the text font
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Set up our string conversion parameters
|
||||
sstr.precision(2);
|
||||
sstr.setf(std::ios::fixed | std::ios::boolalpha);
|
||||
|
||||
// Set up our joystick identification sf::Text objects
|
||||
texts["ID"].label.setPosition(5.f, 5.f);
|
||||
texts["ID"].value.setPosition(80.f, 5.f);
|
||||
|
||||
texts["ID"].label.setString("<Not Connected>");
|
||||
texts["ID"].value.setString("");
|
||||
|
||||
// Set up our threshold sf::Text objects
|
||||
sstr.str("");
|
||||
sstr << threshold << " (Change with up/down arrow keys)";
|
||||
|
||||
texts["Threshold"].label.setPosition(5.f, 5.f + 2 * font.getLineSpacing(14));
|
||||
texts["Threshold"].value.setPosition(80.f, 5.f + 2 * font.getLineSpacing(14));
|
||||
|
||||
texts["Threshold"].label.setString("Threshold:");
|
||||
texts["Threshold"].value.setString(sstr.str());
|
||||
|
||||
// Set up our label-value sf::Text objects
|
||||
for (unsigned int i = 0; i < sf::Joystick::AxisCount; ++i)
|
||||
{
|
||||
JoystickObject& object = texts[axislabels[i]];
|
||||
|
||||
object.label.setPosition(5.f, 5.f + ((i + 4) * font.getLineSpacing(14)));
|
||||
object.label.setString(std::string(axislabels[i]) + ":");
|
||||
|
||||
object.value.setPosition(80.f, 5.f + ((i + 4) * font.getLineSpacing(14)));
|
||||
object.value.setString("N/A");
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < sf::Joystick::ButtonCount; ++i)
|
||||
{
|
||||
sstr.str("");
|
||||
sstr << "Button " << i;
|
||||
JoystickObject& object = texts[sstr.str()];
|
||||
|
||||
object.label.setPosition(5.f, 5.f + ((sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14)));
|
||||
object.label.setString(sstr.str() + ":");
|
||||
|
||||
object.value.setPosition(80.f, 5.f + ((sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14)));
|
||||
object.value.setString("N/A");
|
||||
}
|
||||
|
||||
for (Texts::iterator it = texts.begin(); it != texts.end(); ++it)
|
||||
{
|
||||
it->second.label.setFont(font);
|
||||
it->second.label.setCharacterSize(14);
|
||||
it->second.label.setFillColor(sf::Color::White);
|
||||
|
||||
it->second.value.setFont(font);
|
||||
it->second.value.setCharacterSize(14);
|
||||
it->second.value.setFillColor(sf::Color::White);
|
||||
}
|
||||
|
||||
// Update initially displayed joystick values if a joystick is already connected on startup
|
||||
for (unsigned int i = 0; i < sf::Joystick::Count; ++i)
|
||||
{
|
||||
if (sf::Joystick::isConnected(i))
|
||||
{
|
||||
updateValues(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
// Handle events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
// Window closed or escape key pressed: exit
|
||||
if ((event.type == sf::Event::Closed) ||
|
||||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
|
||||
{
|
||||
window.close();
|
||||
break;
|
||||
}
|
||||
else if ((event.type == sf::Event::JoystickButtonPressed) ||
|
||||
(event.type == sf::Event::JoystickButtonReleased) ||
|
||||
(event.type == sf::Event::JoystickMoved) ||
|
||||
(event.type == sf::Event::JoystickConnected))
|
||||
{
|
||||
// Update displayed joystick values
|
||||
updateValues(event.joystickConnect.joystickId);
|
||||
}
|
||||
else if (event.type == sf::Event::JoystickDisconnected)
|
||||
{
|
||||
// Reset displayed joystick values to empty
|
||||
for (Texts::iterator it = texts.begin(); it != texts.end(); ++it)
|
||||
it->second.value.setString("N/A");
|
||||
|
||||
texts["ID"].label.setString("<Not Connected>");
|
||||
texts["ID"].value.setString("");
|
||||
|
||||
sstr.str("");
|
||||
sstr << threshold << " (Change with up/down arrow keys)";
|
||||
|
||||
texts["Threshold"].value.setString(sstr.str());
|
||||
}
|
||||
}
|
||||
|
||||
// Update threshold if the user wants to change it
|
||||
float newThreshold = threshold;
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||
newThreshold += 0.1f;
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||
newThreshold -= 0.1f;
|
||||
|
||||
newThreshold = std::min(std::max(newThreshold, 0.1f), 100.0f);
|
||||
|
||||
if (newThreshold != threshold)
|
||||
{
|
||||
threshold = newThreshold;
|
||||
window.setJoystickThreshold(threshold);
|
||||
|
||||
sstr.str("");
|
||||
sstr << threshold << " (Change with up/down arrow keys)";
|
||||
|
||||
texts["Threshold"].value.setString(sstr.str());
|
||||
}
|
||||
|
||||
// Clear the window
|
||||
window.clear();
|
||||
|
||||
// Draw the label-value sf::Text objects
|
||||
for (Texts::const_iterator it = texts.begin(); it != texts.end(); ++it)
|
||||
{
|
||||
window.draw(it->second.label);
|
||||
window.draw(it->second.value);
|
||||
}
|
||||
|
||||
// Display things on screen
|
||||
window.display();
|
||||
}
|
||||
}
|
BIN
examples/joystick/resources/sansation.ttf
Normal file
|
@ -1,14 +1,20 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/opengl)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/OpenGL.cpp)
|
||||
|
||||
# find OpenGL and GLU
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
|
||||
# define the opengl target
|
||||
sfml_add_example(opengl GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-graphics sfml-window sfml-system ${OPENGL_LIBRARIES})
|
||||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/opengl)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/OpenGL.cpp)
|
||||
|
||||
if (SFML_OS_IOS)
|
||||
set(RESOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resources/background.jpg
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resources/texture.jpg
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resources/sansation.ttf)
|
||||
set_source_files_properties(${RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
|
||||
endif()
|
||||
|
||||
# define the opengl target
|
||||
sfml_add_example(opengl GUI_APP
|
||||
SOURCES ${SRC}
|
||||
BUNDLE_RESOURCES ${RESOURCES}
|
||||
DEPENDS sfml-graphics
|
||||
RESOURCES_DIR resources)
|
||||
|
|
|
@ -1,194 +1,310 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Request a 32-bits depth buffer when creating the window
|
||||
sf::ContextSettings contextSettings;
|
||||
contextSettings.depthBits = 32;
|
||||
|
||||
// Create the main window
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings);
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
// Make it the active window for OpenGL calls
|
||||
window.setActive();
|
||||
|
||||
// Create a sprite for the background
|
||||
sf::Texture backgroundTexture;
|
||||
if (!backgroundTexture.loadFromFile("resources/background.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sprite background(backgroundTexture);
|
||||
|
||||
// Create some text to draw on top of our OpenGL object
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Text text("SFML / OpenGL demo", font);
|
||||
text.setColor(sf::Color(255, 255, 255, 170));
|
||||
text.setPosition(250.f, 450.f);
|
||||
|
||||
// Load an OpenGL texture.
|
||||
// We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function),
|
||||
// but here we want more control on it (generate mipmaps, ...) so we create a new one from an image
|
||||
GLuint texture = 0;
|
||||
{
|
||||
sf::Image image;
|
||||
if (!image.loadFromFile("resources/texture.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
glClearDepth(1.f);
|
||||
|
||||
// Disable lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
// Configure the viewport (the same size as the window)
|
||||
glViewport(0, 0, window.getSize().x, window.getSize().y);
|
||||
|
||||
// Setup a perspective projection
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
|
||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
|
||||
// Bind the texture
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
||||
GLfloat cube[] =
|
||||
{
|
||||
// positions // texture coordinates
|
||||
-20, -20, -20, 0, 0,
|
||||
-20, 20, -20, 1, 0,
|
||||
-20, -20, 20, 0, 1,
|
||||
-20, -20, 20, 0, 1,
|
||||
-20, 20, -20, 1, 0,
|
||||
-20, 20, 20, 1, 1,
|
||||
|
||||
20, -20, -20, 0, 0,
|
||||
20, 20, -20, 1, 0,
|
||||
20, -20, 20, 0, 1,
|
||||
20, -20, 20, 0, 1,
|
||||
20, 20, -20, 1, 0,
|
||||
20, 20, 20, 1, 1,
|
||||
|
||||
-20, -20, -20, 0, 0,
|
||||
20, -20, -20, 1, 0,
|
||||
-20, -20, 20, 0, 1,
|
||||
-20, -20, 20, 0, 1,
|
||||
20, -20, -20, 1, 0,
|
||||
20, -20, 20, 1, 1,
|
||||
|
||||
-20, 20, -20, 0, 0,
|
||||
20, 20, -20, 1, 0,
|
||||
-20, 20, 20, 0, 1,
|
||||
-20, 20, 20, 0, 1,
|
||||
20, 20, -20, 1, 0,
|
||||
20, 20, 20, 1, 1,
|
||||
|
||||
-20, -20, -20, 0, 0,
|
||||
20, -20, -20, 1, 0,
|
||||
-20, 20, -20, 0, 1,
|
||||
-20, 20, -20, 0, 1,
|
||||
20, -20, -20, 1, 0,
|
||||
20, 20, -20, 1, 1,
|
||||
|
||||
-20, -20, 20, 0, 0,
|
||||
20, -20, 20, 1, 0,
|
||||
-20, 20, 20, 0, 1,
|
||||
-20, 20, 20, 0, 1,
|
||||
20, -20, 20, 1, 0,
|
||||
20, 20, 20, 1, 1
|
||||
};
|
||||
|
||||
// Enable position and texture coordinates vertex components
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), cube);
|
||||
glTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), cube + 3);
|
||||
|
||||
// Disable normal and color vertex components
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
// Create a clock for measuring the time elapsed
|
||||
sf::Clock clock;
|
||||
|
||||
// Start game loop
|
||||
while (window.isOpen())
|
||||
{
|
||||
// Process events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
// Close window : exit
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
|
||||
// Escape key : exit
|
||||
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
|
||||
window.close();
|
||||
|
||||
// Adjust the viewport when the window is resized
|
||||
if (event.type == sf::Event::Resized)
|
||||
glViewport(0, 0, event.size.width, event.size.height);
|
||||
}
|
||||
|
||||
// Draw the background
|
||||
window.pushGLStates();
|
||||
window.draw(background);
|
||||
window.popGLStates();
|
||||
|
||||
// Clear the depth buffer
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// We get the position of the mouse cursor, so that we can move the box accordingly
|
||||
float x = sf::Mouse::getPosition(window).x * 200.f / window.getSize().x - 100.f;
|
||||
float y = -sf::Mouse::getPosition(window).y * 200.f / window.getSize().y + 100.f;
|
||||
|
||||
// Apply some transformations
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(x, y, -100.f);
|
||||
glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
|
||||
glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
|
||||
glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);
|
||||
|
||||
// Draw the cube
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
|
||||
// Draw some text on top of our OpenGL object
|
||||
window.pushGLStates();
|
||||
window.draw(text);
|
||||
window.popGLStates();
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
window.display();
|
||||
}
|
||||
|
||||
// Don't forget to destroy our texture
|
||||
glDeleteTextures(1, &texture);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "gl.h"
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
#include <SFML/Main.hpp>
|
||||
#endif
|
||||
|
||||
#ifndef GL_SRGB8_ALPHA8
|
||||
#define GL_SRGB8_ALPHA8 0x8C43
|
||||
#endif
|
||||
|
||||
std::string resourcesDir()
|
||||
{
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
return "";
|
||||
#else
|
||||
return "resources/";
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
bool exit = false;
|
||||
bool sRgb = false;
|
||||
|
||||
while (!exit)
|
||||
{
|
||||
// Request a 24-bits depth buffer when creating the window
|
||||
sf::ContextSettings contextSettings;
|
||||
contextSettings.depthBits = 24;
|
||||
contextSettings.sRgbCapable = sRgb;
|
||||
|
||||
// Create the main window
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings);
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
// Create a sprite for the background
|
||||
sf::Texture backgroundTexture;
|
||||
backgroundTexture.setSrgb(sRgb);
|
||||
if (!backgroundTexture.loadFromFile(resourcesDir() + "background.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sprite background(backgroundTexture);
|
||||
|
||||
// Create some text to draw on top of our OpenGL object
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile(resourcesDir() + "sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Text text("SFML / OpenGL demo", font);
|
||||
sf::Text sRgbInstructions("Press space to toggle sRGB conversion", font);
|
||||
sf::Text mipmapInstructions("Press return to toggle mipmapping", font);
|
||||
text.setFillColor(sf::Color(255, 255, 255, 170));
|
||||
sRgbInstructions.setFillColor(sf::Color(255, 255, 255, 170));
|
||||
mipmapInstructions.setFillColor(sf::Color(255, 255, 255, 170));
|
||||
text.setPosition(250.f, 450.f);
|
||||
sRgbInstructions.setPosition(150.f, 500.f);
|
||||
mipmapInstructions.setPosition(180.f, 550.f);
|
||||
|
||||
// Load a texture to apply to our 3D cube
|
||||
sf::Texture texture;
|
||||
if (!texture.loadFromFile(resourcesDir() + "texture.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Attempt to generate a mipmap for our cube texture
|
||||
// We don't check the return value here since
|
||||
// mipmapping is purely optional in this example
|
||||
texture.generateMipmap();
|
||||
|
||||
// Make the window the active window for OpenGL calls
|
||||
window.setActive(true);
|
||||
|
||||
// Load OpenGL or OpenGL ES entry points using glad
|
||||
#ifdef SFML_OPENGL_ES
|
||||
gladLoadGLES1(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#else
|
||||
gladLoadGL(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#endif
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glClearDepthf(1.f);
|
||||
#else
|
||||
glClearDepth(1.f);
|
||||
#endif
|
||||
|
||||
// Disable lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
// Configure the viewport (the same size as the window)
|
||||
glViewport(0, 0, window.getSize().x, window.getSize().y);
|
||||
|
||||
// Setup a perspective projection
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#else
|
||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#endif
|
||||
|
||||
// Bind the texture
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
sf::Texture::bind(&texture);
|
||||
|
||||
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
||||
static const GLfloat cube[] =
|
||||
{
|
||||
// positions // texture coordinates
|
||||
-20, -20, -20, 0, 0,
|
||||
-20, 20, -20, 1, 0,
|
||||
-20, -20, 20, 0, 1,
|
||||
-20, -20, 20, 0, 1,
|
||||
-20, 20, -20, 1, 0,
|
||||
-20, 20, 20, 1, 1,
|
||||
|
||||
20, -20, -20, 0, 0,
|
||||
20, 20, -20, 1, 0,
|
||||
20, -20, 20, 0, 1,
|
||||
20, -20, 20, 0, 1,
|
||||
20, 20, -20, 1, 0,
|
||||
20, 20, 20, 1, 1,
|
||||
|
||||
-20, -20, -20, 0, 0,
|
||||
20, -20, -20, 1, 0,
|
||||
-20, -20, 20, 0, 1,
|
||||
-20, -20, 20, 0, 1,
|
||||
20, -20, -20, 1, 0,
|
||||
20, -20, 20, 1, 1,
|
||||
|
||||
-20, 20, -20, 0, 0,
|
||||
20, 20, -20, 1, 0,
|
||||
-20, 20, 20, 0, 1,
|
||||
-20, 20, 20, 0, 1,
|
||||
20, 20, -20, 1, 0,
|
||||
20, 20, 20, 1, 1,
|
||||
|
||||
-20, -20, -20, 0, 0,
|
||||
20, -20, -20, 1, 0,
|
||||
-20, 20, -20, 0, 1,
|
||||
-20, 20, -20, 0, 1,
|
||||
20, -20, -20, 1, 0,
|
||||
20, 20, -20, 1, 1,
|
||||
|
||||
-20, -20, 20, 0, 0,
|
||||
20, -20, 20, 1, 0,
|
||||
-20, 20, 20, 0, 1,
|
||||
-20, 20, 20, 0, 1,
|
||||
20, -20, 20, 1, 0,
|
||||
20, 20, 20, 1, 1
|
||||
};
|
||||
|
||||
// Enable position and texture coordinates vertex components
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), cube);
|
||||
glTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), cube + 3);
|
||||
|
||||
// Disable normal and color vertex components
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
// Make the window no longer the active window for OpenGL calls
|
||||
window.setActive(false);
|
||||
|
||||
// Create a clock for measuring the time elapsed
|
||||
sf::Clock clock;
|
||||
|
||||
// Flag to track whether mipmapping is currently enabled
|
||||
bool mipmapEnabled = true;
|
||||
|
||||
// Start game loop
|
||||
while (window.isOpen())
|
||||
{
|
||||
// Process events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
// Close window: exit
|
||||
if (event.type == sf::Event::Closed)
|
||||
{
|
||||
exit = true;
|
||||
window.close();
|
||||
}
|
||||
|
||||
// Escape key: exit
|
||||
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
|
||||
{
|
||||
exit = true;
|
||||
window.close();
|
||||
}
|
||||
|
||||
// Return key: toggle mipmapping
|
||||
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Enter))
|
||||
{
|
||||
if (mipmapEnabled)
|
||||
{
|
||||
// We simply reload the texture to disable mipmapping
|
||||
if (!texture.loadFromFile(resourcesDir() + "texture.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
mipmapEnabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
texture.generateMipmap();
|
||||
|
||||
mipmapEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Space key: toggle sRGB conversion
|
||||
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
|
||||
{
|
||||
sRgb = !sRgb;
|
||||
window.close();
|
||||
}
|
||||
|
||||
// Adjust the viewport when the window is resized
|
||||
if (event.type == sf::Event::Resized)
|
||||
{
|
||||
sf::Vector2u textureSize = backgroundTexture.getSize();
|
||||
|
||||
// Make the window the active window for OpenGL calls
|
||||
window.setActive(true);
|
||||
|
||||
glViewport(0, 0, event.size.width, event.size.height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
GLfloat ratio = static_cast<float>(event.size.width) / event.size.height;
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#else
|
||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#endif
|
||||
|
||||
// Make the window no longer the active window for OpenGL calls
|
||||
window.setActive(false);
|
||||
|
||||
sf::View view;
|
||||
view.setSize(textureSize.x, textureSize.y);
|
||||
view.setCenter(textureSize.x/2.f, textureSize.y/2.f);
|
||||
window.setView(view);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the background
|
||||
window.pushGLStates();
|
||||
window.draw(background);
|
||||
window.popGLStates();
|
||||
|
||||
// Make the window the active window for OpenGL calls
|
||||
window.setActive(true);
|
||||
|
||||
// Clear the depth buffer
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// We get the position of the mouse cursor (or touch), so that we can move the box accordingly
|
||||
sf::Vector2i pos;
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
pos = sf::Touch::getPosition(0);
|
||||
#else
|
||||
pos = sf::Mouse::getPosition();
|
||||
#endif
|
||||
|
||||
float x = pos.x * 200.f / window.getSize().x - 100.f;
|
||||
float y = -pos.y * 200.f / window.getSize().y + 100.f;
|
||||
|
||||
// Apply some transformations
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(x, y, -100.f);
|
||||
glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
|
||||
glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
|
||||
glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);
|
||||
|
||||
// Draw the cube
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
|
||||
// Make the window no longer the active window for OpenGL calls
|
||||
window.setActive(false);
|
||||
|
||||
// Draw some text on top of our OpenGL object
|
||||
window.pushGLStates();
|
||||
window.draw(text);
|
||||
window.draw(sRgbInstructions);
|
||||
window.draw(mipmapInstructions);
|
||||
window.popGLStates();
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
window.display();
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
7837
examples/opengl/gl.h
Normal file
|
@ -1,10 +1,18 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/pong)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/Pong.cpp)
|
||||
|
||||
# define the pong target
|
||||
sfml_add_example(pong GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-audio sfml-graphics sfml-window sfml-system)
|
||||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/pong)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/Pong.cpp)
|
||||
if (SFML_OS_IOS)
|
||||
set(RESOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resources/ball.wav
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resources/sansation.ttf)
|
||||
set_source_files_properties(${RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
|
||||
endif()
|
||||
|
||||
# define the pong target
|
||||
sfml_add_example(pong GUI_APP
|
||||
SOURCES ${SRC}
|
||||
BUNDLE_RESOURCES ${RESOURCES}
|
||||
DEPENDS sfml-audio sfml-graphics
|
||||
RESOURCES_DIR resources)
|
||||
|
|
|
@ -1,241 +1,282 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
std::srand(static_cast<unsigned int>(std::time(NULL)));
|
||||
|
||||
// Define some constants
|
||||
const float pi = 3.14159f;
|
||||
const int gameWidth = 800;
|
||||
const int gameHeight = 600;
|
||||
sf::Vector2f paddleSize(25, 100);
|
||||
float ballRadius = 10.f;
|
||||
|
||||
// Create the window of the application
|
||||
sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong");
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
// Load the sounds used in the game
|
||||
sf::SoundBuffer ballSoundBuffer;
|
||||
if (!ballSoundBuffer.loadFromFile("resources/ball.wav"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sound ballSound(ballSoundBuffer);
|
||||
|
||||
// Create the left paddle
|
||||
sf::RectangleShape leftPaddle;
|
||||
leftPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
|
||||
leftPaddle.setOutlineThickness(3);
|
||||
leftPaddle.setOutlineColor(sf::Color::Black);
|
||||
leftPaddle.setFillColor(sf::Color(100, 100, 200));
|
||||
leftPaddle.setOrigin(paddleSize / 2.f);
|
||||
|
||||
// Create the right paddle
|
||||
sf::RectangleShape rightPaddle;
|
||||
rightPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
|
||||
rightPaddle.setOutlineThickness(3);
|
||||
rightPaddle.setOutlineColor(sf::Color::Black);
|
||||
rightPaddle.setFillColor(sf::Color(200, 100, 100));
|
||||
rightPaddle.setOrigin(paddleSize / 2.f);
|
||||
|
||||
// Create the ball
|
||||
sf::CircleShape ball;
|
||||
ball.setRadius(ballRadius - 3);
|
||||
ball.setOutlineThickness(3);
|
||||
ball.setOutlineColor(sf::Color::Black);
|
||||
ball.setFillColor(sf::Color::White);
|
||||
ball.setOrigin(ballRadius / 2, ballRadius / 2);
|
||||
|
||||
// Load the text font
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Initialize the pause message
|
||||
sf::Text pauseMessage;
|
||||
pauseMessage.setFont(font);
|
||||
pauseMessage.setCharacterSize(40);
|
||||
pauseMessage.setPosition(170.f, 150.f);
|
||||
pauseMessage.setColor(sf::Color::White);
|
||||
pauseMessage.setString("Welcome to SFML pong!\nPress space to start the game");
|
||||
|
||||
// Define the paddles properties
|
||||
sf::Clock AITimer;
|
||||
const sf::Time AITime = sf::seconds(0.1f);
|
||||
const float paddleSpeed = 400.f;
|
||||
float rightPaddleSpeed = 0.f;
|
||||
const float ballSpeed = 400.f;
|
||||
float ballAngle = 0.f; // to be changed later
|
||||
|
||||
sf::Clock clock;
|
||||
bool isPlaying = false;
|
||||
while (window.isOpen())
|
||||
{
|
||||
// Handle events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
// Window closed or escape key pressed: exit
|
||||
if ((event.type == sf::Event::Closed) ||
|
||||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
|
||||
{
|
||||
window.close();
|
||||
break;
|
||||
}
|
||||
|
||||
// Space key pressed: play
|
||||
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
|
||||
{
|
||||
if (!isPlaying)
|
||||
{
|
||||
// (re)start the game
|
||||
isPlaying = true;
|
||||
clock.restart();
|
||||
|
||||
// Reset the position of the paddles and ball
|
||||
leftPaddle.setPosition(10 + paddleSize.x / 2, gameHeight / 2);
|
||||
rightPaddle.setPosition(gameWidth - 10 - paddleSize.x / 2, gameHeight / 2);
|
||||
ball.setPosition(gameWidth / 2, gameHeight / 2);
|
||||
|
||||
// Reset the ball angle
|
||||
do
|
||||
{
|
||||
// Make sure the ball initial angle is not too much vertical
|
||||
ballAngle = (std::rand() % 360) * 2 * pi / 360;
|
||||
}
|
||||
while (std::abs(std::cos(ballAngle)) < 0.7f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isPlaying)
|
||||
{
|
||||
float deltaTime = clock.restart().asSeconds();
|
||||
|
||||
// Move the player's paddle
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) &&
|
||||
(leftPaddle.getPosition().y - paddleSize.y / 2 > 5.f))
|
||||
{
|
||||
leftPaddle.move(0.f, -paddleSpeed * deltaTime);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) &&
|
||||
(leftPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f))
|
||||
{
|
||||
leftPaddle.move(0.f, paddleSpeed * deltaTime);
|
||||
}
|
||||
|
||||
// Move the computer's paddle
|
||||
if (((rightPaddleSpeed < 0.f) && (rightPaddle.getPosition().y - paddleSize.y / 2 > 5.f)) ||
|
||||
((rightPaddleSpeed > 0.f) && (rightPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)))
|
||||
{
|
||||
rightPaddle.move(0.f, rightPaddleSpeed * deltaTime);
|
||||
}
|
||||
|
||||
// Update the computer's paddle direction according to the ball position
|
||||
if (AITimer.getElapsedTime() > AITime)
|
||||
{
|
||||
AITimer.restart();
|
||||
if (ball.getPosition().y + ballRadius > rightPaddle.getPosition().y + paddleSize.y / 2)
|
||||
rightPaddleSpeed = paddleSpeed;
|
||||
else if (ball.getPosition().y - ballRadius < rightPaddle.getPosition().y - paddleSize.y / 2)
|
||||
rightPaddleSpeed = -paddleSpeed;
|
||||
else
|
||||
rightPaddleSpeed = 0.f;
|
||||
}
|
||||
|
||||
// Move the ball
|
||||
float factor = ballSpeed * deltaTime;
|
||||
ball.move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
|
||||
|
||||
// Check collisions between the ball and the screen
|
||||
if (ball.getPosition().x - ballRadius < 0.f)
|
||||
{
|
||||
isPlaying = false;
|
||||
pauseMessage.setString("You lost !\nPress space to restart or\nescape to exit");
|
||||
}
|
||||
if (ball.getPosition().x + ballRadius > gameWidth)
|
||||
{
|
||||
isPlaying = false;
|
||||
pauseMessage.setString("You won !\nPress space to restart or\nescape to exit");
|
||||
}
|
||||
if (ball.getPosition().y - ballRadius < 0.f)
|
||||
{
|
||||
ballSound.play();
|
||||
ballAngle = -ballAngle;
|
||||
ball.setPosition(ball.getPosition().x, ballRadius + 0.1f);
|
||||
}
|
||||
if (ball.getPosition().y + ballRadius > gameHeight)
|
||||
{
|
||||
ballSound.play();
|
||||
ballAngle = -ballAngle;
|
||||
ball.setPosition(ball.getPosition().x, gameHeight - ballRadius - 0.1f);
|
||||
}
|
||||
|
||||
// Check the collisions between the ball and the paddles
|
||||
// Left Paddle
|
||||
if (ball.getPosition().x - ballRadius < leftPaddle.getPosition().x + paddleSize.x / 2 &&
|
||||
ball.getPosition().x - ballRadius > leftPaddle.getPosition().x &&
|
||||
ball.getPosition().y + ballRadius >= leftPaddle.getPosition().y - paddleSize.y / 2 &&
|
||||
ball.getPosition().y - ballRadius <= leftPaddle.getPosition().y + paddleSize.y / 2)
|
||||
{
|
||||
if (ball.getPosition().y > leftPaddle.getPosition().y)
|
||||
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
|
||||
else
|
||||
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
|
||||
|
||||
ballSound.play();
|
||||
ball.setPosition(leftPaddle.getPosition().x + ballRadius + paddleSize.x / 2 + 0.1f, ball.getPosition().y);
|
||||
}
|
||||
|
||||
// Right Paddle
|
||||
if (ball.getPosition().x + ballRadius > rightPaddle.getPosition().x - paddleSize.x / 2 &&
|
||||
ball.getPosition().x + ballRadius < rightPaddle.getPosition().x &&
|
||||
ball.getPosition().y + ballRadius >= rightPaddle.getPosition().y - paddleSize.y / 2 &&
|
||||
ball.getPosition().y - ballRadius <= rightPaddle.getPosition().y + paddleSize.y / 2)
|
||||
{
|
||||
if (ball.getPosition().y > rightPaddle.getPosition().y)
|
||||
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
|
||||
else
|
||||
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
|
||||
|
||||
ballSound.play();
|
||||
ball.setPosition(rightPaddle.getPosition().x - ballRadius - paddleSize.x / 2 - 0.1f, ball.getPosition().y);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the window
|
||||
window.clear(sf::Color(50, 200, 50));
|
||||
|
||||
if (isPlaying)
|
||||
{
|
||||
// Draw the paddles and the ball
|
||||
window.draw(leftPaddle);
|
||||
window.draw(rightPaddle);
|
||||
window.draw(ball);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw the pause message
|
||||
window.draw(pauseMessage);
|
||||
}
|
||||
|
||||
// Display things on screen
|
||||
window.display();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
#include <SFML/Main.hpp>
|
||||
#endif
|
||||
|
||||
std::string resourcesDir()
|
||||
{
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
return "";
|
||||
#else
|
||||
return "resources/";
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
std::srand(static_cast<unsigned int>(std::time(NULL)));
|
||||
|
||||
// Define some constants
|
||||
const float pi = 3.14159f;
|
||||
const int gameWidth = 800;
|
||||
const int gameHeight = 600;
|
||||
sf::Vector2f paddleSize(25, 100);
|
||||
float ballRadius = 10.f;
|
||||
|
||||
// Create the window of the application
|
||||
sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong",
|
||||
sf::Style::Titlebar | sf::Style::Close);
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
// Load the sounds used in the game
|
||||
sf::SoundBuffer ballSoundBuffer;
|
||||
if (!ballSoundBuffer.loadFromFile(resourcesDir() + "ball.wav"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sound ballSound(ballSoundBuffer);
|
||||
|
||||
// Create the left paddle
|
||||
sf::RectangleShape leftPaddle;
|
||||
leftPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
|
||||
leftPaddle.setOutlineThickness(3);
|
||||
leftPaddle.setOutlineColor(sf::Color::Black);
|
||||
leftPaddle.setFillColor(sf::Color(100, 100, 200));
|
||||
leftPaddle.setOrigin(paddleSize / 2.f);
|
||||
|
||||
// Create the right paddle
|
||||
sf::RectangleShape rightPaddle;
|
||||
rightPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
|
||||
rightPaddle.setOutlineThickness(3);
|
||||
rightPaddle.setOutlineColor(sf::Color::Black);
|
||||
rightPaddle.setFillColor(sf::Color(200, 100, 100));
|
||||
rightPaddle.setOrigin(paddleSize / 2.f);
|
||||
|
||||
// Create the ball
|
||||
sf::CircleShape ball;
|
||||
ball.setRadius(ballRadius - 3);
|
||||
ball.setOutlineThickness(3);
|
||||
ball.setOutlineColor(sf::Color::Black);
|
||||
ball.setFillColor(sf::Color::White);
|
||||
ball.setOrigin(ballRadius / 2, ballRadius / 2);
|
||||
|
||||
// Load the text font
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile(resourcesDir() + "sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Initialize the pause message
|
||||
sf::Text pauseMessage;
|
||||
pauseMessage.setFont(font);
|
||||
pauseMessage.setCharacterSize(40);
|
||||
pauseMessage.setPosition(170.f, 150.f);
|
||||
pauseMessage.setFillColor(sf::Color::White);
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
pauseMessage.setString("Welcome to SFML pong!\nTouch the screen to start the game");
|
||||
#else
|
||||
pauseMessage.setString("Welcome to SFML pong!\nPress space to start the game");
|
||||
#endif
|
||||
|
||||
// Define the paddles properties
|
||||
sf::Clock AITimer;
|
||||
const sf::Time AITime = sf::seconds(0.1f);
|
||||
const float paddleSpeed = 400.f;
|
||||
float rightPaddleSpeed = 0.f;
|
||||
const float ballSpeed = 400.f;
|
||||
float ballAngle = 0.f; // to be changed later
|
||||
|
||||
sf::Clock clock;
|
||||
bool isPlaying = false;
|
||||
while (window.isOpen())
|
||||
{
|
||||
// Handle events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
// Window closed or escape key pressed: exit
|
||||
if ((event.type == sf::Event::Closed) ||
|
||||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
|
||||
{
|
||||
window.close();
|
||||
break;
|
||||
}
|
||||
|
||||
// Space key pressed: play
|
||||
if (((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space)) ||
|
||||
(event.type == sf::Event::TouchBegan))
|
||||
{
|
||||
if (!isPlaying)
|
||||
{
|
||||
// (re)start the game
|
||||
isPlaying = true;
|
||||
clock.restart();
|
||||
|
||||
// Reset the position of the paddles and ball
|
||||
leftPaddle.setPosition(10 + paddleSize.x / 2, gameHeight / 2);
|
||||
rightPaddle.setPosition(gameWidth - 10 - paddleSize.x / 2, gameHeight / 2);
|
||||
ball.setPosition(gameWidth / 2, gameHeight / 2);
|
||||
|
||||
// Reset the ball angle
|
||||
do
|
||||
{
|
||||
// Make sure the ball initial angle is not too much vertical
|
||||
ballAngle = (std::rand() % 360) * 2 * pi / 360;
|
||||
}
|
||||
while (std::abs(std::cos(ballAngle)) < 0.7f);
|
||||
}
|
||||
}
|
||||
|
||||
// Window size changed, adjust view appropriately
|
||||
if (event.type == sf::Event::Resized)
|
||||
{
|
||||
sf::View view;
|
||||
view.setSize(gameWidth, gameHeight);
|
||||
view.setCenter(gameWidth/2.f, gameHeight/2.f);
|
||||
window.setView(view);
|
||||
}
|
||||
}
|
||||
|
||||
if (isPlaying)
|
||||
{
|
||||
float deltaTime = clock.restart().asSeconds();
|
||||
|
||||
// Move the player's paddle
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) &&
|
||||
(leftPaddle.getPosition().y - paddleSize.y / 2 > 5.f))
|
||||
{
|
||||
leftPaddle.move(0.f, -paddleSpeed * deltaTime);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) &&
|
||||
(leftPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f))
|
||||
{
|
||||
leftPaddle.move(0.f, paddleSpeed * deltaTime);
|
||||
}
|
||||
|
||||
if (sf::Touch::isDown(0))
|
||||
{
|
||||
sf::Vector2i pos = sf::Touch::getPosition(0);
|
||||
sf::Vector2f mappedPos = window.mapPixelToCoords(pos);
|
||||
leftPaddle.setPosition(leftPaddle.getPosition().x, mappedPos.y);
|
||||
}
|
||||
|
||||
// Move the computer's paddle
|
||||
if (((rightPaddleSpeed < 0.f) && (rightPaddle.getPosition().y - paddleSize.y / 2 > 5.f)) ||
|
||||
((rightPaddleSpeed > 0.f) && (rightPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)))
|
||||
{
|
||||
rightPaddle.move(0.f, rightPaddleSpeed * deltaTime);
|
||||
}
|
||||
|
||||
// Update the computer's paddle direction according to the ball position
|
||||
if (AITimer.getElapsedTime() > AITime)
|
||||
{
|
||||
AITimer.restart();
|
||||
if (ball.getPosition().y + ballRadius > rightPaddle.getPosition().y + paddleSize.y / 2)
|
||||
rightPaddleSpeed = paddleSpeed;
|
||||
else if (ball.getPosition().y - ballRadius < rightPaddle.getPosition().y - paddleSize.y / 2)
|
||||
rightPaddleSpeed = -paddleSpeed;
|
||||
else
|
||||
rightPaddleSpeed = 0.f;
|
||||
}
|
||||
|
||||
// Move the ball
|
||||
float factor = ballSpeed * deltaTime;
|
||||
ball.move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
const std::string inputString = "Touch the screen to restart";
|
||||
#else
|
||||
const std::string inputString = "Press space to restart or\nescape to exit";
|
||||
#endif
|
||||
|
||||
// Check collisions between the ball and the screen
|
||||
if (ball.getPosition().x - ballRadius < 0.f)
|
||||
{
|
||||
isPlaying = false;
|
||||
pauseMessage.setString("You Lost!\n" + inputString);
|
||||
}
|
||||
if (ball.getPosition().x + ballRadius > gameWidth)
|
||||
{
|
||||
isPlaying = false;
|
||||
pauseMessage.setString("You Won!\n" + inputString);
|
||||
}
|
||||
if (ball.getPosition().y - ballRadius < 0.f)
|
||||
{
|
||||
ballSound.play();
|
||||
ballAngle = -ballAngle;
|
||||
ball.setPosition(ball.getPosition().x, ballRadius + 0.1f);
|
||||
}
|
||||
if (ball.getPosition().y + ballRadius > gameHeight)
|
||||
{
|
||||
ballSound.play();
|
||||
ballAngle = -ballAngle;
|
||||
ball.setPosition(ball.getPosition().x, gameHeight - ballRadius - 0.1f);
|
||||
}
|
||||
|
||||
// Check the collisions between the ball and the paddles
|
||||
// Left Paddle
|
||||
if (ball.getPosition().x - ballRadius < leftPaddle.getPosition().x + paddleSize.x / 2 &&
|
||||
ball.getPosition().x - ballRadius > leftPaddle.getPosition().x &&
|
||||
ball.getPosition().y + ballRadius >= leftPaddle.getPosition().y - paddleSize.y / 2 &&
|
||||
ball.getPosition().y - ballRadius <= leftPaddle.getPosition().y + paddleSize.y / 2)
|
||||
{
|
||||
if (ball.getPosition().y > leftPaddle.getPosition().y)
|
||||
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
|
||||
else
|
||||
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
|
||||
|
||||
ballSound.play();
|
||||
ball.setPosition(leftPaddle.getPosition().x + ballRadius + paddleSize.x / 2 + 0.1f, ball.getPosition().y);
|
||||
}
|
||||
|
||||
// Right Paddle
|
||||
if (ball.getPosition().x + ballRadius > rightPaddle.getPosition().x - paddleSize.x / 2 &&
|
||||
ball.getPosition().x + ballRadius < rightPaddle.getPosition().x &&
|
||||
ball.getPosition().y + ballRadius >= rightPaddle.getPosition().y - paddleSize.y / 2 &&
|
||||
ball.getPosition().y - ballRadius <= rightPaddle.getPosition().y + paddleSize.y / 2)
|
||||
{
|
||||
if (ball.getPosition().y > rightPaddle.getPosition().y)
|
||||
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
|
||||
else
|
||||
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
|
||||
|
||||
ballSound.play();
|
||||
ball.setPosition(rightPaddle.getPosition().x - ballRadius - paddleSize.x / 2 - 0.1f, ball.getPosition().y);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the window
|
||||
window.clear(sf::Color(50, 200, 50));
|
||||
|
||||
if (isPlaying)
|
||||
{
|
||||
// Draw the paddles and the ball
|
||||
window.draw(leftPaddle);
|
||||
window.draw(rightPaddle);
|
||||
window.draw(ball);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw the pause message
|
||||
window.draw(pauseMessage);
|
||||
}
|
||||
|
||||
// Display things on screen
|
||||
window.display();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/shader)
|
||||
|
||||
# all source files
|
||||
set(SRC
|
||||
${SRCROOT}/Effect.hpp
|
||||
${SRCROOT}/Shader.cpp)
|
||||
|
||||
# define the shader target
|
||||
sfml_add_example(shader GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-graphics sfml-window sfml-system)
|
||||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/shader)
|
||||
|
||||
# all source files
|
||||
set(SRC
|
||||
${SRCROOT}/Effect.hpp
|
||||
${SRCROOT}/Shader.cpp)
|
||||
|
||||
# define the shader target
|
||||
sfml_add_example(shader GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-graphics
|
||||
RESOURCES_DIR resources)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
class Effect : public sf::Drawable
|
||||
{
|
||||
public :
|
||||
public:
|
||||
|
||||
virtual ~Effect()
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ public :
|
|||
}
|
||||
}
|
||||
|
||||
protected :
|
||||
protected:
|
||||
|
||||
Effect(const std::string& name) :
|
||||
m_name(name),
|
||||
|
@ -70,14 +70,14 @@ protected :
|
|||
return *s_font;
|
||||
}
|
||||
|
||||
private :
|
||||
private:
|
||||
|
||||
// Virtual functions to be implemented in derived effects
|
||||
virtual bool onLoad() = 0;
|
||||
virtual void onUpdate(float time, float x, float y) = 0;
|
||||
virtual void onDraw(sf::RenderTarget& target, sf::RenderStates states) const = 0;
|
||||
|
||||
private :
|
||||
private:
|
||||
|
||||
std::string m_name;
|
||||
bool m_isLoaded;
|
||||
|
|
|
@ -1,380 +1,460 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include "Effect.hpp"
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
const sf::Font* Effect::s_font = NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Pixelate" fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
class Pixelate : public Effect
|
||||
{
|
||||
public :
|
||||
|
||||
Pixelate() :
|
||||
Effect("pixelate")
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Load the texture and initialize the sprite
|
||||
if (!m_texture.loadFromFile("resources/background.jpg"))
|
||||
return false;
|
||||
m_sprite.setTexture(m_texture);
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/pixelate.frag", sf::Shader::Fragment))
|
||||
return false;
|
||||
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float, float x, float y)
|
||||
{
|
||||
m_shader.setParameter("pixel_threshold", (x + y) / 30);
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
states.shader = &m_shader;
|
||||
target.draw(m_sprite, states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::Texture m_texture;
|
||||
sf::Sprite m_sprite;
|
||||
sf::Shader m_shader;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Wave" vertex shader + "blur" fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
class WaveBlur : public Effect
|
||||
{
|
||||
public :
|
||||
|
||||
WaveBlur() :
|
||||
Effect("wave + blur")
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Create the text
|
||||
m_text.setString("Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n"
|
||||
"Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n"
|
||||
"Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n"
|
||||
"Donec fringilla scelerisque mauris et viverra.\n"
|
||||
"Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n"
|
||||
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n"
|
||||
"Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n"
|
||||
"Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n"
|
||||
"Fusce vel libero sed neque scelerisque venenatis.\n"
|
||||
"Integer mattis tincidunt quam vitae iaculis.\n"
|
||||
"Vivamus fringilla sem non velit venenatis fermentum.\n"
|
||||
"Vivamus varius tincidunt nisi id vehicula.\n"
|
||||
"Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n"
|
||||
"vestibulum sodales sem ante in massa.\n"
|
||||
"Vestibulum in augue non felis convallis viverra.\n"
|
||||
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n"
|
||||
"Duis erat eros, porta in accumsan in, blandit quis sem.\n"
|
||||
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n");
|
||||
m_text.setFont(getFont());
|
||||
m_text.setCharacterSize(22);
|
||||
m_text.setPosition(30, 20);
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/wave.vert", "resources/blur.frag"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float time, float x, float y)
|
||||
{
|
||||
m_shader.setParameter("wave_phase", time);
|
||||
m_shader.setParameter("wave_amplitude", x * 40, y * 40);
|
||||
m_shader.setParameter("blur_radius", (x + y) * 0.008f);
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
states.shader = &m_shader;
|
||||
target.draw(m_text, states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::Text m_text;
|
||||
sf::Shader m_shader;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Storm" vertex shader + "blink" fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
class StormBlink : public Effect
|
||||
{
|
||||
public :
|
||||
|
||||
StormBlink() :
|
||||
Effect("storm + blink")
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Create the points
|
||||
m_points.setPrimitiveType(sf::Points);
|
||||
for (int i = 0; i < 40000; ++i)
|
||||
{
|
||||
float x = static_cast<float>(std::rand() % 800);
|
||||
float y = static_cast<float>(std::rand() % 600);
|
||||
sf::Uint8 r = std::rand() % 255;
|
||||
sf::Uint8 g = std::rand() % 255;
|
||||
sf::Uint8 b = std::rand() % 255;
|
||||
m_points.append(sf::Vertex(sf::Vector2f(x, y), sf::Color(r, g, b)));
|
||||
}
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/storm.vert", "resources/blink.frag"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float time, float x, float y)
|
||||
{
|
||||
float radius = 200 + std::cos(time) * 150;
|
||||
m_shader.setParameter("storm_position", x * 800, y * 600);
|
||||
m_shader.setParameter("storm_inner_radius", radius / 3);
|
||||
m_shader.setParameter("storm_total_radius", radius);
|
||||
m_shader.setParameter("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f);
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
states.shader = &m_shader;
|
||||
target.draw(m_points, states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::VertexArray m_points;
|
||||
sf::Shader m_shader;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Edge" post-effect fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
class Edge : public Effect
|
||||
{
|
||||
public :
|
||||
|
||||
Edge() :
|
||||
Effect("edge post-effect")
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Create the off-screen surface
|
||||
if (!m_surface.create(800, 600))
|
||||
return false;
|
||||
m_surface.setSmooth(true);
|
||||
|
||||
// Load the textures
|
||||
if (!m_backgroundTexture.loadFromFile("resources/sfml.png"))
|
||||
return false;
|
||||
m_backgroundTexture.setSmooth(true);
|
||||
if (!m_entityTexture.loadFromFile("resources/devices.png"))
|
||||
return false;
|
||||
m_entityTexture.setSmooth(true);
|
||||
|
||||
// Initialize the background sprite
|
||||
m_backgroundSprite.setTexture(m_backgroundTexture);
|
||||
m_backgroundSprite.setPosition(135, 100);
|
||||
|
||||
// Load the moving entities
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
sf::Sprite entity(m_entityTexture, sf::IntRect(96 * i, 0, 96, 96));
|
||||
m_entities.push_back(entity);
|
||||
}
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/edge.frag", sf::Shader::Fragment))
|
||||
return false;
|
||||
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float time, float x, float y)
|
||||
{
|
||||
m_shader.setParameter("edge_threshold", 1 - (x + y) / 2);
|
||||
|
||||
// Update the position of the moving entities
|
||||
for (std::size_t i = 0; i < m_entities.size(); ++i)
|
||||
{
|
||||
sf::Vector2f position;
|
||||
position.x = std::cos(0.25f * (time * i + (m_entities.size() - i))) * 300 + 350;
|
||||
position.y = std::sin(0.25f * (time * (m_entities.size() - i) + i)) * 200 + 250;
|
||||
m_entities[i].setPosition(position);
|
||||
}
|
||||
|
||||
// Render the updated scene to the off-screen surface
|
||||
m_surface.clear(sf::Color::White);
|
||||
m_surface.draw(m_backgroundSprite);
|
||||
for (std::size_t i = 0; i < m_entities.size(); ++i)
|
||||
m_surface.draw(m_entities[i]);
|
||||
m_surface.display();
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
states.shader = &m_shader;
|
||||
target.draw(sf::Sprite(m_surface.getTexture()), states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::RenderTexture m_surface;
|
||||
sf::Texture m_backgroundTexture;
|
||||
sf::Texture m_entityTexture;
|
||||
sf::Sprite m_backgroundSprite;
|
||||
std::vector<sf::Sprite> m_entities;
|
||||
sf::Shader m_shader;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Create the main window
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
// Load the application font and pass it to the Effect class
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
Effect::setFont(font);
|
||||
|
||||
// Create the effects
|
||||
std::vector<Effect*> effects;
|
||||
effects.push_back(new Pixelate);
|
||||
effects.push_back(new WaveBlur);
|
||||
effects.push_back(new StormBlink);
|
||||
effects.push_back(new Edge);
|
||||
std::size_t current = 0;
|
||||
|
||||
// Initialize them
|
||||
for (std::size_t i = 0; i < effects.size(); ++i)
|
||||
effects[i]->load();
|
||||
|
||||
// Create the messages background
|
||||
sf::Texture textBackgroundTexture;
|
||||
if (!textBackgroundTexture.loadFromFile("resources/text-background.png"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sprite textBackground(textBackgroundTexture);
|
||||
textBackground.setPosition(0, 520);
|
||||
textBackground.setColor(sf::Color(255, 255, 255, 200));
|
||||
|
||||
// Create the description text
|
||||
sf::Text description("Current effect: " + effects[current]->getName(), font, 20);
|
||||
description.setPosition(10, 530);
|
||||
description.setColor(sf::Color(80, 80, 80));
|
||||
|
||||
// Create the instructions text
|
||||
sf::Text instructions("Press left and right arrows to change the current shader", font, 20);
|
||||
instructions.setPosition(280, 555);
|
||||
instructions.setColor(sf::Color(80, 80, 80));
|
||||
|
||||
// Start the game loop
|
||||
sf::Clock clock;
|
||||
while (window.isOpen())
|
||||
{
|
||||
// Process events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
// Close window: exit
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
|
||||
if (event.type == sf::Event::KeyPressed)
|
||||
{
|
||||
switch (event.key.code)
|
||||
{
|
||||
// Escape key: exit
|
||||
case sf::Keyboard::Escape:
|
||||
window.close();
|
||||
break;
|
||||
|
||||
// Left arrow key: previous shader
|
||||
case sf::Keyboard::Left:
|
||||
if (current == 0)
|
||||
current = effects.size() - 1;
|
||||
else
|
||||
current--;
|
||||
description.setString("Current effect: " + effects[current]->getName());
|
||||
break;
|
||||
|
||||
// Right arrow key: next shader
|
||||
case sf::Keyboard::Right:
|
||||
if (current == effects.size() - 1)
|
||||
current = 0;
|
||||
else
|
||||
current++;
|
||||
description.setString("Current effect: " + effects[current]->getName());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the current example
|
||||
float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
|
||||
float y = static_cast<float>(sf::Mouse::getPosition(window).y) / window.getSize().y;
|
||||
effects[current]->update(clock.getElapsedTime().asSeconds(), x, y);
|
||||
|
||||
// Clear the window
|
||||
window.clear(sf::Color(255, 128, 0));
|
||||
|
||||
// Draw the current example
|
||||
window.draw(*effects[current]);
|
||||
|
||||
// Draw the text
|
||||
window.draw(textBackground);
|
||||
window.draw(instructions);
|
||||
window.draw(description);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
window.display();
|
||||
}
|
||||
|
||||
// delete the effects
|
||||
for (std::size_t i = 0; i < effects.size(); ++i)
|
||||
delete effects[i];
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include "Effect.hpp"
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
const sf::Font* Effect::s_font = NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Pixelate" fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
class Pixelate : public Effect
|
||||
{
|
||||
public:
|
||||
|
||||
Pixelate() :
|
||||
Effect("pixelate")
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Load the texture and initialize the sprite
|
||||
if (!m_texture.loadFromFile("resources/background.jpg"))
|
||||
return false;
|
||||
m_sprite.setTexture(m_texture);
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/pixelate.frag", sf::Shader::Fragment))
|
||||
return false;
|
||||
m_shader.setUniform("texture", sf::Shader::CurrentTexture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float, float x, float y)
|
||||
{
|
||||
m_shader.setUniform("pixel_threshold", (x + y) / 30);
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
states.shader = &m_shader;
|
||||
target.draw(m_sprite, states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::Texture m_texture;
|
||||
sf::Sprite m_sprite;
|
||||
sf::Shader m_shader;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Wave" vertex shader + "blur" fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
class WaveBlur : public Effect
|
||||
{
|
||||
public:
|
||||
|
||||
WaveBlur() :
|
||||
Effect("wave + blur")
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Create the text
|
||||
m_text.setString("Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n"
|
||||
"Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n"
|
||||
"Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n"
|
||||
"Donec fringilla scelerisque mauris et viverra.\n"
|
||||
"Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n"
|
||||
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n"
|
||||
"Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n"
|
||||
"Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n"
|
||||
"Fusce vel libero sed neque scelerisque venenatis.\n"
|
||||
"Integer mattis tincidunt quam vitae iaculis.\n"
|
||||
"Vivamus fringilla sem non velit venenatis fermentum.\n"
|
||||
"Vivamus varius tincidunt nisi id vehicula.\n"
|
||||
"Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n"
|
||||
"vestibulum sodales sem ante in massa.\n"
|
||||
"Vestibulum in augue non felis convallis viverra.\n"
|
||||
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n"
|
||||
"Duis erat eros, porta in accumsan in, blandit quis sem.\n"
|
||||
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n");
|
||||
m_text.setFont(getFont());
|
||||
m_text.setCharacterSize(22);
|
||||
m_text.setPosition(30, 20);
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/wave.vert", "resources/blur.frag"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float time, float x, float y)
|
||||
{
|
||||
m_shader.setUniform("wave_phase", time);
|
||||
m_shader.setUniform("wave_amplitude", sf::Vector2f(x * 40, y * 40));
|
||||
m_shader.setUniform("blur_radius", (x + y) * 0.008f);
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
states.shader = &m_shader;
|
||||
target.draw(m_text, states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::Text m_text;
|
||||
sf::Shader m_shader;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Storm" vertex shader + "blink" fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
class StormBlink : public Effect
|
||||
{
|
||||
public:
|
||||
|
||||
StormBlink() :
|
||||
Effect("storm + blink")
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Create the points
|
||||
m_points.setPrimitiveType(sf::Points);
|
||||
for (int i = 0; i < 40000; ++i)
|
||||
{
|
||||
float x = static_cast<float>(std::rand() % 800);
|
||||
float y = static_cast<float>(std::rand() % 600);
|
||||
sf::Uint8 r = std::rand() % 255;
|
||||
sf::Uint8 g = std::rand() % 255;
|
||||
sf::Uint8 b = std::rand() % 255;
|
||||
m_points.append(sf::Vertex(sf::Vector2f(x, y), sf::Color(r, g, b)));
|
||||
}
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/storm.vert", "resources/blink.frag"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float time, float x, float y)
|
||||
{
|
||||
float radius = 200 + std::cos(time) * 150;
|
||||
m_shader.setUniform("storm_position", sf::Vector2f(x * 800, y * 600));
|
||||
m_shader.setUniform("storm_inner_radius", radius / 3);
|
||||
m_shader.setUniform("storm_total_radius", radius);
|
||||
m_shader.setUniform("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f);
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
states.shader = &m_shader;
|
||||
target.draw(m_points, states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::VertexArray m_points;
|
||||
sf::Shader m_shader;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Edge" post-effect fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
class Edge : public Effect
|
||||
{
|
||||
public:
|
||||
|
||||
Edge() :
|
||||
Effect("edge post-effect")
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Create the off-screen surface
|
||||
if (!m_surface.create(800, 600))
|
||||
return false;
|
||||
m_surface.setSmooth(true);
|
||||
|
||||
// Load the textures
|
||||
if (!m_backgroundTexture.loadFromFile("resources/sfml.png"))
|
||||
return false;
|
||||
m_backgroundTexture.setSmooth(true);
|
||||
if (!m_entityTexture.loadFromFile("resources/devices.png"))
|
||||
return false;
|
||||
m_entityTexture.setSmooth(true);
|
||||
|
||||
// Initialize the background sprite
|
||||
m_backgroundSprite.setTexture(m_backgroundTexture);
|
||||
m_backgroundSprite.setPosition(135, 100);
|
||||
|
||||
// Load the moving entities
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
sf::Sprite entity(m_entityTexture, sf::IntRect(96 * i, 0, 96, 96));
|
||||
m_entities.push_back(entity);
|
||||
}
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/edge.frag", sf::Shader::Fragment))
|
||||
return false;
|
||||
m_shader.setUniform("texture", sf::Shader::CurrentTexture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float time, float x, float y)
|
||||
{
|
||||
m_shader.setUniform("edge_threshold", 1 - (x + y) / 2);
|
||||
|
||||
// Update the position of the moving entities
|
||||
for (std::size_t i = 0; i < m_entities.size(); ++i)
|
||||
{
|
||||
sf::Vector2f position;
|
||||
position.x = std::cos(0.25f * (time * i + (m_entities.size() - i))) * 300 + 350;
|
||||
position.y = std::sin(0.25f * (time * (m_entities.size() - i) + i)) * 200 + 250;
|
||||
m_entities[i].setPosition(position);
|
||||
}
|
||||
|
||||
// Render the updated scene to the off-screen surface
|
||||
m_surface.clear(sf::Color::White);
|
||||
m_surface.draw(m_backgroundSprite);
|
||||
for (std::size_t i = 0; i < m_entities.size(); ++i)
|
||||
m_surface.draw(m_entities[i]);
|
||||
m_surface.display();
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
states.shader = &m_shader;
|
||||
target.draw(sf::Sprite(m_surface.getTexture()), states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::RenderTexture m_surface;
|
||||
sf::Texture m_backgroundTexture;
|
||||
sf::Texture m_entityTexture;
|
||||
sf::Sprite m_backgroundSprite;
|
||||
std::vector<sf::Sprite> m_entities;
|
||||
sf::Shader m_shader;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Geometry" geometry shader example
|
||||
////////////////////////////////////////////////////////////
|
||||
class Geometry : public Effect
|
||||
{
|
||||
public:
|
||||
|
||||
Geometry() :
|
||||
Effect("geometry shader billboards"),
|
||||
m_pointCloud(sf::Points, 10000)
|
||||
{
|
||||
}
|
||||
|
||||
bool onLoad()
|
||||
{
|
||||
// Check if geometry shaders are supported
|
||||
if (!sf::Shader::isGeometryAvailable())
|
||||
return false;
|
||||
|
||||
// Move the points in the point cloud to random positions
|
||||
for (std::size_t i = 0; i < 10000; i++)
|
||||
{
|
||||
// Spread the coordinates from -480 to +480
|
||||
// So they'll always fill the viewport at 800x600
|
||||
m_pointCloud[i].position.x = rand() % 960 - 480.f;
|
||||
m_pointCloud[i].position.y = rand() % 960 - 480.f;
|
||||
}
|
||||
|
||||
// Load the texture
|
||||
if (!m_logoTexture.loadFromFile("resources/logo.png"))
|
||||
return false;
|
||||
|
||||
// Load the shader
|
||||
if (!m_shader.loadFromFile("resources/billboard.vert", "resources/billboard.geom", "resources/billboard.frag"))
|
||||
return false;
|
||||
m_shader.setUniform("texture", sf::Shader::CurrentTexture);
|
||||
|
||||
// Set the render resolution (used for proper scaling)
|
||||
m_shader.setUniform("resolution", sf::Vector2f(800, 600));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onUpdate(float time, float x, float y)
|
||||
{
|
||||
// Reset our transformation matrix
|
||||
m_transform = sf::Transform::Identity;
|
||||
// Move to the center of the window
|
||||
m_transform.translate(400, 300);
|
||||
// Rotate everything based on cursor position
|
||||
m_transform.rotate(x * 360.f);
|
||||
|
||||
// Adjust billboard size to scale between 25 and 75
|
||||
float size = 25 + std::abs(y) * 50;
|
||||
|
||||
// Update the shader parameter
|
||||
m_shader.setUniform("size", sf::Vector2f(size, size));
|
||||
}
|
||||
|
||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
// Prepare the render state
|
||||
states.shader = &m_shader;
|
||||
states.texture = &m_logoTexture;
|
||||
states.transform = m_transform;
|
||||
|
||||
// Draw the point cloud
|
||||
target.draw(m_pointCloud, states);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sf::Texture m_logoTexture;
|
||||
sf::Transform m_transform;
|
||||
sf::Shader m_shader;
|
||||
sf::VertexArray m_pointCloud;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Create the main window
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader",
|
||||
sf::Style::Titlebar | sf::Style::Close);
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
// Load the application font and pass it to the Effect class
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
Effect::setFont(font);
|
||||
|
||||
// Create the effects
|
||||
std::vector<Effect*> effects;
|
||||
effects.push_back(new Pixelate);
|
||||
effects.push_back(new WaveBlur);
|
||||
effects.push_back(new StormBlink);
|
||||
effects.push_back(new Edge);
|
||||
effects.push_back(new Geometry);
|
||||
std::size_t current = 0;
|
||||
|
||||
// Initialize them
|
||||
for (std::size_t i = 0; i < effects.size(); ++i)
|
||||
effects[i]->load();
|
||||
|
||||
// Create the messages background
|
||||
sf::Texture textBackgroundTexture;
|
||||
if (!textBackgroundTexture.loadFromFile("resources/text-background.png"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sprite textBackground(textBackgroundTexture);
|
||||
textBackground.setPosition(0, 520);
|
||||
textBackground.setColor(sf::Color(255, 255, 255, 200));
|
||||
|
||||
// Create the description text
|
||||
sf::Text description("Current effect: " + effects[current]->getName(), font, 20);
|
||||
description.setPosition(10, 530);
|
||||
description.setFillColor(sf::Color(80, 80, 80));
|
||||
|
||||
// Create the instructions text
|
||||
sf::Text instructions("Press left and right arrows to change the current shader", font, 20);
|
||||
instructions.setPosition(280, 555);
|
||||
instructions.setFillColor(sf::Color(80, 80, 80));
|
||||
|
||||
// Start the game loop
|
||||
sf::Clock clock;
|
||||
while (window.isOpen())
|
||||
{
|
||||
// Process events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
// Close window: exit
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
|
||||
if (event.type == sf::Event::KeyPressed)
|
||||
{
|
||||
switch (event.key.code)
|
||||
{
|
||||
// Escape key: exit
|
||||
case sf::Keyboard::Escape:
|
||||
window.close();
|
||||
break;
|
||||
|
||||
// Left arrow key: previous shader
|
||||
case sf::Keyboard::Left:
|
||||
if (current == 0)
|
||||
current = effects.size() - 1;
|
||||
else
|
||||
current--;
|
||||
description.setString("Current effect: " + effects[current]->getName());
|
||||
break;
|
||||
|
||||
// Right arrow key: next shader
|
||||
case sf::Keyboard::Right:
|
||||
if (current == effects.size() - 1)
|
||||
current = 0;
|
||||
else
|
||||
current++;
|
||||
description.setString("Current effect: " + effects[current]->getName());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the current example
|
||||
float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
|
||||
float y = static_cast<float>(sf::Mouse::getPosition(window).y) / window.getSize().y;
|
||||
effects[current]->update(clock.getElapsedTime().asSeconds(), x, y);
|
||||
|
||||
// Clear the window
|
||||
window.clear(sf::Color(255, 128, 0));
|
||||
|
||||
// Draw the current example
|
||||
window.draw(*effects[current]);
|
||||
|
||||
// Draw the text
|
||||
window.draw(textBackground);
|
||||
window.draw(instructions);
|
||||
window.draw(description);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
window.display();
|
||||
}
|
||||
|
||||
// delete the effects
|
||||
for (std::size_t i = 0; i < effects.size(); ++i)
|
||||
delete effects[i];
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
11
examples/shader/resources/billboard.frag
Normal file
|
@ -0,0 +1,11 @@
|
|||
#version 150
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
in vec2 tex_coord;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Read and apply a color from the texture
|
||||
gl_FragColor = texture2D(texture, tex_coord);
|
||||
}
|
56
examples/shader/resources/billboard.geom
Normal file
|
@ -0,0 +1,56 @@
|
|||
#version 150
|
||||
|
||||
// The render target's resolution (used for scaling)
|
||||
uniform vec2 resolution;
|
||||
|
||||
// The billboards' size
|
||||
uniform vec2 size;
|
||||
|
||||
// Input is the passed point cloud
|
||||
layout (points) in;
|
||||
|
||||
// The output will consist of triangle strips with four vertices each
|
||||
layout (triangle_strip, max_vertices = 4) out;
|
||||
|
||||
// Output texture coordinates
|
||||
out vec2 tex_coord;
|
||||
|
||||
// Main entry point
|
||||
void main()
|
||||
{
|
||||
// Caculate the half width/height of the billboards
|
||||
vec2 half_size = size / 2.f;
|
||||
|
||||
// Scale the size based on resolution (1 would be full width/height)
|
||||
half_size /= resolution;
|
||||
|
||||
// Iterate over all vertices
|
||||
for (int i = 0; i < gl_in.length(); i++)
|
||||
{
|
||||
// Retrieve the passed vertex position
|
||||
vec2 pos = gl_in[i].gl_Position.xy;
|
||||
|
||||
// Bottom left vertex
|
||||
gl_Position = vec4(pos - half_size, 0.f, 1.f);
|
||||
tex_coord = vec2(1.f, 1.f);
|
||||
EmitVertex();
|
||||
|
||||
// Bottom right vertex
|
||||
gl_Position = vec4(pos.x + half_size.x, pos.y - half_size.y, 0.f, 1.f);
|
||||
tex_coord = vec2(0.f, 1.f);
|
||||
EmitVertex();
|
||||
|
||||
// Top left vertex
|
||||
gl_Position = vec4(pos.x - half_size.x, pos.y + half_size.y, 0.f, 1.f);
|
||||
tex_coord = vec2(1.f, 0.f);
|
||||
EmitVertex();
|
||||
|
||||
// Top right vertex
|
||||
gl_Position = vec4(pos + half_size, 0.f, 1.f);
|
||||
tex_coord = vec2(0.f, 0.f);
|
||||
EmitVertex();
|
||||
|
||||
// And finalize the primitive
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
5
examples/shader/resources/billboard.vert
Normal file
|
@ -0,0 +1,5 @@
|
|||
void main()
|
||||
{
|
||||
// Transform the vertex position
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
|
@ -5,5 +5,5 @@ void main()
|
|||
{
|
||||
vec4 pixel = gl_Color;
|
||||
pixel.a = blink_alpha;
|
||||
gl_FragColor = pixel;
|
||||
gl_FragColor = pixel;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
uniform sampler2D texture;
|
||||
uniform float blur_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 offx = vec2(blur_radius, 0.0);
|
||||
vec2 offy = vec2(0.0, blur_radius);
|
||||
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 4.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offy) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
||||
|
||||
gl_FragColor = gl_Color * (pixel / 16.0);
|
||||
}
|
||||
uniform sampler2D texture;
|
||||
uniform float blur_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 offx = vec2(blur_radius, 0.0);
|
||||
vec2 offy = vec2(0.0, blur_radius);
|
||||
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 4.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offy) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
||||
|
||||
gl_FragColor = gl_Color * (pixel / 16.0);
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
uniform sampler2D texture;
|
||||
uniform float edge_threshold;
|
||||
|
||||
void main()
|
||||
{
|
||||
const float offset = 1.0 / 512.0;
|
||||
vec2 offx = vec2(offset, 0.0);
|
||||
vec2 offy = vec2(0.0, offset);
|
||||
|
||||
vec4 hEdge = texture2D(texture, gl_TexCoord[0].xy - offy) * -2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * -1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * -1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
||||
|
||||
vec4 vEdge = texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx) * -2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * -1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * -1.0;
|
||||
|
||||
vec3 result = sqrt(hEdge.rgb * hEdge.rgb + vEdge.rgb * vEdge.rgb);
|
||||
float edge = length(result);
|
||||
vec4 pixel = gl_Color * texture2D(texture, gl_TexCoord[0].xy);
|
||||
if (edge > (edge_threshold * 8.0))
|
||||
pixel.rgb = vec3(0.0, 0.0, 0.0);
|
||||
else
|
||||
pixel.a = edge_threshold;
|
||||
gl_FragColor = pixel;
|
||||
}
|
||||
uniform sampler2D texture;
|
||||
uniform float edge_threshold;
|
||||
|
||||
void main()
|
||||
{
|
||||
const float offset = 1.0 / 512.0;
|
||||
vec2 offx = vec2(offset, 0.0);
|
||||
vec2 offy = vec2(0.0, offset);
|
||||
|
||||
vec4 hEdge = texture2D(texture, gl_TexCoord[0].xy - offy) * -2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * -1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * -1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
||||
|
||||
vec4 vEdge = texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx) * -2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * -1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * -1.0;
|
||||
|
||||
vec3 result = sqrt(hEdge.rgb * hEdge.rgb + vEdge.rgb * vEdge.rgb);
|
||||
float edge = length(result);
|
||||
vec4 pixel = gl_Color * texture2D(texture, gl_TexCoord[0].xy);
|
||||
if (edge > (edge_threshold * 8.0))
|
||||
pixel.rgb = vec3(0.0, 0.0, 0.0);
|
||||
else
|
||||
pixel.a = edge_threshold;
|
||||
gl_FragColor = pixel;
|
||||
}
|
||||
|
|
BIN
examples/shader/resources/logo.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
|
@ -1,9 +1,9 @@
|
|||
uniform sampler2D texture;
|
||||
uniform float pixel_threshold;
|
||||
|
||||
void main()
|
||||
{
|
||||
float factor = 1.0 / (pixel_threshold + 0.001);
|
||||
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
|
||||
gl_FragColor = texture2D(texture, pos) * gl_Color;
|
||||
}
|
||||
uniform sampler2D texture;
|
||||
uniform float pixel_threshold;
|
||||
|
||||
void main()
|
||||
{
|
||||
float factor = 1.0 / (pixel_threshold + 0.001);
|
||||
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
|
||||
gl_FragColor = texture2D(texture, pos) * gl_Color;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ void main()
|
|||
vertex.xy = storm_position + normalize(offset) * push_distance;
|
||||
}
|
||||
|
||||
gl_Position = gl_ProjectionMatrix * vertex;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_FrontColor = gl_Color;
|
||||
gl_Position = gl_ProjectionMatrix * vertex;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_FrontColor = gl_Color;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ void main()
|
|||
vertex.y += sin(gl_Vertex.x * 0.02 + wave_phase * 2.4) * wave_amplitude.y
|
||||
+ cos(gl_Vertex.x * 0.02 + wave_phase * 5.2) * wave_amplitude.y * 0.3;
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vertex;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_FrontColor = gl_Color;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vertex;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_FrontColor = gl_Color;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sockets)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/Sockets.cpp
|
||||
${SRCROOT}/TCP.cpp
|
||||
${SRCROOT}/UDP.cpp)
|
||||
|
||||
# define the sockets target
|
||||
sfml_add_example(sockets
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-network sfml-system)
|
||||
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sockets)
|
||||
|
||||
# all source files
|
||||
set(SRC ${SRCROOT}/Sockets.cpp
|
||||
${SRCROOT}/TCP.cpp
|
||||
${SRCROOT}/UDP.cpp)
|
||||
|
||||
# define the sockets target
|
||||
sfml_add_example(sockets
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-network)
|
||||
|
|
|
@ -1,59 +1,59 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
void runTcpServer(unsigned short port);
|
||||
void runTcpClient(unsigned short port);
|
||||
void runUdpServer(unsigned short port);
|
||||
void runUdpClient(unsigned short port);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Choose an arbitrary port for opening sockets
|
||||
const unsigned short port = 50001;
|
||||
|
||||
// TCP, UDP or connected UDP ?
|
||||
char protocol;
|
||||
std::cout << "Do you want to use TCP (t) or UDP (u) ? ";
|
||||
std::cin >> protocol;
|
||||
|
||||
// Client or server ?
|
||||
char who;
|
||||
std::cout << "Do you want to be a server (s) or a client (c) ? ";
|
||||
std::cin >> who;
|
||||
|
||||
if (protocol == 't')
|
||||
{
|
||||
// Test the TCP protocol
|
||||
if (who == 's')
|
||||
runTcpServer(port);
|
||||
else
|
||||
runTcpClient(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Test the unconnected UDP protocol
|
||||
if (who == 's')
|
||||
runUdpServer(port);
|
||||
else
|
||||
runUdpClient(port);
|
||||
}
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
std::cout << "Press enter to exit..." << std::endl;
|
||||
std::cin.ignore(10000, '\n');
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
void runTcpServer(unsigned short port);
|
||||
void runTcpClient(unsigned short port);
|
||||
void runUdpServer(unsigned short port);
|
||||
void runUdpClient(unsigned short port);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Choose an arbitrary port for opening sockets
|
||||
const unsigned short port = 50001;
|
||||
|
||||
// TCP, UDP or connected UDP ?
|
||||
char protocol;
|
||||
std::cout << "Do you want to use TCP (t) or UDP (u)? ";
|
||||
std::cin >> protocol;
|
||||
|
||||
// Client or server ?
|
||||
char who;
|
||||
std::cout << "Do you want to be a server (s) or a client (c)? ";
|
||||
std::cin >> who;
|
||||
|
||||
if (protocol == 't')
|
||||
{
|
||||
// Test the TCP protocol
|
||||
if (who == 's')
|
||||
runTcpServer(port);
|
||||
else
|
||||
runTcpClient(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Test the unconnected UDP protocol
|
||||
if (who == 's')
|
||||
runUdpServer(port);
|
||||
else
|
||||
runUdpClient(port);
|
||||
}
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
std::cout << "Press enter to exit..." << std::endl;
|
||||
std::cin.ignore(10000, '\n');
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -1,81 +1,81 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Launch a server, wait for an incoming connection,
|
||||
/// send a message and wait for the answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void runTcpServer(unsigned short port)
|
||||
{
|
||||
// Create a server socket to accept new connections
|
||||
sf::TcpListener listener;
|
||||
|
||||
// Listen to the given port for incoming connections
|
||||
if (listener.listen(port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||
|
||||
// Wait for a connection
|
||||
sf::TcpSocket socket;
|
||||
if (listener.accept(socket) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Client connected: " << socket.getRemoteAddress() << std::endl;
|
||||
|
||||
// Send a message to the connected client
|
||||
const char out[] = "Hi, I'm the server";
|
||||
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
||||
|
||||
// Receive a message back from the client
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Answer received from the client: \"" << in << "\"" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a client, connect it to a server, display the
|
||||
/// welcome message and send an answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void runTcpClient(unsigned short port)
|
||||
{
|
||||
// Ask for the server address
|
||||
sf::IpAddress server;
|
||||
do
|
||||
{
|
||||
std::cout << "Type the address or name of the server to connect to: ";
|
||||
std::cin >> server;
|
||||
}
|
||||
while (server == sf::IpAddress::None);
|
||||
|
||||
// Create a socket for communicating with the server
|
||||
sf::TcpSocket socket;
|
||||
|
||||
// Connect to the server
|
||||
if (socket.connect(server, port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Connected to server " << server << std::endl;
|
||||
|
||||
// Receive a message from the server
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from the server: \"" << in << "\"" << std::endl;
|
||||
|
||||
// Send an answer to the server
|
||||
const char out[] = "Hi, I'm a client";
|
||||
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Launch a server, wait for an incoming connection,
|
||||
/// send a message and wait for the answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void runTcpServer(unsigned short port)
|
||||
{
|
||||
// Create a server socket to accept new connections
|
||||
sf::TcpListener listener;
|
||||
|
||||
// Listen to the given port for incoming connections
|
||||
if (listener.listen(port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||
|
||||
// Wait for a connection
|
||||
sf::TcpSocket socket;
|
||||
if (listener.accept(socket) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Client connected: " << socket.getRemoteAddress() << std::endl;
|
||||
|
||||
// Send a message to the connected client
|
||||
const char out[] = "Hi, I'm the server";
|
||||
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
||||
|
||||
// Receive a message back from the client
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Answer received from the client: \"" << in << "\"" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a client, connect it to a server, display the
|
||||
/// welcome message and send an answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void runTcpClient(unsigned short port)
|
||||
{
|
||||
// Ask for the server address
|
||||
sf::IpAddress server;
|
||||
do
|
||||
{
|
||||
std::cout << "Type the address or name of the server to connect to: ";
|
||||
std::cin >> server;
|
||||
}
|
||||
while (server == sf::IpAddress::None);
|
||||
|
||||
// Create a socket for communicating with the server
|
||||
sf::TcpSocket socket;
|
||||
|
||||
// Connect to the server
|
||||
if (socket.connect(server, port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Connected to server " << server << std::endl;
|
||||
|
||||
// Receive a message from the server
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from the server: \"" << in << "\"" << std::endl;
|
||||
|
||||
// Send an answer to the server
|
||||
const char out[] = "Hi, I'm a client";
|
||||
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
||||
}
|
||||
|
|
|
@ -1,72 +1,72 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Launch a server, wait for a message, send an answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void runUdpServer(unsigned short port)
|
||||
{
|
||||
// Create a socket to receive a message from anyone
|
||||
sf::UdpSocket socket;
|
||||
|
||||
// Listen to messages on the specified port
|
||||
if (socket.bind(port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl;
|
||||
|
||||
// Wait for a message
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
sf::IpAddress sender;
|
||||
unsigned short senderPort;
|
||||
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from client " << sender << ": \"" << in << "\"" << std::endl;
|
||||
|
||||
// Send an answer to the client
|
||||
const char out[] = "Hi, I'm the server";
|
||||
if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Send a message to the server, wait for the answer
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void runUdpClient(unsigned short port)
|
||||
{
|
||||
// Ask for the server address
|
||||
sf::IpAddress server;
|
||||
do
|
||||
{
|
||||
std::cout << "Type the address or name of the server to connect to: ";
|
||||
std::cin >> server;
|
||||
}
|
||||
while (server == sf::IpAddress::None);
|
||||
|
||||
// Create a socket for communicating with the server
|
||||
sf::UdpSocket socket;
|
||||
|
||||
// Send a message to the server
|
||||
const char out[] = "Hi, I'm a client";
|
||||
if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
||||
|
||||
// Receive an answer from anyone (but most likely from the server)
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
sf::IpAddress sender;
|
||||
unsigned short senderPort;
|
||||
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from " << sender << ": \"" << in << "\"" << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Launch a server, wait for a message, send an answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void runUdpServer(unsigned short port)
|
||||
{
|
||||
// Create a socket to receive a message from anyone
|
||||
sf::UdpSocket socket;
|
||||
|
||||
// Listen to messages on the specified port
|
||||
if (socket.bind(port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl;
|
||||
|
||||
// Wait for a message
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
sf::IpAddress sender;
|
||||
unsigned short senderPort;
|
||||
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from client " << sender << ": \"" << in << "\"" << std::endl;
|
||||
|
||||
// Send an answer to the client
|
||||
const char out[] = "Hi, I'm the server";
|
||||
if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Send a message to the server, wait for the answer
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void runUdpClient(unsigned short port)
|
||||
{
|
||||
// Ask for the server address
|
||||
sf::IpAddress server;
|
||||
do
|
||||
{
|
||||
std::cout << "Type the address or name of the server to connect to: ";
|
||||
std::cin >> server;
|
||||
}
|
||||
while (server == sf::IpAddress::None);
|
||||
|
||||
// Create a socket for communicating with the server
|
||||
sf::UdpSocket socket;
|
||||
|
||||
// Send a message to the server
|
||||
const char out[] = "Hi, I'm a client";
|
||||
if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
||||
|
||||
// Receive an answer from anyone (but most likely from the server)
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
sf::IpAddress sender;
|
||||
unsigned short senderPort;
|
||||
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from " << sender << ": \"" << in << "\"" << std::endl;
|
||||
}
|
||||
|
|