Compare commits
429 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6f3c99a295 | ||
![]() |
9ce2331cc1 | ||
![]() |
cacd4a9d90 | ||
![]() |
be7f717a24 | ||
![]() |
4992edab24 | ||
![]() |
af3df8bdd6 | ||
![]() |
02a533768c | ||
![]() |
46046bf018 | ||
![]() |
bc29720024 | ||
![]() |
6a2e51ec78 | ||
![]() |
e6d304cdc2 | ||
![]() |
4663cc03f3 | ||
![]() |
77484cb19c | ||
![]() |
15345ded25 | ||
![]() |
c715cae18d | ||
![]() |
98a7d35bab | ||
![]() |
4f7d090fb2 | ||
![]() |
954f029118 | ||
![]() |
4fa2c32906 | ||
![]() |
7e9bed5c89 | ||
![]() |
5ec87c4c6f | ||
![]() |
05443cd0c8 | ||
![]() |
b02c6127a0 | ||
![]() |
46774a8167 | ||
![]() |
f28c1ef675 | ||
![]() |
eee995ec3d | ||
![]() |
a3ca859db2 | ||
![]() |
40d6c15798 | ||
![]() |
d41386d661 | ||
![]() |
7ae426c377 | ||
![]() |
fa0d5bbf9e | ||
![]() |
d10ff78822 | ||
![]() |
e932d23cf4 | ||
![]() |
49b723e76d | ||
![]() |
71017993ce | ||
![]() |
42d56d2f37 | ||
![]() |
cff38308b7 | ||
![]() |
9c52a4932d | ||
![]() |
edc1d2511d | ||
![]() |
1c4dadcf68 | ||
![]() |
d797bb3e1c | ||
![]() |
bec467705e | ||
![]() |
fe0d04c879 | ||
![]() |
406373caa9 | ||
![]() |
6a46dcb374 | ||
![]() |
7e77dc7a21 | ||
![]() |
56e7a75a77 | ||
![]() |
0b4af7d341 | ||
![]() |
8deac79028 | ||
![]() |
2031c06880 | ||
![]() |
20e446cc7d | ||
![]() |
1eae4b483b | ||
![]() |
1f82b0d847 | ||
![]() |
b0ce16b460 | ||
![]() |
237972652d | ||
![]() |
9f699af138 | ||
![]() |
4525c897e2 | ||
![]() |
019434a37e | ||
![]() |
22b7713287 | ||
![]() |
a748c3bf25 | ||
![]() |
cc827041a9 | ||
![]() |
95d31b0986 | ||
![]() |
e30995c65c | ||
![]() |
2829cec720 | ||
![]() |
a63a422972 | ||
![]() |
e043dad2a6 | ||
![]() |
aca9f20c2e | ||
![]() |
da51abf07f | ||
![]() |
31af42ee8e | ||
![]() |
c77f97c84a | ||
![]() |
d8f1aad494 | ||
![]() |
6b2aa173fc | ||
![]() |
2cf8352b95 | ||
![]() |
55e7428924 | ||
![]() |
c7fe2c772e | ||
![]() |
a4a10a6edd | ||
![]() |
c2e79a212c | ||
![]() |
680cbdf1f0 | ||
![]() |
9961e3b0d7 | ||
![]() |
5997fa8fe1 | ||
![]() |
59a44bf5b9 | ||
![]() |
30f21438bc | ||
![]() |
ebcbe292c1 | ||
![]() |
b978dec51c | ||
![]() |
8cef1d12f2 | ||
![]() |
a77505c554 | ||
![]() |
e0d4cc3143 | ||
![]() |
fcf15fe8c0 | ||
![]() |
1694887f9b | ||
![]() |
0237231a8d | ||
![]() |
e88099bfd3 | ||
![]() |
887881486b | ||
![]() |
f21bd8836a | ||
![]() |
18c309fb38 | ||
![]() |
bc07636d6b | ||
![]() |
7104911236 | ||
![]() |
ca329bba0d | ||
![]() |
d1a4c1f789 | ||
![]() |
451969de1b | ||
![]() |
7fe8d25253 | ||
![]() |
b17937dda8 | ||
![]() |
6f0a4a7663 | ||
![]() |
98f4e06a37 | ||
![]() |
1db9a85b5d | ||
![]() |
e5c9e5e328 | ||
![]() |
eb8512b43c | ||
![]() |
6321dd4614 | ||
![]() |
689f3c086b | ||
![]() |
9f79ed2972 | ||
![]() |
421bbde1e0 | ||
![]() |
10982fa184 | ||
![]() |
a1809fad4c | ||
![]() |
8f05322263 | ||
![]() |
358ca7595d | ||
![]() |
89fedf0bb9 | ||
![]() |
4211056354 | ||
![]() |
6d56c99a37 | ||
![]() |
f46fcb8307 | ||
![]() |
b708965ab7 | ||
![]() |
3c8b7a41b2 | ||
![]() |
a08508f6a4 | ||
![]() |
7e0929e3b4 | ||
![]() |
793977db4a | ||
![]() |
b5b3bbb30b | ||
![]() |
615cb35d96 | ||
![]() |
21c30f43d4 | ||
![]() |
c20ccfe274 | ||
![]() |
c0d1425aac | ||
![]() |
350cb0a8a8 | ||
![]() |
cedd5efe4c | ||
![]() |
f8bd56b07f | ||
![]() |
9fbf5c8ca2 | ||
![]() |
caa1f45643 | ||
![]() |
5e8b6b0157 | ||
![]() |
8473e94879 | ||
![]() |
8dece6a179 | ||
![]() |
ccf085ac70 | ||
![]() |
dde1d68a02 | ||
![]() |
14884a2a6c | ||
![]() |
9c62d8a400 | ||
![]() |
6e1326143e | ||
![]() |
03e6006ac8 | ||
![]() |
e614942a2d | ||
![]() |
1397242d88 | ||
![]() |
b8246d8592 | ||
![]() |
7eacac24d5 | ||
![]() |
2a64aa2abd | ||
![]() |
f976b03a4f | ||
![]() |
8db130289e | ||
![]() |
3aad221b1e | ||
![]() |
ff499fe57d | ||
![]() |
3c75bb5e6d | ||
![]() |
8a08a9b225 | ||
![]() |
1b7d136daa | ||
![]() |
f346c672fb | ||
![]() |
08adb4b8c3 | ||
![]() |
3d936061c8 | ||
![]() |
95f3b6e18e | ||
![]() |
8eecbbe4aa | ||
![]() |
ea5cd42e6c | ||
![]() |
3ffe34f9bb | ||
![]() |
416a52b5bc | ||
![]() |
91faf72dda | ||
![]() |
60e8511543 | ||
![]() |
97abaff4c5 | ||
![]() |
5ad65d9291 | ||
![]() |
776304e8e8 | ||
![]() |
d5aab98ac9 | ||
![]() |
1f66f0d9a2 | ||
![]() |
c1a02e9fca | ||
![]() |
f987ac9dca | ||
![]() |
1d3f230c92 | ||
![]() |
ae301a1d23 | ||
![]() |
b132ae099b | ||
![]() |
2783d0d63e | ||
![]() |
5d27c1e6c9 | ||
![]() |
d2882a68fe | ||
![]() |
2ae5849826 | ||
![]() |
25ae374f62 | ||
![]() |
8b7db29ba0 | ||
![]() |
74642ba1c6 | ||
![]() |
96b0563249 | ||
![]() |
00c611a5fb | ||
![]() |
bba8454034 | ||
![]() |
29b9b054dd | ||
![]() |
e8b89b5ecf | ||
![]() |
5d9df629d7 | ||
![]() |
dc6136e820 | ||
![]() |
75b0264f35 | ||
![]() |
64c588e9d8 | ||
![]() |
862ef0524e | ||
![]() |
d73abe73e5 | ||
![]() |
6bf746d531 | ||
![]() |
f6df47dfe5 | ||
![]() |
3f12fa54f7 | ||
![]() |
90b3dceb54 | ||
![]() |
a6db31c01e | ||
![]() |
39e22046c1 | ||
![]() |
3d8b1165a8 | ||
![]() |
163a9e1f41 | ||
![]() |
9b6227688f | ||
![]() |
3c2ce77b7b | ||
![]() |
1878a9ea01 | ||
![]() |
06910eedfd | ||
![]() |
ca92f43c27 | ||
![]() |
ea70c47a1a | ||
![]() |
3f7fa6d6e7 | ||
![]() |
ab52f98480 | ||
![]() |
c1d282d9e8 | ||
![]() |
e25f4dca1f | ||
![]() |
68dcb55349 | ||
![]() |
b75511248d | ||
![]() |
e40c26dea5 | ||
![]() |
7baa2975ec | ||
![]() |
e0cb892d2d | ||
![]() |
12d3e21f1b | ||
![]() |
161c8b7d08 | ||
![]() |
82306af111 | ||
![]() |
596338b26a | ||
![]() |
eb772bc1e0 | ||
![]() |
047f093503 | ||
![]() |
df84f93938 | ||
![]() |
a8e63b9724 | ||
![]() |
99e86d180b | ||
![]() |
8adcec185e | ||
![]() |
3fcf2ee19a | ||
![]() |
bdcb16e7bb | ||
![]() |
a679b0ccc0 | ||
![]() |
acedf4a0d5 | ||
![]() |
1f730b3b35 | ||
![]() |
b331edd7a6 | ||
![]() |
9d53e07883 | ||
![]() |
bce2dd1231 | ||
![]() |
d089e1cd34 | ||
![]() |
741afde3bc | ||
![]() |
314c4061df | ||
![]() |
08165fed18 | ||
![]() |
112874fe07 | ||
![]() |
c10348cc85 | ||
![]() |
904a7ee032 | ||
![]() |
4ccf1e61be | ||
![]() |
6916ff58b1 | ||
![]() |
e5d5f6e367 | ||
![]() |
7caedff9ca | ||
![]() |
d9d9c6111b | ||
![]() |
8d6f179062 | ||
![]() |
7e08b312d5 | ||
![]() |
c6d2502bdb | ||
![]() |
a2fd427224 | ||
![]() |
74ed3d07f9 | ||
![]() |
ce58b168f6 | ||
![]() |
c247c371c3 | ||
![]() |
0a2177b4bc | ||
![]() |
ae2452d280 | ||
![]() |
2d6bc1ff42 | ||
![]() |
dec5f332ad | ||
![]() |
d93f8eadf8 | ||
![]() |
53b32f1c20 | ||
![]() |
402ce4e53b | ||
![]() |
861a619053 | ||
![]() |
fc95ceadf0 | ||
![]() |
dde1e0671f | ||
![]() |
4e43192561 | ||
![]() |
97101d1003 | ||
![]() |
37bb8e9554 | ||
![]() |
41732bebe8 | ||
![]() |
e2183f0b99 | ||
![]() |
f565ff018e | ||
![]() |
8241dcf80b | ||
![]() |
c661cad692 | ||
![]() |
37a6f12037 | ||
![]() |
addbd88833 | ||
![]() |
8e86f3586d | ||
![]() |
e67c842faa | ||
![]() |
061294e4d1 | ||
![]() |
20fa362700 | ||
![]() |
20257f3e49 | ||
![]() |
3db13edd89 | ||
![]() |
a727f5768f | ||
![]() |
bf0db83134 | ||
![]() |
ef3b01dffc | ||
![]() |
64575e711b | ||
![]() |
3414910809 | ||
![]() |
2f42b0ce85 | ||
![]() |
12bcdb977a | ||
![]() |
973d32f9a7 | ||
![]() |
049a1c8f6d | ||
![]() |
4b79f63d07 | ||
![]() |
7ebcd06652 | ||
![]() |
ce8d7042c6 | ||
![]() |
d8b8c0f3fc | ||
![]() |
c387bc586d | ||
![]() |
c629b16ebc | ||
![]() |
cef1e6e2e2 | ||
![]() |
740834bb83 | ||
![]() |
2c2ccadd32 | ||
![]() |
6f2f09947f | ||
![]() |
e6e48675cc | ||
![]() |
108f7f6fee | ||
![]() |
2234158049 | ||
![]() |
3ebc55fdfe | ||
![]() |
084fb31186 | ||
![]() |
2d5cc5ddbf | ||
![]() |
f3555a1016 | ||
![]() |
5f1990e044 | ||
![]() |
3d46297cc1 | ||
![]() |
439e73a8ec | ||
![]() |
3d5fa81bf2 | ||
![]() |
2a913b6587 | ||
![]() |
042499188c | ||
![]() |
b354c10072 | ||
![]() |
6267fd1865 | ||
![]() |
f518c4e939 | ||
![]() |
e53e42f43d | ||
![]() |
94abe0db88 | ||
![]() |
89c16baf18 | ||
![]() |
68ffbc06c7 | ||
![]() |
f81cb1a252 | ||
![]() |
1da7e1da8c | ||
![]() |
5775f9d224 | ||
![]() |
38ee6156f8 | ||
![]() |
b83d165764 | ||
![]() |
895f9613d2 | ||
![]() |
602d2a65dd | ||
![]() |
879c874330 | ||
![]() |
153f078bd1 | ||
![]() |
9a478bef1a | ||
![]() |
a1c551c6c4 | ||
![]() |
e44eae3cd5 | ||
![]() |
814952c01d | ||
![]() |
6baf8bccb1 | ||
![]() |
f46ffb98a6 | ||
![]() |
65d003507b | ||
![]() |
251f90cd31 | ||
![]() |
8e870f0eda | ||
![]() |
7c05e498fc | ||
![]() |
eed53a5b44 | ||
![]() |
9909c83012 | ||
![]() |
73a3d4a183 | ||
![]() |
ae95111006 | ||
![]() |
8730f22371 | ||
![]() |
a5329efb23 | ||
![]() |
b4d67499a7 | ||
![]() |
543c0ba30d | ||
![]() |
47137b1489 | ||
![]() |
7b448f59e2 | ||
![]() |
2cb3b91913 | ||
![]() |
2433f30b4b | ||
![]() |
b44b7dd310 | ||
![]() |
632d064b21 | ||
![]() |
bc3983a3dd | ||
![]() |
f501d42e47 | ||
![]() |
4b2f6b2b5f | ||
![]() |
3fd48a14a2 | ||
![]() |
55e76dab47 | ||
![]() |
8d576aaf2b | ||
![]() |
e5271dbdc3 | ||
![]() |
e8829538c9 | ||
![]() |
c563b53afb | ||
![]() |
e19616592d | ||
![]() |
24566c0cf3 | ||
![]() |
a386cedae6 | ||
![]() |
83f6ae148a | ||
![]() |
f9a2d89ed2 | ||
![]() |
b4da7b6777 | ||
![]() |
4ad1fa85a4 | ||
![]() |
892813de76 | ||
![]() |
83a4eb0852 | ||
![]() |
a4e307ed96 | ||
![]() |
65a21ab416 | ||
![]() |
1b249ac1e1 | ||
![]() |
e0854696b4 | ||
![]() |
f951f0c536 | ||
![]() |
e36a80f730 | ||
![]() |
d21422687a | ||
![]() |
9a7d4ccb79 | ||
![]() |
5baab54f93 | ||
![]() |
721d18589f | ||
![]() |
dccd61bef9 | ||
![]() |
9c991bd079 | ||
![]() |
81d8302d53 | ||
![]() |
a43d49ed72 | ||
![]() |
0c60af8981 | ||
![]() |
9609ebf49a | ||
![]() |
55380f8489 | ||
![]() |
266df463cc | ||
![]() |
5fec3ef895 | ||
![]() |
396b830db5 | ||
![]() |
034e9ba1b8 | ||
![]() |
d7f4be0715 | ||
![]() |
baf7d7d19a | ||
![]() |
632d16e27d | ||
![]() |
f6db1ef9c5 | ||
![]() |
9b3b28c81f | ||
![]() |
391555a063 | ||
![]() |
63e320d405 | ||
![]() |
59b7412772 | ||
![]() |
718f7a0161 | ||
![]() |
dee602464b | ||
![]() |
baf225dc01 | ||
![]() |
6945511e82 | ||
![]() |
e1f3f84e84 | ||
![]() |
eb1b2535f6 | ||
![]() |
566a8d17c8 | ||
![]() |
af38e18389 | ||
![]() |
37ce51b274 | ||
![]() |
498c172d8e | ||
![]() |
272d9d58e3 | ||
![]() |
7b4831f1b7 | ||
![]() |
bdbc05c0dc | ||
![]() |
e3ef738264 | ||
![]() |
03720b30a1 | ||
![]() |
ddaa4a304d | ||
![]() |
24c7549698 | ||
![]() |
c5f605e888 | ||
![]() |
5c8191f8a7 | ||
![]() |
923f4b9bbd | ||
![]() |
e103320ad8 | ||
![]() |
7367140fb4 | ||
![]() |
df7a058216 | ||
![]() |
1ba5f1515d | ||
![]() |
0b7373446d | ||
![]() |
767ac9bc3e | ||
![]() |
6f9c176d93 | ||
![]() |
538dfa010d | ||
![]() |
2eb7e96f4b | ||
![]() |
093042b760 | ||
![]() |
434e460c18 | ||
![]() |
65474c621c |
6
.github/FUNDING.yml
vendored
@@ -1,8 +1,8 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: raylib
|
||||
github: raysan5
|
||||
patreon: # raylib
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: raysan
|
||||
ko_fi: # raysan
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
custom: # Replace with a single custom sponsorship URL
|
||||
|
30
.github/workflows/cd_src_release.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
name: CD - Source Build & Release - Linux
|
||||
|
||||
# Trigger the workflow on release publish
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@master
|
||||
|
||||
# TODO: Build project and zip generated files
|
||||
- name: Build project
|
||||
id: build_project
|
||||
run: |
|
||||
zip raylib.zip README.md
|
||||
|
||||
- name: Upload Release Asset
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1.0.1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
|
||||
asset_path: ./raylib.zip
|
||||
asset_name: raylib.zip
|
||||
asset_content_type: application/zip
|
18
.github/workflows/ci_src_examples_linux.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
name: CI - Source & Examples - Linux
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@master
|
||||
- name: apt-update
|
||||
run: sudo apt-get update -qq
|
||||
- name: apt get glfw
|
||||
run: sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev
|
||||
- name: make src
|
||||
run: cd src && make PLATFORM=PLATFORM_DESKTOP
|
||||
- name: make examples
|
||||
run: cd examples && make PLATFORM=PLATFORM_DESKTOP
|
13
.github/workflows/ci_src_examples_macos.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
name: CI - Source & Examples - macOS
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: make src
|
||||
run: cd src && make PLATFORM=PLATFORM_DESKTOP
|
||||
- name: make examples
|
||||
run: cd examples && make PLATFORM=PLATFORM_DESKTOP
|
64
.github/workflows/ci_src_examples_win.yml
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
name: CI - Source & Examples - Windows
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
compiler: [mingw, msvc16]
|
||||
bits: [32, 64]
|
||||
include:
|
||||
- compiler: mingw
|
||||
bits: 32
|
||||
CFLAGS: -m32
|
||||
GENERATOR: "MinGW Makefiles"
|
||||
- compiler: mingw
|
||||
bits: 64
|
||||
CFLAGS: -m64
|
||||
GENERATOR: "MinGW Makefiles"
|
||||
- compiler: msvc16
|
||||
bits: 32
|
||||
GENERATOR: "Visual Studio 16 2019"
|
||||
ARCH: "-A Win32"
|
||||
- compiler: msvc16
|
||||
bits: 64
|
||||
GENERATOR: "Visual Studio 16 2019"
|
||||
ARCH: "-A x64"
|
||||
|
||||
env:
|
||||
CFLAGS: ${{ matrix.CFLAGS }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: Setup Environment
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
# Trying to solve an issue with CMake and Chocolatey for MinGW
|
||||
- run: cmake -E remove c:\ProgramData\chocolatey\bin\cpack.exe
|
||||
if: matrix.compiler == 'mingw'
|
||||
|
||||
# Setup MSBuild.exe path if required
|
||||
- uses: warrenbuckley/Setup-MSBuild@v1
|
||||
if: matrix.compiler == 'msvc16'
|
||||
|
||||
- name: Build MinGW Project
|
||||
run: |
|
||||
cd ../raylib/src
|
||||
make PLATFORM=PLATFORM_DESKTOP CC=gcc
|
||||
if: matrix.compiler == 'mingw'
|
||||
|
||||
- name: Setup CMake Project
|
||||
run: cmake -G "${{ matrix.GENERATOR }}" ${{ matrix.ARCH }} -DCMAKE_SH="CMAKE_SH-NOTFOUND" -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=ON -DBUILD_GAMES=OFF -DINCLUDE_EVERYTHING=ON ../raylib
|
||||
if: matrix.compiler == 'msvc16'
|
||||
|
||||
- name: Build raylib Source & Examples
|
||||
run: cmake --build . --target install
|
||||
if: matrix.compiler == 'msvc16'
|
2
.gitignore
vendored
@@ -30,6 +30,7 @@ Thumbs.db
|
||||
*.cache
|
||||
*.ilk
|
||||
*.log
|
||||
|
||||
[Bb]in
|
||||
[Dd]ebug/
|
||||
[Dd]ebug.win32/
|
||||
@@ -52,6 +53,7 @@ packages/
|
||||
*.exe
|
||||
*.a
|
||||
*.bc
|
||||
*.so
|
||||
!raylib.rc.o
|
||||
|
||||
# Ignore all examples files
|
||||
|
77
BINDINGS.md
@@ -2,31 +2,62 @@
|
||||
|
||||
Some people ported raylib to other languages in form of bindings or wrappers to the library, here is a list with the ones I'm aware of:
|
||||
|
||||
- [raylib](https://github.com/raysan5/raylib) : raylib **C/C++** version (default)
|
||||
- [raylib-lua](https://github.com/raysan5/raylib-lua) : raylib **Lua** binding
|
||||
- [raylib-lua-ffi](https://github.com/raysan5/raylib/issues/693) : raylib **Lua** ffi binding
|
||||
- [raylib-go](https://github.com/gen2brain/raylib-go) : raylib **Go** binding
|
||||
- [raylib-Nim](https://gitlab.com/define-private-public/raylib-Nim) : raylib **Nim** binding
|
||||
- [raylib-cr](https://github.com/AregevDev/raylib-cr) : raylib **Crystal** binding
|
||||
- [cray](https://gitlab.com/Zatherz/cray) - raylib **Crystal** binding
|
||||
- [Graphics::Raylib](https://metacpan.org/pod/Graphics::Raylib) : raylib **Perl** wrapper
|
||||
- [raylib-pascal](https://github.com/drezgames/raylib-pascal) - raylib **Pascal** binding
|
||||
- [Raylib-cs](https://github.com/ChrisDill/Raylib-cs) : raylib **C#** binding
|
||||
- [RaylibSharp](https://github.com/TheLumaio/RaylibSharp) : raylib **C#** binding
|
||||
- [raylib-ruby-ffi](https://github.com/D3nX/raylib-ruby-ffi) : raylib **Ruby** binding
|
||||
- [raylib-rs](https://github.com/deltaphc/raylib-rs) : raylib **Rust** binding
|
||||
- [raylib-py](https://github.com/overdev/raylib-py) : raylib **Python** binding
|
||||
- [raylib-haskell](https://github.com/DevJac/raylib-haskell) : raylib **Haskell** binding
|
||||
- [raylib-java](https://github.com/XoanaIO/raylib-java) : raylib **Java** binding
|
||||
- [raylib-chaiscript](https://github.com/RobLoach/raylib-chaiscript) : raylib **ChaiScript** binding
|
||||
- [node-raylib](https://github.com/RobLoach/node-raylib) : **Node.js** raylib binding
|
||||
- [raylib-odin](https://github.com/kevinw/raylib-odin): **Odin** raylib binding
|
||||
- [raylib-factor](https://github.com/Silverbeard00/raylib-factor): **Factor** raylib binding
|
||||
- *[raylib COBOL Usage example](https://github.com/Martinfx/Cobol/tree/master/OpenCobol/Games/raylib)*
|
||||
- *raylib flat-assembler Usage example*: not uploaded yet...
|
||||
| name | language | repo |
|
||||
|:------------------:|:--------------:|----------------------------------------------------------------------|
|
||||
| raylib | C | https://github.com/raysan5/raylib |
|
||||
| raylib-cpp | C++ | https://github.com/robloach/raylib-cpp |
|
||||
| Raylib-cs | C# | https://github.com/ChrisDill/Raylib-cs |
|
||||
| RaylibSharp | C# | https://github.com/TheLumaio/RaylibSharp |
|
||||
| RaylibFS | F# | https://github.com/dallinbeutler/RaylibFS |
|
||||
| raylib_d | D | https://github.com/0xFireball/raylib_d |
|
||||
| raylib-d | D | https://github.com/onroundit/raylib-d |
|
||||
| raylib-go | Go | https://github.com/gen2brain/raylib-go |
|
||||
| raylib-goplus | Go | https://github.com/Lachee/raylib-goplus |
|
||||
| raylib-rs | Rust | https://github.com/deltaphc/raylib-rs |
|
||||
| raylib-lua | Lua | https://github.com/raysan5/raylib-lua |
|
||||
| raylib-lua-ffi | Lua | https://github.com/raysan5/raylib/issues/693 |
|
||||
| raylib-lua-sol | Lua | https://github.com/RobLoach/raylib-lua-sol |
|
||||
| raylib-Nim | Nim | https://gitlab.com/define-private-public/raylib-Nim |
|
||||
| raylib-nim | Nim | https://github.com/Skrylar/raylib-nim |
|
||||
| raylib-haskell | Haskell | https://github.com/DevJac/raylib-haskell |
|
||||
| raylib-cr | Crystal | https://github.com/AregevDev/raylib-cr |
|
||||
| cray | Crystal | https://gitlab.com/Zatherz/cray |
|
||||
| cray | Crystal | https://github.com/tapgg/cray |
|
||||
| raylib-pascal | Pascal | https://github.com/drezgames/raylib-pascal |
|
||||
| raylib-pas | Pascal | https://github.com/tazdij/raylib-pas |
|
||||
| Graphics-Raylib | Perl | https://github.com/athreef/Graphics-Raylib |
|
||||
| raylib-ruby-ffi | Ruby | https://github.com/D3nX/raylib-ruby-ffi |
|
||||
| raylib-ruby | Ruby | https://github.com/a0/raylib-ruby |
|
||||
| raylib-mruby | mruby | https://github.com/lihaochen910/raylib-mruby |
|
||||
| raylib-py | Python | https://github.com/overdev/raylib-py |
|
||||
| raylib-python-cffi | Python | https://github.com/electronstudio/raylib-python-cffi |
|
||||
| raylib-java | Java | https://github.com/XoanaIO/raylib-java |
|
||||
| node-raylib | Node.js | https://github.com/RobLoach/node-raylib |
|
||||
| QuickJS-raylib | QuickJS | https://github.com/sntg-p/QuickJS-raylib |
|
||||
| raylib-js | JavaScript | https://github.com/RobLoach/raylib-js |
|
||||
| raylib-chaiscript | ChaiScript | https://github.com/RobLoach/raylib-chaiscript |
|
||||
| raylib-squirrel | Squirrel | https://github.com/RobLoach/raylib-squirrel |
|
||||
| racket-raylib-2d | Racket | https://github.com/arvyy/racket-raylib-2d |
|
||||
| raylib-php | PHP | https://github.com/joseph-montanez/raylib-php |
|
||||
| raylib-php-ffi | PHP | https://github.com/oraoto/raylib-php-ffi |
|
||||
| raylib-phpcpp | PHP | https://github.com/oraoto/raylib-phpcpp |
|
||||
| raylib-factor | Factor | https://github.com/Silverbeard00/raylib-factor |
|
||||
| raylib-haxe | Haxe | https://github.com/ibilon/raylib-haxe |
|
||||
| ringraylib | Ring | https://github.com/ringpackages/ringraylib |
|
||||
| cl-raylib | Common Lisp | https://github.com/longlene/cl-raylib |
|
||||
| raylib-scm | Chicken Scheme | https://github.com/yashrk/raylib-scm |
|
||||
| Euraylib | Euphoria | https://github.com/gAndy50/Euraylib |
|
||||
| raylib-wren | Wren | https://github.com/TSnake41/raylib-wren |
|
||||
| raylib-odin | Odin | https://github.com/kevinw/raylib-odin |
|
||||
| ray.zig | Zig | https://github.com/BitPuffin/zig-raylib-experiments |
|
||||
| raylib-Ada | Ada | https://github.com/mimo/raylib-Ada |
|
||||
| jaylib | Janet | https://github.com/janet-lang/jaylib |
|
||||
| raykit | Kit | https://github.com/Gamerfiend/raykit |
|
||||
| vraylib | V | https://github.com/MajorHard/vraylib |
|
||||
| raylib.cbl | COBOL | *[code examples](https://github.com/Martinfx/Cobol/tree/master/OpenCobol/Games/raylib)* |
|
||||
|
||||
Missing some language? Check the [bindings not yet in this list](https://gist.github.com/raysan5/5764cc5b885183f523fce47f098f3d9b#bindings-not-yet-in-the-official-list) or create a new binding! :)
|
||||
|
||||
|
||||
Usually, raylib bindings follow the convention: `raylib-{language}`
|
||||
|
||||
Let me know if you're writing a new binding for raylib, I will list it here and I usually
|
||||
|
@@ -1,46 +0,0 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ray@raylib.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
@@ -6,26 +6,26 @@ Do you enjoy raylib and want to contribute? Nice! You can help with the followin
|
||||
|
||||
- C programming - Can you write/review/test/improve the code?
|
||||
- Documentation/Tutorials/Example - Can you write some tutorial/example?
|
||||
- Web Development - Can you help [with the web](https://github.com/raysan5/raylib.com)?
|
||||
- Porting to other platforms - Can you port and compile raylib on another systems?
|
||||
- Testing - Can you find some bugs on raylib?
|
||||
- Web Development - Can you help [with the website](https://github.com/raysan5/raylib.com)?
|
||||
- Porting to other platforms - Can you port and compile raylib on other systems?
|
||||
- Testing - Can you find some bugs in raylib?
|
||||
|
||||
This document contains a set of guidelines to contribute to the project. These are mostly guidelines, not rules.
|
||||
Use your best judgement, and feel free to propose changes to this document in a pull-request.
|
||||
Use your best judgement, and feel free to propose changes to this document in a pull request.
|
||||
|
||||
### raylib philosophy
|
||||
|
||||
- raylib is a tool to enjoy videogames programming, every single function in raylib should be a tutorial on itself.
|
||||
- raylib is SIMPLE and EASY-TO-USE, I tried to keep it compact with a small set of functions, if a function is too complex or is not clearly useful, better not to include it.
|
||||
- raylib is open source and free; educators and institutions can use this tool to TEACH videogames programming completely by free.
|
||||
- raylib is collaborative; contribution of tutorials / code-examples / bugs-solving / code-comments are highly appreciated.
|
||||
- raylib is collaborative; contribution of tutorials / code examples / bug fixes / code comments are highly appreciated.
|
||||
- raylib's license (and its external libs respective licenses) allow using it for commercial products.
|
||||
|
||||
### Some interesting reads to start with
|
||||
|
||||
- [raylib history](HISTORY.md)
|
||||
- [raylib architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture)
|
||||
- [raylib license](LICENSE.md)
|
||||
- [raylib license](LICENSE)
|
||||
- [raylib roadmap](ROADMAP.md)
|
||||
|
||||
[raylib Wiki](https://github.com/raysan5/raylib/wiki) contains some information about the library and is open to anyone for edit.
|
||||
@@ -42,7 +42,7 @@ Source code is extensively commented for that purpose, raylib primary learning m
|
||||
|
||||
> learn by reading code and examples
|
||||
|
||||
For detailed information on building raylib and examples, please check [raylib Wiki](https://github.com/raysan5/raylib/wiki).
|
||||
For detailed information on building raylib and examples, please see [raylib Wiki](https://github.com/raysan5/raylib/wiki).
|
||||
|
||||
### Opening new Issues
|
||||
|
||||
@@ -53,13 +53,13 @@ To open new issue for raylib (bug, enhancement, discussion...), just try to foll
|
||||
title and clear description, as much relevant information as possible, and a code sample demonstrating the unexpected behavior.
|
||||
- If applies, attach some screenshot of the issue and a .zip file with the code sample and required resources.
|
||||
- On issue description, add a brackets tag about the raylib module that relates to this issue.
|
||||
If don't know the module, just report the issue, I will review it.
|
||||
If don't know which module, just report the issue, I will review it.
|
||||
- You can check other issues to see how is being done!
|
||||
|
||||
### Sending a Pull-Request
|
||||
|
||||
- Make sure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
|
||||
- Don't send big pull-requests (lots of changelists), they are difficult to review. It's better to send small pull-request, one at a time.
|
||||
- Don't send big pull requests (lots of changelists), they are difficult to review. It's better to send small pull requests, one at a time.
|
||||
- Verify that changes don't break the build (at least on Windows platform). As many platforms where you can test it, the better, but don't worry
|
||||
if you cannot test all the platforms.
|
||||
|
||||
@@ -107,15 +107,13 @@ contributing (in some way or another) to make the raylib project better. Huge th
|
||||
- [Richard Goodwin](https://github.com/AudioMorphology) for adding RPI touchscreen support.
|
||||
- [Milan Nikolic](https://github.com/gen2brain) for adding Android build support with custom standalone toolchain.
|
||||
- [Michael Vetter](https://github.com/jubalh) for improvements on build system and his work on Suse Linux package... and multiple fixes!
|
||||
- [Wilhem Barbier](https://github.com/nounoursheureux) for adding Image generation functions and some fixes.
|
||||
- [Wilhem Barbier](https://github.com/nounoursheureux) for adding Image generation functions, shaders work and some fixes.
|
||||
- [Benjamin Summerton](https://github.com/define-private-public) for improving OSX building and his amazing work on CMake build sytem.
|
||||
- [MartinFX](https://github.com/Martinfx) for adding compilation support for FreeBSD OS and derivatives.
|
||||
- [Wilhem Barbier](https://github.com/nounoursheureux) for supporting default shaders on shader loading, if shader not provided.
|
||||
- [Ahmad Fatoum](https://github.com/a3f) for implementing CI support for raylib (Travis and AppVeyor) and great improvements on build system.
|
||||
- [SamNChiet](https://github.com/SamNChiet) for a greatly improved UWP input implementation.
|
||||
- [David Reid](https://github.com/mackron) for a complete review of audio module to support his amazing miniaudio library.
|
||||
- [Kai](https://github.com/questor) for multiple code reviews and improvements.
|
||||
- [RDR8](https://github.com/RDR8) for improvements on Makefiles for Linux.
|
||||
- [Max Danielsson](https://github.com/autious) for adding support for orthographic 3d camera projection
|
||||
- [Lumaio](https://github.com/TheLumaio) for his great work on GBuffers and GetCollisionRayModel().
|
||||
- [Jonas Daeyaert](https://github.com/culacant) for an amazing work on IQM animated models support.
|
||||
@@ -132,5 +130,7 @@ contributing (in some way or another) to make the raylib project better. Huge th
|
||||
- [Anata](https://github.com/anatagawa) for creating amazing examples and contributing with them
|
||||
- [Narice](https://github.com/narice) made easings.h includable as standalone header
|
||||
- [Eric J.](https://github.com/ProfJski) for shaders_eratosthenes example contribution
|
||||
- [PompPenguin](https://github.com/PompPenguin) for reviewing 3rd person camera
|
||||
- [Mohamed Shazan](https://github.com/msmshazan) for adding support for ANGLE graphics backend
|
||||
|
||||
Please, if I forget someone in this list, excuse me and send a PR!
|
||||
|
16
LICENSE
Normal file
@@ -0,0 +1,16 @@
|
||||
Copyright (c) 2013-2020 Ramon Santamaria (@raysan5)
|
||||
|
||||
This software is provided "as-is", without any express or implied warranty. In no event
|
||||
will the authors be held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
wrote the original software. If you use this software in a product, an acknowledgment
|
||||
in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
51
LICENSE.md
@@ -1,51 +0,0 @@
|
||||
license
|
||||
=======
|
||||
|
||||
source code
|
||||
-----------
|
||||
|
||||
raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||
BSD-like license that allows static linking with closed source software:
|
||||
|
||||
Copyright (c) 2013-2019 Ramon Santamaria (@raysan5)
|
||||
|
||||
This software is provided "as-is", without any express or implied warranty. In no event
|
||||
will the authors be held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
wrote the original software. If you use this software in a product, an acknowledgment
|
||||
in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
fonts
|
||||
------
|
||||
|
||||
The following fonts [provided with raylib](https://github.com/raysan5/raylib/tree/master/examples/text/resources/fonts) are free to use (freeware) and have been designed by the following people:
|
||||
|
||||
* Alpha Beta - Brian Kent (AEnigma)
|
||||
* Setback - Brian Kent (AEnigma)
|
||||
* Jupiter Crash - Brian Kent (AEnigma)
|
||||
* Alagard - Hewett Tsoi
|
||||
* Romulus - Hewett Tsoi
|
||||
* Mecha - Captain Falcon
|
||||
* PixelPlay - Aleksander Shevchuk
|
||||
* PixAntiqua - Gerhard Großmann
|
||||
|
||||
2d art
|
||||
------
|
||||
|
||||
[scarfy spritesheet](https://github.com/raysan5/raylib/blob/master/examples/textures/resources/scarfy.png) and [fudesumi image](https://github.com/raysan5/raylib/blob/master/examples/textures/resources/fudesumi.png) have been created by [Eiden Marsal](https://www.artstation.com/artist/marshall_z) and are licensed as [Creative Commons Attribution-NonCommercial 3.0](https://creativecommons.org/licenses/by-nc/3.0/legalcode)
|
||||
|
||||
[cyberpunk street environments](https://github.com/raysan5/raylib/blob/master/examples/textures/resources) have been created by Luis Zuno ([@ansimuz](https://twitter.com/ansimuz)) and are licensed as [CC-BY-3.0](http://creativecommons.org/licenses/by/3.0/)
|
||||
|
||||
3d models
|
||||
---------
|
||||
|
||||
[medieval city 3d models and textures](https://github.com/raysan5/raylib/tree/master/examples/models/resources/medieval) have been created by Alberto Cano and are licensed as [Creative Commons Attribution-NonCommercial 4.0](https://creativecommons.org/licenses/by-nc/4.0/legalcode)
|
@@ -8,13 +8,16 @@ raylib is highly inspired by Borland BGI graphics lib and by XNA framework and i
|
||||
|
||||
Ready to learn? Jump to [code examples!](http://www.raylib.com/examples.html)
|
||||
|
||||
|
||||
[](https://travis-ci.org/raysan5/raylib)
|
||||
[](https://ci.appveyor.com/project/raysan5/raylib)
|
||||
[](https://discord.gg/VkzNHUE)
|
||||
[](LICENSE.md)
|
||||
[](LICENSE)
|
||||
[](https://twitter.com/raysan5)
|
||||
|
||||
[](https://github.com/raysan5/raylib/actions)
|
||||
[](https://github.com/raysan5/raylib/actions)
|
||||
[](https://github.com/raysan5/raylib/actions)
|
||||
|
||||
features
|
||||
--------
|
||||
- **NO external dependencies**, all required libraries are bundled into raylib
|
||||
|
13
SPONSORS.md
Normal file
@@ -0,0 +1,13 @@
|
||||
The following people has contributed with a generous donation to the raylib project.
|
||||
|
||||
## 🥇 Gold Contributors
|
||||
|
||||
...
|
||||
|
||||
## 🥈 Silver Contributors
|
||||
|
||||
...
|
||||
|
||||
## 🥉 Bronze Contributors
|
||||
|
||||
...
|
@@ -12,12 +12,14 @@
|
||||
# raylib_DEFINITIONS - Compiler switches required for using raylib
|
||||
|
||||
set(XPREFIX PC_RAYLIB)
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(${XPREFIX} QUIET raylib)
|
||||
|
||||
if (raylib_USE_STATIC_LIBS)
|
||||
set(XPREFIX ${XPREFIX}_STATIC)
|
||||
endif()
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(${XPREFIX} QUIET raylib)
|
||||
set(raylib_DEFINITIONS ${${XPREFIX}_CFLAGS})
|
||||
|
||||
find_path(raylib_INCLUDE_DIR
|
||||
@@ -25,17 +27,16 @@ find_path(raylib_INCLUDE_DIR
|
||||
HINTS ${${XPREFIX}_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(RAYLIB_NAMES raylib)
|
||||
|
||||
if (raylib_USE_STATIC_LIBS)
|
||||
find_library(raylib_LIBRARY
|
||||
NAMES raylib_static
|
||||
HINTS ${${XPREFIX}_LIBRARY_DIRS}
|
||||
)
|
||||
else ()
|
||||
find_library(raylib_LIBRARY
|
||||
NAMES raylib
|
||||
HINTS ${${XPREFIX}_LIBRARY_DIRS}
|
||||
)
|
||||
endif ()
|
||||
set(RAYLIB_NAMES libraylib.a raylib.lib ${RAYLIB_NAMES})
|
||||
endif()
|
||||
|
||||
find_library(raylib_LIBRARY
|
||||
NAMES ${RAYLIB_NAMES}
|
||||
HINTS ${${XPREFIX}_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
set(raylib_LIBRARIES ${raylib_LIBRARY})
|
||||
set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS})
|
||||
|
@@ -67,6 +67,8 @@ if(${PLATFORM} MATCHES "Android")
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_heightmap.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_billboard.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_rlgl_solar_system.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_rlgl_full_solar_system.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_solar_system.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_obj_viewer.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_animation.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_first_person_maze.c)
|
||||
@@ -76,15 +78,19 @@ if(${PLATFORM} MATCHES "Android")
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_postprocessing.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_raymarching.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_palette_switch.c)
|
||||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_basic_lighting.c)
|
||||
|
||||
elseif(${PLATFORM} MATCHES "Web")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1")
|
||||
# Since WASM is used, ALLOW_MEMORY_GROWTH has no extra overheads
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 --no-heap-copy")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --shell-file ${CMAKE_SOURCE_DIR}/src/shell.html")
|
||||
|
||||
set(OUTPUT_EXT ".html")
|
||||
|
||||
# Remove the -rdynamic flag because otherwise emscripten
|
||||
# does not generate HTML+JS+WASM files, only a non-working
|
||||
# and fat HTML
|
||||
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
|
||||
endif()
|
||||
|
||||
include_directories(BEFORE SYSTEM others/external/include)
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
|
||||
#
|
||||
# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5)
|
||||
# Copyright (c) 2013-2020 Ramon Santamaria (@raysan5)
|
||||
#
|
||||
# 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.
|
||||
@@ -115,13 +115,12 @@ endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Emscripten required variables
|
||||
EMSDK_PATH ?= C:/emsdk
|
||||
EMSCRIPTEN_VERSION ?= 1.38.31
|
||||
CLANG_VERSION = e$(EMSCRIPTEN_VERSION)_64bit
|
||||
PYTHON_VERSION = 2.7.13.1_64bit\python-2.7.13.amd64
|
||||
NODE_VERSION = 8.9.1_64bit
|
||||
export PATH = $(EMSDK_PATH);$(EMSDK_PATH)\clang\$(CLANG_VERSION);$(EMSDK_PATH)\node\$(NODE_VERSION)\bin;$(EMSDK_PATH)\python\$(PYTHON_VERSION);$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION);C:\raylib\MinGW\bin:$$(PATH)
|
||||
EMSCRIPTEN = $(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION)
|
||||
EMSDK_PATH ?= C:/emsdk
|
||||
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/fastcomp/emscripten
|
||||
CLANG_PATH = $(EMSDK_PATH)/fastcomp/bin
|
||||
PYTHON_PATH = $(EMSDK_PATH)/python/2.7.13.1_64bit/python-2.7.13.amd64
|
||||
NODE_PATH = $(EMSDK_PATH)/node/12.9.1_64bit/bin
|
||||
export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:\raylib\MinGW\bin:$$(PATH)
|
||||
endif
|
||||
|
||||
# Define raylib release directory for compiled library.
|
||||
@@ -165,7 +164,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# HTML5 emscripten compiler
|
||||
# WARNING: To compile to HTML5, code must be redesigned
|
||||
# WARNING: To compile to HTML5, code must be redesigned
|
||||
# to use emscripten.h and emscripten_set_main_loop()
|
||||
CC = emcc
|
||||
endif
|
||||
@@ -188,10 +187,19 @@ endif
|
||||
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
||||
# -Wno-missing-braces ignore invalid warning (GCC bug 53119)
|
||||
# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
|
||||
CFLAGS += -O1 -s -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
|
||||
CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
|
||||
|
||||
ifeq ($(BUILD_MODE),DEBUG)
|
||||
CFLAGS += -g
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -s ASSERTIONS=1 --profiling
|
||||
endif
|
||||
else
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -Os
|
||||
else
|
||||
CFLAGS += -s -O1
|
||||
endif
|
||||
endif
|
||||
|
||||
# Additional flags for compiler (if desired)
|
||||
@@ -200,7 +208,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# resource file contains windows executable icon and properties
|
||||
# -Wl,--subsystem,windows hides the console window
|
||||
CFLAGS += $(RAYLIB_PATH)/raylib.rc.data -Wl,--subsystem,windows
|
||||
CFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data -Wl,--subsystem,windows
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
ifeq ($(RAYLIB_LIBTYPE),STATIC)
|
||||
@@ -230,17 +238,15 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# --profiling # include information for code profiling
|
||||
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
|
||||
# --preload-file resources # specify a resources folder for data compilation
|
||||
CFLAGS += -Os -s USE_GLFW=3 -s FORCE_FILESYSTEM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 --preload-file $(dir $<)resources@resources
|
||||
ifeq ($(BUILD_MODE), DEBUG)
|
||||
CFLAGS += -s ASSERTIONS=1 --profiling
|
||||
endif
|
||||
CFLAGS += -s USE_GLFW=3 -s FORCE_FILESYSTEM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 --preload-file $(dir $<)resources@resources
|
||||
|
||||
# NOTE: Simple raylib examples are compiled to be interpreter by emterpreter, that way,
|
||||
# we can compile same code for ALL platforms with no change required, but, working on bigger
|
||||
# projects, code needs to be refactored to avoid a blocking while() loop, moving Update and Draw
|
||||
# logic to a self contained function: UpdateDrawFrame(), check core_basic_window_web.c for reference.
|
||||
|
||||
# Define a custom shell .html and output extension
|
||||
CFLAGS += --shell-file $(RAYLIB_PATH)\src\shell.html
|
||||
CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
|
||||
EXT = .html
|
||||
endif
|
||||
|
||||
@@ -300,12 +306,12 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
# Libraries for Debian GNU/Linux desktop compiling
|
||||
# NOTE: Required packages: libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
|
||||
|
||||
|
||||
# On X11 requires also below libraries
|
||||
LDLIBS += -lX11
|
||||
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
||||
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
|
||||
|
||||
# On Wayland windowing system, additional libraries requires
|
||||
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
||||
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
||||
@@ -318,7 +324,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# Libraries for OSX 10.9 desktop compiling
|
||||
# NOTE: Required packages: libopenal-dev libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa
|
||||
LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling
|
||||
@@ -343,8 +349,8 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc
|
||||
endif
|
||||
|
||||
# Define all source files required
|
||||
EXAMPLES = \
|
||||
# Define all object files required
|
||||
CORE = \
|
||||
core/core_basic_window \
|
||||
core/core_input_keys \
|
||||
core/core_input_mouse \
|
||||
@@ -353,6 +359,7 @@ EXAMPLES = \
|
||||
core/core_input_multitouch \
|
||||
core/core_input_gestures \
|
||||
core/core_2d_camera \
|
||||
core/core_2d_camera_platformer \
|
||||
core/core_3d_camera_mode \
|
||||
core/core_3d_camera_free \
|
||||
core/core_3d_camera_first_person \
|
||||
@@ -362,9 +369,12 @@ EXAMPLES = \
|
||||
core/core_window_letterbox \
|
||||
core/core_drop_files \
|
||||
core/core_random_values \
|
||||
core/core_scissor_test \
|
||||
core/core_storage_values \
|
||||
core/core_vr_simulator \
|
||||
core/core_loading_thread \
|
||||
core/core_loading_thread
|
||||
|
||||
SHAPES = \
|
||||
shapes/shapes_basic_shapes \
|
||||
shapes/shapes_bouncing_ball \
|
||||
shapes/shapes_colors_palette \
|
||||
@@ -379,18 +389,11 @@ EXAMPLES = \
|
||||
shapes/shapes_easings_rectangle_array \
|
||||
shapes/shapes_draw_ring \
|
||||
shapes/shapes_draw_circle_sector \
|
||||
shapes/shapes_draw_rectangle_rounded \
|
||||
text/text_raylib_fonts \
|
||||
text/text_sprite_fonts \
|
||||
text/text_ttf_loading \
|
||||
text/text_bmfont_ttf \
|
||||
text/text_font_sdf \
|
||||
text/text_format_text \
|
||||
text/text_input_box \
|
||||
text/text_writing_anim \
|
||||
text/text_rectangle_bounds \
|
||||
text/text_unicode \
|
||||
shapes/shapes_draw_rectangle_rounded
|
||||
|
||||
TEXTURES = \
|
||||
textures/textures_logo_raylib \
|
||||
textures/textures_mouse_painting \
|
||||
textures/textures_rectangle \
|
||||
textures/textures_srcrec_dstrec \
|
||||
textures/textures_image_drawing \
|
||||
@@ -405,7 +408,21 @@ EXAMPLES = \
|
||||
textures/textures_background_scrolling \
|
||||
textures/textures_sprite_button \
|
||||
textures/textures_sprite_explosion \
|
||||
textures/textures_bunnymark \
|
||||
textures/textures_bunnymark
|
||||
|
||||
TEXT = \
|
||||
text/text_raylib_fonts \
|
||||
text/text_font_spritefont \
|
||||
text/text_font_loading \
|
||||
text/text_font_filters \
|
||||
text/text_font_sdf \
|
||||
text/text_format_text \
|
||||
text/text_input_box \
|
||||
text/text_writing_anim \
|
||||
text/text_rectangle_bounds \
|
||||
text/text_unicode
|
||||
|
||||
MODELS = \
|
||||
models/models_animation \
|
||||
models/models_billboard \
|
||||
models/models_box_collisions \
|
||||
@@ -415,13 +432,15 @@ EXAMPLES = \
|
||||
models/models_material_pbr \
|
||||
models/models_mesh_generation \
|
||||
models/models_mesh_picking \
|
||||
models/models_obj_loading \
|
||||
models/models_obj_viewer \
|
||||
models/models_loading \
|
||||
models/models_orthographic_projection \
|
||||
models/models_rlgl_solar_system \
|
||||
models/models_skybox \
|
||||
models/models_yaw_pitch_roll \
|
||||
models/models_heightmap \
|
||||
models/models_waving_cubes
|
||||
|
||||
SHADERS = \
|
||||
shaders/shaders_model_shader \
|
||||
shaders/shaders_shapes_textures \
|
||||
shaders/shaders_custom_uniform \
|
||||
@@ -432,21 +451,38 @@ EXAMPLES = \
|
||||
shaders/shaders_texture_waves \
|
||||
shaders/shaders_julia_set \
|
||||
shaders/shaders_eratosthenes \
|
||||
shaders/shaders_basic_lighting \
|
||||
shaders/shaders_fog \
|
||||
shaders/shaders_simple_mask
|
||||
|
||||
AUDIO = \
|
||||
audio/audio_module_playing \
|
||||
audio/audio_music_stream \
|
||||
audio/audio_raw_stream \
|
||||
audio/audio_sound_loading \
|
||||
physac/physics_demo \
|
||||
physac/physics_friction \
|
||||
physac/physics_movement \
|
||||
physac/physics_restitution \
|
||||
physac/physics_shatter
|
||||
audio/audio_multichannel_sound
|
||||
|
||||
PHYSICS = \
|
||||
physics/physics_demo \
|
||||
physics/physics_friction \
|
||||
physics/physics_movement \
|
||||
physics/physics_restitution \
|
||||
physics/physics_shatter
|
||||
|
||||
|
||||
CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST))
|
||||
|
||||
# Default target entry
|
||||
all: $(EXAMPLES)
|
||||
all: $(CORE) $(SHAPES) $(TEXT) $(TEXTURES) $(MODELS) $(SHADERS) $(AUDIO) $(PHYSICS)
|
||||
|
||||
core: $(CORE)
|
||||
shapes: $(SHAPES)
|
||||
text: $(TEXT)
|
||||
textures: $(TEXTURES)
|
||||
models: $(MODELS)
|
||||
shaders: $(SHADERS)
|
||||
audio: $(AUDIO)
|
||||
physics: $(PHYSICS)
|
||||
|
||||
# Generic compilation pattern
|
||||
# NOTE: Examples must be ready for Android compilation!
|
||||
@@ -464,7 +500,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
del *.o *.exe /s
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv
|
||||
find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable|x-pie-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
find . -type f -perm +ugo+x -delete
|
||||
|
191
examples/README.md
Normal file
@@ -0,0 +1,191 @@
|
||||
## EXAMPLES LIST
|
||||
|
||||
### category: core
|
||||
|
||||
Examples using raylib core platform functionality like window creation, inputs, drawing modes and system functionality.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 01 | [core_basic_window](core/core_basic_window.c) | <img src="core/core_basic_window.png" alt="core_basic_window" width="200"> | ray | |
|
||||
| 02 | [core_input_keys](core/core_input_keys.c) | <img src="core/core_input_keys.png" alt="core_input_keys" width="200"> | ray | |
|
||||
| 03 | [core_input_mouse](core/core_input_mouse.c) | <img src="core/core_input_mouse.png" alt="core_input_mouse" width="200"> | ray | |
|
||||
| 04 | [core_input_mouse_wheel](core/core_input_mouse_wheel.c) | <img src="core/core_input_mouse_wheel.png" alt="core_input_mouse_wheel" width="200"> | ray | |
|
||||
| 05 | [core_input_gamepad](core/core_input_gamepad.c) | <img src="core/core_input_gamepad.png" alt="core_input_gamepad" width="200"> | ray | |
|
||||
| 06 | [core_input_multitouch](core/core_input_multitouch.c) | <img src="core/core_input_multitouch.png" alt="core_input_multitouch" width="200"> | [Berni](https://github.com/Berni8k) | |
|
||||
| 07 | [core_input_gestures](core/core_input_gestures.c) | <img src="core/core_input_gestures.png" alt="core_input_gestures" width="200"> | ray | |
|
||||
| 08 | [core_2d_camera](core/core_2d_camera.c) | <img src="core/core_2d_camera.png" alt="core_2d_camera" width="200"> | ray | |
|
||||
| 09 | [core_2d_camera_platformer](core/core_2d_camera_platformer.c) | <img src="core/core_2d_camera_platformer.png" alt="core_2d_camera_platformer" width="200"> | [avyy](https://github.com/avyy) | ⭐️ |
|
||||
| 10 | [core_3d_camera_mode](core/core_3d_camera_mode.c) | <img src="core/core_3d_camera_mode.png" alt="core_3d_camera_mode" width="200"> | ray | |
|
||||
| 11 | [core_3d_camera_free](core/core_3d_camera_free.c) | <img src="core/core_3d_camera_free.png" alt="core_3d_camera_free" width="200"> | ray | |
|
||||
| 12 | [core_3d_camera_first_person](core/core_3d_camera_first_person.c) | <img src="core/core_3d_camera_first_person.png" alt="core_3d_camera_first_person" width="200"> | ray | |
|
||||
| 13 | [core_3d_picking](core/core_3d_picking.c) | <img src="core/core_3d_picking.png" alt="core_3d_picking" width="200"> | ray | |
|
||||
| 14 | [core_world_screen](core/core_world_screen.c) | <img src="core/core_world_screen.png" alt="core_world_screen" width="200"> | ray | |
|
||||
| 15 | [core_custom_logging](core/core_custom_logging.c) | <img src="core/core_custom_logging.png" alt="core_custom_logging" width="200"> | [Pablo Marcos](https://github.com/pamarcos) | |
|
||||
| 16 | [core_window_letterbox](core/core_window_letterbox.c) | <img src="core/core_window_letterbox.png" alt="core_window_letterbox" width="200"> | [Anata](https://github.com/anatagawa) | |
|
||||
| 17 | [core_drop_files](core/core_drop_files.c) | <img src="core/core_drop_files.png" alt="core_drop_files" width="200"> | ray | |
|
||||
| 18 | [core_random_values](core/core_random_values.c) | <img src="core/core_random_values.png" alt="core_random_values" width="200"> | ray | |
|
||||
| 19 | [core_storage_values](core/core_storage_values.c) | <img src="core/core_storage_values.png" alt="core_storage_values" width="200"> | ray | |
|
||||
| 20 | [core_vr_simulator](core/core_vr_simulator.c) | <img src="core/core_vr_simulator.png" alt="core_vr_simulator" width="200"> | ray | |
|
||||
| 21 | [core_loading_thread](core/core_loading_thread.c) | <img src="core/core_loading_thread.png" alt="core_loading_thread" width="200"> | ray | ⭐️ |
|
||||
| 22 | [core_scissor_test](core/core_scissor_test.c) | <img src="core/core_scissor_test.png" alt="core_scissor_test" width="200"> | [Chris Dill](https://github.com/MysteriousSpace) | ⭐️ |
|
||||
|
||||
### category: shapes
|
||||
|
||||
Examples using raylib shapes drawing functionality, provided by raylib [shapes](../src/shapes.c) module.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 23 | [shapes_basic_shapes](shapes/shapes_basic_shapes.c) | <img src="shapes/shapes_basic_shapes.png" alt="shapes_basic_shapes" width="200"> | ray | |
|
||||
| 24 | [shapes_bouncing_ball](shapes/shapes_bouncing_ball.c) | <img src="shapes/shapes_bouncing_ball.png" alt="shapes_bouncing_ball" width="200"> | ray | ⭐️ |
|
||||
| 25 | [shapes_colors_palette](shapes/shapes_colors_palette.c) | <img src="shapes/shapes_colors_palette.png" alt="shapes_colors_palette" width="200"> | ray | |
|
||||
| 26 | [shapes_logo_raylib](shapes/shapes_logo_raylib.c) | <img src="shapes/shapes_logo_raylib.png" alt="shapes_logo_raylib" width="200"> | ray | |
|
||||
| 27 | [shapes_logo_raylib_anim](shapes/shapes_logo_raylib_anim.c) | <img src="shapes/shapes_logo_raylib_anim.png" alt="shapes_logo_raylib_anim" width="200"> | ray | |
|
||||
| 28 | [shapes_rectangle_scaling](shapes/shapes_rectangle_scaling.c) | <img src="shapes/shapes_rectangle_scaling.png" alt="shapes_rectangle_scaling" width="200"> | [Vlad Adrian](https://github.com/demizdor) | |
|
||||
| 29 | [shapes_lines_bezier](shapes/shapes_lines_bezier.c) | <img src="shapes/shapes_lines_bezier.png" alt="shapes_lines_bezier" width="200"> | ray | |
|
||||
| 30 | [shapes_collision_area](shapes/shapes_collision_area.c) | <img src="shapes/shapes_collision_area.png" alt="shapes_collision_area" width="200"> | ray | ⭐️ |
|
||||
| 31 | [shapes_following_eyes](shapes/shapes_following_eyes.c) | <img src="shapes/shapes_following_eyes.png" alt="shapes_following_eyes" width="200"> | ray | ⭐️ |
|
||||
| 32 | [shapes_easings_ball_anim](shapes/shapes_easings_ball_anim.c) | <img src="shapes/shapes_easings_ball_anim.png" alt="shapes_easings_ball_anim" width="200"> | ray | ⭐️ |
|
||||
| 33 | [shapes_easings_box_anim](shapes/shapes_easings_box_anim.c) | <img src="shapes/shapes_easings_box_anim.png" alt="shapes_easings_box_anim" width="200"> | ray | ⭐️ |
|
||||
| 34 | [shapes_easings_rectangle_array](shapes/shapes_easings_rectangle_array.c) | <img src="shapes/shapes_easings_rectangle_array.png" alt="shapes_easings_rectangle_array" width="200"> | ray | ⭐️ |
|
||||
| 35 | [shapes_draw_ring](shapes/shapes_draw_ring.c) | <img src="shapes/shapes_draw_ring.png" alt="shapes_draw_ring" width="200"> | [Vlad Adrian](https://github.com/demizdor) | ⭐️ |
|
||||
| 36 | [shapes_draw_circle_sector](shapes/shapes_draw_circle_sector.c) | <img src="shapes/shapes_draw_circle_sector.png" alt="shapes_draw_circle_sector" width="200"> | [Vlad Adrian](https://github.com/demizdor) | |
|
||||
| 37 | [shapes_draw_rectangle_rounded](shapes/shapes_draw_rectangle_rounded.c) | <img src="shapes/shapes_draw_rectangle_rounded.png" alt="shapes_draw_rectangle_rounded" width="200"> | [Vlad Adrian](https://github.com/demizdor) | |
|
||||
|
||||
### category: text
|
||||
|
||||
Examples using raylib text functionality, including sprite fonts loading/generation and text drawing, provided by raylib [text](../src/text.c) module.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 38 | [text_raylib_fonts](text/text_raylib_fonts.c) | <img src="text/text_raylib_fonts.png" alt="text_raylib_fonts" width="200"> | ray | |
|
||||
| 39 | [text_font_spritefont](text/text_font_spritefont.c) | <img src="text/text_font_spritefont.png" alt="text_font_spritefont" width="200"> | ray | |
|
||||
| 40 | [text_font_filters](text/text_font_filters.c) | <img src="text/text_font_filters.png" alt="text_font_filters" width="200"> | ray | |
|
||||
| 41 | [text_font_loading](text/text_font_loading.c) | <img src="text/text_font_loading.png" alt="text_font_loading" width="200"> | ray | |
|
||||
| 42 | [text_font_sdf](text/text_font_sdf.c) | <img src="text/text_font_sdf.png" alt="text_font_sdf" width="200"> | ray | ⭐️ |
|
||||
| 43 | [text_format_text](text/text_format_text.c) | <img src="text/text_format_text.png" alt="text_format_text" width="200"> | ray | |
|
||||
| 44 | [text_input_box](text/text_input_box.c) | <img src="text/text_input_box.png" alt="text_input_box" width="200"> | ray | |
|
||||
| 45 | [text_writing_anim](text/text_writing_anim.c) | <img src="text/text_writing_anim.png" alt="text_writing_anim" width="200"> | ray | |
|
||||
| 46 | [text_rectangle_bounds](text/text_rectangle_bounds.c) | <img src="text/text_rectangle_bounds.png" alt="text_rectangle_bounds" width="200"> | [Vlad Adrian](https://github.com/demizdor) | |
|
||||
| 47 | [text_unicode](text/text_unicode.c) | <img src="text/text_unicode.png" alt="text_unicode" width="200"> | [Vlad Adrian](https://github.com/demizdor) | |
|
||||
|
||||
### category: textures
|
||||
|
||||
Examples using raylib textures functionality, including image/textures loading/generation and drawing, provided by raylib [textures](../src/textures.c) module.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 48 | [textures_logo_raylib](textures/textures_logo_raylib.c) | <img src="textures/textures_logo_raylib.png" alt="textures_logo_raylib" width="200"> | ray | |
|
||||
| 49 | [textures_rectangle](textures/textures_rectangle.c) | <img src="textures/textures_rectangle.png" alt="textures_rectangle" width="200"> | ray | |
|
||||
| 50 | [textures_srcrec_dstrec](textures/textures_srcrec_dstrec.c) | <img src="textures/textures_srcrec_dstrec.png" alt="textures_srcrec_dstrec" width="200"> | ray | |
|
||||
| 51 | [textures_image_drawing](textures/textures_image_drawing.c) | <img src="textures/textures_image_drawing.png" alt="textures_image_drawing" width="200"> | ray | |
|
||||
| 52 | [textures_image_generation](textures/textures_image_generation.c) | <img src="textures/textures_image_generation.png" alt="textures_image_generation" width="200"> | ray | |
|
||||
| 53 | [textures_image_loading](textures/textures_image_loading.c) | <img src="textures/textures_image_loading.png" alt="textures_image_loading" width="200"> | ray | |
|
||||
| 54 | [textures_image_processing](textures/textures_image_processing.c) | <img src="textures/textures_image_processing.png" alt="textures_image_processing" width="200"> | ray | |
|
||||
| 55 | [textures_image_text](textures/textures_image_text.c) | <img src="textures/textures_image_text.png" alt="textures_image_text" width="200"> | ray | ⭐️ |
|
||||
| 56 | [textures_to_image](textures/textures_to_image.c) | <img src="textures/textures_to_image.png" alt="textures_to_image" width="200"> | ray | |
|
||||
| 57 | [textures_raw_data](textures/textures_raw_data.c) | <img src="textures/textures_raw_data.png" alt="textures_raw_data" width="200"> | ray | |
|
||||
| 58 | [textures_particles_blending](textures/textures_particles_blending.c) | <img src="textures/textures_particles_blending.png" alt="textures_particles_blending" width="200"> | ray | |
|
||||
| 59 | [textures_npatch_drawing](textures/textures_npatch_drawing.c) | <img src="textures/textures_npatch_drawing.png" alt="textures_npatch_drawing" width="200"> | [Jorge A. Gomes](https://github.com/overdev) | |
|
||||
| 60 | [textures_background_scrolling](textures/textures_background_scrolling.c) | <img src="textures/textures_background_scrolling.png" alt="textures_background_scrolling" width="200"> | ray | ⭐️ |
|
||||
| 61 | [textures_sprite_button](textures/textures_sprite_button.c) | <img src="textures/textures_sprite_button.png" alt="textures_sprite_button" width="200"> | ray | ⭐️ |
|
||||
| 62 | [textures_sprite_explosion](textures/textures_sprite_explosion.c) | <img src="textures/textures_sprite_explosion.png" alt="textures_sprite_explosion" width="200"> | ray | ⭐️ |
|
||||
| 63 | [textures_bunnymark](textures/textures_bunnymark.c) | <img src="textures/textures_bunnymark.png" alt="textures_bunnymark" width="200"> | ray | ⭐️ |
|
||||
| 64 | [textures_mouse_painting](textures/textures_mouse_painting.c) | <img src="textures/textures_mouse_painting.png" alt="textures_mouse_painting" width="200"> | [Chris Dill](https://github.com/MysteriousSpace) | ⭐️ |
|
||||
|
||||
### category: models
|
||||
|
||||
Examples using raylib models functionality, including models loading/generation and drawing, provided by raylib [models](../src/models.c) module.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 65 | [models_animation](models/models_animation.c) | <img src="models/models_animation.png" alt="models_animation" width="200"> | [culacant](https://github.com/culacant) | ⭐️ |
|
||||
| 66 | [models_billboard](models/models_billboard.c) | <img src="models/models_billboard.png" alt="models_billboard" width="200"> | ray | |
|
||||
| 67 | [models_box_collisions](models/models_box_collisions.c) | <img src="models/models_box_collisions.png" alt="models_box_collisions" width="200"> | ray | |
|
||||
| 68 | [models_cubicmap](models/models_cubicmap.c) | <img src="models/models_cubicmap.png" alt="models_cubicmap" width="200"> | ray | |
|
||||
| 69 | [models_first_person_maze](models/models_first_person_maze.c) | <img src="models/models_first_person_maze.png" alt="models_first_person_maze" width="200"> | ray | ⭐️ |
|
||||
| 70 | [models_geometric_shapes](models/models_geometric_shapes.c) | <img src="models/models_geometric_shapes.png" alt="models_geometric_shapes" width="200"> | ray | |
|
||||
| 71 | [models_material_pbr](models/models_material_pbr.c) | <img src="models/models_material_pbr.png" alt="models_material_pbr" width="200"> | ray | |
|
||||
| 72 | [models_mesh_generation](models/models_mesh_generation.c) | <img src="models/models_mesh_generation.png" alt="models_mesh_generation" width="200"> | ray | |
|
||||
| 73 | [models_mesh_picking](models/models_mesh_picking.c) | <img src="models/models_mesh_picking.png" alt="models_mesh_picking" width="200"> | [Joel Davis](https://github.com/joeld42) | |
|
||||
| 74 | [models_loading](models/models_loading.c) | <img src="models/models_loading.png" alt="models_loading" width="200"> | ray | |
|
||||
| 75 | [models_orthographic_projection](models/models_orthographic_projection.c) | <img src="models/models_orthographic_projection.png" alt="models_orthographic_projection" width="200"> | [Max Danielsson](https://github.com/autious) | |
|
||||
| 76 | *TODO* | *TODO* | *TODO* | |
|
||||
| 77 | *TODO* | *TODO* | *TODO* | |
|
||||
| 78 | [models_solar_system_rlgl](models/models_rlgl_solar_system.c) | <img src="models/models_rlgl_solar_system.png" alt="models_rlgl_solar_system" width="200"> | ray | ⭐️ |
|
||||
| 79 | [models_yaw_pitch_roll](models/models_yaw_pitch_roll.c) | <img src="models/models_yaw_pitch_roll.png" alt="models_yaw_pitch_roll" width="200"> | [Berni](https://github.com/Berni8k) | |
|
||||
| 80 | [models_waving_cubes](models/models_waving_cubes.c) | <img src="models/models_waving_cubes.png" alt="models_waving_cubes" width="200"> | [codecat](https://github.com/codecat) | ⭐️ |
|
||||
| 81 | [models_heightmap](models/models_heightmap.c) | <img src="models/models_heightmap.png" alt="models_heightmap" width="200"> | ray | |
|
||||
| 82 | [models_skybox](models/models_skybox.c) | <img src="models/models_skybox.png" alt="models_skybox" width="200"> | ray | |
|
||||
|
||||
### category: shaders
|
||||
|
||||
Examples using raylib shaders functionality, including shaders loading, parameters configuration and drawing using them (model shaders and postprocessing shaders). This functionality is directly provided by raylib [rlgl](../src/rlgl.c) module.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 83 | [shaders_basic_lighting](shaders/shaders_basic_lighting.c) | <img src="shaders/shaders_basic_lighting.png" alt="shaders_basic_lighting" width="200"> | [Chris Camacho](https://github.com/codifies) | ⭐️ |
|
||||
| 84 | [shaders_model_shader](shaders/shaders_model_shader.c) | <img src="shaders/shaders_model_shader.png" alt="shaders_model_shader" width="200"> | ray | |
|
||||
| 85 | [shaders_shapes_textures](shaders/shaders_shapes_textures.c) | <img src="shaders/shaders_shapes_textures.png" alt="shaders_shapes_textures" width="200"> | ray | |
|
||||
| 86 | [shaders_custom_uniform](shaders/shaders_custom_uniform.c) | <img src="shaders/shaders_custom_uniform.png" alt="shaders_custom_uniform" width="200"> | ray | |
|
||||
| 87 | [shaders_postprocessing](shaders/shaders_postprocessing.c) | <img src="shaders/shaders_postprocessing.png" alt="shaders_postprocessing" width="200"> | ray | |
|
||||
| 88 | [shaders_palette_switch](shaders/shaders_palette_switch.c) | <img src="shaders/shaders_palette_switch.png" alt="shaders_palette_switch" width="200"> | [Marco Lizza](https://github.com/MarcoLizza) | |
|
||||
| 89 | [shaders_raymarching](shaders/shaders_raymarching.c) | <img src="shaders/shaders_raymarching.png" alt="shaders_raymarching" width="200"> | Shader by Iñigo Quilez | ⭐️ |
|
||||
| 90 | [shaders_texture_drawing](shaders/shaders_texture_drawing.c) | <img src="shaders/shaders_texture_drawing.png" alt="shaders_texture_drawing" width="200"> | Michał Ciesielski | ⭐️ |
|
||||
| 91 | [shaders_texture_waves](shaders/shaders_texture_waves.c) | <img src="shaders/shaders_texture_waves.png" alt="shaders_texture_waves" width="200"> | [Anata](https://github.com/anatagawa) | ⭐️ |
|
||||
| 92 | [shaders_julia_set](shaders/shaders_julia_set.c) | <img src="shaders/shaders_julia_set.png" alt="shaders_julia_set" width="200"> | [eggmund](https://github.com/eggmund) | ⭐️ |
|
||||
| 93 | [shaders_eratosthenes](shaders/shaders_eratosthenes.c) | <img src="shaders/shaders_eratosthenes.png" alt="shaders_eratosthenes" width="200"> | [ProfJski](https://github.com/ProfJski) | ⭐️ |
|
||||
| 94 | [shaders_fog](shaders/shaders_fog.c) | <img src="shaders/shaders_fog.png" alt="shaders_fog" width="200"> | [Chris Camacho](https://github.com/codifies) | ⭐️ |
|
||||
| 95 | [shaders_simple_mask](shaders/shaders_simple_mask.c) | <img src="shaders/shaders_simple_mask.png" alt="shaders_simple_mask" width="200"> | [Chris Camacho](https://github.com/codifies) | ⭐️ |
|
||||
|
||||
### category: audio
|
||||
|
||||
Examples using raylib audio functionality, including sound/music loading and playing. This functionality is provided by raylib [raudio](../src/raudio.c) module. Note this module can be used standalone independently of raylib, check [raudio_standalone](others/raudio_standalone.c) example.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 96 | [audio_module_playing](audio/audio_module_playing.c) | <img src="audio/audio_module_playing.png" alt="audio_module_playing" width="200"> | ray | |
|
||||
| 97 | [audio_music_stream](audio/audio_music_stream.c) | <img src="audio/audio_music_stream.png" alt="audio_music_stream" width="200"> | ray | |
|
||||
| 98 | [audio_raw_stream](audio/audio_raw_stream.c) | <img src="audio/audio_raw_stream.png" alt="audio_raw_stream" width="200"> | ray | |
|
||||
| 99 | [audio_sound_loading](audio/audio_sound_loading.c) | <img src="audio/audio_sound_loading.png" alt="audio_sound_loading" width="200"> | ray | |
|
||||
| 100 | [audio_multichannel_sound](audio/audio_multichannel_sound.c) | <img src="audio/audio_multichannel_sound.png" alt="audio_multichannel_sound" width="200"> | [Chris Camacho](https://github.com/codifies) | ⭐️ |
|
||||
|
||||
### category: physics
|
||||
|
||||
Examples showing physics functionality with raylib. This functionality is provided by [physac](https://github.com/victorfisac/Physac) library, included with raylib [sources](../src/physac.h). Note this library is not linked with raylib by default, it should be manually included in user code.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 101 | [physics_demo](physics/physics_demo.c) | <img src="physics/physics_demo.png" alt="physics_demo" width="200"> | [Victor Fisac](https://github.com/victorfisac) | |
|
||||
| 102 | [physics_friction](physics/physics_friction.c) | <img src="physics/physics_friction.png" alt="physics_friction" width="200"> | [Victor Fisac](https://github.com/victorfisac) | |
|
||||
| 103 | [physics_movement](physics/physics_movement.c) | <img src="physics/physics_movement.png" alt="physics_movement" width="200"> | [Victor Fisac](https://github.com/victorfisac) | |
|
||||
| 104 | [physics_restitution](physics/physics_restitution.c) | <img src="physics/physics_restitution.png" alt="physics_restitution" width="200"> | [Victor Fisac](https://github.com/victorfisac) | |
|
||||
| 105 | [physics_shatter](physics/physics_shatter.c) | <img src="physics/physics_shatter.png" alt="physics_shatter" width="200"> | [Victor Fisac](https://github.com/victorfisac) | |
|
||||
|
||||
### category: network
|
||||
|
||||
Examples showing raylib network functionality. This functionality is provided by [rnet](../src/rnet.h) module.
|
||||
|
||||
**Note that rnet module is under development and not ready yet.**
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 106 | [network_ping_pong](network/network_ping_pong.c) | | [Jak Barnes](https://github.com/syphonx) | |
|
||||
| 107 | [network_resolve_host](network/network_resolve_host.c) | | [Jak Barnes](https://github.com/syphonx) | |
|
||||
| 108 | [network_tcp_client](network/network_tcp_client.c) | | [Jak Barnes](https://github.com/syphonx) | |
|
||||
| 109 | [network_tcp_server](network/network_tcp_server.c) | | [Jak Barnes](https://github.com/syphonx) | |
|
||||
| 110 | [network_test](network/network_test.c) | | [Jak Barnes](https://github.com/syphonx) | |
|
||||
| 111 | [network_udp_client](network/network_udp_client.c) | | [Jak Barnes](https://github.com/syphonx) | |
|
||||
| 112 | [network_udp_server](network/network_udp_server.c) | | [Jak Barnes](https://github.com/syphonx) | |
|
||||
|
||||
### category: others
|
||||
|
||||
Examples showing raylib misc functionality that does not fit in other categories, like standalone modules usage or examples integrating external libraries.
|
||||
|
||||
| ## | example | image | developer | new |
|
||||
|----|----------|--------|:----------:|:---:|
|
||||
| 113 | [raudio_standalone](others/raudio_standalone.c) | | ray | |
|
||||
| 114 | [rlgl_standalone](others/rlgl_standalone.c) | | ray | |
|
||||
| 115 | [easings_testbed](others/easings_testbed.c) | | ray | |
|
||||
|
||||
As always contributions are welcome, feel free to send new examples! Here it is an [examples template](examples_template.c) to start with!
|
||||
|
@@ -2,8 +2,6 @@
|
||||
*
|
||||
* raylib [audio] example - Module playing (streaming)
|
||||
*
|
||||
* NOTE: This example requires OpenAL Soft library installed
|
||||
*
|
||||
* This example has been created using raylib 1.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
@@ -48,13 +46,13 @@ int main(void)
|
||||
circles[i].radius = GetRandomValue(10, 40);
|
||||
circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius);
|
||||
circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius);
|
||||
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
||||
circles[i].speed = (float)GetRandomValue(1, 100)/2000.0f;
|
||||
circles[i].color = colors[GetRandomValue(0, 13)];
|
||||
}
|
||||
|
||||
Music xm = LoadMusicStream("resources/chiptun1.mod");
|
||||
Music music = LoadMusicStream("resources/mini1111.xm");
|
||||
|
||||
PlayMusicStream(xm);
|
||||
PlayMusicStream(music);
|
||||
|
||||
float timePlayed = 0.0f;
|
||||
bool pause = false;
|
||||
@@ -67,13 +65,13 @@ int main(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateMusicStream(xm); // Update music buffer with new stream data
|
||||
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||
|
||||
// Restart music playing (stop and play)
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
StopMusicStream(xm);
|
||||
PlayMusicStream(xm);
|
||||
StopMusicStream(music);
|
||||
PlayMusicStream(music);
|
||||
}
|
||||
|
||||
// Pause/Resume music playing
|
||||
@@ -81,12 +79,12 @@ int main(void)
|
||||
{
|
||||
pause = !pause;
|
||||
|
||||
if (pause) PauseMusicStream(xm);
|
||||
else ResumeMusicStream(xm);
|
||||
if (pause) PauseMusicStream(music);
|
||||
else ResumeMusicStream(music);
|
||||
}
|
||||
|
||||
// Get timePlayed scaled to bar dimensions
|
||||
timePlayed = GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40);
|
||||
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*(screenWidth - 40);
|
||||
|
||||
// Color circles animation
|
||||
for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--)
|
||||
@@ -103,7 +101,7 @@ int main(void)
|
||||
circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius);
|
||||
circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius);
|
||||
circles[i].color = colors[GetRandomValue(0, 13)];
|
||||
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
||||
circles[i].speed = (float)GetRandomValue(1, 100)/2000.0f;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
@@ -130,7 +128,7 @@ int main(void)
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadMusicStream(xm); // Unload music stream buffers from RAM
|
||||
UnloadMusicStream(music); // Unload music stream buffers from RAM
|
||||
|
||||
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||
|
||||
|
73
examples/audio/audio_multichannel_sound.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [audio] example - Multichannel sound playing
|
||||
*
|
||||
* This example has been created using raylib 2.6 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2019 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing");
|
||||
|
||||
InitAudioDevice(); // Initialize audio device
|
||||
|
||||
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
||||
Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file
|
||||
|
||||
SetSoundVolume(fxWav, 0.2);
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyPressed(KEY_ENTER)) PlaySoundMulti(fxWav); // Play a new wav sound instance
|
||||
if (IsKeyPressed(KEY_SPACE)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
|
||||
DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
|
||||
DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY);
|
||||
|
||||
DrawText(FormatText("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
StopSoundMulti(); // We must stop the buffer pool before unloading
|
||||
|
||||
UnloadSound(fxWav); // Unload sound data
|
||||
UnloadSound(fxOgg); // Unload sound data
|
||||
|
||||
CloseAudioDevice(); // Close audio device
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
BIN
examples/audio/audio_multichannel_sound.png
Normal file
After Width: | Height: | Size: 16 KiB |
@@ -2,8 +2,6 @@
|
||||
*
|
||||
* raylib [audio] example - Music playing (streaming)
|
||||
*
|
||||
* NOTE: This example requires OpenAL Soft library installed
|
||||
*
|
||||
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
|
@@ -2,11 +2,11 @@
|
||||
*
|
||||
* raylib [audio] example - Raw audio streaming
|
||||
*
|
||||
* NOTE: This example requires OpenAL Soft library installed
|
||||
*
|
||||
* This example has been created using raylib 1.6 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example created by Ramon Santamaria (@raysan5) and reviewed by James Hofmann (@triplefox)
|
||||
*
|
||||
* Copyright (c) 2015-2019 Ramon Santamaria (@raysan5) and James Hofmann (@triplefox)
|
||||
*
|
||||
********************************************************************************************/
|
||||
@@ -99,7 +99,7 @@ int main(void)
|
||||
}
|
||||
|
||||
// Refill audio stream if required
|
||||
if (IsAudioBufferProcessed(stream))
|
||||
if (IsAudioStreamProcessed(stream))
|
||||
{
|
||||
// Synthesize a buffer that is exactly the requested size
|
||||
int writeCursor = 0;
|
||||
|
@@ -2,8 +2,6 @@
|
||||
*
|
||||
* raylib [audio] example - Sound loading and playing
|
||||
*
|
||||
* NOTE: This example requires OpenAL Soft library installed
|
||||
*
|
||||
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
|
@@ -42,7 +42,7 @@ int main(void)
|
||||
|
||||
Camera2D camera = { 0 };
|
||||
camera.target = (Vector2){ player.x + 20, player.y + 20 };
|
||||
camera.offset = (Vector2){ 0, 0 };
|
||||
camera.offset = (Vector2){ screenWidth/2, screenHeight/2 };
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
@@ -54,16 +54,10 @@ int main(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyDown(KEY_RIGHT))
|
||||
{
|
||||
player.x += 2; // Player movement
|
||||
camera.offset.x -= 2; // Camera displacement with player movement
|
||||
}
|
||||
else if (IsKeyDown(KEY_LEFT))
|
||||
{
|
||||
player.x -= 2; // Player movement
|
||||
camera.offset.x += 2; // Camera displacement with player movement
|
||||
}
|
||||
|
||||
// Player movement
|
||||
if (IsKeyDown(KEY_RIGHT)) player.x += 2;
|
||||
else if (IsKeyDown(KEY_LEFT)) player.x -= 2;
|
||||
|
||||
// Camera target follows player
|
||||
camera.target = (Vector2){ player.x + 20, player.y + 20 };
|
||||
@@ -135,4 +129,4 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
293
examples/core/core_2d_camera_platformer.c
Normal file
@@ -0,0 +1,293 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [core] example - 2d camera platformer
|
||||
*
|
||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by arvyy (@arvyy) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2019 arvyy (@arvyy)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#define G 400
|
||||
#define PLAYER_JUMP_SPD 350.f
|
||||
#define PLAYER_HOR_SPD 200.f
|
||||
|
||||
typedef struct Player {
|
||||
Vector2 position;
|
||||
float speed;
|
||||
bool canJump;
|
||||
} Player;
|
||||
|
||||
typedef struct EnvItem {
|
||||
Rectangle rect;
|
||||
int blocking;
|
||||
Color color;
|
||||
} EnvItem;
|
||||
|
||||
|
||||
void UpdatePlayer(Player *player, EnvItem *envItems, int envItemsLength, float delta);
|
||||
|
||||
void UpdateCameraCenter(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height);
|
||||
void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height);
|
||||
void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height);
|
||||
void UpdateCameraEvenOutOnLanding(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height);
|
||||
void UpdateCameraPlayerBoundsPush(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height);
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
|
||||
|
||||
Player player = { 0 };
|
||||
player.position = (Vector2){ 400, 280 };
|
||||
player.speed = 0;
|
||||
player.canJump = false;
|
||||
EnvItem envItems[] = {
|
||||
{{ 0, 0, 1000, 400 }, 0, LIGHTGRAY },
|
||||
{{ 0, 400, 1000, 200 }, 1, GRAY },
|
||||
{{ 300, 200, 400, 10 }, 1, GRAY },
|
||||
{{ 250, 300, 100, 10 }, 1, GRAY },
|
||||
{{ 650, 300, 100, 10 }, 1, GRAY }
|
||||
};
|
||||
|
||||
int envItemsLength = sizeof(envItems)/sizeof(envItems[0]);
|
||||
|
||||
Camera2D camera = { 0 };
|
||||
camera.target = player.position;
|
||||
camera.offset = (Vector2){ screenWidth/2, screenHeight/2 };
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
// Store pointers to the multiple update camera functions
|
||||
void (*cameraUpdaters[])(Camera2D*, Player*, EnvItem*, int, float, int, int) = {
|
||||
UpdateCameraCenter,
|
||||
UpdateCameraCenterInsideMap,
|
||||
UpdateCameraCenterSmoothFollow,
|
||||
UpdateCameraEvenOutOnLanding,
|
||||
UpdateCameraPlayerBoundsPush
|
||||
};
|
||||
|
||||
int cameraOption = 0;
|
||||
int cameraUpdatersLength = sizeof(cameraUpdaters)/sizeof(cameraUpdaters[0]);
|
||||
|
||||
char *cameraDescriptions[] = {
|
||||
"Follow player center",
|
||||
"Follow player center, but clamp to map edges",
|
||||
"Follow player center; smoothed",
|
||||
"Follow player center horizontally; updateplayer center vertically after landing",
|
||||
"Player push camera on getting too close to screen edge"
|
||||
};
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
float deltaTime = GetFrameTime();
|
||||
|
||||
UpdatePlayer(&player, envItems, envItemsLength, deltaTime);
|
||||
|
||||
camera.zoom += ((float)GetMouseWheelMove()*0.05f);
|
||||
|
||||
if (camera.zoom > 3.0f) camera.zoom = 3.0f;
|
||||
else if (camera.zoom < 0.25f) camera.zoom = 0.25f;
|
||||
|
||||
if (IsKeyPressed(KEY_R))
|
||||
{
|
||||
camera.zoom = 1.0f;
|
||||
player.position = (Vector2){ 400, 280 };
|
||||
}
|
||||
|
||||
if (IsKeyPressed(KEY_C)) cameraOption = (cameraOption + 1)%cameraUpdatersLength;
|
||||
|
||||
// Call update camera function by its pointer
|
||||
cameraUpdaters[cameraOption](&camera, &player, envItems, envItemsLength, deltaTime, screenWidth, screenHeight);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(LIGHTGRAY);
|
||||
|
||||
BeginMode2D(camera);
|
||||
|
||||
for (int i = 0; i < envItemsLength; i++) DrawRectangleRec(envItems[i].rect, envItems[i].color);
|
||||
|
||||
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40, 40 };
|
||||
DrawRectangleRec(playerRect, RED);
|
||||
|
||||
EndMode2D();
|
||||
|
||||
DrawText("Controls:", 20, 20, 10, BLACK);
|
||||
DrawText("- Right/Left to move", 40, 40, 10, DARKGRAY);
|
||||
DrawText("- Space to jump", 40, 60, 10, DARKGRAY);
|
||||
DrawText("- Mouse Wheel to Zoom in-out, R to reset zoom", 40, 80, 10, DARKGRAY);
|
||||
DrawText("- C to change camera mode", 40, 100, 10, DARKGRAY);
|
||||
DrawText("Current camera mode:", 20, 120, 10, BLACK);
|
||||
DrawText(cameraDescriptions[cameraOption], 40, 140, 10, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UpdatePlayer(Player *player, EnvItem *envItems, int envItemsLength, float delta)
|
||||
{
|
||||
if (IsKeyDown(KEY_LEFT)) player->position.x -= PLAYER_HOR_SPD*delta;
|
||||
if (IsKeyDown(KEY_RIGHT)) player->position.x += PLAYER_HOR_SPD*delta;
|
||||
if (IsKeyDown(KEY_SPACE) && player->canJump)
|
||||
{
|
||||
player->speed = -PLAYER_JUMP_SPD;
|
||||
player->canJump = false;
|
||||
}
|
||||
|
||||
int hitObstacle = 0;
|
||||
for (int i = 0; i < envItemsLength; i++)
|
||||
{
|
||||
EnvItem *ei = envItems + i;
|
||||
Vector2 *p = &(player->position);
|
||||
if (ei->blocking &&
|
||||
ei->rect.x <= p->x &&
|
||||
ei->rect.x + ei->rect.width >= p->x &&
|
||||
ei->rect.y >= p->y &&
|
||||
ei->rect.y < p->y + player->speed*delta)
|
||||
{
|
||||
hitObstacle = 1;
|
||||
player->speed = 0.0f;
|
||||
p->y = ei->rect.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hitObstacle)
|
||||
{
|
||||
player->position.y += player->speed*delta;
|
||||
player->speed += G*delta;
|
||||
player->canJump = false;
|
||||
}
|
||||
else player->canJump = true;
|
||||
}
|
||||
|
||||
void UpdateCameraCenter(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||
{
|
||||
camera->offset = (Vector2){ width/2, height/2 };
|
||||
camera->target = player->position;
|
||||
}
|
||||
|
||||
void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||
{
|
||||
camera->target = player->position;
|
||||
camera->offset = (Vector2){ width/2, height/2 };
|
||||
float minX = 1000, minY = 1000, maxX = -1000, maxY = -1000;
|
||||
|
||||
for (int i = 0; i < envItemsLength; i++)
|
||||
{
|
||||
EnvItem *ei = envItems + i;
|
||||
minX = fminf(ei->rect.x, minX);
|
||||
maxX = fmaxf(ei->rect.x + ei->rect.width, maxX);
|
||||
minY = fminf(ei->rect.y, minY);
|
||||
maxY = fmaxf(ei->rect.y + ei->rect.height, maxY);
|
||||
}
|
||||
|
||||
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, *camera);
|
||||
Vector2 min = GetWorldToScreen2D((Vector2){ minX, minY }, *camera);
|
||||
|
||||
if (max.x < width) camera->offset.x = width - (max.x - width/2);
|
||||
if (max.y < height) camera->offset.y = height - (max.y - height/2);
|
||||
if (min.x > 0) camera->offset.x = width/2 - min.x;
|
||||
if (min.y > 0) camera->offset.y = height/2 - min.y;
|
||||
}
|
||||
|
||||
void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||
{
|
||||
static float minSpeed = 30;
|
||||
static float minEffectLength = 10;
|
||||
static float fractionSpeed = 0.8f;
|
||||
|
||||
camera->offset = (Vector2){ width/2, height/2 };
|
||||
Vector2 diff = Vector2Subtract(player->position, camera->target);
|
||||
float length = Vector2Length(diff);
|
||||
|
||||
if (length > minEffectLength)
|
||||
{
|
||||
float speed = fmaxf(fractionSpeed*length, minSpeed);
|
||||
camera->target = Vector2Add(camera->target, Vector2Scale(diff, speed*delta/length));
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateCameraEvenOutOnLanding(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||
{
|
||||
static float evenOutSpeed = 700;
|
||||
static int eveningOut = false;
|
||||
static float evenOutTarget;
|
||||
|
||||
camera->offset = (Vector2){ width/2, height/2 };
|
||||
camera->target.x = player->position.x;
|
||||
|
||||
if (eveningOut)
|
||||
{
|
||||
if (evenOutTarget > camera->target.y)
|
||||
{
|
||||
camera->target.y += evenOutSpeed*delta;
|
||||
|
||||
if (camera->target.y > evenOutTarget)
|
||||
{
|
||||
camera->target.y = evenOutTarget;
|
||||
eveningOut = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
camera->target.y -= evenOutSpeed*delta;
|
||||
|
||||
if (camera->target.y < evenOutTarget)
|
||||
{
|
||||
camera->target.y = evenOutTarget;
|
||||
eveningOut = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player->canJump && (player->speed == 0) && (player->position.y != camera->target.y))
|
||||
{
|
||||
eveningOut = 1;
|
||||
evenOutTarget = player->position.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateCameraPlayerBoundsPush(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||
{
|
||||
static Vector2 bbox = { 0.2f, 0.2f };
|
||||
|
||||
Vector2 bboxWorldMin = GetScreenToWorld2D((Vector2){ (1 - bbox.x)*0.5f*width, (1 - bbox.y)*0.5f*height }, *camera);
|
||||
Vector2 bboxWorldMax = GetScreenToWorld2D((Vector2){ (1 + bbox.x)*0.5f*width, (1 + bbox.y)*0.5f*height }, *camera);
|
||||
camera->offset = (Vector2){ (1 - bbox.x)*0.5f * width, (1 - bbox.y)*0.5f*height };
|
||||
|
||||
if (player->position.x < bboxWorldMin.x) camera->target.x = player->position.x;
|
||||
if (player->position.y < bboxWorldMin.y) camera->target.y = player->position.y;
|
||||
if (player->position.x > bboxWorldMax.x) camera->target.x = bboxWorldMin.x + (player->position.x - bboxWorldMax.x);
|
||||
if (player->position.y > bboxWorldMax.y) camera->target.y = bboxWorldMin.y + (player->position.y - bboxWorldMax.y);
|
||||
}
|
BIN
examples/core/core_2d_camera_platformer.png
Normal file
After Width: | Height: | Size: 16 KiB |
@@ -23,40 +23,40 @@
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
71
examples/core/core_scissor_test.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [core] example - Scissor test
|
||||
*
|
||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Chris Dill (@MysteriousSpace) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2019 Chris Dill (@MysteriousSpace)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - scissor test");
|
||||
|
||||
Rectangle scissorArea = { 0, 0, 300, 300 };
|
||||
bool scissorMode = true;
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyPressed(KEY_S)) scissorMode = !scissorMode;
|
||||
|
||||
// Centre the scissor area around the mouse position
|
||||
scissorArea.x = GetMouseX() - scissorArea.width/2;
|
||||
scissorArea.y = GetMouseY() - scissorArea.height/2;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
if (scissorMode) BeginScissorMode(scissorArea.x, scissorArea.y, scissorArea.width, scissorArea.height);
|
||||
|
||||
// Draw full screen rectangle and some text
|
||||
// NOTE: Only part defined by scissor area will be rendered
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), RED);
|
||||
DrawText("Move the mouse around to reveal this text!", 190, 200, 20, LIGHTGRAY);
|
||||
|
||||
if (scissorMode) EndScissorMode();
|
||||
|
||||
DrawRectangleLinesEx(scissorArea, 1, BLACK);
|
||||
DrawText("Press S to toggle scissor test", 10, 10, 20, BLACK);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
BIN
examples/core/core_scissor_test.png
Normal file
After Width: | Height: | Size: 15 KiB |
@@ -29,7 +29,7 @@ int main(void)
|
||||
int gameScreenWidth = 640;
|
||||
int gameScreenHeight = 480;
|
||||
|
||||
// Render texture initialization
|
||||
// Render texture initialization, used to hold the rendering result so we can easily resize it
|
||||
RenderTexture2D target = LoadRenderTexture(gameScreenWidth, gameScreenHeight);
|
||||
SetTextureFilter(target.texture, FILTER_BILINEAR); // Texture scale filter to use
|
||||
|
||||
@@ -59,14 +59,14 @@ int main(void)
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
// Draw everything in the render texture
|
||||
// Draw everything in the render texture, note this will not be rendered on screen, yet
|
||||
BeginTextureMode(target);
|
||||
|
||||
ClearBackground(RAYWHITE); // Clear render texture background color
|
||||
|
||||
for (int i = 0; i < 10; i++) DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i]);
|
||||
|
||||
DrawText("You can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
|
||||
DrawText("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
|
@@ -62,8 +62,8 @@ int main(void)
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20) / 2, cubeScreenPosition.y, 20, BLACK);
|
||||
DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2, 25, 20, GRAY);
|
||||
DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20)/2, cubeScreenPosition.y, 20, BLACK);
|
||||
DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20))/2, 25, 20, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@@ -11,14 +11,14 @@ uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
uniform vec2 leftLensCenter = vec2(0.288, 0.5);
|
||||
uniform vec2 rightLensCenter = vec2(0.712, 0.5);
|
||||
uniform vec2 leftScreenCenter = vec2(0.25, 0.5);
|
||||
uniform vec2 rightScreenCenter = vec2(0.75, 0.5);
|
||||
uniform vec2 scale = vec2(0.25, 0.45);
|
||||
uniform vec2 scaleIn = vec2(4, 2.2222);
|
||||
uniform vec4 hmdWarpParam = vec4(1, 0.22, 0.24, 0);
|
||||
uniform vec4 chromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
|
||||
uniform vec2 leftLensCenter;
|
||||
uniform vec2 rightLensCenter;
|
||||
uniform vec2 leftScreenCenter;
|
||||
uniform vec2 rightScreenCenter;
|
||||
uniform vec2 scale;
|
||||
uniform vec2 scaleIn;
|
||||
uniform vec4 hmdWarpParam;
|
||||
uniform vec4 chromaAbParam;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@@ -5,10 +5,19 @@
|
||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2019 Ramon Santamaria (@raysan5) and @culacant
|
||||
* Example contributed by Culacant (@culacant) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2019 Culacant (@culacant) and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************
|
||||
*
|
||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||
* same position as they would be in edit mode.
|
||||
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "raylib.h"
|
||||
|
||||
int main(void)
|
||||
@@ -89,8 +98,11 @@ int main(void)
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
|
||||
// Unload model animations data
|
||||
for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
|
||||
RL_FREE(anims);
|
||||
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
|
@@ -21,7 +21,7 @@ int main(void)
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
||||
|
||||
// Define our custom camera to look into our 3d world
|
||||
Camera camera = { { 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
||||
Camera camera = { { 18.0f, 18.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
||||
|
||||
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
|
||||
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
|
||||
|
142
examples/models/models_loading.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Models loading
|
||||
*
|
||||
* raylib supports multiple models file formats:
|
||||
*
|
||||
* - OBJ > Text file, must include vertex position-texcoords-normals information,
|
||||
* if files references some .mtl materials file, it will be loaded (or try to)
|
||||
* - GLTF > Modern text/binary file format, includes lot of information and it could
|
||||
* also reference external files, raylib will try loading mesh and materials data
|
||||
* - IQM > Binary file format including mesh vertex data but also animation data,
|
||||
* raylib can load .iqm animations.
|
||||
*
|
||||
* This example has been created using raylib 2.6 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - models loading");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 50.0f, 50.0f, 50.0f }; // Camera position
|
||||
camera.target = (Vector3){ 0.0f, 10.0f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
|
||||
Model model = LoadModel("resources/models/castle.obj"); // Load model
|
||||
Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
|
||||
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||
|
||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||
|
||||
BoundingBox bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
|
||||
|
||||
// NOTE: bounds are calculated from the original size of the model,
|
||||
// if model is scaled on drawing, bounds must be also scaled
|
||||
|
||||
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
|
||||
|
||||
bool selected = false; // Selected object flag
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera);
|
||||
|
||||
// Load new models/textures on drag&drop
|
||||
if (IsFileDropped())
|
||||
{
|
||||
int count = 0;
|
||||
char **droppedFiles = GetDroppedFiles(&count);
|
||||
|
||||
if (count == 1) // Only support one file dropped
|
||||
{
|
||||
if (IsFileExtension(droppedFiles[0], ".obj") ||
|
||||
IsFileExtension(droppedFiles[0], ".gltf") ||
|
||||
IsFileExtension(droppedFiles[0], ".iqm")) // Model file formats supported
|
||||
{
|
||||
UnloadModel(model); // Unload previous model
|
||||
model = LoadModel(droppedFiles[0]); // Load new model
|
||||
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set current map diffuse texture
|
||||
|
||||
bounds = MeshBoundingBox(model.meshes[0]);
|
||||
|
||||
// TODO: Move camera position from target enough distance to visualize model properly
|
||||
}
|
||||
else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
|
||||
{
|
||||
// Unload current model texture and load new one
|
||||
UnloadTexture(texture);
|
||||
texture = LoadTexture(droppedFiles[0]);
|
||||
model.materials[0].maps[MAP_DIFFUSE].texture = texture;
|
||||
}
|
||||
}
|
||||
|
||||
ClearDroppedFiles(); // Clear internal buffers
|
||||
}
|
||||
|
||||
// Select model on mouse click
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
// Check collision between ray and box
|
||||
if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) selected = !selected;
|
||||
else selected = false;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
DrawModel(model, position, 1.0f, WHITE); // Draw 3d model with texture
|
||||
|
||||
DrawGrid(20, 10.0f); // Draw a grid
|
||||
|
||||
if (selected) DrawBoundingBox(bounds, GREEN); // Draw selection box
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawText("Drag & drop model to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
|
||||
if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);
|
||||
|
||||
DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
BIN
examples/models/models_loading.png
Normal file
After Width: | Height: | Size: 217 KiB |
@@ -50,16 +50,15 @@ int main(void)
|
||||
// NOTE: New VBO for tangents is generated at default location and also binded to mesh VAO
|
||||
MeshTangents(&model.meshes[0]);
|
||||
|
||||
UnloadMaterial(model.materials[0]); // get rid of default material
|
||||
model.materials[0] = LoadMaterialPBR((Color){ 255, 255, 255, 255 }, 1.0f, 1.0f);
|
||||
|
||||
// Define lights attributes
|
||||
// NOTE: Shader is passed to every light on creation to define shader bindings internally
|
||||
Light lights[MAX_LIGHTS] = {
|
||||
CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 0, 255 }, model.materials[0].shader),
|
||||
CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 255, 0, 255 }, model.materials[0].shader),
|
||||
CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 255, 255 }, model.materials[0].shader),
|
||||
CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 255, 255 }, model.materials[0].shader)
|
||||
};
|
||||
// Create lights
|
||||
// NOTE: Lights are added to an internal lights pool automatically
|
||||
CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 0, 255 }, model.materials[0].shader);
|
||||
CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 255, 0, 255 }, model.materials[0].shader);
|
||||
CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 255, 255 }, model.materials[0].shader);
|
||||
CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 255, 255 }, model.materials[0].shader);
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
@@ -100,7 +99,20 @@ int main(void)
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(model); // Unload skybox model
|
||||
|
||||
// Shaders and textures must be unloaded by user,
|
||||
// they could be in use by other models
|
||||
UnloadTexture(model.materials[0].maps[MAP_ALBEDO].texture);
|
||||
UnloadTexture(model.materials[0].maps[MAP_NORMAL].texture);
|
||||
UnloadTexture(model.materials[0].maps[MAP_METALNESS].texture);
|
||||
UnloadTexture(model.materials[0].maps[MAP_ROUGHNESS].texture);
|
||||
UnloadTexture(model.materials[0].maps[MAP_OCCLUSION].texture);
|
||||
UnloadTexture(model.materials[0].maps[MAP_IRRADIANCE].texture);
|
||||
UnloadTexture(model.materials[0].maps[MAP_PREFILTER].texture);
|
||||
UnloadTexture(model.materials[0].maps[MAP_BRDF].texture);
|
||||
UnloadShader(model.materials[0].shader);
|
||||
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
@@ -112,8 +124,8 @@ int main(void)
|
||||
// NOTE: PBR shader is loaded inside this function
|
||||
static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
{
|
||||
Material mat = { 0 }; // NOTE: All maps textures are set to { 0 }
|
||||
|
||||
Material mat = LoadMaterialDefault(); // Initialize material to default
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
mat.shader = LoadShader("resources/shaders/glsl330/pbr.vs", "resources/shaders/glsl330/pbr.fs");
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
@@ -135,7 +147,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
|
||||
// Set view matrix location
|
||||
mat.shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(mat.shader, "matModel");
|
||||
mat.shader.locs[LOC_MATRIX_VIEW] = GetShaderLocation(mat.shader, "view");
|
||||
//mat.shader.locs[LOC_MATRIX_VIEW] = GetShaderLocation(mat.shader, "view");
|
||||
mat.shader.locs[LOC_VECTOR_VIEW] = GetShaderLocation(mat.shader, "viewPos");
|
||||
|
||||
// Set PBR standard maps
|
||||
|
@@ -115,11 +115,12 @@ int main(void)
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
|
||||
// Unload models data (GPU VRAM)
|
||||
for (int i = 0; i < NUM_MODELS; i++) UnloadModel(models[i]);
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
|
@@ -105,7 +105,7 @@ int main(void)
|
||||
|
||||
// Check ray collision against model
|
||||
// NOTE: It considers model.transform matrix!
|
||||
meshHitInfo = GetCollisionRayModel(ray, &tower);
|
||||
meshHitInfo = GetCollisionRayModel(ray, tower);
|
||||
|
||||
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
|
||||
{
|
||||
|
@@ -1,80 +0,0 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Load and draw a 3d model (OBJ)
|
||||
*
|
||||
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 8.0f, 8.0f, 8.0f }; // Camera position
|
||||
camera.target = (Vector3){ 0.0f, 2.5f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
|
||||
Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
|
||||
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
DrawGizmo(position); // Draw gizmo
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
Before Width: | Height: | Size: 260 KiB |
@@ -1,127 +0,0 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - OBJ models viewer
|
||||
*
|
||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include <string.h> // Required for: strcpy()
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib example - obj viewer");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = { { 30.0f, 30.0f, 30.0f }, { 0.0f, 10.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
||||
|
||||
Model model = LoadModel("resources/models/turret.obj"); // Load default model obj
|
||||
Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load default model texture
|
||||
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model
|
||||
|
||||
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
|
||||
BoundingBox bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
|
||||
bool selected = false; // Selected object flag
|
||||
|
||||
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
|
||||
|
||||
char objFilename[64] = "turret.obj";
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsFileDropped())
|
||||
{
|
||||
int count = 0;
|
||||
char **droppedFiles = GetDroppedFiles(&count);
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
if (IsFileExtension(droppedFiles[0], ".obj"))
|
||||
{
|
||||
for (int i = 0; i < model.meshCount; i++) UnloadMesh(&model.meshes[i]);
|
||||
model.meshes = LoadMeshes(droppedFiles[0], &model.meshCount);
|
||||
bounds = MeshBoundingBox(model.meshes[0]);
|
||||
}
|
||||
else if (IsFileExtension(droppedFiles[0], ".png"))
|
||||
{
|
||||
UnloadTexture(texture);
|
||||
texture = LoadTexture(droppedFiles[0]);
|
||||
model.materials[0].maps[MAP_DIFFUSE].texture = texture;
|
||||
}
|
||||
|
||||
strcpy(objFilename, GetFileName(droppedFiles[0]));
|
||||
}
|
||||
|
||||
ClearDroppedFiles(); // Clear internal buffers
|
||||
}
|
||||
|
||||
UpdateCamera(&camera);
|
||||
|
||||
// Select model on mouse click
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
// Check collision between ray and box
|
||||
if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) selected = !selected;
|
||||
else selected = false;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
DrawModel(model, position, 1.0f, WHITE); // Draw 3d model with texture
|
||||
|
||||
DrawGrid(20.0, 10.0); // Draw a grid
|
||||
|
||||
if (selected) DrawBoundingBox(bounds, GREEN);
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawText("Free camera default controls:", 10, 20, 10, DARKGRAY);
|
||||
DrawText("- Mouse Wheel to Zoom in-out", 20, 40, 10, GRAY);
|
||||
DrawText("- Mouse Wheel Pressed to Pan", 20, 60, 10, GRAY);
|
||||
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 20, 80, 10, GRAY);
|
||||
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 20, 100, 10, GRAY);
|
||||
|
||||
DrawText("Drag & drop .obj/.png to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
|
||||
DrawText(FormatText("Current file: %s", objFilename), 250, GetScreenHeight() - 20, 10, GRAY);
|
||||
if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);
|
||||
|
||||
DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
ClearDroppedFiles(); // Clear internal buffers
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
Before Width: | Height: | Size: 95 KiB |
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* This example uses [rlgl] module funtionality (pseudo-OpenGL 1.1 style coding)
|
||||
*
|
||||
* This example has been created using raylib 2.2 (www.raylib.com)
|
||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2018 Ramon Santamaria (@raysan5)
|
||||
|
@@ -89,7 +89,10 @@ int main(void)
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(skybox); // Unload skybox model (and textures)
|
||||
UnloadShader(skybox.materials[0].shader);
|
||||
UnloadTexture(skybox.materials[0].maps[MAP_CUBEMAP].texture);
|
||||
|
||||
UnloadModel(skybox); // Unload skybox model
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
112
examples/models/models_waving_cubes.c
Normal file
@@ -0,0 +1,112 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Waving cubes
|
||||
*
|
||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Codecat (@codecat) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2019 Codecat (@codecat) and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - waving cubes");
|
||||
|
||||
// Initialize the camera
|
||||
Camera3D camera = { 0 };
|
||||
camera.position = (Vector3){ 30.0f, 20.0f, 30.0f };
|
||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||
camera.fovy = 70.0f;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
|
||||
// Specify the amount of blocks in each direction
|
||||
const int numBlocks = 15;
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
double time = GetTime();
|
||||
|
||||
// Calculate time scale for cube position and size
|
||||
float scale = (2.0f + (float)sin(time))*0.7f;
|
||||
|
||||
// Move camera around the scene
|
||||
double cameraTime = time*0.3;
|
||||
camera.position.x = (float)cos(cameraTime)*40.0f;
|
||||
camera.position.z = (float)sin(cameraTime)*40.0f;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
DrawGrid(10, 5.0f);
|
||||
|
||||
for (int x = 0; x < numBlocks; x++)
|
||||
{
|
||||
for (int y = 0; y < numBlocks; y++)
|
||||
{
|
||||
for (int z = 0; z < numBlocks; z++)
|
||||
{
|
||||
// Scale of the blocks depends on x/y/z positions
|
||||
float blockScale = (x + y + z)/30.0f;
|
||||
|
||||
// Scatter makes the waving effect by adding blockScale over time
|
||||
float scatter = sinf(blockScale*20.0f + (float)(time*4.0f));
|
||||
|
||||
// Calculate the cube position
|
||||
Vector3 cubePos = {
|
||||
(float)(x - numBlocks/2)*(scale*3.0f) + scatter,
|
||||
(float)(y - numBlocks/2)*(scale*2.0f) + scatter,
|
||||
(float)(z - numBlocks/2)*(scale*3.0f) + scatter
|
||||
};
|
||||
|
||||
// Pick a color with a hue depending on cube position for the rainbow color effect
|
||||
Color cubeColor = ColorFromHSV((Vector3){ (float)(((x + y + z)*18)%360), 0.75f, 0.9f });
|
||||
|
||||
// Calculate cube size
|
||||
float cubeSize = (2.4f - scale)*blockScale;
|
||||
|
||||
// And finally, draw the cube!
|
||||
DrawCube(cubePos, cubeSize, cubeSize, cubeSize, cubeColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
BIN
examples/models/models_waving_cubes.png
Normal file
After Width: | Height: | Size: 37 KiB |
@@ -92,6 +92,7 @@ int main(void)
|
||||
while (pitchOffset < -180) pitchOffset += 360;
|
||||
pitchOffset *= 10;
|
||||
|
||||
/* matrix transform done with multiplication to combine rotations
|
||||
Matrix transform = MatrixIdentity();
|
||||
|
||||
transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll));
|
||||
@@ -99,8 +100,11 @@ int main(void)
|
||||
transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw));
|
||||
|
||||
model.transform = transform;
|
||||
//----------------------------------------------------------------------------------
|
||||
*/
|
||||
// matrix created from multiple axes at once
|
||||
model.transform = MatrixRotateXYZ((Vector3){DEG2RAD*pitch,DEG2RAD*yaw,DEG2RAD*roll});
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
@@ -165,6 +169,7 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload all loaded data
|
||||
UnloadTexture(model.materials[0].maps[MAP_DIFFUSE].texture);
|
||||
UnloadModel(model);
|
||||
|
||||
UnloadRenderTexture(framebuffer);
|
||||
|
BIN
examples/models/resources/models/Duck/Duck.glb
Normal file
219
examples/models/resources/models/Duck/Duck.gltf
Normal file
@@ -0,0 +1,219 @@
|
||||
{
|
||||
"asset": {
|
||||
"generator": "COLLADA2GLTF",
|
||||
"version": "2.0"
|
||||
},
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"children": [
|
||||
2,
|
||||
1
|
||||
],
|
||||
"matrix": [
|
||||
0.009999999776482582,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.009999999776482582,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.009999999776482582,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"matrix": [
|
||||
-0.7289686799049377,
|
||||
0.0,
|
||||
-0.6845470666885376,
|
||||
0.0,
|
||||
-0.4252049028873444,
|
||||
0.7836934328079224,
|
||||
0.4527972936630249,
|
||||
0.0,
|
||||
0.5364750623703003,
|
||||
0.6211478114128113,
|
||||
-0.571287989616394,
|
||||
0.0,
|
||||
400.1130065917969,
|
||||
463.2640075683594,
|
||||
-431.0780334472656,
|
||||
1.0
|
||||
],
|
||||
"camera": 0
|
||||
},
|
||||
{
|
||||
"mesh": 0
|
||||
}
|
||||
],
|
||||
"cameras": [
|
||||
{
|
||||
"perspective": {
|
||||
"aspectRatio": 1.5,
|
||||
"yfov": 0.6605925559997559,
|
||||
"zfar": 10000.0,
|
||||
"znear": 1.0
|
||||
},
|
||||
"type": "perspective"
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"NORMAL": 1,
|
||||
"POSITION": 2,
|
||||
"TEXCOORD_0": 3
|
||||
},
|
||||
"indices": 0,
|
||||
"mode": 4,
|
||||
"material": 0
|
||||
}
|
||||
],
|
||||
"name": "LOD3spShape"
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5123,
|
||||
"count": 12636,
|
||||
"max": [
|
||||
2398
|
||||
],
|
||||
"min": [
|
||||
0
|
||||
],
|
||||
"type": "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 2399,
|
||||
"max": [
|
||||
0.9995989799499512,
|
||||
0.999580979347229,
|
||||
0.9984359741210938
|
||||
],
|
||||
"min": [
|
||||
-0.9990839958190918,
|
||||
-1.0,
|
||||
-0.9998319745063782
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 28788,
|
||||
"componentType": 5126,
|
||||
"count": 2399,
|
||||
"max": [
|
||||
96.17990112304688,
|
||||
163.97000122070313,
|
||||
53.92519760131836
|
||||
],
|
||||
"min": [
|
||||
-69.29850006103516,
|
||||
9.929369926452637,
|
||||
-61.32819747924805
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 2,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 2399,
|
||||
"max": [
|
||||
0.9833459854125976,
|
||||
0.9800369739532472
|
||||
],
|
||||
"min": [
|
||||
0.026409000158309938,
|
||||
0.01996302604675293
|
||||
],
|
||||
"type": "VEC2"
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorTexture": {
|
||||
"index": 0
|
||||
},
|
||||
"metallicFactor": 0.0
|
||||
},
|
||||
"emissiveFactor": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"name": "blinn3-fx"
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
{
|
||||
"sampler": 0,
|
||||
"source": 0
|
||||
}
|
||||
],
|
||||
"images": [
|
||||
{
|
||||
"uri": "DuckCM.png"
|
||||
}
|
||||
],
|
||||
"samplers": [
|
||||
{
|
||||
"magFilter": 9729,
|
||||
"minFilter": 9986,
|
||||
"wrapS": 10497,
|
||||
"wrapT": 10497
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 76768,
|
||||
"byteLength": 25272,
|
||||
"target": 34963
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 57576,
|
||||
"byteStride": 12,
|
||||
"target": 34962
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 57576,
|
||||
"byteLength": 19192,
|
||||
"byteStride": 8,
|
||||
"target": 34962
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 102040,
|
||||
"uri": "Duck0.bin"
|
||||
}
|
||||
]
|
||||
}
|
BIN
examples/models/resources/models/Duck/Duck0.bin
Normal file
BIN
examples/models/resources/models/Duck/DuckCM.png
Normal file
After Width: | Height: | Size: 16 KiB |
14
examples/models/resources/models/Duck/Duck_license.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
# Duck
|
||||
## Screenshot
|
||||
|
||||

|
||||
|
||||
## License Information
|
||||
|
||||
Copyright 2006 Sony Computer Entertainment Inc.
|
||||
|
||||
Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:
|
||||
|
||||
http://research.scea.com/scea_shared_source_license.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
4
examples/models/resources/models/LICENSE
Normal file
@@ -0,0 +1,4 @@
|
||||
Medieval City models and textures have been created by Alberto Cano,
|
||||
and licensed as Creative Commons Attribution-NonCommercial 4.0.
|
||||
|
||||
Check for details: https://creativecommons.org/licenses/by-nc/4.0/legalcode
|
Before Width: | Height: | Size: 364 KiB After Width: | Height: | Size: 295 KiB |
@@ -73,6 +73,8 @@ vec3 fresnelSchlick(float cosTheta, vec3 F0);
|
||||
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness);
|
||||
vec2 ParallaxMapping(vec2 texCoords, vec3 viewDir);
|
||||
|
||||
// WARNING: There is some weird behaviour with this function, always returns black!
|
||||
// Yes, I even tried: return texture(property.sampler, texCoord).rgb;
|
||||
vec3 ComputeMaterialProperty(MaterialProperty property)
|
||||
{
|
||||
vec3 result = vec3(0.0, 0.0, 0.0);
|
||||
@@ -187,17 +189,17 @@ void main()
|
||||
else texCoord = fragTexCoord; // Use default texture coordinates
|
||||
|
||||
// Fetch material values from texture sampler or color attributes
|
||||
vec3 color = ComputeMaterialProperty(albedo);
|
||||
vec3 metal = ComputeMaterialProperty(metalness);
|
||||
vec3 rough = ComputeMaterialProperty(roughness);
|
||||
vec3 emiss = ComputeMaterialProperty(emission);
|
||||
vec3 ao = ComputeMaterialProperty(occlusion);
|
||||
vec3 color = texture(albedo.sampler, texCoord).rgb; //ComputeMaterialProperty(albedo);
|
||||
vec3 metal = texture(metalness.sampler, texCoord).rgb; //ComputeMaterialProperty(metalness);
|
||||
vec3 rough = texture(roughness.sampler, texCoord).rgb; //ComputeMaterialProperty(roughness);
|
||||
vec3 emiss = texture(emission.sampler, texCoord).rgb; //ComputeMaterialProperty(emission);
|
||||
vec3 ao = texture(occlusion.sampler, texCoord).rgb; //ComputeMaterialProperty(occlusion);
|
||||
|
||||
// Check if normal mapping is enabled
|
||||
if (normals.useSampler == 1)
|
||||
{
|
||||
// Fetch normal map color and transform lighting values to tangent space
|
||||
normal = ComputeMaterialProperty(normals);
|
||||
normal = texture(normals.sampler, texCoord).rgb; //ComputeMaterialProperty(normals);
|
||||
normal = normalize(normal*2.0 - 1.0);
|
||||
normal = normalize(normal*TBN);
|
||||
|
||||
|
@@ -33,6 +33,8 @@
|
||||
#ifndef RLIGHTS_H
|
||||
#define RLIGHTS_H
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
@@ -65,16 +67,11 @@ typedef struct {
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
int lightsCount = 0; // Current amount of created lights
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
Light CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shader); // Defines a light and get locations from PBR shader
|
||||
void UpdateLightValues(Shader shader, Light light); // Send to PBR shader light values
|
||||
void CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shader); // Defines a light and get locations from PBR shader
|
||||
void UpdateLightValues(Shader shader, Light light); // Send to PBR shader light values
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@@ -106,7 +103,8 @@ void UpdateLightValues(Shader shader, Light light);
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
// ...
|
||||
static Light lights[MAX_LIGHTS] = { 0 };
|
||||
static int lightsCount = 0; // Current amount of created lights
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
@@ -118,7 +116,7 @@ void UpdateLightValues(Shader shader, Light light);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Defines a light and get locations from PBR shader
|
||||
Light CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shader)
|
||||
void CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shader)
|
||||
{
|
||||
Light light = { 0 };
|
||||
|
||||
@@ -148,10 +146,10 @@ Light CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shade
|
||||
light.colorLoc = GetShaderLocation(shader, colorName);
|
||||
|
||||
UpdateLightValues(shader, light);
|
||||
|
||||
lights[lightsCount] = light;
|
||||
lightsCount++;
|
||||
}
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
// Send to PBR shader light values
|
||||
|
@@ -48,178 +48,178 @@ char recvBuffer[512];
|
||||
// Attempt to connect to the network (Either TCP, or UDP)
|
||||
void NetworkConnect()
|
||||
{
|
||||
// If the server is configured as UDP, ignore connection requests
|
||||
if (server_cfg.type == SOCKET_UDP && client_cfg.type == SOCKET_UDP) {
|
||||
ping = true;
|
||||
connected = true;
|
||||
} else {
|
||||
// If the client is connected, run the server code to check for a connection
|
||||
if (client_connected) {
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
if (active > 0) {
|
||||
if ((connection = SocketAccept(server_res->socket, &connection_cfg)) != NULL) {
|
||||
AddSocket(socket_set, connection);
|
||||
ping = true;
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check if we're connected every _delay_ seconds
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (IsSocketConnected(client_res->socket)) {
|
||||
client_connected = true;
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the server is configured as UDP, ignore connection requests
|
||||
if (server_cfg.type == SOCKET_UDP && client_cfg.type == SOCKET_UDP) {
|
||||
ping = true;
|
||||
connected = true;
|
||||
} else {
|
||||
// If the client is connected, run the server code to check for a connection
|
||||
if (client_connected) {
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
if (active > 0) {
|
||||
if ((connection = SocketAccept(server_res->socket, &connection_cfg)) != NULL) {
|
||||
AddSocket(socket_set, connection);
|
||||
ping = true;
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check if we're connected every _delay_ seconds
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (IsSocketConnected(client_res->socket)) {
|
||||
client_connected = true;
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Once connected to the network, check the sockets for pending information
|
||||
// and when information is ready, send either a Ping or a Pong.
|
||||
void NetworkUpdate()
|
||||
{
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
int bytesRecv = 0;
|
||||
if (server_cfg.type == SOCKET_UDP && client_cfg.type == SOCKET_UDP) {
|
||||
if (IsSocketReady(client_res->socket)) {
|
||||
bytesRecv = SocketReceive(client_res->socket, recvBuffer, msglen);
|
||||
}
|
||||
if (IsSocketReady(server_res->socket)) {
|
||||
bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen);
|
||||
}
|
||||
} else {
|
||||
if (IsSocketReady(connection)) {
|
||||
bytesRecv = SocketReceive(connection, recvBuffer, msglen);
|
||||
}
|
||||
}
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
int bytesRecv = 0;
|
||||
if (server_cfg.type == SOCKET_UDP && client_cfg.type == SOCKET_UDP) {
|
||||
if (IsSocketReady(client_res->socket)) {
|
||||
bytesRecv = SocketReceive(client_res->socket, recvBuffer, msglen);
|
||||
}
|
||||
if (IsSocketReady(server_res->socket)) {
|
||||
bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen);
|
||||
}
|
||||
} else {
|
||||
if (IsSocketReady(connection)) {
|
||||
bytesRecv = SocketReceive(connection, recvBuffer, msglen);
|
||||
}
|
||||
}
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
if (server_cfg.type == SOCKET_UDP && client_cfg.type == SOCKET_UDP) {
|
||||
SocketSend(client_res->socket, pingmsg, msglen);
|
||||
} else {
|
||||
SocketSend(client_res->socket, pingmsg, msglen);
|
||||
}
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
if (server_cfg.type == SOCKET_UDP && client_cfg.type == SOCKET_UDP) {
|
||||
SocketSend(client_res->socket, pongmsg, msglen);
|
||||
} else {
|
||||
SocketSend(client_res->socket, pongmsg, msglen);
|
||||
}
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
if (server_cfg.type == SOCKET_UDP && client_cfg.type == SOCKET_UDP) {
|
||||
SocketSend(client_res->socket, pingmsg, msglen);
|
||||
} else {
|
||||
SocketSend(client_res->socket, pingmsg, msglen);
|
||||
}
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
if (server_cfg.type == SOCKET_UDP && client_cfg.type == SOCKET_UDP) {
|
||||
SocketSend(client_res->socket, pongmsg, msglen);
|
||||
} else {
|
||||
SocketSend(client_res->socket, pongmsg, msglen);
|
||||
}
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
|
||||
// Networking
|
||||
InitNetwork();
|
||||
// Networking
|
||||
InitNetwork();
|
||||
|
||||
// Create the server
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// bind
|
||||
// listen
|
||||
server_res = AllocSocketResult();
|
||||
if (!SocketCreate(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!SocketBind(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!(server_cfg.type == SOCKET_UDP)) {
|
||||
if (!SocketListen(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING,
|
||||
"Failed to start listen server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Create the server
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// bind
|
||||
// listen
|
||||
server_res = AllocSocketResult();
|
||||
if (!SocketCreate(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!SocketBind(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!(server_cfg.type == SOCKET_UDP)) {
|
||||
if (!SocketListen(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING,
|
||||
"Failed to start listen server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the client
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// connect (TCP only)
|
||||
client_res = AllocSocketResult();
|
||||
if (!SocketCreate(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
} else {
|
||||
if (!(client_cfg.type == SOCKET_UDP)) {
|
||||
if (!SocketConnect(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING,
|
||||
"Failed to connect to server: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Create the client
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// connect (TCP only)
|
||||
client_res = AllocSocketResult();
|
||||
if (!SocketCreate(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
} else {
|
||||
if (!(client_cfg.type == SOCKET_UDP)) {
|
||||
if (!SocketConnect(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING,
|
||||
"Failed to connect to server: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(3);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, server_res->socket);
|
||||
AddSocket(socket_set, client_res->socket);
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(3);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, server_res->socket);
|
||||
AddSocket(socket_set, client_res->socket);
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
if (connected) {
|
||||
NetworkUpdate();
|
||||
} else {
|
||||
NetworkConnect();
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
if (connected) {
|
||||
NetworkUpdate();
|
||||
} else {
|
||||
NetworkConnect();
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
@@ -28,30 +28,30 @@ uint16_t port = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
||||
SetTargetFPS(60);
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
||||
SetTargetFPS(60);
|
||||
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
|
||||
// Networking
|
||||
InitNetwork();
|
||||
|
||||
// Networking
|
||||
InitNetwork();
|
||||
|
||||
AddressInformation* addr = AllocAddressList(1);
|
||||
int count = ResolveHost(
|
||||
NULL,
|
||||
"5210",
|
||||
ADDRESS_TYPE_IPV4,
|
||||
int count = ResolveHost(
|
||||
NULL,
|
||||
"5210",
|
||||
ADDRESS_TYPE_IPV4,
|
||||
0 // Uncomment any of these flags
|
||||
// ADDRESS_INFO_NUMERICHOST // or try them in conjunction to
|
||||
// ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
|
||||
// ADDRESS_INFO_DNS_ONLY // the function getaddrinfo()
|
||||
// ADDRESS_INFO_ALL //
|
||||
// ADDRESS_INFO_FQDN // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
|
||||
,
|
||||
,
|
||||
addr
|
||||
);
|
||||
|
||||
@@ -61,20 +61,20 @@ int main()
|
||||
TraceLog(LOG_INFO, "Resolved to ip %s::%d\n", buffer, port);
|
||||
}
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
// Draw
|
||||
BeginDrawing();
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
// Draw
|
||||
BeginDrawing();
|
||||
|
||||
// Clear
|
||||
ClearBackground(RAYWHITE);
|
||||
// Clear
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// End draw
|
||||
EndDrawing();
|
||||
}
|
||||
// End draw
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
@@ -43,109 +43,109 @@ char recvBuffer[512];
|
||||
// Attempt to connect to the network (Either TCP, or UDP)
|
||||
void NetworkConnect()
|
||||
{
|
||||
// Check if we're connected every _delay_ seconds
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (IsSocketConnected(client_res->socket)) { connected = true; }
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
// Check if we're connected every _delay_ seconds
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (IsSocketConnected(client_res->socket)) { connected = true; }
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// Once connected to the network, check the sockets for pending information
|
||||
// and when information is ready, send either a Ping or a Pong.
|
||||
void NetworkUpdate()
|
||||
{
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
int bytesRecv = 0;
|
||||
if (IsSocketReady(client_res->socket)) {
|
||||
bytesRecv = SocketReceive(client_res->socket, recvBuffer, msglen);
|
||||
}
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
int bytesRecv = 0;
|
||||
if (IsSocketReady(client_res->socket)) {
|
||||
bytesRecv = SocketReceive(client_res->socket, recvBuffer, msglen);
|
||||
}
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
SocketSend(client_res->socket, pingmsg, msglen);
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
SocketSend(client_res->socket, pongmsg, msglen);
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
SocketSend(client_res->socket, pingmsg, msglen);
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
SocketSend(client_res->socket, pongmsg, msglen);
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - tcp client");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - tcp client");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
|
||||
// Networking
|
||||
InitNetwork();
|
||||
// Networking
|
||||
InitNetwork();
|
||||
|
||||
// Create the client
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// connect (TCP only)
|
||||
client_res = AllocSocketResult();
|
||||
if (!SocketCreate(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
} else {
|
||||
if (!(client_cfg.type == SOCKET_UDP)) {
|
||||
if (!SocketConnect(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING,
|
||||
"Failed to connect to server: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Create the client
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// connect (TCP only)
|
||||
client_res = AllocSocketResult();
|
||||
if (!SocketCreate(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
} else {
|
||||
if (!(client_cfg.type == SOCKET_UDP)) {
|
||||
if (!SocketConnect(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING,
|
||||
"Failed to connect to server: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(1);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, client_res->socket);
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(1);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, client_res->socket);
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
if (connected) {
|
||||
NetworkUpdate();
|
||||
} else {
|
||||
NetworkConnect();
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
if (connected) {
|
||||
NetworkUpdate();
|
||||
} else {
|
||||
NetworkConnect();
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
@@ -45,121 +45,121 @@ char recvBuffer[512];
|
||||
// Attempt to connect to the network (Either TCP, or UDP)
|
||||
void NetworkConnect()
|
||||
{
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
if (active > 0) {
|
||||
if ((connection = SocketAccept(server_res->socket, &connection_cfg)) != NULL) {
|
||||
AddSocket(socket_set, connection);
|
||||
ping = true;
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
if (active > 0) {
|
||||
if ((connection = SocketAccept(server_res->socket, &connection_cfg)) != NULL) {
|
||||
AddSocket(socket_set, connection);
|
||||
ping = true;
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Once connected to the network, check the sockets for pending information
|
||||
// and when information is ready, send either a Ping or a Pong.
|
||||
void NetworkUpdate()
|
||||
{
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
int bytesRecv = 0;
|
||||
if (IsSocketReady(connection)) {
|
||||
bytesRecv = SocketReceive(connection, recvBuffer, msglen);
|
||||
}
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
int bytesRecv = 0;
|
||||
if (IsSocketReady(connection)) {
|
||||
bytesRecv = SocketReceive(connection, recvBuffer, msglen);
|
||||
}
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
SocketSend(connection, pingmsg, msglen);
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
SocketSend(connection, pongmsg, msglen);
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
SocketSend(connection, pingmsg, msglen);
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
SocketSend(connection, pongmsg, msglen);
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - tcp server");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - tcp server");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
|
||||
// Networking
|
||||
InitNetwork();
|
||||
// Networking
|
||||
InitNetwork();
|
||||
|
||||
// Create the server
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// bind
|
||||
// listen
|
||||
server_res = AllocSocketResult();
|
||||
if (!SocketCreate(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!SocketBind(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!(server_cfg.type == SOCKET_UDP)) {
|
||||
if (!SocketListen(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING,
|
||||
"Failed to start listen server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Create the server
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// bind
|
||||
// listen
|
||||
server_res = AllocSocketResult();
|
||||
if (!SocketCreate(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!SocketBind(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!(server_cfg.type == SOCKET_UDP)) {
|
||||
if (!SocketListen(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING,
|
||||
"Failed to start listen server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(2);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, server_res->socket);
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(2);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, server_res->socket);
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
if (connected) {
|
||||
NetworkUpdate();
|
||||
} else {
|
||||
NetworkConnect();
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
if (connected) {
|
||||
NetworkUpdate();
|
||||
} else {
|
||||
NetworkConnect();
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
@@ -27,80 +27,80 @@
|
||||
|
||||
void test_network_initialise()
|
||||
{
|
||||
assert(InitNetwork() == true);
|
||||
assert(InitNetwork() == true);
|
||||
}
|
||||
|
||||
void test_socket_result()
|
||||
{
|
||||
SocketResult *result = AllocSocketResult();
|
||||
assert(result != NULL);
|
||||
FreeSocketResult(&result);
|
||||
assert(result == NULL);
|
||||
SocketResult *result = AllocSocketResult();
|
||||
assert(result != NULL);
|
||||
FreeSocketResult(&result);
|
||||
assert(result == NULL);
|
||||
}
|
||||
|
||||
void test_socket()
|
||||
{
|
||||
Socket *socket = AllocSocket();
|
||||
assert(socket != NULL);
|
||||
FreeSocket(&socket);
|
||||
assert(socket == NULL);
|
||||
Socket *socket = AllocSocket();
|
||||
assert(socket != NULL);
|
||||
FreeSocket(&socket);
|
||||
assert(socket == NULL);
|
||||
}
|
||||
|
||||
void test_resolve_ip()
|
||||
{
|
||||
const char *host = "8.8.8.8";
|
||||
const char *port = "8080";
|
||||
char ip[ADDRESS_IPV6_ADDRSTRLEN];
|
||||
const char *host = "8.8.8.8";
|
||||
const char *port = "8080";
|
||||
char ip[ADDRESS_IPV6_ADDRSTRLEN];
|
||||
char service[ADDRESS_MAXSERV];
|
||||
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NUMERICHOST, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "8.8.8.8") == 0);
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NUMERICHOST, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "8.8.8.8") == 0);
|
||||
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_DEFAULT, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a.google.com") == 0);
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_DEFAULT, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a.google.com") == 0);
|
||||
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NOFQDN, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a") == 0);
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NOFQDN, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a") == 0);
|
||||
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NUMERICHOST, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "8.8.8.8") == 0);
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NUMERICHOST, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "8.8.8.8") == 0);
|
||||
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NAMEREQD, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a.google.com") == 0);
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NAMEREQD, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a.google.com") == 0);
|
||||
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NUMERICSERV, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a.google.com") == 0);
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_NUMERICSERV, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a.google.com") == 0);
|
||||
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_DGRAM, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a.google.com") == 0);
|
||||
memset(ip, '\0', ADDRESS_IPV6_ADDRSTRLEN);
|
||||
ResolveIP(host, port, NAME_INFO_DGRAM, ip, service);
|
||||
TraceLog(LOG_INFO, "Resolved %s to %s", host, ip);
|
||||
assert(strcmp(ip, "google-public-dns-a.google.com") == 0);
|
||||
}
|
||||
|
||||
void test_resolve_host()
|
||||
{
|
||||
const char * address = "localhost";
|
||||
const char * port = "80";
|
||||
AddressInformation *addr = AllocAddressList(3);
|
||||
int count = ResolveHost(address, port, ADDRESS_TYPE_ANY, 0, addr);
|
||||
const char * address = "localhost";
|
||||
const char * port = "80";
|
||||
AddressInformation *addr = AllocAddressList(3);
|
||||
int count = ResolveHost(address, port, ADDRESS_TYPE_ANY, 0, addr);
|
||||
|
||||
assert(GetAddressFamily(addr[0]) == ADDRESS_TYPE_IPV6);
|
||||
assert(GetAddressFamily(addr[1]) == ADDRESS_TYPE_IPV4);
|
||||
assert(GetAddressSocketType(addr[0]) == 0);
|
||||
assert(GetAddressProtocol(addr[0]) == 0);
|
||||
// for (size_t i = 0; i < count; i++) { PrintAddressInfo(addr[i]); }
|
||||
assert(GetAddressFamily(addr[0]) == ADDRESS_TYPE_IPV6);
|
||||
assert(GetAddressFamily(addr[1]) == ADDRESS_TYPE_IPV4);
|
||||
assert(GetAddressSocketType(addr[0]) == 0);
|
||||
assert(GetAddressProtocol(addr[0]) == 0);
|
||||
// for (size_t i = 0; i < count; i++) { PrintAddressInfo(addr[i]); }
|
||||
}
|
||||
|
||||
void test_address()
|
||||
@@ -113,36 +113,36 @@ void test_address_list()
|
||||
|
||||
void test_socket_create()
|
||||
{
|
||||
SocketConfig server_cfg = {.host = "127.0.0.1", .port = "8080", .server = true, .nonblocking = true};
|
||||
Socket * socket = AllocSocket();
|
||||
SocketResult *server_res = AllocSocketResult();
|
||||
SocketSet * socket_set = AllocSocketSet(1);
|
||||
assert(SocketCreate(&server_cfg, server_res));
|
||||
assert(AddSocket(socket_set, server_res->socket));
|
||||
assert(SocketListen(&server_cfg, server_res));
|
||||
SocketConfig server_cfg = {.host = "127.0.0.1", .port = "8080", .server = true, .nonblocking = true};
|
||||
Socket * socket = AllocSocket();
|
||||
SocketResult *server_res = AllocSocketResult();
|
||||
SocketSet * socket_set = AllocSocketSet(1);
|
||||
assert(SocketCreate(&server_cfg, server_res));
|
||||
assert(AddSocket(socket_set, server_res->socket));
|
||||
assert(SocketListen(&server_cfg, server_res));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - network test");
|
||||
SetTargetFPS(60);
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - network test");
|
||||
SetTargetFPS(60);
|
||||
|
||||
// Run the tests
|
||||
test_network_initialise();
|
||||
test_resolve_host();
|
||||
// Run the tests
|
||||
test_network_initialise();
|
||||
test_resolve_host();
|
||||
// test_socket_create();
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
EndDrawing();
|
||||
}
|
||||
CloseWindow();
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
EndDrawing();
|
||||
}
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
@@ -43,86 +43,86 @@ char recvBuffer[512];
|
||||
// and when information is ready, send either a Ping or a Pong.
|
||||
void NetworkUpdate()
|
||||
{
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
int bytesRecv = 0;
|
||||
if (IsSocketReady(client_res->socket)) {
|
||||
bytesRecv = SocketReceive(client_res->socket, recvBuffer, msglen);
|
||||
}
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
int bytesRecv = 0;
|
||||
if (IsSocketReady(client_res->socket)) {
|
||||
bytesRecv = SocketReceive(client_res->socket, recvBuffer, msglen);
|
||||
}
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
SocketSend(client_res->socket, pingmsg, msglen);
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
SocketSend(client_res->socket, pongmsg, msglen);
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
SocketSend(client_res->socket, pingmsg, msglen);
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
SocketSend(client_res->socket, pongmsg, msglen);
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - udp client");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - udp client");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
|
||||
// Networking
|
||||
InitNetwork();
|
||||
// Networking
|
||||
InitNetwork();
|
||||
|
||||
// Create the client
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// connect (TCP only)
|
||||
client_res = AllocSocketResult();
|
||||
if (!SocketCreate(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
}
|
||||
// Create the client
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// connect (TCP only)
|
||||
client_res = AllocSocketResult();
|
||||
if (!SocketCreate(&client_cfg, client_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d",
|
||||
client_res->status, client_res->socket->status);
|
||||
}
|
||||
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(1);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
ping = true;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, client_res->socket);
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(1);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
ping = true;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, client_res->socket);
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
NetworkUpdate();
|
||||
EndDrawing();
|
||||
}
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
NetworkUpdate();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
@@ -43,92 +43,92 @@ char recvBuffer[512];
|
||||
// and when information is ready, send either a Ping or a Pong.
|
||||
void NetworkUpdate()
|
||||
{
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
// CheckSockets
|
||||
//
|
||||
// If any of the sockets in the socket_set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socket_set, 0);
|
||||
if (active != 0) {
|
||||
TraceLog(LOG_DEBUG,
|
||||
"There are currently %d socket(s) with data to be processed.", active);
|
||||
}
|
||||
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
// int bytesRecv = 0;
|
||||
// if (IsSocketReady(server_res->socket)) {
|
||||
// bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen);
|
||||
// }
|
||||
int bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen);
|
||||
// IsSocketReady
|
||||
//
|
||||
// If the socket is ready, attempt to receive data from the socket
|
||||
// int bytesRecv = 0;
|
||||
// if (IsSocketReady(server_res->socket)) {
|
||||
// bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen);
|
||||
// }
|
||||
int bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen);
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0) {
|
||||
if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
|
||||
}
|
||||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
SocketSend(server_res->socket, pingmsg, msglen);
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
SocketSend(server_res->socket, pongmsg, msglen);
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay) {
|
||||
if (ping) {
|
||||
ping = false;
|
||||
SocketSend(server_res->socket, pingmsg, msglen);
|
||||
} else if (pong) {
|
||||
pong = false;
|
||||
SocketSend(server_res->socket, pongmsg, msglen);
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - udp server");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - udp server");
|
||||
SetTargetFPS(60);
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
|
||||
// Networking
|
||||
InitNetwork();
|
||||
// Networking
|
||||
InitNetwork();
|
||||
|
||||
// Create the server
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// bind
|
||||
// listen
|
||||
server_res = AllocSocketResult();
|
||||
if (!SocketCreate(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!SocketBind(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
}
|
||||
}
|
||||
// Create the server
|
||||
//
|
||||
// Performs
|
||||
// getaddrinfo
|
||||
// socket
|
||||
// setsockopt
|
||||
// bind
|
||||
// listen
|
||||
server_res = AllocSocketResult();
|
||||
if (!SocketCreate(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
} else {
|
||||
if (!SocketBind(&server_cfg, server_res)) {
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d",
|
||||
server_res->status, server_res->socket->status);
|
||||
}
|
||||
}
|
||||
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(1);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, server_res->socket);
|
||||
// Create & Add sockets to the socket set
|
||||
socket_set = AllocSocketSet(1);
|
||||
msglen = strlen(pingmsg) + 1;
|
||||
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||
AddSocket(socket_set, server_res->socket);
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
NetworkUpdate();
|
||||
EndDrawing();
|
||||
}
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
NetworkUpdate();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
// Cleanup
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
@@ -58,29 +58,29 @@
|
||||
// Check if a key has been pressed
|
||||
static int kbhit(void)
|
||||
{
|
||||
struct termios oldt, newt;
|
||||
int ch;
|
||||
int oldf;
|
||||
struct termios oldt, newt;
|
||||
int ch;
|
||||
int oldf;
|
||||
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
newt = oldt;
|
||||
newt.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
newt = oldt;
|
||||
newt.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
|
||||
|
||||
ch = getchar();
|
||||
ch = getchar();
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||
fcntl(STDIN_FILENO, F_SETFL, oldf);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||
fcntl(STDIN_FILENO, F_SETFL, oldf);
|
||||
|
||||
if (ch != EOF)
|
||||
{
|
||||
ungetc(ch, stdin);
|
||||
return 1;
|
||||
}
|
||||
if (ch != EOF)
|
||||
{
|
||||
ungetc(ch, stdin);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get pressed character
|
||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
@@ -120,6 +120,10 @@ int main(void)
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
DestroyPhysicsBody(circleA);
|
||||
DestroyPhysicsBody(circleB);
|
||||
DestroyPhysicsBody(circleC);
|
||||
DestroyPhysicsBody(floor);
|
||||
ClosePhysics(); // Unitialize physics
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
BIN
examples/shaders/resources/mask.png
Normal file
After Width: | Height: | Size: 73 KiB |
BIN
examples/shaders/resources/plasma.png
Normal file
After Width: | Height: | Size: 568 KiB |
@@ -7,8 +7,8 @@ varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Custom variables
|
||||
#define PI 3.14159265358979323846
|
||||
uniform float uTime = 0.0;
|
||||
const float PI = 3.14159265358979323846;
|
||||
uniform float uTime;
|
||||
|
||||
float divisions = 5.0;
|
||||
float angle = 0.0;
|
||||
@@ -19,9 +19,9 @@ vec2 VectorRotateTime(vec2 v, float speed)
|
||||
float localTime = fract(time); // The time domain this works on is 1 sec.
|
||||
|
||||
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
||||
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4*sin(2*PI*localTime - PI/2);
|
||||
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0);
|
||||
else if ((localTime >= 0.50) && (localTime < 0.75)) angle = PI*0.25;
|
||||
else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4*sin(2*PI*localTime);
|
||||
else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4.0*sin(2.0*PI*localTime);
|
||||
|
||||
// Rotate vector by angle
|
||||
v -= 0.5;
|
||||
|
@@ -37,22 +37,24 @@ vec4 Colorizer(float counter, float maxSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = vec4(1.0);
|
||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
||||
int value = int(scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale)); // Group pixels into boxes representing integer values
|
||||
|
||||
if ((value == 0) || (value == 1) || (value == 2)) gl_FragColor = vec4(1.0);
|
||||
else
|
||||
vec4 color = vec4(1.0);
|
||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
||||
float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values
|
||||
int valuei = int(value);
|
||||
|
||||
//if ((valuei == 0) || (valuei == 1) || (valuei == 2)) gl_FragColor = vec4(1.0);
|
||||
//else
|
||||
{
|
||||
for (int i = 2; (i < max(2, sqrt(value) + 1)); i++)
|
||||
//for (int i = 2; (i < int(max(2.0, sqrt(value) + 1.0))); i++)
|
||||
// NOTE: On GLSL 100 for loops are restricted and loop condition must be a constant
|
||||
// Tested on RPI, it seems loops are limited around 60 iteractions
|
||||
for (int i = 2; i < 48; i++)
|
||||
{
|
||||
if ((value - i*floor(value/i)) == 0)
|
||||
if ((value - float(i)*floor(value/float(i))) <= 0.0)
|
||||
{
|
||||
color = Colorizer(float(i), scale);
|
||||
gl_FragColor = Colorizer(float(i), scale);
|
||||
//break; // Uncomment to color by the largest factor instead
|
||||
}
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,9 @@ uniform vec2 c; // c.x = real, c.y = imaginary component. Equati
|
||||
uniform vec2 offset; // Offset of the scale.
|
||||
uniform float zoom; // Zoom of the scale.
|
||||
|
||||
const int MAX_ITERATIONS = 255; // Max iterations to do.
|
||||
// NOTE: Maximum number of shader for-loop iterations depend on GPU,
|
||||
// for example, on RasperryPi for this examply only supports up to 60
|
||||
const int MAX_ITERATIONS = 48; // Max iterations to do
|
||||
|
||||
// Square a complex number
|
||||
vec2 ComplexSquare(vec2 z)
|
||||
@@ -30,7 +32,6 @@ vec3 Hsv2rgb(vec3 c)
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
/**********************************************************************************************
|
||||
@@ -56,21 +57,22 @@ void main()
|
||||
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom
|
||||
vec2 z = vec2((fragTexCoord.x + offset.x/screenDims.x)*2.5/zoom, (fragTexCoord.y + offset.y/screenDims.y)*1.5/zoom);
|
||||
|
||||
int iterations = 0;
|
||||
for (iterations = 0; iterations < MAX_ITERATIONS; iterations++)
|
||||
int iter = 0;
|
||||
for (int iterations = 0; iterations < 60; iterations++)
|
||||
{
|
||||
z = ComplexSquare(z) + c; // Iterate function
|
||||
|
||||
if (dot(z, z) > 4.0) break;
|
||||
|
||||
iter = iterations;
|
||||
}
|
||||
|
||||
|
||||
// Another few iterations decreases errors in the smoothing calculation.
|
||||
// See http://linas.org/art-gallery/escape/escape.html for more information.
|
||||
z = ComplexSquare(z) + c;
|
||||
z = ComplexSquare(z) + c;
|
||||
|
||||
// This last part smooths the color (again see link above).
|
||||
float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||
float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||
|
||||
// Normalize the value so it is between 0 and 1.
|
||||
float norm = smoothVal/float(MAX_ITERATIONS);
|
||||
|
@@ -15,15 +15,27 @@ uniform ivec3 palette[colors];
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord) * fragColor;
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord)*fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
int index = int(texelColor.r * 255.0);
|
||||
ivec3 color = palette[index];
|
||||
int index = int(texelColor.r*255.0);
|
||||
|
||||
ivec3 color = ivec3(0);
|
||||
|
||||
// NOTE: On GLSL 100 we are not allowed to index a uniform array by a variable value,
|
||||
// a constantmust be used, so this logic...
|
||||
if (index == 0) color = palette[0];
|
||||
else if (index == 1) color = palette[1];
|
||||
else if (index == 2) color = palette[2];
|
||||
else if (index == 3) color = palette[3];
|
||||
else if (index == 4) color = palette[4];
|
||||
else if (index == 5) color = palette[5];
|
||||
else if (index == 6) color = palette[6];
|
||||
else if (index == 7) color = palette[7];
|
||||
|
||||
// Calculate final fragment color. Note that the palette color components
|
||||
// are defined in the range [0, 255] and need to be normalized to [0, 1]
|
||||
// for OpenGL to work.
|
||||
gl_FragColor = vec4(color / 255.0, texelColor.a);
|
||||
gl_FragColor = vec4(float(color.x)/255.0, float(color.y)/255.0, float(color.z)/255.0, texelColor.a);
|
||||
}
|
||||
|
@@ -8,8 +8,6 @@ varying vec4 fragColor;
|
||||
|
||||
uniform vec3 viewEye;
|
||||
uniform vec3 viewCenter;
|
||||
uniform vec3 viewUp;
|
||||
uniform float deltaTime;
|
||||
uniform float runTime;
|
||||
uniform vec2 resolution;
|
||||
|
||||
@@ -428,4 +426,4 @@ void main()
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4( tot, 1.0 );
|
||||
}
|
||||
}
|
||||
|
82
examples/shaders/resources/shaders/glsl330/basic_lighting.fs
Normal file
@@ -0,0 +1,82 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec3 fragPosition;
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
in vec3 fragNormal;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
|
||||
struct MaterialProperty {
|
||||
vec3 color;
|
||||
int useSampler;
|
||||
sampler2D sampler;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
vec3 position;
|
||||
vec3 target;
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
// Input lighting values
|
||||
uniform Light lights[MAX_LIGHTS];
|
||||
uniform vec4 ambient;
|
||||
uniform vec3 viewPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
vec3 lightDot = vec3(0.0);
|
||||
vec3 normal = normalize(fragNormal);
|
||||
vec3 viewD = normalize(viewPos - fragPosition);
|
||||
vec3 specular = vec3(0.0);
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||
{
|
||||
if (lights[i].enabled == 1)
|
||||
{
|
||||
vec3 light = vec3(0.0);
|
||||
|
||||
if (lights[i].type == LIGHT_DIRECTIONAL)
|
||||
{
|
||||
light = -normalize(lights[i].target - lights[i].position);
|
||||
}
|
||||
|
||||
if (lights[i].type == LIGHT_POINT)
|
||||
{
|
||||
light = normalize(lights[i].position - fragPosition);
|
||||
}
|
||||
|
||||
float NdotL = max(dot(normal, light), 0.0);
|
||||
lightDot += lights[i].color.rgb*NdotL;
|
||||
|
||||
float specCo = 0.0;
|
||||
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16); // 16 refers to shine
|
||||
specular += specCo;
|
||||
}
|
||||
}
|
||||
|
||||
finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
finalColor += texelColor*(ambient/10.0);
|
||||
|
||||
// Gamma correction
|
||||
finalColor = pow(finalColor, vec4(1.0/2.2));
|
||||
}
|
33
examples/shaders/resources/shaders/glsl330/basic_lighting.vs
Normal file
@@ -0,0 +1,33 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec3 fragPosition;
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
out vec3 fragNormal;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
99
examples/shaders/resources/shaders/glsl330/fog.fs
Normal file
@@ -0,0 +1,99 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
in vec3 fragPosition;
|
||||
in vec3 fragNormal;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
|
||||
struct MaterialProperty {
|
||||
vec3 color;
|
||||
int useSampler;
|
||||
sampler2D sampler;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
vec3 position;
|
||||
vec3 target;
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
// Input lighting values
|
||||
uniform Light lights[MAX_LIGHTS];
|
||||
uniform vec4 ambient;
|
||||
uniform vec3 viewPos;
|
||||
uniform float fogDensity;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
vec3 lightDot = vec3(0.0);
|
||||
vec3 normal = normalize(fragNormal);
|
||||
vec3 viewD = normalize(viewPos - fragPosition);
|
||||
vec3 specular = vec3(0.0);
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||
{
|
||||
if (lights[i].enabled == 1)
|
||||
{
|
||||
vec3 light = vec3(0.0);
|
||||
if (lights[i].type == LIGHT_DIRECTIONAL) {
|
||||
light = -normalize(lights[i].target - lights[i].position);
|
||||
}
|
||||
if (lights[i].type == LIGHT_POINT) {
|
||||
light = normalize(lights[i].position - fragPosition);
|
||||
}
|
||||
float NdotL = max(dot(normal, light), 0.0);
|
||||
lightDot += lights[i].color.rgb * NdotL;
|
||||
|
||||
float specCo = 0.0;
|
||||
if(NdotL > 0.0)
|
||||
specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16);//16 =shine
|
||||
specular += specCo;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
finalColor = (texelColor * ((colDiffuse+vec4(specular,1)) * vec4(lightDot, 1.0)));
|
||||
finalColor += texelColor * (ambient/10.0);
|
||||
|
||||
// Gamma correction
|
||||
finalColor = pow(finalColor, vec4(1.0/2.2));
|
||||
|
||||
// Fog calculation
|
||||
float dist = length(viewPos - fragPosition);
|
||||
|
||||
// these could be parameters...
|
||||
const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0);
|
||||
//const float fogDensity = 0.16;
|
||||
|
||||
// Exponential fog
|
||||
float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity));
|
||||
|
||||
// Linear fog (less nice)
|
||||
//const float fogStart = 2.0;
|
||||
//const float fogEnd = 10.0;
|
||||
//float fogFactor = (fogEnd - dist)/(fogEnd - fogStart);
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
finalColor = mix(fogColor, finalColor, fogFactor);
|
||||
}
|
32
examples/shaders/resources/shaders/glsl330/fog.vs
Normal file
@@ -0,0 +1,32 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
out vec3 fragPosition;
|
||||
out vec3 fragNormal;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
21
examples/shaders/resources/shaders/glsl330/mask.fs
Normal file
@@ -0,0 +1,21 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform sampler2D mask;
|
||||
uniform int frame;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 maskColour = texture(mask, fragTexCoord+vec2(sin(-frame/150.0)/10.0,cos(-frame/170.0)/10.0));
|
||||
if (maskColour.r < 0.25) discard;
|
||||
vec4 texelColor = texture(texture0, fragTexCoord+vec2(sin(frame/90.0)/8.0,cos(frame/60.0)/8.0));
|
||||
|
||||
finalColor = texelColor * maskColour;
|
||||
}
|
21
examples/shaders/resources/shaders/glsl330/mask.vs
Normal file
@@ -0,0 +1,21 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec2 fragTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragTexCoord = vertexTexCoord;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
@@ -9,8 +9,6 @@ out vec4 finalColor;
|
||||
|
||||
uniform vec3 viewEye;
|
||||
uniform vec3 viewCenter;
|
||||
uniform vec3 viewUp;
|
||||
uniform float deltaTime;
|
||||
uniform float runTime;
|
||||
uniform vec2 resolution;
|
||||
|
||||
@@ -429,4 +427,4 @@ void main()
|
||||
#endif
|
||||
|
||||
finalColor = vec4( tot, 1.0 );
|
||||
}
|
||||
}
|
||||
|
BIN
examples/shaders/resources/texel_checker.png
Normal file
After Width: | Height: | Size: 56 KiB |
187
examples/shaders/rlights.h
Normal file
@@ -0,0 +1,187 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.lights - Some useful functions to deal with lights data
|
||||
*
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define RLIGHTS_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2017-2019 Victor Fisac (@victorfisac) and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef RLIGHTS_H
|
||||
#define RLIGHTS_H
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#define MAX_LIGHTS 4 // Max dynamic lights supported by shader
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Light data
|
||||
typedef struct {
|
||||
int type;
|
||||
Vector3 position;
|
||||
Vector3 target;
|
||||
Color color;
|
||||
bool enabled;
|
||||
|
||||
// Shader locations
|
||||
int enabledLoc;
|
||||
int typeLoc;
|
||||
int posLoc;
|
||||
int targetLoc;
|
||||
int colorLoc;
|
||||
} Light;
|
||||
|
||||
// Light type
|
||||
typedef enum {
|
||||
LIGHT_DIRECTIONAL,
|
||||
LIGHT_POINT
|
||||
} LightType;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
int lightsCount = 0; // Current amount of created lights
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shader shader); // Create a light and get shader locations
|
||||
void UpdateLightValues(Shader shader, Light light); // Send light properties to shader
|
||||
//void InitLightLocations(Shader shader, Light *light); // Init light shader locations
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // RLIGHTS_H
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
*
|
||||
* RLIGHTS IMPLEMENTATION
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(RLIGHTS_IMPLEMENTATION)
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
// ...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
// ...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
// ...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
// ...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Create a light and get shader locations
|
||||
Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shader shader)
|
||||
{
|
||||
Light light = { 0 };
|
||||
|
||||
if (lightsCount < MAX_LIGHTS)
|
||||
{
|
||||
light.enabled = true;
|
||||
light.type = type;
|
||||
light.position = position;
|
||||
light.target = target;
|
||||
light.color = color;
|
||||
|
||||
// TODO: Below code doesn't look good to me,
|
||||
// it assumes a specific shader naming and structure
|
||||
// Probably this implementation could be improved
|
||||
char enabledName[32] = "lights[x].enabled\0";
|
||||
char typeName[32] = "lights[x].type\0";
|
||||
char posName[32] = "lights[x].position\0";
|
||||
char targetName[32] = "lights[x].target\0";
|
||||
char colorName[32] = "lights[x].color\0";
|
||||
enabledName[7] = '0' + lightsCount;
|
||||
typeName[7] = '0' + lightsCount;
|
||||
posName[7] = '0' + lightsCount;
|
||||
targetName[7] = '0' + lightsCount;
|
||||
colorName[7] = '0' + lightsCount;
|
||||
|
||||
light.enabledLoc = GetShaderLocation(shader, enabledName);
|
||||
light.typeLoc = GetShaderLocation(shader, typeName);
|
||||
light.posLoc = GetShaderLocation(shader, posName);
|
||||
light.targetLoc = GetShaderLocation(shader, targetName);
|
||||
light.colorLoc = GetShaderLocation(shader, colorName);
|
||||
|
||||
UpdateLightValues(shader, light);
|
||||
|
||||
lightsCount++;
|
||||
}
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
// Send light properties to shader
|
||||
// NOTE: Light shader locations should be available
|
||||
void UpdateLightValues(Shader shader, Light light)
|
||||
{
|
||||
// Send to shader light enabled state and type
|
||||
SetShaderValue(shader, light.enabledLoc, &light.enabled, UNIFORM_INT);
|
||||
SetShaderValue(shader, light.typeLoc, &light.type, UNIFORM_INT);
|
||||
|
||||
// Send to shader light position values
|
||||
float position[3] = { light.position.x, light.position.y, light.position.z };
|
||||
SetShaderValue(shader, light.posLoc, position, UNIFORM_VEC3);
|
||||
|
||||
// Send to shader light target position values
|
||||
float target[3] = { light.target.x, light.target.y, light.target.z };
|
||||
SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3);
|
||||
|
||||
// Send to shader light color values
|
||||
float color[4] = { (float)light.color.r/(float)255, (float)light.color.g/(float)255,
|
||||
(float)light.color.b/(float)255, (float)light.color.a/(float)255 };
|
||||
SetShaderValue(shader, light.colorLoc, color, UNIFORM_VEC4);
|
||||
}
|
||||
|
||||
#endif // RLIGHTS_IMPLEMENTATION
|
184
examples/shaders/shaders_basic_lighting.c
Normal file
@@ -0,0 +1,184 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - basic lighting
|
||||
*
|
||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
||||
*
|
||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
||||
*
|
||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Chris Camacho (@codifies - http://bedroomcoders.co.uk/) notes:
|
||||
*
|
||||
* This is based on the PBR lighting example, but greatly simplified to aid learning...
|
||||
* actually there is very little of the PBR example left!
|
||||
* When I first looked at the bewildering complexity of the PBR example I feared
|
||||
* I would never understand how I could do simple lighting with raylib however its
|
||||
* a testement to the authors of raylib (including rlights.h) that the example
|
||||
* came together fairly quickly.
|
||||
*
|
||||
* Copyright (c) 2019 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include "raymath.h"
|
||||
|
||||
#define RLIGHTS_IMPLEMENTATION
|
||||
#include "rlights.h"
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
#define GLSL_VERSION 330
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
#define GLSL_VERSION 100
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic lighting");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 2.0f, 2.0f, 6.0f }; // Camera position
|
||||
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
|
||||
// Load models
|
||||
Model modelA = LoadModelFromMesh(GenMeshTorus(0.4f, 1.0f, 16, 32));
|
||||
Model modelB = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
|
||||
Model modelC = LoadModelFromMesh(GenMeshSphere(0.5f, 32, 32));
|
||||
|
||||
// Load models texture
|
||||
Texture texture = LoadTexture("resources/texel_checker.png");
|
||||
|
||||
// Assign texture to default model material
|
||||
modelA.materials[0].maps[MAP_DIFFUSE].texture = texture;
|
||||
modelB.materials[0].maps[MAP_DIFFUSE].texture = texture;
|
||||
modelC.materials[0].maps[MAP_DIFFUSE].texture = texture;
|
||||
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/basic_lighting.vs",
|
||||
"resources/shaders/glsl330/basic_lighting.fs");
|
||||
|
||||
// Get some shader loactions
|
||||
shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||
shader.locs[LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||
|
||||
// ambient light level
|
||||
int ambientLoc = GetShaderLocation(shader, "ambient");
|
||||
SetShaderValue(shader, ambientLoc, (float[4]){ 0.2f, 0.2f, 0.2f, 1.0f }, UNIFORM_VEC4);
|
||||
|
||||
float angle = 6.282f;
|
||||
|
||||
// All models use the same shader
|
||||
modelA.materials[0].shader = shader;
|
||||
modelB.materials[0].shader = shader;
|
||||
modelC.materials[0].shader = shader;
|
||||
|
||||
// Using 4 point lights, white, red, green and blue
|
||||
Light lights[MAX_LIGHTS] = { 0 };
|
||||
lights[0] = CreateLight(LIGHT_POINT, (Vector3){ 4, 2, 4 }, Vector3Zero(), WHITE, shader);
|
||||
lights[1] = CreateLight(LIGHT_POINT, (Vector3){ 4, 2, 4 }, Vector3Zero(), RED, shader);
|
||||
lights[2] = CreateLight(LIGHT_POINT, (Vector3){ 0, 4, 2 }, Vector3Zero(), GREEN, shader);
|
||||
lights[3] = CreateLight(LIGHT_POINT, (Vector3){ 0, 4, 2 }, Vector3Zero(), BLUE, shader);
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyPressed(KEY_W)) { lights[0].enabled = !lights[0].enabled; }
|
||||
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
|
||||
if (IsKeyPressed(KEY_G)) { lights[2].enabled = !lights[2].enabled; }
|
||||
if (IsKeyPressed(KEY_B)) { lights[3].enabled = !lights[3].enabled; }
|
||||
|
||||
UpdateCamera(&camera); // Update camera
|
||||
|
||||
// Make the lights do differing orbits
|
||||
angle -= 0.02;
|
||||
lights[0].position.x = cosf(angle)*4.0f;
|
||||
lights[0].position.z = sinf(angle)*4.0f;
|
||||
lights[1].position.x = cosf(-angle*0.6f)*4.0f;
|
||||
lights[1].position.z = sinf(-angle*0.6f)*4.0f;
|
||||
lights[2].position.y = cosf(angle*0.2f)*4.0f;
|
||||
lights[2].position.z = sinf(angle*0.2f)*4.0f;
|
||||
lights[3].position.y = cosf(-angle*0.35f)*4.0f;
|
||||
lights[3].position.z = sinf(-angle*0.35f)*4.0f;
|
||||
|
||||
UpdateLightValues(shader, lights[0]);
|
||||
UpdateLightValues(shader, lights[1]);
|
||||
UpdateLightValues(shader, lights[2]);
|
||||
UpdateLightValues(shader, lights[3]);
|
||||
|
||||
// Rotate the torus
|
||||
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025));
|
||||
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012));
|
||||
|
||||
// Update the light shader with the camera view position
|
||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||
SetShaderValue(shader, shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
// Draw the three models
|
||||
DrawModel(modelA, Vector3Zero(), 1.0f, WHITE);
|
||||
DrawModel(modelB, (Vector3){-1.6,0,0}, 1.0f, WHITE);
|
||||
DrawModel(modelC, (Vector3){ 1.6,0,0}, 1.0f, WHITE);
|
||||
|
||||
// Draw markers to show where the lights are
|
||||
if (lights[0].enabled) { DrawSphereEx(lights[0].position, 0.2f, 8, 8, WHITE); }
|
||||
if (lights[1].enabled) { DrawSphereEx(lights[1].position, 0.2f, 8, 8, RED); }
|
||||
if (lights[2].enabled) { DrawSphereEx(lights[2].position, 0.2f, 8, 8, GREEN); }
|
||||
if (lights[3].enabled) { DrawSphereEx(lights[3].position, 0.2f, 8, 8, BLUE); }
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
DrawText("Keys RGB & W toggle lights", 10, 30, 20, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(modelA); // Unload the modelA
|
||||
UnloadModel(modelB); // Unload the modelB
|
||||
UnloadModel(modelC); // Unload the modelC
|
||||
|
||||
UnloadTexture(texture); // Unload the texture
|
||||
UnloadShader(shader); // Unload shader
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
BIN
examples/shaders/shaders_basic_lighting.png
Normal file
After Width: | Height: | Size: 81 KiB |
153
examples/shaders/shaders_fog.c
Normal file
@@ -0,0 +1,153 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - fog
|
||||
*
|
||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
||||
*
|
||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
||||
*
|
||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Chris Camacho (@codifies - http://bedroomcoders.co.uk/) notes:
|
||||
*
|
||||
* This is based on the PBR lighting example, but greatly simplified to aid learning...
|
||||
* actually there is very little of the PBR example left!
|
||||
* When I first looked at the bewildering complexity of the PBR example I feared
|
||||
* I would never understand how I could do simple lighting with raylib however its
|
||||
* a testement to the authors of raylib (including rlights.h) that the example
|
||||
* came together fairly quickly.
|
||||
*
|
||||
* Copyright (c) 2019 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include "raymath.h"
|
||||
|
||||
#define RLIGHTS_IMPLEMENTATION
|
||||
#include "rlights.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - fog");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = {
|
||||
(Vector3){ 2.0f, 2.0f, 6.0f }, // position
|
||||
(Vector3){ 0.0f, 0.5f, 0.0f }, // target
|
||||
(Vector3){ 0.0f, 1.0f, 0.0f }, // up
|
||||
45.0f, CAMERA_PERSPECTIVE }; // fov, type
|
||||
|
||||
// Load models and texture
|
||||
Model modelA = LoadModelFromMesh(GenMeshTorus(0.4f, 1.0f, 16, 32));
|
||||
Model modelB = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
|
||||
Model modelC = LoadModelFromMesh(GenMeshSphere(0.5f, 32, 32));
|
||||
Texture texture = LoadTexture("resources/texel_checker.png");
|
||||
|
||||
// Assign texture to default model material
|
||||
modelA.materials[0].maps[MAP_DIFFUSE].texture = texture;
|
||||
modelB.materials[0].maps[MAP_DIFFUSE].texture = texture;
|
||||
modelC.materials[0].maps[MAP_DIFFUSE].texture = texture;
|
||||
|
||||
// Load shader and set up some uniforms
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/fog.vs", "resources/shaders/glsl330/fog.fs");
|
||||
shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||
shader.locs[LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||
|
||||
// Ambient light level
|
||||
int ambientLoc = GetShaderLocation(shader, "ambient");
|
||||
SetShaderValue(shader, ambientLoc, (float[4]){ 0.2f, 0.2f, 0.2f, 1.0f }, UNIFORM_VEC4);
|
||||
|
||||
float fogDensity = 0.15f;
|
||||
int fogDensityLoc = GetShaderLocation(shader, "fogDensity");
|
||||
SetShaderValue(shader, fogDensityLoc, &fogDensity, UNIFORM_FLOAT);
|
||||
|
||||
// NOTE: All models share the same shader
|
||||
modelA.materials[0].shader = shader;
|
||||
modelB.materials[0].shader = shader;
|
||||
modelC.materials[0].shader = shader;
|
||||
|
||||
// Using just 1 point lights
|
||||
CreateLight(LIGHT_POINT, (Vector3){ 0, 2, 6 }, Vector3Zero(), WHITE, shader);
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera); // Update camera
|
||||
|
||||
if (IsKeyDown(KEY_UP))
|
||||
{
|
||||
fogDensity += 0.001;
|
||||
if (fogDensity > 1.0) fogDensity = 1.0;
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_DOWN))
|
||||
{
|
||||
fogDensity -= 0.001;
|
||||
if (fogDensity < 0.0) fogDensity = 0.0;
|
||||
}
|
||||
|
||||
SetShaderValue(shader, fogDensityLoc, &fogDensity, UNIFORM_FLOAT);
|
||||
|
||||
// Rotate the torus
|
||||
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025));
|
||||
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012));
|
||||
|
||||
// Update the light shader with the camera view position
|
||||
SetShaderValue(shader, shader.locs[LOC_VECTOR_VIEW], &camera.position.x, UNIFORM_VEC3);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(GRAY);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
// Draw the three models
|
||||
DrawModel(modelA, Vector3Zero(), 1.0f, WHITE);
|
||||
DrawModel(modelB, (Vector3){ -2.6, 0, 0 }, 1.0f, WHITE);
|
||||
DrawModel(modelC, (Vector3){ 2.6, 0, 0 }, 1.0f, WHITE);
|
||||
|
||||
for (int i = -20; i < 20; i += 2) DrawModel(modelA,(Vector3){ i, 0, 2 }, 1.0f, WHITE);
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawText(TextFormat("Use KEY_UP/KEY_DOWN to change fog density [%.2f]", fogDensity), 10, 10, 20, RAYWHITE);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(modelA); // Unload the model A
|
||||
UnloadModel(modelB); // Unload the model B
|
||||
UnloadModel(modelC); // Unload the model C
|
||||
UnloadTexture(texture); // Unload the texture
|
||||
UnloadShader(shader); // Unload shader
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
BIN
examples/shaders/shaders_fog.png
Normal file
After Width: | Height: | Size: 80 KiB |
@@ -28,9 +28,10 @@ int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - raymarching shapes");
|
||||
|
||||
Camera camera = { 0 };
|
||||
@@ -48,12 +49,10 @@ int main(void)
|
||||
// Get shader locations for required uniforms
|
||||
int viewEyeLoc = GetShaderLocation(shader, "viewEye");
|
||||
int viewCenterLoc = GetShaderLocation(shader, "viewCenter");
|
||||
int viewUpLoc = GetShaderLocation(shader, "viewUp");
|
||||
int deltaTimeLoc = GetShaderLocation(shader, "deltaTime");
|
||||
int runTimeLoc = GetShaderLocation(shader, "runTime");
|
||||
int resolutionLoc = GetShaderLocation(shader, "resolution");
|
||||
|
||||
float resolution[2] = { screenWidth, screenHeight };
|
||||
float resolution[2] = { (float)screenWidth, (float)screenHeight };
|
||||
SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2);
|
||||
|
||||
float runTime = 0.0f;
|
||||
@@ -64,13 +63,22 @@ int main(void)
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Check if screen is resized
|
||||
//----------------------------------------------------------------------------------
|
||||
if(IsWindowResized())
|
||||
{
|
||||
screenWidth = GetScreenWidth();
|
||||
screenHeight = GetScreenHeight();
|
||||
float resolution[2] = { (float)screenWidth, (float)screenHeight };
|
||||
SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2);
|
||||
}
|
||||
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera); // Update camera
|
||||
|
||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||
float cameraTarget[3] = { camera.target.x, camera.target.y, camera.target.z };
|
||||
float cameraUp[3] = { camera.up.x, camera.up.y, camera.up.z };
|
||||
|
||||
float deltaTime = GetFrameTime();
|
||||
runTime += deltaTime;
|
||||
@@ -78,8 +86,6 @@ int main(void)
|
||||
// Set shader required uniform values
|
||||
SetShaderValue(shader, viewEyeLoc, cameraPos, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, viewCenterLoc, cameraTarget, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, viewUpLoc, cameraUp, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, deltaTimeLoc, &deltaTime, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, runTimeLoc, &runTime, UNIFORM_FLOAT);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@@ -95,7 +101,7 @@ int main(void)
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
||||
EndShaderMode();
|
||||
|
||||
DrawText("(c) Raymarching shader by Iñigo Quilez. MIT License.", screenWidth - 280, screenHeight - 20, 10, GRAY);
|
||||
DrawText("(c) Raymarching shader by Iñigo Quilez. MIT License.", screenWidth - 280, screenHeight - 20, 10, BLACK);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
@@ -109,4 +115,4 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
139
examples/shaders/shaders_simple_mask.c
Normal file
@@ -0,0 +1,139 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Simple shader mask
|
||||
*
|
||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2019 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************
|
||||
*
|
||||
* After a model is loaded it has a default material, this material can be
|
||||
* modified in place rather than creating one from scratch...
|
||||
* While all of the maps have particular names, they can be used for any purpose
|
||||
* except for three maps that are applied as cubic maps (see below)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib - simple shader mask");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 0.0f, 1.0f, 2.0f };
|
||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||
camera.fovy = 45.0f;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
|
||||
// Define our three models to show the shader on
|
||||
Mesh torus = GenMeshTorus(.3, 1, 16, 32);
|
||||
Model model1 = LoadModelFromMesh(torus);
|
||||
|
||||
Mesh cube = GenMeshCube(.8,.8,.8);
|
||||
Model model2 = LoadModelFromMesh(cube);
|
||||
|
||||
// Generate model to be shaded just to see the gaps in the other two
|
||||
Mesh sphere = GenMeshSphere(1, 16, 16);
|
||||
Model model3 = LoadModelFromMesh(sphere);
|
||||
|
||||
// Load the shader
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/mask.vs", "resources/shaders/glsl330/mask.fs");
|
||||
|
||||
// Load and apply the diffuse texture (colour map)
|
||||
Texture texDiffuse = LoadTexture("resources/plasma.png");
|
||||
model1.materials[0].maps[MAP_DIFFUSE].texture = texDiffuse;
|
||||
model2.materials[0].maps[MAP_DIFFUSE].texture = texDiffuse;
|
||||
|
||||
// Using MAP_EMISSION as a spare slot to use for 2nd texture
|
||||
// NOTE: Don't use MAP_IRRADIANCE, MAP_PREFILTER or MAP_CUBEMAP
|
||||
// as they are bound as cube maps
|
||||
Texture texMask = LoadTexture("resources/mask.png");
|
||||
model1.materials[0].maps[MAP_EMISSION].texture = texMask;
|
||||
model2.materials[0].maps[MAP_EMISSION].texture = texMask;
|
||||
shader.locs[LOC_MAP_EMISSION] = GetShaderLocation(shader, "mask");
|
||||
|
||||
// Frame is incremented each frame to animate the shader
|
||||
int shaderFrame = GetShaderLocation(shader, "framesCounter");
|
||||
|
||||
// Apply the shader to the two models
|
||||
model1.materials[0].shader = shader;
|
||||
model2.materials[0].shader = shader;
|
||||
|
||||
int framesCounter = 0;
|
||||
Vector3 rotation = { 0 }; // Model rotation angles
|
||||
|
||||
SetTargetFPS(60); // Set to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
framesCounter++;
|
||||
rotation.x += 0.01f;
|
||||
rotation.y += 0.005f;
|
||||
rotation.z -= 0.0025f;
|
||||
|
||||
// Send frames counter to shader for animation
|
||||
SetShaderValue(shader, shaderFrame, &framesCounter, UNIFORM_INT);
|
||||
|
||||
// Rotate one of the models
|
||||
model1.transform = MatrixRotateXYZ(rotation);
|
||||
|
||||
UpdateCamera(&camera);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(DARKBLUE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
DrawModel(model1, (Vector3){0.5,0,0}, 1, WHITE);
|
||||
DrawModelEx(model2, (Vector3){-.5,0,0}, (Vector3){1,1,0}, 50, (Vector3){1,1,1}, WHITE);
|
||||
DrawModel(model3,(Vector3){0,0,-1.5}, 1, WHITE);
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawRectangle(16, 698, MeasureText(FormatText("Frame: %i", framesCounter), 20) + 8, 42, BLUE);
|
||||
DrawText(FormatText("Frame: %i", framesCounter), 20, 700, 20, WHITE);
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(model1);
|
||||
UnloadModel(model2);
|
||||
UnloadModel(model3);
|
||||
|
||||
UnloadTexture(texDiffuse); // Unload default diffuse texture
|
||||
UnloadTexture(texMask); // Unload texture mask
|
||||
|
||||
UnloadShader(shader); // Unload shader
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
BIN
examples/shaders/shaders_simple_mask.png
Normal file
After Width: | Height: | Size: 427 KiB |
@@ -33,38 +33,38 @@ int main(void)
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves");
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves");
|
||||
|
||||
// Load texture texture to apply shaders
|
||||
Texture2D texture = LoadTexture("resources/space.png");
|
||||
|
||||
Texture2D texture = LoadTexture("resources/space.png");
|
||||
|
||||
// Load shader and setup location points and values
|
||||
Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/wave.fs", GLSL_VERSION));
|
||||
|
||||
int secondsLoc = GetShaderLocation(shader, "secondes");
|
||||
int freqXLoc = GetShaderLocation(shader, "freqX");
|
||||
int freqYLoc = GetShaderLocation(shader, "freqY");
|
||||
int ampXLoc = GetShaderLocation(shader, "ampX");
|
||||
int ampYLoc = GetShaderLocation(shader, "ampY");
|
||||
int speedXLoc = GetShaderLocation(shader, "speedX");
|
||||
int speedYLoc = GetShaderLocation(shader, "speedY");
|
||||
int secondsLoc = GetShaderLocation(shader, "secondes");
|
||||
int freqXLoc = GetShaderLocation(shader, "freqX");
|
||||
int freqYLoc = GetShaderLocation(shader, "freqY");
|
||||
int ampXLoc = GetShaderLocation(shader, "ampX");
|
||||
int ampYLoc = GetShaderLocation(shader, "ampY");
|
||||
int speedXLoc = GetShaderLocation(shader, "speedX");
|
||||
int speedYLoc = GetShaderLocation(shader, "speedY");
|
||||
|
||||
// Shader uniform values that can be updated at any time
|
||||
float freqX = 25.0f;
|
||||
float freqY = 25.0f;
|
||||
float ampX = 5.0f;
|
||||
float ampY = 5.0f;
|
||||
float speedX = 8.0f;
|
||||
float speedY = 8.0f;
|
||||
float freqX = 25.0f;
|
||||
float freqY = 25.0f;
|
||||
float ampX = 5.0f;
|
||||
float ampY = 5.0f;
|
||||
float speedX = 8.0f;
|
||||
float speedY = 8.0f;
|
||||
|
||||
float screenSize[2] = { (float)GetScreenWidth(), (float)GetScreenHeight() };
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "size"), &screenSize, UNIFORM_VEC2);
|
||||
SetShaderValue(shader, freqXLoc, &freqX, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, freqYLoc, &freqY, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, ampXLoc, &X, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, ampYLoc, &Y, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, speedXLoc, &speedX, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, speedYLoc, &speedY, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "size"), &screenSize, UNIFORM_VEC2);
|
||||
SetShaderValue(shader, freqXLoc, &freqX, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, freqYLoc, &freqY, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, ampXLoc, &X, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, ampYLoc, &Y, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, speedXLoc, &speedX, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, speedYLoc, &speedY, UNIFORM_FLOAT);
|
||||
|
||||
float seconds = 0.0f;
|
||||
|
||||
@@ -76,9 +76,9 @@ int main(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
seconds += GetFrameTime();
|
||||
seconds += GetFrameTime();
|
||||
|
||||
SetShaderValue(shader, secondsLoc, &seconds, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, secondsLoc, &seconds, UNIFORM_FLOAT);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@@ -87,12 +87,12 @@ int main(void)
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginShaderMode(shader);
|
||||
BeginShaderMode(shader);
|
||||
|
||||
DrawTexture(texture, 0, 0, WHITE);
|
||||
DrawTexture(texture, texture.width, 0, WHITE);
|
||||
DrawTexture(texture, 0, 0, WHITE);
|
||||
DrawTexture(texture, texture.width, 0, WHITE);
|
||||
|
||||
EndShaderMode();
|
||||
EndShaderMode();
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|