Compare commits
192 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
17f09cb034 | ||
![]() |
a81dfabf86 | ||
![]() |
784aa1b6b5 | ||
![]() |
fda91436b5 | ||
![]() |
05f68c22d5 | ||
![]() |
0925f4ec4d | ||
![]() |
b8481369f7 | ||
![]() |
f1bcfc1352 | ||
![]() |
d1c9c34b2f | ||
![]() |
e8630c78d0 | ||
![]() |
d0fca7e02b | ||
![]() |
aa9353feb4 | ||
![]() |
0716125ee9 | ||
![]() |
918fc002d0 | ||
![]() |
bdbb1eb901 | ||
![]() |
481ce3d39d | ||
![]() |
85c400c006 | ||
![]() |
f0626324ab | ||
![]() |
6fa5dec16d | ||
![]() |
0603e59cae | ||
![]() |
6b072e696d | ||
![]() |
f7b706263a | ||
![]() |
c7f0350182 | ||
![]() |
b0d5a7a372 | ||
![]() |
bee283b12b | ||
![]() |
e23e73d9b2 | ||
![]() |
6f3186eacc | ||
![]() |
f18c8cea16 | ||
![]() |
41e49c5a6e | ||
![]() |
5d46c27cd5 | ||
![]() |
6d1b712a96 | ||
![]() |
9d3ad52160 | ||
![]() |
4123233f78 | ||
![]() |
a3d71dd58d | ||
![]() |
2b50440a77 | ||
![]() |
9fb6eda5f1 | ||
![]() |
38df2cad25 | ||
![]() |
4245237892 | ||
![]() |
773b0b6bc0 | ||
![]() |
66d22acfb3 | ||
![]() |
aa945055fa | ||
![]() |
ca96122a7b | ||
![]() |
ed4fdfdaf8 | ||
![]() |
3be81b01d7 | ||
![]() |
f2d61d4d43 | ||
![]() |
f16f39e8aa | ||
![]() |
80f6b2f963 | ||
![]() |
64f67f6e9f | ||
![]() |
6d3b11ef91 | ||
![]() |
3393fda384 | ||
![]() |
673dcf9436 | ||
![]() |
cc917fbac6 | ||
![]() |
16101ce3d8 | ||
![]() |
836d3341a5 | ||
![]() |
988d39029f | ||
![]() |
43fd9ffe08 | ||
![]() |
02842a3e2f | ||
![]() |
4ff98f34bb | ||
![]() |
5c80f65082 | ||
![]() |
137057f499 | ||
![]() |
6d34adbd60 | ||
![]() |
1142d4edae | ||
![]() |
b8ce680511 | ||
![]() |
0ce7f0c409 | ||
![]() |
d5e0f4e84e | ||
![]() |
8f60996b64 | ||
![]() |
a9315fc422 | ||
![]() |
1c05017548 | ||
![]() |
9e285d8dc3 | ||
![]() |
98d7a10c08 | ||
![]() |
4a3ed6d73c | ||
![]() |
b3bc4b21d1 | ||
![]() |
76a67a149e | ||
![]() |
97e3277d58 | ||
![]() |
648676f46b | ||
![]() |
5fecf5c088 | ||
![]() |
c384b375df | ||
![]() |
b1651baea5 | ||
![]() |
4c791100cc | ||
![]() |
5af1b4a7c9 | ||
![]() |
3396743aba | ||
![]() |
efa286a550 | ||
![]() |
b4a3f294bf | ||
![]() |
2a158c4795 | ||
![]() |
db6538859c | ||
![]() |
b082807b0b | ||
![]() |
637d3195ec | ||
![]() |
2ae9ce29eb | ||
![]() |
978c49472a | ||
![]() |
753b549aa5 | ||
![]() |
87fc7254e7 | ||
![]() |
65d4eb5e82 | ||
![]() |
4a65b19f0f | ||
![]() |
1ffe713d93 | ||
![]() |
478d3cbb79 | ||
![]() |
c5bf9623d1 | ||
![]() |
79c8eb543e | ||
![]() |
9923fe51a7 | ||
![]() |
7f0880a735 | ||
![]() |
173f199313 | ||
![]() |
94142ecce5 | ||
![]() |
0c58c1198f | ||
![]() |
1e55c30824 | ||
![]() |
8b35de3276 | ||
![]() |
10280c4b91 | ||
![]() |
36f20376e6 | ||
![]() |
9d66bc4a05 | ||
![]() |
a9ab516dae | ||
![]() |
d27709b1f2 | ||
![]() |
384602e5b5 | ||
![]() |
d0cf19e035 | ||
![]() |
be97583f00 | ||
![]() |
7dbb17792a | ||
![]() |
4770e2010d | ||
![]() |
5d88eb1d95 | ||
![]() |
f1c3f2870b | ||
![]() |
2a9b8d7a39 | ||
![]() |
1d71e1b754 | ||
![]() |
959a228815 | ||
![]() |
342b89c5b9 | ||
![]() |
852813bdf1 | ||
![]() |
1ffc4c7825 | ||
![]() |
bd26b66c27 | ||
![]() |
3377a4485b | ||
![]() |
c98b7eecd8 | ||
![]() |
6e20037f7d | ||
![]() |
29f14186c1 | ||
![]() |
289e04a62a | ||
![]() |
a1b6b217e4 | ||
![]() |
eb9072a2f1 | ||
![]() |
cc2b3228d1 | ||
![]() |
caecb1c1eb | ||
![]() |
7e36727328 | ||
![]() |
ed387d00aa | ||
![]() |
7fbd821727 | ||
![]() |
f69f930b51 | ||
![]() |
cae209816c | ||
![]() |
2c079d7c6e | ||
![]() |
46248b0922 | ||
![]() |
47b6e62744 | ||
![]() |
6f27941e28 | ||
![]() |
1950085893 | ||
![]() |
306945fe14 | ||
![]() |
16ac468bdb | ||
![]() |
58c762baa3 | ||
![]() |
865b216ebe | ||
![]() |
82a0fae678 | ||
![]() |
7f9513fbf4 | ||
![]() |
cfe47cc854 | ||
![]() |
4960e6b6d7 | ||
![]() |
3b80e2c1e0 | ||
![]() |
d5f5f0a930 | ||
![]() |
ae70540a96 | ||
![]() |
00c7e54d3c | ||
![]() |
5f1b4e9474 | ||
![]() |
5da66e7ec8 | ||
![]() |
3d519c7a39 | ||
![]() |
80789e6140 | ||
![]() |
055d501345 | ||
![]() |
70ec517fda | ||
![]() |
5c30e079f4 | ||
![]() |
735968e685 | ||
![]() |
d3d9aaceb1 | ||
![]() |
8c0bd30fcb | ||
![]() |
50ccc39d6b | ||
![]() |
68d647c1af | ||
![]() |
58d2f70b7e | ||
![]() |
36cf1f7dfd | ||
![]() |
2dc5f580a6 | ||
![]() |
02c456432d | ||
![]() |
a61b832c4a | ||
![]() |
13ebc745fe | ||
![]() |
8f7cb6fb19 | ||
![]() |
a008d49230 | ||
![]() |
a422e39492 | ||
![]() |
07a375e2d6 | ||
![]() |
6d68c78989 | ||
![]() |
9e8232d750 | ||
![]() |
c604b53f78 | ||
![]() |
020601092e | ||
![]() |
a94b553aff | ||
![]() |
4facc03a64 | ||
![]() |
53056f3e7e | ||
![]() |
fbf0362943 | ||
![]() |
7fa1f2ffde | ||
![]() |
ab5d1df7cb | ||
![]() |
7921d85dc8 | ||
![]() |
32a671b9da | ||
![]() |
3e1321ac24 | ||
![]() |
7a09043cba | ||
![]() |
9fea631bfb | ||
![]() |
1aecd5be07 |
16
.gitignore
vendored
@@ -49,7 +49,7 @@ ipch/
|
|||||||
# Ignore compiled binaries
|
# Ignore compiled binaries
|
||||||
*.o
|
*.o
|
||||||
*.exe
|
*.exe
|
||||||
!tools/rrem.exe
|
!tools/rREM/rrem.exe
|
||||||
|
|
||||||
# Ignore files build by xcode
|
# Ignore files build by xcode
|
||||||
*.mode*v*
|
*.mode*v*
|
||||||
@@ -75,4 +75,16 @@ src/libraylib.bc
|
|||||||
!src/external/glfw3/lib/win32/glfw3.dll
|
!src/external/glfw3/lib/win32/glfw3.dll
|
||||||
!src/external/openal_soft/lib/win32/OpenAL32.dll
|
!src/external/openal_soft/lib/win32/OpenAL32.dll
|
||||||
!src/external/OculusSDK/LibOVR/LibOVRRT32_1.dll
|
!src/external/OculusSDK/LibOVR/LibOVRRT32_1.dll
|
||||||
!src/external/pthread/pthreadGC2.dll
|
!src/external/pthread/lib/pthreadGC2.dll
|
||||||
|
|
||||||
|
# Visual Studio project
|
||||||
|
project/vs2015/*.db
|
||||||
|
project/vs2015/*.opendb
|
||||||
|
!project/vs2015/raylib.sln
|
||||||
|
!project/vs2015/raylib/*.vcxproj
|
||||||
|
!project/vs2015/examples/*.vcxproj
|
||||||
|
!project/vs2015/external/glfw3/lib/win32/glfw3.dll
|
||||||
|
!project/vs2015/external/openal_soft/lib/win32/OpenAL32.dll
|
||||||
|
!project/vs2015/external/openal_soft/lib/win64/OpenAL32.dll
|
||||||
|
!project/vs2015/external/lua/lib/win32/lua53.dll
|
||||||
|
|
||||||
|
60
CHANGELOG
@@ -1,10 +1,64 @@
|
|||||||
changelog
|
changelog
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Current Release: raylib 1.5.0 (18 July 2016)
|
Current Release: raylib 1.6.0 (20 November 2016)
|
||||||
|
|
||||||
NOTE: Only versions marked as 'Release' are available in installer, updates are only available as source.
|
-----------------------------------------------
|
||||||
NOTE: Current Release includes all previous updates.
|
Release: raylib 1.6.0 (20 November 2016)
|
||||||
|
-----------------------------------------------
|
||||||
|
NOTE:
|
||||||
|
This new raylib version commemorates raylib 3rd anniversary and represents another complete review of the library.
|
||||||
|
It includes some interesting new features and is a stepping stone towards raylib future.
|
||||||
|
|
||||||
|
HUGE changes:
|
||||||
|
[rlua] LUA BINDING: Complete raylib LUA binding, ALL raylib functions ported to LUA plus the +60 code examples.
|
||||||
|
[audio] COMPLETE REDESIGN: Improved music support and also raw audio data processing and playing, +20 new functions added.
|
||||||
|
[physac] COMPLETE REWRITE: Improved performance, functionality and simplified usage, moved to own repository and added multiple examples!
|
||||||
|
|
||||||
|
Other changes:
|
||||||
|
|
||||||
|
[core] Corrected issue on OSX with HighDPI display
|
||||||
|
[core] Added flag to allow resizable window
|
||||||
|
[core] Allow no default font loading
|
||||||
|
[core] Corrected old issue with mouse buttons on web
|
||||||
|
[core] Improved gamepad support, unified across platforms
|
||||||
|
[core] Gamepad id functionality: GetGamepadName(), IsGamepadName()
|
||||||
|
[core] Gamepad buttons/axis checking functionality:
|
||||||
|
[core] Reviewed Android key inputs system, unified with desktop
|
||||||
|
[rlgl] Redesigned lighting shader system
|
||||||
|
[rlgl] Updated standard shader for better performance
|
||||||
|
[rlgl] Support alpha on framebuffer: rlglLoadRenderTexture()
|
||||||
|
[rlgl] Reviewed UpdateVrTracking() to update camera
|
||||||
|
[rlgl] Added IsVrSimulator() to check for VR simulator
|
||||||
|
[shapes] Corrected issue on DrawPolyEx()
|
||||||
|
[textures] Simplified supported image formats support
|
||||||
|
[textures] Improved text drawing within an image: ImageDrawText()
|
||||||
|
[textures] Support image alpha mixing: ImageAlphaMask()
|
||||||
|
[textures] Support textures filtering: SetTextureFilter()
|
||||||
|
[textures] Support textures wrap modes: SetTextureWrap()
|
||||||
|
[text] Improved TTF spritefont generation: LoadSpriteFontTTF()
|
||||||
|
[text] Improved AngelCode fonts support (unordered chars)
|
||||||
|
[text] Added TraceLog info on image spritefont loading
|
||||||
|
[text] Improved text measurement: MeasureTextEx()
|
||||||
|
[models] Improved OBJ loading flexibility
|
||||||
|
[models] Reviewed functions: DrawLine3D(), DrawCircle3D()
|
||||||
|
[models] Removed function: ResolveCollisionCubicmap()
|
||||||
|
[camera] Redesigned camera system and ported to header-only
|
||||||
|
[camera] Removed function: UpdateCameraPlayer()
|
||||||
|
[gestures] Redesigned gestures module to header-only
|
||||||
|
[audio] Simplified Music loading and playing system
|
||||||
|
[audio] Added trace on audio device closing
|
||||||
|
[audio] Reviewed Wave struct, improved flexibility
|
||||||
|
[audio] Support sound data update: UpdateSound()
|
||||||
|
[audio] Added support for FLAC audio loading/streaming
|
||||||
|
[raygui] Removed raygui from raylib repo (moved to own repo)
|
||||||
|
[build] Added OpenAL static library
|
||||||
|
[build] Added Visual Studio 2015 projects
|
||||||
|
[build] Support shared/dynamic raylib compilation
|
||||||
|
[*] Updated LibOVR to SDK version 1.8
|
||||||
|
[*] Updated games to latest raylib version
|
||||||
|
[*] Improved examples and added new ones
|
||||||
|
[*] Improved Android support
|
||||||
|
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
Release: raylib 1.5.0 (18 July 2016)
|
Release: raylib 1.5.0 (18 July 2016)
|
||||||
|
28
README.md
@@ -153,11 +153,33 @@ Up to 8 new code examples have been added to show the new raylib features and al
|
|||||||
|
|
||||||
Lots of code changes (+400 commits) and lots of hours of hard work have concluded in this amazing new raylib 1.5.
|
Lots of code changes (+400 commits) and lots of hours of hard work have concluded in this amazing new raylib 1.5.
|
||||||
|
|
||||||
|
notes on raylib 1.6
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
On November 2016, only 4 months after raylib 1.5, arrives raylib 1.6. This new version represents another big review of the library and includes some interesting additions. This version conmmemorates raylib 3rd anniversary (raylib 1.0 was published on November 2013) and it is a stepping stone for raylib future. raylib roadmap has been reviewed and redefined to focus on its primary objective: create a simple and easy-to-use library to learn videogames programming. Some of the new features:
|
||||||
|
|
||||||
|
Complete raylib LUA binding. All raylib functions plus the +60 code examples have been ported to LUA, now LUA users can enjoy coding videogames in LUA while using all the internal power of raylib. This addition also open the doors to LUA scripting support for a future raylib-based engine, being able to move game logic (Init, Update, Draw, De-Init) to LUA scripts while keep using raylib functionality.
|
||||||
|
|
||||||
|
Completely redesigned audio module. Based on the new direction taken in raylib 1.5, it has been further improved and more functionality added (+20 new functions) to allow raw audio processing and streaming. FLAC file format support has also been added. In the same line, OpenAL Soft backend is now provided as a static library in Windows to allow static linking and get ride of OpenAL32.dll. Now raylib Windows games are completey self-contained, no external libraries required any more!
|
||||||
|
|
||||||
|
Physac module has been moved to its own repository and it has been improved A LOT, actually, library has been completely rewritten from scratch by @victorfisac, multiple samples have been added together with countless new features to match current standard 2D physic libraries. Results are amazing!
|
||||||
|
|
||||||
|
Camera and gestures modules have been reviewed, highly simplified and ported to single-file header-only libraries for easier portability and usage flexibility. Consequently, camera system usage has been simplified in all examples.
|
||||||
|
|
||||||
|
Improved Gamepad support on Windows and Raspberry Pi with the addition of new functions for custom gamepad configurations but supporting by default PS3 and Xbox-based gamepads.
|
||||||
|
|
||||||
|
Improved textures and text functionality, adding new functions for texture filtering control and better TTF/AngelCode fonts loading and generation support.
|
||||||
|
|
||||||
|
Build system improvement. Added support for raylib dynamic library generation (raylib.dll) for users that prefer dynamic library linking. Also thinking on advance users, it has been added pre-configured Visual Studio C++ 2015 solution with raylib project and C/C++ examples for users that prefer that professional IDE and compiler.
|
||||||
|
|
||||||
|
New examples, new functions, complete code-base review, multiple bugs corrected... this is raylib 1.6. Enjoy making games.
|
||||||
|
|
||||||
|
|
||||||
features
|
features
|
||||||
--------
|
--------
|
||||||
|
|
||||||
* Written in plain C code (C99)
|
* Written in plain C code (C99)
|
||||||
* Uses C# PascalCase/camelCase notation
|
* Uses PascalCase/camelCase notation
|
||||||
* Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES2)
|
* Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES2)
|
||||||
* Unique OpenGL abstraction layer (usable as standalone module): [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c)
|
* Unique OpenGL abstraction layer (usable as standalone module): [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c)
|
||||||
* Powerful fonts module with multiple SpriteFonts formats support (XNA bitmap fonts, AngelCode fonts, TTF)
|
* Powerful fonts module with multiple SpriteFonts formats support (XNA bitmap fonts, AngelCode fonts, TTF)
|
||||||
@@ -166,11 +188,12 @@ features
|
|||||||
* Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support
|
* Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support
|
||||||
* Shaders support, including Model shaders and Postprocessing shaders
|
* Shaders support, including Model shaders and Postprocessing shaders
|
||||||
* Powerful math module for Vector and Matrix operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.c)
|
* Powerful math module for Vector and Matrix operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.c)
|
||||||
* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD)
|
* Audio loading and playing with streaming support and mixing channels (WAV, OGG, FLAC, XM, MOD)
|
||||||
* VR stereo rendering support with configurable HMD device parameters
|
* VR stereo rendering support with configurable HMD device parameters
|
||||||
* Multiple platforms support: Windows, Linux, Mac, **Android**, **Raspberry Pi**, **HTML5** and **Oculus Rift CV1**
|
* Multiple platforms support: Windows, Linux, Mac, **Android**, **Raspberry Pi**, **HTML5** and **Oculus Rift CV1**
|
||||||
* Custom color palette for fancy visuals on raywhite background
|
* Custom color palette for fancy visuals on raywhite background
|
||||||
* Minimal external dependencies (GLFW3, OpenGL, OpenAL)
|
* Minimal external dependencies (GLFW3, OpenGL, OpenAL)
|
||||||
|
* Complete binding to LUA
|
||||||
|
|
||||||
raylib uses on its core module the outstanding [GLFW3](http://www.glfw.org/) library. The best option by far I found for
|
raylib uses on its core module the outstanding [GLFW3](http://www.glfw.org/) library. The best option by far I found for
|
||||||
multiplatform (Windows, Linux, Mac) window/context and input management (clean, focused, great license, well documented, modern, ...).
|
multiplatform (Windows, Linux, Mac) window/context and input management (clean, focused, great license, well documented, modern, ...).
|
||||||
@@ -249,6 +272,7 @@ contributing (in some way or another) to make raylib project better. Huge thanks
|
|||||||
- [Chris Hemingway](https://github.com/cHemingway) for improving raylib on OSX build system.
|
- [Chris Hemingway](https://github.com/cHemingway) for improving raylib on OSX build system.
|
||||||
- [Emanuele Petriglia](https://github.com/LelixSuper) for working on multiple GNU/Linux improvements and developing [TicTacToe](https://github.com/LelixSuper/TicTacToe) raylib game.
|
- [Emanuele Petriglia](https://github.com/LelixSuper) for working on multiple GNU/Linux improvements and developing [TicTacToe](https://github.com/LelixSuper/TicTacToe) raylib game.
|
||||||
- [Joshua Reisenauer](https://github.com/kd7tck) for adding audio modules support (XM, MOD) and reviewing audio system.
|
- [Joshua Reisenauer](https://github.com/kd7tck) for adding audio modules support (XM, MOD) and reviewing audio system.
|
||||||
|
- Marcelo Paez (paezao) for his help on OSX to solve High DPI display issue. Thanks Marcelo!
|
||||||
|
|
||||||
|
|
||||||
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"
|
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"
|
||||||
|
11
ROADMAP.md
@@ -4,16 +4,21 @@ roadmap
|
|||||||
Current version of raylib is quite complete and functional but there is still a lot of things to add and improve.
|
Current version of raylib is quite complete and functional but there is still a lot of things to add and improve.
|
||||||
Here it is a wish list of features I would like to add and functions to improve.
|
Here it is a wish list of features I would like to add and functions to improve.
|
||||||
|
|
||||||
Note that around the raylib source code there are multiple TODO points with pending revisions/bugs. Check [GitHub Issues](https://github.com/raysan5/raylib/issues) for further details!
|
Note raylib source code has multiple TODO points with pending things to review and improve. Check [GitHub Issues](https://github.com/raysan5/raylib/issues) for further details!
|
||||||
|
|
||||||
raylib 1.x
|
raylib 1.x
|
||||||
|
|
||||||
[IN PROGRESS] LUA scripting support (wrapper to lua lib)
|
|
||||||
Basic GPU stats sytem (memory, draws, time...)
|
Basic GPU stats sytem (memory, draws, time...)
|
||||||
|
Improved custom file-format (.rres) and packaging tool
|
||||||
Procedural image generation functions (spot, gradient, noise...)
|
Procedural image generation functions (spot, gradient, noise...)
|
||||||
Procedural mesh generation functions (cube, cone, sphere...)
|
Procedural mesh generation functions (cube, cone, sphere...)
|
||||||
Touch-based camera controls for Android
|
Touch-based camera controls for Android
|
||||||
Skybox and Fog support
|
Gamepad support on HTML5
|
||||||
|
|
||||||
|
raylib 1.6
|
||||||
|
|
||||||
|
[DONE] LUA scripting support (raylib lua wrapper)
|
||||||
|
[DONE] Redesigned audio module
|
||||||
|
|
||||||
raylib 1.5
|
raylib 1.5
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 371 KiB After Width: | Height: | Size: 371 KiB |
BIN
docs/raylib_cheatsheet_v1.5.png
Normal file
After Width: | Height: | Size: 2.2 MiB |
@@ -2,6 +2,8 @@
|
|||||||
#
|
#
|
||||||
# raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten)
|
# raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten)
|
||||||
#
|
#
|
||||||
|
# NOTE: By default examples are compiled using raylib static library and OpenAL Soft shared library
|
||||||
|
#
|
||||||
# Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
# Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
#
|
#
|
||||||
# This software is provided "as-is", without any express or implied warranty. In no event
|
# This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
@@ -26,6 +28,9 @@
|
|||||||
# WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop()
|
# WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop()
|
||||||
PLATFORM ?= PLATFORM_DESKTOP
|
PLATFORM ?= PLATFORM_DESKTOP
|
||||||
|
|
||||||
|
# define NO to use OpenAL Soft as static library (shared by default)
|
||||||
|
SHARED_OPENAL ?= YES
|
||||||
|
|
||||||
# determine PLATFORM_OS in case PLATFORM_DESKTOP selected
|
# determine PLATFORM_OS in case PLATFORM_DESKTOP selected
|
||||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
# No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
|
# No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
|
||||||
@@ -62,12 +67,13 @@ endif
|
|||||||
|
|
||||||
# define compiler flags:
|
# define compiler flags:
|
||||||
# -O2 defines optimization level
|
# -O2 defines optimization level
|
||||||
|
# -s strip unnecessary data from build
|
||||||
# -Wall turns on most, but not all, compiler warnings
|
# -Wall turns on most, but not all, compiler warnings
|
||||||
# -std=c99 use standard C from 1999 revision
|
# -std=c99 use standard C from 1999 revision
|
||||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline
|
CFLAGS = -O2 -s -Wall -std=gnu99 -fgnu89-inline
|
||||||
else
|
else
|
||||||
CFLAGS = -O2 -Wall -std=c99
|
CFLAGS = -O2 -s -Wall -std=c99
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources
|
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources
|
||||||
@@ -77,8 +83,27 @@ endif
|
|||||||
|
|
||||||
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||||
|
|
||||||
|
# define raylib release directory for compiled library
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
|
RAYLIB_PATH = ../release/win32/mingw32
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM_OS),LINUX)
|
||||||
|
RAYLIB_PATH = ../release/linux
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
RAYLIB_PATH = ../release/osx
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
|
RAYLIB_PATH = ../release/html5
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
RAYLIB_PATH = ../release/rpi
|
||||||
|
endif
|
||||||
|
|
||||||
# define any directories containing required header files
|
# define any directories containing required header files
|
||||||
INCLUDES = -I. -I../src -I../src/external
|
INCLUDES = -I. -I../src -I../src/external -I$(RAYLIB_PATH)
|
||||||
|
|
||||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
INCLUDES += -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
INCLUDES += -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
||||||
@@ -97,7 +122,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# define library paths containing required libs
|
# define library paths containing required libs
|
||||||
LFLAGS = -L. -L../src
|
LFLAGS = -L. -L../src -L$(RAYLIB_PATH)
|
||||||
|
|
||||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
LFLAGS += -L/opt/vc/lib
|
LFLAGS += -L/opt/vc/lib
|
||||||
@@ -120,7 +145,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
|||||||
# libraries for Debian GNU/Linux desktop compiling
|
# libraries for Debian GNU/Linux desktop compiling
|
||||||
# requires the following packages:
|
# requires the following packages:
|
||||||
# libglfw3-dev libopenal-dev libegl1-mesa-dev
|
# libglfw3-dev libopenal-dev libegl1-mesa-dev
|
||||||
LIBS = -lraylib -lglfw3 -lGL -lopenal -lm -pthread -ldl
|
LIBS = -lraylib -lglfw3 -lGL -lopenal -lm -lpthread -ldl
|
||||||
# on XWindow could require also below libraries, just uncomment
|
# on XWindow could require also below libraries, just uncomment
|
||||||
#LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
#LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||||
else
|
else
|
||||||
@@ -132,7 +157,14 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
|||||||
else
|
else
|
||||||
# libraries for Windows desktop compiling
|
# libraries for Windows desktop compiling
|
||||||
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
|
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
|
||||||
LIBS = -lraylib -lglfw3 -lopengl32 -lopenal32 -lgdi32
|
LIBS = -lraylib -lglfw3 -lopengl32 -lgdi32
|
||||||
|
# if static OpenAL Soft required, define the corresponding libs
|
||||||
|
ifeq ($(SHARED_OPENAL),NO)
|
||||||
|
LIBS += -lopenal32 -lwinmm
|
||||||
|
CFLAGS += -Wl,-allow-multiple-definition
|
||||||
|
else
|
||||||
|
LIBS += -lopenal32dll
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -196,6 +228,8 @@ EXAMPLES = \
|
|||||||
text_format_text \
|
text_format_text \
|
||||||
text_font_select \
|
text_font_select \
|
||||||
text_writing_anim \
|
text_writing_anim \
|
||||||
|
text_ttf_loading \
|
||||||
|
text_bmfont_unordered \
|
||||||
models_geometric_shapes \
|
models_geometric_shapes \
|
||||||
models_box_collisions \
|
models_box_collisions \
|
||||||
models_billboard \
|
models_billboard \
|
||||||
@@ -210,6 +244,12 @@ EXAMPLES = \
|
|||||||
audio_sound_loading \
|
audio_sound_loading \
|
||||||
audio_music_stream \
|
audio_music_stream \
|
||||||
audio_module_playing \
|
audio_module_playing \
|
||||||
|
audio_raw_stream \
|
||||||
|
physics_demo \
|
||||||
|
physics_friction \
|
||||||
|
physics_movement \
|
||||||
|
physics_restitution \
|
||||||
|
physics_shatter \
|
||||||
fix_dylib \
|
fix_dylib \
|
||||||
|
|
||||||
|
|
||||||
@@ -380,6 +420,14 @@ text_font_select: text_font_select.c
|
|||||||
text_writing_anim: text_writing_anim.c
|
text_writing_anim: text_writing_anim.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [text] example - text ttf loading
|
||||||
|
text_ttf_loading: text_ttf_loading.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [text] example - text bmfont unordered
|
||||||
|
text_bmfont_unordered: text_bmfont_unordered.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
# compile [models] example - basic geometric 3d shapes
|
# compile [models] example - basic geometric 3d shapes
|
||||||
models_geometric_shapes: models_geometric_shapes.c
|
models_geometric_shapes: models_geometric_shapes.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
@@ -436,10 +484,34 @@ audio_sound_loading: audio_sound_loading.c
|
|||||||
audio_music_stream: audio_music_stream.c
|
audio_music_stream: audio_music_stream.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
# compile [audio] example - module playing (OGG)
|
# compile [audio] example - module playing (XM)
|
||||||
audio_module_playing: audio_module_playing.c
|
audio_module_playing: audio_module_playing.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [audio] example - raw audio streaming
|
||||||
|
audio_raw_stream: audio_raw_stream.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [physac] example - physics demo
|
||||||
|
physics_demo: physics_demo.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [physac] example - physics friction
|
||||||
|
physics_friction: physics_friction.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [physac] example - physics movement
|
||||||
|
physics_movement: physics_movement.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [physac] example - physics restitution
|
||||||
|
physics_restitution: physics_restitution.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [physac] example - physics shatter
|
||||||
|
physics_shatter: physics_shatter.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
# fix dylib install path name for each executable (MAC)
|
# fix dylib install path name for each executable (MAC)
|
||||||
fix_dylib:
|
fix_dylib:
|
||||||
ifeq ($(PLATFORM_OS),OSX)
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
@@ -30,6 +30,8 @@ int main()
|
|||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)");
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
@@ -49,17 +51,13 @@ int main()
|
|||||||
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
||||||
circles[i].color = colors[GetRandomValue(0, 13)];
|
circles[i].color = colors[GetRandomValue(0, 13)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Music xm = LoadMusicStream("resources/audio/mini1111.xm");
|
||||||
|
|
||||||
// Load postprocessing bloom shader
|
PlayMusicStream(xm);
|
||||||
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
|
||||||
"resources/shaders/glsl330/bloom.fs");
|
|
||||||
|
|
||||||
// Create a RenderTexture2D to be used for render to texture
|
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
|
||||||
|
|
||||||
PlayMusicStream(0, "resources/audio/2t2m_spa.xm"); // Play module stream
|
|
||||||
|
|
||||||
float timePlayed = 0.0f;
|
float timePlayed = 0.0f;
|
||||||
|
bool pause = false;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -69,7 +67,29 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
UpdateMusicStream(xm); // Update music buffer with new stream data
|
||||||
|
|
||||||
|
// Restart music playing (stop and play)
|
||||||
|
if (IsKeyPressed(KEY_SPACE))
|
||||||
|
{
|
||||||
|
StopMusicStream(xm);
|
||||||
|
PlayMusicStream(xm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause/Resume music playing
|
||||||
|
if (IsKeyPressed(KEY_P))
|
||||||
|
{
|
||||||
|
pause = !pause;
|
||||||
|
|
||||||
|
if (pause) PauseMusicStream(xm);
|
||||||
|
else ResumeMusicStream(xm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get timePlayed scaled to bar dimensions
|
||||||
|
timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2;
|
||||||
|
|
||||||
|
// Color circles animation
|
||||||
|
for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--)
|
||||||
{
|
{
|
||||||
circles[i].alpha += circles[i].speed;
|
circles[i].alpha += circles[i].speed;
|
||||||
circles[i].radius += circles[i].speed*10.0f;
|
circles[i].radius += circles[i].speed*10.0f;
|
||||||
@@ -86,39 +106,23 @@ int main()
|
|||||||
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timePlayed scaled to bar dimensions
|
|
||||||
timePlayed = (GetMusicTimePlayed(0)/GetMusicTimeLength(0)*(screenWidth - 40))*2;
|
|
||||||
|
|
||||||
UpdateMusicStream(0); // Update music buffer with new stream data
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(BLACK);
|
ClearBackground(WHITE);
|
||||||
|
|
||||||
BeginTextureMode(target); // Enable drawing to texture
|
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha));
|
||||||
{
|
}
|
||||||
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha));
|
|
||||||
}
|
|
||||||
|
|
||||||
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
|
|
||||||
|
|
||||||
BeginShaderMode(shader);
|
|
||||||
|
|
||||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
|
||||||
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
|
||||||
|
|
||||||
EndShaderMode();
|
|
||||||
|
|
||||||
// Draw time bar
|
// Draw time bar
|
||||||
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY);
|
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY);
|
||||||
DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON);
|
DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON);
|
||||||
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE);
|
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, GRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@@ -126,8 +130,7 @@ int main()
|
|||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadShader(shader); // Unload shader
|
UnloadMusicStream(xm); // Unload music stream buffers from RAM
|
||||||
UnloadRenderTexture(target); // Unload render texture
|
|
||||||
|
|
||||||
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
101
examples/audio_module_playing.lua
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [audio] example - Module playing (streaming)
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_CIRCLES = 64
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)")
|
||||||
|
|
||||||
|
InitAudioDevice() -- Initialize audio device
|
||||||
|
|
||||||
|
local colors = { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK,
|
||||||
|
YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE }
|
||||||
|
|
||||||
|
-- Creates ome circles for visual effect
|
||||||
|
local circles = {}
|
||||||
|
|
||||||
|
for i = MAX_CIRCLES, 1, -1 do
|
||||||
|
circles[i] = {}
|
||||||
|
circles[i].alpha = 0.0
|
||||||
|
circles[i].radius = GetRandomValue(10, 40)
|
||||||
|
circles[i].position = Vector2(0, 0)
|
||||||
|
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 = GetRandomValue(1, 100)/20000.0
|
||||||
|
circles[i].color = colors[GetRandomValue(1, 14)]
|
||||||
|
end
|
||||||
|
|
||||||
|
local xm = LoadMusicStream("resources/audio/mini1111.xm")
|
||||||
|
|
||||||
|
PlayMusicStream(xm)
|
||||||
|
|
||||||
|
local timePlayed = 0.0
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
for i = MAX_CIRCLES, 1, -1 do
|
||||||
|
circles[i].alpha = circles[i].alpha + circles[i].speed
|
||||||
|
circles[i].radius = circles[i].radius + circles[i].speed*10.0
|
||||||
|
|
||||||
|
if (circles[i].alpha > 1.0) then circles[i].speed = circles[i].speed*-1 end
|
||||||
|
|
||||||
|
if (circles[i].alpha <= 0.0) then
|
||||||
|
circles[i].alpha = 0.0
|
||||||
|
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].color = colors[GetRandomValue(1, 14)]
|
||||||
|
circles[i].speed = GetRandomValue(1, 100)/20000.0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get timePlayed scaled to bar dimensions
|
||||||
|
timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2
|
||||||
|
|
||||||
|
UpdateMusicStream(xm) -- Update music buffer with new stream data
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
for i = MAX_CIRCLES, 1, -1 do
|
||||||
|
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Draw time bar
|
||||||
|
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY)
|
||||||
|
DrawRectangle(20, screenHeight - 20 - 12, timePlayed//1, 12, MAROON)
|
||||||
|
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadMusicStream(xm) -- Unload music stream buffers from RAM
|
||||||
|
|
||||||
|
CloseAudioDevice() -- Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
Before Width: | Height: | Size: 210 KiB After Width: | Height: | Size: 47 KiB |
@@ -24,11 +24,12 @@ int main()
|
|||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
PlayMusicStream(0, "resources/audio/guitar_noodling.ogg"); // Play music stream
|
Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
|
||||||
|
|
||||||
|
PlayMusicStream(music);
|
||||||
|
|
||||||
int framesCounter = 0;
|
|
||||||
float timePlayed = 0.0f;
|
float timePlayed = 0.0f;
|
||||||
//float volume = 1.0;
|
bool pause = false;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -38,32 +39,26 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
framesCounter++;
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
// Testing music fading from one file to another
|
|
||||||
/*
|
|
||||||
if (framesCounter > 600) // Wait for 10 seconds (600 frames)
|
|
||||||
{
|
|
||||||
volume -= 0.01; // Decrement music volume level
|
|
||||||
|
|
||||||
// When music volume level equal or lower than 0,
|
|
||||||
// restore volume level and init another music file
|
|
||||||
if (volume <= 0)
|
|
||||||
{
|
|
||||||
volume = 1.0;
|
|
||||||
framesCounter = 0;
|
|
||||||
PlayMusicStream(1, "resources/audio/another_file.ogg");
|
|
||||||
}
|
|
||||||
|
|
||||||
SetMusicVolume(volume);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (IsWindowMinimized()) PauseMusicStream(0);
|
|
||||||
else ResumeMusicStream(0);
|
|
||||||
|
|
||||||
timePlayed = GetMusicTimePlayed(0)/GetMusicTimeLength(0)*100*4; // We scale by 4 to fit 400 pixels
|
|
||||||
|
|
||||||
UpdateMusicStream(0); // Update music buffer with new stream data
|
// Restart music playing (stop and play)
|
||||||
|
if (IsKeyPressed(KEY_SPACE))
|
||||||
|
{
|
||||||
|
StopMusicStream(music);
|
||||||
|
PlayMusicStream(music);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause/Resume music playing
|
||||||
|
if (IsKeyPressed(KEY_P))
|
||||||
|
{
|
||||||
|
pause = !pause;
|
||||||
|
|
||||||
|
if (pause) PauseMusicStream(music);
|
||||||
|
else ResumeMusicStream(music);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get timePlayed scaled to bar dimensions (400 pixels)
|
||||||
|
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@@ -72,10 +67,14 @@ int main()
|
|||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY);
|
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
|
||||||
|
|
||||||
DrawRectangle(200, 250, 400, 12, LIGHTGRAY);
|
DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
|
||||||
DrawRectangle(200, 250, (int)timePlayed, 12, MAROON);
|
DrawRectangle(200, 200, (int)timePlayed, 12, MAROON);
|
||||||
|
DrawRectangleLines(200, 200, 400, 12, GRAY);
|
||||||
|
|
||||||
|
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
|
||||||
|
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@@ -83,9 +82,11 @@ int main()
|
|||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
UnloadMusicStream(music); // Unload music stream buffers from RAM
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
66
examples/audio_music_stream.lua
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [audio] example - Music playing (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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)")
|
||||||
|
|
||||||
|
InitAudioDevice() -- Initialize audio device
|
||||||
|
|
||||||
|
local music = LoadMusicStream("resources/audio/guitar_noodling.ogg")
|
||||||
|
|
||||||
|
PlayMusicStream(music)
|
||||||
|
|
||||||
|
local framesCounter = 0
|
||||||
|
local timePlayed = 0.0
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
framesCounter = framesCounter + 1
|
||||||
|
|
||||||
|
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4 -- We scale by 4 to fit 400 pixels
|
||||||
|
|
||||||
|
UpdateMusicStream(music) -- Update music buffer with new stream data
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
DrawRectangle(200, 250, 400, 12, LIGHTGRAY)
|
||||||
|
DrawRectangle(200, 250, timePlayed//1, 12, MAROON)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadMusicStream(music) -- Unload music stream buffers from RAM
|
||||||
|
|
||||||
|
CloseAudioDevice() -- Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
111
examples/audio_raw_stream.c
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
|
#include <math.h> // Required for: sinf()
|
||||||
|
|
||||||
|
#define MAX_SAMPLES 20000
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming");
|
||||||
|
|
||||||
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
|
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||||
|
AudioStream stream = InitAudioStream(22050, 32, 1);
|
||||||
|
|
||||||
|
// Fill audio stream with some samples (sine wave)
|
||||||
|
float *data = (float *)malloc(sizeof(float)*MAX_SAMPLES);
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_SAMPLES; i++)
|
||||||
|
{
|
||||||
|
data[i] = sinf(((2*PI*(float)i)/2)*DEG2RAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
||||||
|
// for that reason, there is a clip everytime audio stream is looped
|
||||||
|
|
||||||
|
PlayAudioStream(stream);
|
||||||
|
|
||||||
|
int totalSamples = MAX_SAMPLES;
|
||||||
|
int samplesLeft = totalSamples;
|
||||||
|
|
||||||
|
Vector2 position = { 0, 0 };
|
||||||
|
|
||||||
|
SetTargetFPS(30); // Set our game to run at 30 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Refill audio stream if required
|
||||||
|
if (IsAudioBufferProcessed(stream))
|
||||||
|
{
|
||||||
|
int numSamples = 0;
|
||||||
|
if (samplesLeft >= 4096) numSamples = 4096;
|
||||||
|
else numSamples = samplesLeft;
|
||||||
|
|
||||||
|
UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples);
|
||||||
|
|
||||||
|
samplesLeft -= numSamples;
|
||||||
|
|
||||||
|
// Reset samples feeding (loop audio)
|
||||||
|
if (samplesLeft <= 0) samplesLeft = totalSamples;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY);
|
||||||
|
|
||||||
|
// NOTE: Draw a part of the sine wave (only screen width)
|
||||||
|
for (int i = 0; i < GetScreenWidth(); i++)
|
||||||
|
{
|
||||||
|
position.x = i;
|
||||||
|
position.y = 250 + 50*data[i];
|
||||||
|
|
||||||
|
DrawPixelV(position, RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
free(data); // Unload sine wave data
|
||||||
|
|
||||||
|
CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM
|
||||||
|
|
||||||
|
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
97
examples/audio_raw_stream.lua
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_SAMPLES = 20000
|
||||||
|
DEG2RAD = math.pi/180.0
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming")
|
||||||
|
|
||||||
|
InitAudioDevice() -- Initialize audio device
|
||||||
|
|
||||||
|
-- Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||||
|
local stream = InitAudioStream(22050, 32, 1)
|
||||||
|
|
||||||
|
-- Fill audio stream with some samples (sine wave)
|
||||||
|
local data = {}
|
||||||
|
|
||||||
|
for i = 1, MAX_SAMPLES do
|
||||||
|
data[i] = math.sin(((2*math.pi*i)/2)*DEG2RAD)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
||||||
|
-- for that reason, there is a clip everytime audio stream is looped
|
||||||
|
|
||||||
|
PlayAudioStream(stream)
|
||||||
|
|
||||||
|
local totalSamples = MAX_SAMPLES
|
||||||
|
local samplesLeft = totalSamples
|
||||||
|
|
||||||
|
local position = Vector2(0, 0)
|
||||||
|
|
||||||
|
SetTargetFPS(30) -- Set our game to run at 30 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Refill audio stream if required
|
||||||
|
if (IsAudioBufferProcessed(stream)) then
|
||||||
|
local numSamples = 0
|
||||||
|
|
||||||
|
if (samplesLeft >= 4096) then numSamples = 4096
|
||||||
|
else numSamples = samplesLeft end
|
||||||
|
|
||||||
|
UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples)
|
||||||
|
|
||||||
|
samplesLeft = samplesLeft - numSamples
|
||||||
|
|
||||||
|
-- Reset samples feeding (loop audio)
|
||||||
|
if (samplesLeft <= 0) then samplesLeft = totalSamples end
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
-- NOTE: Draw a part of the sine wave (only screen width)
|
||||||
|
for i = 1, GetScreenWidth() do
|
||||||
|
position.x = (i - 1)
|
||||||
|
position.y = 250 + 50*data[i]
|
||||||
|
|
||||||
|
DrawPixelV(position, RED)
|
||||||
|
end
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseAudioStream(stream) -- Close raw audio stream and delete buffers from RAM
|
||||||
|
|
||||||
|
CloseAudioDevice() -- Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
BIN
examples/audio_raw_stream.png
Normal file
After Width: | Height: | Size: 16 KiB |
@@ -36,7 +36,6 @@ int main()
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
|
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
|
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
59
examples/audio_sound_loading.lua
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [audio] example - Sound loading and playing
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing")
|
||||||
|
|
||||||
|
InitAudioDevice() -- Initialize audio device
|
||||||
|
|
||||||
|
local fxWav = LoadSound("resources/audio/weird.wav") -- Load WAV audio file
|
||||||
|
local fxOgg = LoadSound("resources/audio/tanatana.ogg") -- Load OGG audio file
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed(KEY.SPACE)) then PlaySound(fxWav) end -- Play WAV sound
|
||||||
|
if (IsKeyPressed(KEY.ENTER)) then PlaySound(fxOgg) end -- Play OGG sound
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadSound(fxWav) -- Unload sound data
|
||||||
|
UnloadSound(fxOgg) -- Unload sound data
|
||||||
|
|
||||||
|
CloseAudioDevice() -- Close audio device
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
unsigned char key;
|
unsigned char key;
|
||||||
|
|
||||||
InitAudioDevice();
|
InitAudioDevice();
|
||||||
@@ -39,10 +41,13 @@ int main()
|
|||||||
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
|
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
|
||||||
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
|
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
|
||||||
|
|
||||||
PlayMusicStream(0, "resources/audio/guitar_noodling.ogg");
|
Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
|
||||||
|
PlayMusicStream(music);
|
||||||
|
|
||||||
printf("\nPress s or d to play sounds...\n");
|
printf("\nPress s or d to play sounds...\n");
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main loop
|
||||||
while (key != KEY_ESCAPE)
|
while (key != KEY_ESCAPE)
|
||||||
{
|
{
|
||||||
if (kbhit()) key = getch();
|
if (kbhit()) key = getch();
|
||||||
@@ -59,16 +64,18 @@ int main()
|
|||||||
key = 0;
|
key = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMusicStream(0);
|
UpdateMusicStream(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadSound(fxWav); // Unload sound data
|
// De-Initialization
|
||||||
UnloadSound(fxOgg); // Unload sound data
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadSound(fxWav); // Unload sound data
|
||||||
|
UnloadSound(fxOgg); // Unload sound data
|
||||||
|
|
||||||
|
UnloadMusicStream(music); // Unload music stream data
|
||||||
|
|
||||||
CloseAudioDevice();
|
CloseAudioDevice();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
printf("\n\nPress ENTER to close...");
|
|
||||||
getchar();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
130
examples/core_2d_camera.lua
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - 2d camera
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_BUILDINGS = 100
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")
|
||||||
|
|
||||||
|
local player = Rectangle(400, 280, 40, 40)
|
||||||
|
local buildings = {}
|
||||||
|
local buildColors = {}
|
||||||
|
|
||||||
|
local spacing = 0;
|
||||||
|
|
||||||
|
for i = 1, MAX_BUILDINGS do
|
||||||
|
buildings[i] = Rectangle(0, 0, 0, 0)
|
||||||
|
buildings[i].width = GetRandomValue(50, 200)
|
||||||
|
buildings[i].height = GetRandomValue(100, 800)
|
||||||
|
buildings[i].y = screenHeight - 130 - buildings[i].height
|
||||||
|
buildings[i].x = -6000 + spacing
|
||||||
|
|
||||||
|
spacing = spacing + buildings[i].width
|
||||||
|
|
||||||
|
buildColors[i] = Color(GetRandomValue(200, 240), GetRandomValue(200, 240), GetRandomValue(200, 250), 255)
|
||||||
|
end
|
||||||
|
|
||||||
|
local camera = Camera2D(Vector2(0, 0), Vector2(0, 0), 0.0, 1.0)
|
||||||
|
|
||||||
|
camera.target = Vector2(player.x + 20, player.y + 20)
|
||||||
|
camera.offset = Vector2(0, 0)
|
||||||
|
camera.rotation = 0.0
|
||||||
|
camera.zoom = 1.0
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
if (IsKeyDown(KEY.RIGHT)) then
|
||||||
|
player.x = player.x + 2 -- Player movement
|
||||||
|
camera.offset.x = camera.offset.x - 2 -- Camera displacement with player movement
|
||||||
|
elseif (IsKeyDown(KEY.LEFT)) then
|
||||||
|
player.x = player.x - 2 -- Player movement
|
||||||
|
camera.offset.x = camera.offset.x + 2 -- Camera displacement with player movement
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Camera target follows player
|
||||||
|
camera.target = Vector2(player.x + 20, player.y + 20)
|
||||||
|
|
||||||
|
-- Camera rotation controls
|
||||||
|
if (IsKeyDown(KEY.A)) then camera.rotation = camera.rotation - 1
|
||||||
|
elseif (IsKeyDown(KEY.S)) then camera.rotation = camera.rotation + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Limit camera rotation to 80 degrees (-40 to 40)
|
||||||
|
if (camera.rotation > 40) then camera.rotation = 40
|
||||||
|
elseif (camera.rotation < -40) then camera.rotation = -40
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Camera zoom controls
|
||||||
|
camera.zoom = camera.zoom + (GetMouseWheelMove()*0.05)
|
||||||
|
|
||||||
|
if (camera.zoom > 3.0) then camera.zoom = 3.0
|
||||||
|
elseif (camera.zoom < 0.1) then camera.zoom = 0.1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Camera reset (zoom and rotation)
|
||||||
|
if (IsKeyPressed(KEY.R)) then
|
||||||
|
camera.zoom = 1.0
|
||||||
|
camera.rotation = 0.0
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin2dMode(camera)
|
||||||
|
|
||||||
|
DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY)
|
||||||
|
|
||||||
|
for i = 1, MAX_BUILDINGS, 1 do DrawRectangleRec(buildings[i], buildColors[i]) end
|
||||||
|
|
||||||
|
DrawRectangleRec(player, RED)
|
||||||
|
|
||||||
|
DrawRectangle(camera.target.x, -500, 1, screenHeight*4, GREEN)
|
||||||
|
DrawRectangle(-500, camera.target.y, screenWidth*4, 1, GREEN)
|
||||||
|
|
||||||
|
End2dMode()
|
||||||
|
|
||||||
|
DrawText("SCREEN AREA", 640, 10, 20, RED)
|
||||||
|
|
||||||
|
DrawRectangle(0, 0, screenWidth, 5, RED)
|
||||||
|
DrawRectangle(0, 5, 5, screenHeight - 10, RED)
|
||||||
|
DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, RED)
|
||||||
|
DrawRectangle(0, screenHeight - 5, screenWidth, 5, RED)
|
||||||
|
|
||||||
|
DrawRectangle( 10, 10, 250, 113, Fade(SKYBLUE, 0.5))
|
||||||
|
DrawRectangleLines( 10, 10, 250, 113, BLUE)
|
||||||
|
|
||||||
|
DrawText("Free 2d camera controls:", 20, 20, 10, BLACK)
|
||||||
|
DrawText("- Right/Left to move Offset", 40, 40, 10, DARKGRAY)
|
||||||
|
DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY)
|
||||||
|
DrawText("- A / S to Rotate", 40, 80, 10, DARKGRAY)
|
||||||
|
DrawText("- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY)
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -23,7 +23,7 @@ int main()
|
|||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world (position, target, up vector)
|
// Define the camera to look into our 3d world (position, target, up vector)
|
||||||
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 60.0f };
|
Camera camera = {{ 4.0f, 2.0f, 4.0f }, { 0.0f, 1.8f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 60.0f };
|
||||||
|
|
||||||
// Generates some random columns
|
// Generates some random columns
|
||||||
float heights[MAX_COLUMNS];
|
float heights[MAX_COLUMNS];
|
||||||
@@ -37,10 +37,7 @@ int main()
|
|||||||
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 playerPosition = { 4.0f, 2.0f, 4.0f }; // Define player position
|
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode
|
|
||||||
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -50,7 +47,7 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCameraPlayer(&camera, &playerPosition); // Update camera and player position
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
84
examples/core_3d_camera_first_person.lua
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
--------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - 3d camera first person
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
--------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_COLUMNS = 20
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world (position, target, up vector)
|
||||||
|
local camera = Camera(Vector3(4.0, 2.0, 4.0), Vector3(0.0, 1.8, 0.0), Vector3(0.0, 1.0, 0.0), 60.0)
|
||||||
|
|
||||||
|
-- Generates some random columns
|
||||||
|
local heights = {}
|
||||||
|
local positions = {}
|
||||||
|
local colors = {}
|
||||||
|
|
||||||
|
for i = 1, MAX_COLUMNS do
|
||||||
|
heights[i] = GetRandomValue(1, 12)
|
||||||
|
positions[i] = Vector3(GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15))
|
||||||
|
colors[i] = Color(GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255)
|
||||||
|
end
|
||||||
|
|
||||||
|
local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position
|
||||||
|
|
||||||
|
SetCameraMode(camera, CameraMode.FIRST_PERSON) -- Set a first person camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawPlane(Vector3(0.0, 0.0, 0.0), Vector2(32.0, 32.0), LIGHTGRAY) -- Draw ground
|
||||||
|
DrawCube(Vector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, BLUE) -- Draw a blue wall
|
||||||
|
DrawCube(Vector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, LIME) -- Draw a green wall
|
||||||
|
DrawCube(Vector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, GOLD) -- Draw a yellow wall
|
||||||
|
|
||||||
|
-- Draw some cubes around
|
||||||
|
for i = 1, MAX_COLUMNS do
|
||||||
|
DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i])
|
||||||
|
DrawCubeWires(positions[i], 2.0, heights[i], 2.0, MAROON)
|
||||||
|
end
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5))
|
||||||
|
DrawRectangleLines( 10, 10, 220, 70, BLUE)
|
||||||
|
|
||||||
|
DrawText("First person camera default controls:", 20, 20, 10, BLACK)
|
||||||
|
DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY)
|
||||||
|
DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -22,17 +22,14 @@ int main()
|
|||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera;
|
Camera camera;
|
||||||
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
|
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
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.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
|
||||||
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -42,7 +39,9 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
|
|
||||||
|
if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
72
examples/core_3d_camera_free.lua
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Initialize 3d camera free
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
--------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = {}
|
||||||
|
camera.position = Vector3(10.0, 10.0, 10.0) -- Camera position
|
||||||
|
camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
|
||||||
|
camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0 -- Camera field-of-view Y
|
||||||
|
|
||||||
|
local cubePosition = Vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
|
||||||
|
DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5))
|
||||||
|
DrawRectangleLines( 10, 10, 320, 133, BLUE)
|
||||||
|
|
||||||
|
DrawText("Free camera default controls:", 20, 20, 10, BLACK)
|
||||||
|
DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY)
|
||||||
|
DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY)
|
||||||
|
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY)
|
||||||
|
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY)
|
||||||
|
DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
64
examples/core_3d_mode.lua
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Initialize 3d mode
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = {}
|
||||||
|
camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position
|
||||||
|
camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
|
||||||
|
camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0 -- Camera field-of-view Y
|
||||||
|
|
||||||
|
local cubePosition = Vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update your variables here
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera) -- ERROR: Lua Error: attempt to index a number value (?)
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
|
||||||
|
DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -22,7 +22,7 @@ int main()
|
|||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera;
|
Camera camera;
|
||||||
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
|
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
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.fovy = 45.0f; // Camera field-of-view Y
|
||||||
@@ -34,9 +34,7 @@ int main()
|
|||||||
|
|
||||||
bool collision = false;
|
bool collision = false;
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -46,7 +44,7 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
{
|
{
|
||||||
|
96
examples/core_3d_picking.lua
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Picking in 3d mode
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = {}
|
||||||
|
camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position
|
||||||
|
camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
|
||||||
|
camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0 -- Camera field-of-view Y
|
||||||
|
|
||||||
|
local cubePosition = Vector3(0.0, 1.0, 0.0)
|
||||||
|
local cubeSize = Vector3(2.0, 2.0, 2.0)
|
||||||
|
|
||||||
|
local ray = Ray(Vector3(0, 0, 0), Vector3(0, 0, 0)) -- Picking line ray
|
||||||
|
|
||||||
|
local collision = false
|
||||||
|
|
||||||
|
SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
|
||||||
|
if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then
|
||||||
|
-- NOTE: This function is NOT WORKING properly!
|
||||||
|
ray = GetMouseRay(GetMousePosition(), camera)
|
||||||
|
|
||||||
|
-- Check collision between ray and box
|
||||||
|
collision = CheckCollisionRayBox(ray,
|
||||||
|
BoundingBox(Vector3(cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2),
|
||||||
|
Vector3(cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2)))
|
||||||
|
|
||||||
|
--print("collision check:", collision)
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
if (collision) then
|
||||||
|
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED)
|
||||||
|
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON)
|
||||||
|
|
||||||
|
DrawCubeWires(cubePosition, cubeSize.x + 0.2, cubeSize.y + 0.2, cubeSize.z + 0.2, GREEN)
|
||||||
|
else
|
||||||
|
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY)
|
||||||
|
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY)
|
||||||
|
end
|
||||||
|
|
||||||
|
DrawRay(ray, MAROON)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY)
|
||||||
|
|
||||||
|
if (collision) then
|
||||||
|
DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30))/2, screenHeight*0.1, 30, GREEN)
|
||||||
|
end
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
62
examples/core_basic_window.cpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Basic window
|
||||||
|
*
|
||||||
|
* Welcome to raylib!
|
||||||
|
*
|
||||||
|
* To test examples, just press F6 and execute raylib_compile_execute script
|
||||||
|
* Note that compiled executable is placed in the same folder as .c file
|
||||||
|
*
|
||||||
|
* You can find all basic examples on C:\raylib\raylib\examples folder or
|
||||||
|
* raylib official webpage: www.raylib.com
|
||||||
|
*
|
||||||
|
* Enjoy using raylib. :)
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
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
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
examples/core_basic_window.lua
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Basic window
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window")
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- 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()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
82
examples/core_color_select.lua
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Color selection by mouse (collision detection)
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NUM_RECTANGLES = 21
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)")
|
||||||
|
|
||||||
|
local colors = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
|
||||||
|
GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
|
||||||
|
GREEN, SKYBLUE, PURPLE, BEIGE }
|
||||||
|
|
||||||
|
local colorsRecs = {} -- Rectangles array
|
||||||
|
local selected = {}
|
||||||
|
|
||||||
|
-- Fills colorsRecs data (for every rectangle)
|
||||||
|
for i = 1, NUM_RECTANGLES do
|
||||||
|
colorsRecs[i] = Rectangle(0, 0, 0, 0)
|
||||||
|
colorsRecs[i].x = 20 + 100*((i-1)%7) + 10*((i-1)%7)
|
||||||
|
colorsRecs[i].y = 60 + 100*((i-1)//7) + 10*((i-1)//7) -- Using floor division: //
|
||||||
|
colorsRecs[i].width = 100
|
||||||
|
colorsRecs[i].height = 100
|
||||||
|
selected[i] = false
|
||||||
|
end
|
||||||
|
|
||||||
|
local mousePoint = Vector2(0, 0)
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
mousePoint = GetMousePosition()
|
||||||
|
|
||||||
|
for i = 1, NUM_RECTANGLES do -- Iterate along all the rectangles
|
||||||
|
if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) then
|
||||||
|
colors[i].a = 120
|
||||||
|
if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then selected[i] = not selected[i] end
|
||||||
|
else colors[i].a = 255 end
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
for i = 1, NUM_RECTANGLES do -- Draw all rectangles
|
||||||
|
DrawRectangleRec(colorsRecs[i], colors[i])
|
||||||
|
|
||||||
|
-- Draw four rectangles around selected rectangle
|
||||||
|
if (selected[i]) then
|
||||||
|
DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 100, 10, RAYWHITE) -- Square top rectangle
|
||||||
|
DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 10, 100, RAYWHITE) -- Square left rectangle
|
||||||
|
DrawRectangle(colorsRecs[i].x + 90, colorsRecs[i].y, 10, 100, RAYWHITE) -- Square right rectangle
|
||||||
|
DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + 90, 100, 10, RAYWHITE) -- Square bottom rectangle
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -23,7 +23,7 @@ int main()
|
|||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char **droppedFiles;
|
char **droppedFiles = { 0 };
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
66
examples/core_drop_files.lua
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Windows drop files
|
||||||
|
--
|
||||||
|
-- This example only works on platforms that support drag & drop (Windows, Linux, OSX)
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files")
|
||||||
|
|
||||||
|
local count = 0
|
||||||
|
local droppedFiles = {}
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
if (IsFileDropped()) then
|
||||||
|
droppedFiles = GetDroppedFiles()
|
||||||
|
count = #droppedFiles
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
if (count == 0) then DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY)
|
||||||
|
else
|
||||||
|
DrawText("Dropped files:", 100, 40, 20, DARKGRAY)
|
||||||
|
|
||||||
|
for i = 0, count-1 do
|
||||||
|
if (i%2 == 0) then DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5))
|
||||||
|
else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3)) end
|
||||||
|
|
||||||
|
DrawText(droppedFiles[i+1], 120, 100 + 40*i, 10, GRAY)
|
||||||
|
end
|
||||||
|
|
||||||
|
DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY)
|
||||||
|
end
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
ClearDroppedFiles() -- Clear internal buffers
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
102
examples/core_gestures_detection.lua
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Gestures Detection
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_GESTURE_STRINGS = 20
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection")
|
||||||
|
|
||||||
|
local touchPosition = Vector2(0, 0)
|
||||||
|
local touchArea = Rectangle(220, 10, screenWidth - 230, screenHeight - 20)
|
||||||
|
|
||||||
|
local gesturesCount = 0
|
||||||
|
local gestureStrings = {}
|
||||||
|
|
||||||
|
for i = 1, MAX_GESTURE_STRINGS do gestureStrings[i] = "" end
|
||||||
|
|
||||||
|
local currentGesture = Gestures.NONE
|
||||||
|
local lastGesture = Gestures.NONE
|
||||||
|
|
||||||
|
--SetGesturesEnabled(0b0000000000001001) -- Enable only some gestures to be detected
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
lastGesture = currentGesture
|
||||||
|
currentGesture = GetGestureDetected()
|
||||||
|
touchPosition = GetTouchPosition(0)
|
||||||
|
|
||||||
|
if (CheckCollisionPointRec(touchPosition, touchArea) and (currentGesture ~= Gestures.NONE)) then
|
||||||
|
if (currentGesture ~= lastGesture) then
|
||||||
|
-- Store gesture string
|
||||||
|
if (currentGesture == Gestures.TAP) then gestureStrings[gesturesCount] = "GESTURE TAP"
|
||||||
|
elseif (currentGesture == Gestures.DOUBLETAP) then gestureStrings[gesturesCount] = "GESTURE DOUBLETAP"
|
||||||
|
elseif (currentGesture == Gestures.HOLD) then gestureStrings[gesturesCount] = "GESTURE HOLD"
|
||||||
|
elseif (currentGesture == Gestures.DRAG) then gestureStrings[gesturesCount] = "GESTURE DRAG"
|
||||||
|
elseif (currentGesture == Gestures.SWIPE_RIGHT) then gestureStrings[gesturesCount] = "GESTURE SWIPE RIGHT"
|
||||||
|
elseif (currentGesture == Gestures.SWIPE_LEFT) then gestureStrings[gesturesCount] = "GESTURE SWIPE LEFT"
|
||||||
|
elseif (currentGesture == Gestures.SWIPE_UP) then gestureStrings[gesturesCount] = "GESTURE SWIPE UP"
|
||||||
|
elseif (currentGesture == Gestures.SWIPE_DOWN) then gestureStrings[gesturesCount] = "GESTURE SWIPE DOWN"
|
||||||
|
elseif (currentGesture == Gestures.PINCH_IN) then gestureStrings[gesturesCount] = "GESTURE PINCH IN"
|
||||||
|
elseif (currentGesture == Gestures.PINCH_OUT) then gestureStrings[gesturesCount] = "GESTURE PINCH OUT"
|
||||||
|
end
|
||||||
|
|
||||||
|
gesturesCount = gesturesCount + 1
|
||||||
|
|
||||||
|
-- Reset gestures strings
|
||||||
|
if (gesturesCount >= MAX_GESTURE_STRINGS) then
|
||||||
|
for i = 1, MAX_GESTURE_STRINGS do gestureStrings[i] = "\0" end
|
||||||
|
gesturesCount = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawRectangleRec(touchArea, GRAY)
|
||||||
|
DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5))
|
||||||
|
|
||||||
|
for i = 1, gesturesCount do
|
||||||
|
if ((i - 1)%2 == 0) then DrawRectangle(10, 30 + 20*(i - 1), 200, 20, Fade(LIGHTGRAY, 0.5))
|
||||||
|
else DrawRectangle(10, 30 + 20*(i - 1), 200, 20, Fade(LIGHTGRAY, 0.3)) end
|
||||||
|
|
||||||
|
if (i < gesturesCount) then DrawText(gestureStrings[i], 35, 36 + 20*(i - 1), 10, DARKGRAY)
|
||||||
|
else DrawText(gestureStrings[i], 35, 36 + 20*(i - 1), 10, MAROON) end
|
||||||
|
end
|
||||||
|
|
||||||
|
DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY)
|
||||||
|
DrawText("DETECTED GESTURES", 50, 15, 10, GRAY)
|
||||||
|
|
||||||
|
if (currentGesture ~= GESTURE_NONE) then DrawCircleV(touchPosition, 30, MAROON) end
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -3,17 +3,29 @@
|
|||||||
* raylib [core] example - Gamepad input
|
* raylib [core] example - Gamepad input
|
||||||
*
|
*
|
||||||
* NOTE: This example requires a Gamepad connected to the system
|
* NOTE: This example requires a Gamepad connected to the system
|
||||||
* raylib is configured to work with Xbox 360 gamepad, check raylib.h for buttons configuration
|
* raylib is configured to work with the following gamepads:
|
||||||
|
* Xbox 360 Controller (Xbox 360, Xbox One)
|
||||||
|
* PLAYSTATION(R)3 Controller
|
||||||
|
* Check raylib.h for buttons configuration
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 1.0 (www.raylib.com)
|
* 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)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
// NOTE: Gamepad name ID depends on drivers and OS
|
||||||
|
#if defined(PLATFORM_RPI)
|
||||||
|
#define XBOX360_NAME_ID "Microsoft X-Box 360 pad"
|
||||||
|
#define PS3_NAME_ID "PLAYSTATION(R)3 Controller"
|
||||||
|
#else
|
||||||
|
#define XBOX360_NAME_ID "Xbox 360 Controller"
|
||||||
|
#define PS3_NAME_ID "PLAYSTATION(R)3 Controller"
|
||||||
|
#endif
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
@@ -21,12 +33,14 @@ int main()
|
|||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
||||||
|
|
||||||
|
Texture2D texPs3Pad = LoadTexture("resources/ps3.png");
|
||||||
|
Texture2D texXboxPad = LoadTexture("resources/xbox.png");
|
||||||
|
|
||||||
Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
|
SetTargetFPS(60);
|
||||||
Vector2 gamepadMovement = { 0.0f, 0.0f };
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set target frames-per-second
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
@@ -34,20 +48,7 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsGamepadAvailable(GAMEPAD_PLAYER1))
|
// ...
|
||||||
{
|
|
||||||
gamepadMovement.x = GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X);
|
|
||||||
gamepadMovement.y = GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y);
|
|
||||||
|
|
||||||
ballPosition.x += gamepadMovement.x;
|
|
||||||
ballPosition.y -= gamepadMovement.y;
|
|
||||||
|
|
||||||
if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A))
|
|
||||||
{
|
|
||||||
ballPosition.x = (float)screenWidth/2;
|
|
||||||
ballPosition.y = (float)screenHeight/2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@@ -55,10 +56,127 @@ int main()
|
|||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
if (IsGamepadAvailable(GAMEPAD_PLAYER1))
|
||||||
|
{
|
||||||
|
DrawText(FormatText("GP1: %s", GetGamepadName(GAMEPAD_PLAYER1)), 10, 10, 10, BLACK);
|
||||||
|
|
||||||
DrawText("move the ball with gamepad", 10, 10, 20, DARKGRAY);
|
if (IsGamepadName(GAMEPAD_PLAYER1, XBOX360_NAME_ID))
|
||||||
|
{
|
||||||
|
DrawTexture(texXboxPad, 0, 0, DARKGRAY);
|
||||||
|
|
||||||
|
// Draw buttons: xbox home
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_HOME)) DrawCircle(394, 89, 19, RED);
|
||||||
|
|
||||||
DrawCircleV(ballPosition, 50, MAROON);
|
// Draw buttons: basic
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_START)) DrawCircle(436, 150, 9, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_SELECT)) DrawCircle(352, 150, 9, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_X)) DrawCircle(501, 151, 15, BLUE);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_A)) DrawCircle(536, 187, 15, LIME);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_B)) DrawCircle(572, 151, 15, MAROON);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_Y)) DrawCircle(536, 115, 15, GOLD);
|
||||||
|
|
||||||
|
// Draw buttons: d-pad
|
||||||
|
DrawRectangle(317, 202, 19, 71, BLACK);
|
||||||
|
DrawRectangle(293, 228, 69, 19, BLACK);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_UP)) DrawRectangle(317, 202, 19, 26, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_DOWN)) DrawRectangle(317, 202 + 45, 19, 26, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_LEFT)) DrawRectangle(292, 228, 25, 19, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_RIGHT)) DrawRectangle(292 + 44, 228, 26, 19, RED);
|
||||||
|
|
||||||
|
// Draw buttons: left-right back
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_LB)) DrawCircle(259, 61, 20, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_RB)) DrawCircle(536, 61, 20, RED);
|
||||||
|
|
||||||
|
// Draw axis: left joystick
|
||||||
|
DrawCircle(259, 152, 39, BLACK);
|
||||||
|
DrawCircle(259, 152, 34, LIGHTGRAY);
|
||||||
|
DrawCircle(259 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X)*20),
|
||||||
|
152 - (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y)*20), 25, BLACK);
|
||||||
|
|
||||||
|
// Draw axis: right joystick
|
||||||
|
DrawCircle(461, 237, 38, BLACK);
|
||||||
|
DrawCircle(461, 237, 33, LIGHTGRAY);
|
||||||
|
DrawCircle(461 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_RIGHT_X)*20),
|
||||||
|
237 - (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_RIGHT_Y)*20), 25, BLACK);
|
||||||
|
|
||||||
|
// Draw axis: left-right triggers
|
||||||
|
DrawRectangle(170, 30, 15, 70, GRAY);
|
||||||
|
DrawRectangle(604, 30, 15, 70, GRAY);
|
||||||
|
DrawRectangle(170, 30, 15, (((1.0f + GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LT))/2.0f)*70), RED);
|
||||||
|
DrawRectangle(604, 30, 15, (((1.0f + GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_RT))/2.0f)*70), RED);
|
||||||
|
|
||||||
|
//DrawText(FormatText("Xbox axis LT: %02.02f", GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LT)), 10, 40, 10, BLACK);
|
||||||
|
//DrawText(FormatText("Xbox axis RT: %02.02f", GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_RT)), 10, 60, 10, BLACK);
|
||||||
|
}
|
||||||
|
else if (IsGamepadName(GAMEPAD_PLAYER1, PS3_NAME_ID))
|
||||||
|
{
|
||||||
|
DrawTexture(texPs3Pad, 0, 0, DARKGRAY);
|
||||||
|
|
||||||
|
// Draw buttons: ps
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_PS)) DrawCircle(396, 222, 13, RED);
|
||||||
|
|
||||||
|
// Draw buttons: basic
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_SELECT)) DrawRectangle(328, 170, 32, 13, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_START)) DrawTriangle((Vector2){ 436, 168 }, (Vector2){ 436, 185 }, (Vector2){ 464, 177 }, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_TRIANGLE)) DrawCircle(557, 144, 13, LIME);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_CIRCLE)) DrawCircle(586, 173, 13, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_CROSS)) DrawCircle(557, 203, 13, VIOLET);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_SQUARE)) DrawCircle(527, 173, 13, PINK);
|
||||||
|
|
||||||
|
// Draw buttons: d-pad
|
||||||
|
DrawRectangle(225, 132, 24, 84, BLACK);
|
||||||
|
DrawRectangle(195, 161, 84, 25, BLACK);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_UP)) DrawRectangle(225, 132, 24, 29, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_DOWN)) DrawRectangle(225, 132 + 54, 24, 30, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_LEFT)) DrawRectangle(195, 161, 30, 25, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_RIGHT)) DrawRectangle(195 + 54, 161, 30, 25, RED);
|
||||||
|
|
||||||
|
// Draw buttons: left-right back buttons
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_L1)) DrawCircle(239, 82, 20, RED);
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_R1)) DrawCircle(557, 82, 20, RED);
|
||||||
|
|
||||||
|
// Draw axis: left joystick
|
||||||
|
DrawCircle(319, 255, 35, BLACK);
|
||||||
|
DrawCircle(319, 255, 31, LIGHTGRAY);
|
||||||
|
DrawCircle(319 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_LEFT_X)*20),
|
||||||
|
255 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_LEFT_Y)*20), 25, BLACK);
|
||||||
|
|
||||||
|
// Draw axis: right joystick
|
||||||
|
DrawCircle(475, 255, 35, BLACK);
|
||||||
|
DrawCircle(475, 255, 31, LIGHTGRAY);
|
||||||
|
DrawCircle(475 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_RIGHT_X)*20),
|
||||||
|
255 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_RIGHT_Y)*20), 25, BLACK);
|
||||||
|
|
||||||
|
// Draw axis: left-right triggers
|
||||||
|
DrawRectangle(169, 48, 15, 70, GRAY);
|
||||||
|
DrawRectangle(611, 48, 15, 70, GRAY);
|
||||||
|
DrawRectangle(169, 48, 15, (((1.0f - GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_L2))/2.0f)*70), RED);
|
||||||
|
DrawRectangle(611, 48, 15, (((1.0f - GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_R2))/2.0f)*70), RED);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY);
|
||||||
|
|
||||||
|
// TODO: Draw generic gamepad
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText(FormatText("DETECTED AXIS [%i]:", GetGamepadAxisCount(GAMEPAD_PLAYER1)), 10, 50, 10, MAROON);
|
||||||
|
|
||||||
|
for (int i = 0; i < GetGamepadAxisCount(GAMEPAD_PLAYER1); i++)
|
||||||
|
{
|
||||||
|
DrawText(FormatText("AXIS %i: %.02f", i, GetGamepadAxisMovement(GAMEPAD_PLAYER1, i)), 20, 70 + 20*i, 10, DARKGRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetGamepadButtonPressed() != -1) DrawText(FormatText("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED);
|
||||||
|
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawText("GP1: NOT DETECTED", 10, 10, 10, GRAY);
|
||||||
|
|
||||||
|
DrawTexture(texXboxPad, 0, 0, LIGHTGRAY);
|
||||||
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@@ -66,6 +184,9 @@ int main()
|
|||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadTexture(texPs3Pad);
|
||||||
|
UnloadTexture(texXboxPad);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
163
examples/core_input_gamepad.lua
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Gamepad input
|
||||||
|
--
|
||||||
|
-- NOTE: This example requires a Gamepad connected to the system
|
||||||
|
-- raylib is configured to work with Xbox 360 gamepad, check raylib.h for buttons configuration
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input")
|
||||||
|
|
||||||
|
local texPs3Pad = LoadTexture("resources/ps3.png")
|
||||||
|
local texXboxPad = LoadTexture("resources/xbox.png")
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- ...
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then
|
||||||
|
DrawText(string.format("GP1: %s", GetGamepadName(GAMEPAD.PLAYER1)), 10, 10, 10, BLACK)
|
||||||
|
|
||||||
|
if (IsGamepadName(GAMEPAD.PLAYER1, "Xbox 360 Controller")) then
|
||||||
|
DrawTexture(texXboxPad, 0, 0, DARKGRAY)
|
||||||
|
|
||||||
|
-- Draw buttons: xbox home
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_HOME)) then DrawCircle(394, 89, 19, RED) end
|
||||||
|
|
||||||
|
-- Draw buttons: basic
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_START)) then DrawCircle(436, 150, 9, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_SELECT)) then DrawCircle(352, 150, 9, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_X)) then DrawCircle(501, 151, 15, BLUE) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_A)) then DrawCircle(536, 187, 15, LIME) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_B)) then DrawCircle(572, 151, 15, MAROON) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_Y)) then DrawCircle(536, 115, 15, GOLD) end
|
||||||
|
|
||||||
|
-- Draw buttons: d-pad
|
||||||
|
DrawRectangle(317, 202, 19, 71, BLACK)
|
||||||
|
DrawRectangle(293, 228, 69, 19, BLACK)
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_UP)) then DrawRectangle(317, 202, 19, 26, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_DOWN)) then DrawRectangle(317, 202 + 45, 19, 26, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LEFT)) then DrawRectangle(292, 228, 25, 19, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RIGHT)) then DrawRectangle(292 + 44, 228, 26, 19, RED) end
|
||||||
|
|
||||||
|
-- Draw buttons: left-right back
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LB)) then DrawCircle(259, 61, 20, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RB)) then DrawCircle(536, 61, 20, RED) end
|
||||||
|
|
||||||
|
-- Draw axis: left joystick
|
||||||
|
DrawCircle(259, 152, 39, BLACK)
|
||||||
|
DrawCircle(259, 152, 34, LIGHTGRAY)
|
||||||
|
DrawCircle(259 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X)*20),
|
||||||
|
152 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y)*20), 25, BLACK)
|
||||||
|
|
||||||
|
-- Draw axis: right joystick
|
||||||
|
DrawCircle(461, 237, 38, BLACK)
|
||||||
|
DrawCircle(461, 237, 33, LIGHTGRAY)
|
||||||
|
DrawCircle(461 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_X)*20),
|
||||||
|
237 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_Y)*20), 25, BLACK)
|
||||||
|
|
||||||
|
-- Draw axis: left-right triggers
|
||||||
|
DrawRectangle(170, 30, 15, 70, GRAY)
|
||||||
|
DrawRectangle(604, 30, 15, 70, GRAY)
|
||||||
|
DrawRectangle(170, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT))/2.0)*70), RED)
|
||||||
|
DrawRectangle(604, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT))/2.0)*70), RED)
|
||||||
|
|
||||||
|
--DrawText(FormatText("Xbox axis LT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT)), 10, 40, 10, BLACK)
|
||||||
|
--DrawText(FormatText("Xbox axis RT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT)), 10, 60, 10, BLACK)
|
||||||
|
elseif (IsGamepadName(GAMEPAD.PLAYER1, "PLAYSTATION(R)3 Controller")) then
|
||||||
|
DrawTexture(texPs3Pad, 0, 0, DARKGRAY)
|
||||||
|
|
||||||
|
-- Draw buttons: ps
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_PS)) then DrawCircle(396, 222, 13, RED) end
|
||||||
|
|
||||||
|
-- Draw buttons: basic
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SELECT)) then DrawRectangle(328, 170, 32, 13, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_START)) then DrawTriangle((Vector2){ 436, 168 }, (Vector2){ 436, 185 }, (Vector2){ 464, 177 }, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_TRIANGLE)) then DrawCircle(557, 144, 13, LIME) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CIRCLE)) then DrawCircle(586, 173, 13, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CROSS)) then DrawCircle(557, 203, 13, VIOLET) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SQUARE)) then DrawCircle(527, 173, 13, PINK) end
|
||||||
|
|
||||||
|
-- Draw buttons: d-pad
|
||||||
|
DrawRectangle(225, 132, 24, 84, BLACK)
|
||||||
|
DrawRectangle(195, 161, 84, 25, BLACK)
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_UP)) then DrawRectangle(225, 132, 24, 29, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_DOWN)) then DrawRectangle(225, 132 + 54, 24, 30, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_LEFT)) then DrawRectangle(195, 161, 30, 25, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_RIGHT)) then DrawRectangle(195 + 54, 161, 30, 25, RED) end
|
||||||
|
|
||||||
|
-- Draw buttons: left-right back buttons
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_L1)) then DrawCircle(239, 82, 20, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_R1)) then DrawCircle(557, 82, 20, RED) end
|
||||||
|
|
||||||
|
-- Draw axis: left joystick
|
||||||
|
DrawCircle(319, 255, 35, BLACK)
|
||||||
|
DrawCircle(319, 255, 31, LIGHTGRAY)
|
||||||
|
DrawCircle(319 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_X)*20),
|
||||||
|
255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_Y)*20), 25, BLACK)
|
||||||
|
|
||||||
|
-- Draw axis: right joystick
|
||||||
|
DrawCircle(475, 255, 35, BLACK)
|
||||||
|
DrawCircle(475, 255, 31, LIGHTGRAY)
|
||||||
|
DrawCircle(475 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_X)*20),
|
||||||
|
255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_Y)*20), 25, BLACK)
|
||||||
|
|
||||||
|
-- Draw axis: left-right triggers
|
||||||
|
DrawRectangle(169, 48, 15, 70, GRAY)
|
||||||
|
DrawRectangle(611, 48, 15, 70, GRAY)
|
||||||
|
DrawRectangle(169, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_L2))/2.0)*70), RED)
|
||||||
|
DrawRectangle(611, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_R2))/2.0)*70), RED)
|
||||||
|
else
|
||||||
|
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY)
|
||||||
|
|
||||||
|
-- TODO: Draw generic gamepad
|
||||||
|
end
|
||||||
|
|
||||||
|
DrawText(string.format("DETECTED AXIS [%i]:", GetGamepadAxisCount(GAMEPAD.PLAYER1)), 10, 50, 10, MAROON)
|
||||||
|
|
||||||
|
for i = 1, GetGamepadAxisCount(GAMEPAD.PLAYER1) do -- Iterate along all the rectangles
|
||||||
|
DrawText(string.format("AXIS %i: %.02f", i, GetGamepadAxisMovement(GAMEPAD.PLAYER1, i)), 20, 70 + 20*i, 10, DARKGRAY)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (GetGamepadButtonPressed() ~= -1) then DrawText(string.format("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED)
|
||||||
|
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY) end
|
||||||
|
else
|
||||||
|
DrawText("GP1: NOT DETECTED", 10, 10, 10, GRAY)
|
||||||
|
|
||||||
|
DrawTexture(texXboxPad, 0, 0, LIGHTGRAY)
|
||||||
|
end
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadTexture(texPs3Pad) -- Unload gamepad texture
|
||||||
|
UnloadTexture(texXboxPad) -- Unload gamepad texture
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 37 KiB |
51
examples/core_input_keys.lua
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Keyboard input
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window")
|
||||||
|
|
||||||
|
local ballPosition = Vector2(screenWidth/2, screenHeight/2)
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
if (IsKeyDown(KEY.RIGHT)) then ballPosition.x = ballPosition.x + 0.8 end
|
||||||
|
if (IsKeyDown(KEY.LEFT)) then ballPosition.x = ballPosition.x - 0.8 end
|
||||||
|
if (IsKeyDown(KEY.UP)) then ballPosition.y = ballPosition.y - 0.8 end
|
||||||
|
if (IsKeyDown(KEY.DOWN)) then ballPosition.y = ballPosition.y + 0.8 end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY)
|
||||||
|
|
||||||
|
DrawCircleV(ballPosition, 50, MAROON)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
54
examples/core_input_mouse.lua
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Mouse input
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input")
|
||||||
|
|
||||||
|
local ballPosition = Vector2(-100.0, -100.0)
|
||||||
|
local ballColor = DARKBLUE
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
ballPosition = GetMousePosition()
|
||||||
|
|
||||||
|
if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then ballColor = MAROON
|
||||||
|
elseif (IsMouseButtonPressed(MOUSE.MIDDLE_BUTTON)) then ballColor = LIME
|
||||||
|
elseif (IsMouseButtonPressed(MOUSE.RIGHT_BUTTON)) then ballColor = DARKBLUE
|
||||||
|
end
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawCircleV(ballPosition, 40, ballColor)
|
||||||
|
|
||||||
|
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
----------------------------------------------------------------------------------------
|
50
examples/core_mouse_wheel.lua
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] examples - Mouse wheel
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel")
|
||||||
|
|
||||||
|
local boxPositionY = screenHeight/2 - 40
|
||||||
|
local scrollSpeed = 4 -- Scrolling speed in pixels
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
boxPositionY = boxPositionY - (GetMouseWheelMove()*scrollSpeed)
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON)
|
||||||
|
|
||||||
|
DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY)
|
||||||
|
DrawText(string.format("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
----------------------------------------------------------------------------------------
|
@@ -30,13 +30,15 @@ int main()
|
|||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera;
|
Camera camera;
|
||||||
camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position
|
camera.position = (Vector3){ 5.0f, 2.0f, 5.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 60.0f; // Camera field-of-view Y
|
camera.fovy = 60.0f; // Camera field-of-view Y
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode
|
||||||
|
|
||||||
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
|
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -45,9 +47,10 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateVrTracking();
|
if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode)
|
||||||
|
else if (IsVrDeviceReady()) UpdateVrTracking(&camera); // Update camera with device tracking data
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_SPACE)) ToggleVrMode();
|
if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@@ -61,7 +64,7 @@ int main()
|
|||||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(40, 1.0f);
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
73
examples/core_oculus_rift.lua
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Oculus Rift CV1
|
||||||
|
--
|
||||||
|
-- NOTE: Example requires linkage with LibOVR
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 1080
|
||||||
|
local screenHeight = 600
|
||||||
|
|
||||||
|
-- NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - oculus rift")
|
||||||
|
|
||||||
|
-- NOTE: If device is not available, it fallbacks to default device (simulator)
|
||||||
|
InitVrDevice(VrDevice.OCULUS_RIFT_CV1) -- Init VR device (Oculus Rift CV1)
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = {}
|
||||||
|
camera.position = Vector3(5.0, 5.0, 5.0) -- Camera position
|
||||||
|
camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
|
||||||
|
camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 60.0 -- Camera field-of-view Y
|
||||||
|
|
||||||
|
local cubePosition = Vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
SetTargetFPS(90) -- Set our game to run at 90 frames-per-second
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
UpdateVrTracking()
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY.SPACE)) then ToggleVrMode() end
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
|
||||||
|
DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
CloseVrDevice() -- Close VR device
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
----------------------------------------------------------------------------------------
|
56
examples/core_random_values.lua
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Generate random values
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values")
|
||||||
|
|
||||||
|
local framesCounter = 0 -- Variable used to count frames
|
||||||
|
|
||||||
|
local randValue = GetRandomValue(-8, 5) -- Get a random integer number between -8 and 5 (both included)
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
framesCounter = framesCounter + 1
|
||||||
|
|
||||||
|
-- Every two seconds (120 frames) a new random value is generated
|
||||||
|
if (((framesCounter/120)%2) == 1) then
|
||||||
|
randValue = GetRandomValue(-8, 5)
|
||||||
|
framesCounter = 0
|
||||||
|
end
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON)
|
||||||
|
|
||||||
|
DrawText(string.format("%i", randValue), 360, 180, 80, LIGHTGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
----------------------------------------------------------------------------------------
|
74
examples/core_storage_values.lua
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Storage save/load values
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- NOTE: Storage positions must start with 0, directly related to file memory layout
|
||||||
|
STORAGE_SCORE = 0
|
||||||
|
STORAGE_HISCORE = 1
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values")
|
||||||
|
|
||||||
|
local score = 0
|
||||||
|
local hiscore = 0
|
||||||
|
|
||||||
|
local framesCounter = 0
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed(KEY.R)) then
|
||||||
|
score = GetRandomValue(1000, 2000)
|
||||||
|
hiscore = GetRandomValue(2000, 4000)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY.ENTER)) then
|
||||||
|
StorageSaveValue(STORAGE_SCORE, score)
|
||||||
|
StorageSaveValue(STORAGE_HISCORE, hiscore)
|
||||||
|
elseif (IsKeyPressed(KEY.SPACE)) then
|
||||||
|
-- NOTE: If requested position could not be found, value 0 is returned
|
||||||
|
score = StorageLoadValue(STORAGE_SCORE)
|
||||||
|
hiscore = StorageLoadValue(STORAGE_HISCORE)
|
||||||
|
end
|
||||||
|
|
||||||
|
framesCounter = framesCounter + 1
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText(string.format("SCORE: %i", score), 280, 130, 40, MAROON)
|
||||||
|
DrawText(string.format("HI-SCORE: %i", hiscore), 210, 200, 50, BLACK)
|
||||||
|
|
||||||
|
DrawText(string.format("frames: %i", framesCounter), 10, 10, 20, LIME)
|
||||||
|
|
||||||
|
DrawText("Press R to generate random numbers", 220, 40, 20, LIGHTGRAY)
|
||||||
|
DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY)
|
||||||
|
DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -21,16 +21,13 @@ int main()
|
|||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
|
Camera camera = {{ 10.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
Vector2 cubeScreenPosition;
|
Vector2 cubeScreenPosition;
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
|
||||||
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -40,7 +37,7 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
|
|
||||||
// Calculate cube screen space position (with a little offset to be in top)
|
// Calculate cube screen space position (with a little offset to be in top)
|
||||||
cubeScreenPosition = GetWorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera);
|
cubeScreenPosition = GetWorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera);
|
||||||
|
66
examples/core_world_screen.lua
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - World to screen
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local cubePosition = Vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
local cubeScreenPosition = Vector2(0, 0)
|
||||||
|
|
||||||
|
SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
|
||||||
|
-- Calculate cube screen space position (with a little offset to be in top)
|
||||||
|
cubeScreenPosition = GetWorldToScreen(Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera)
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
|
||||||
|
DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("Enemy: 100 / 100", cubeScreenPosition.x//1 - MeasureText("Enemy: 100 / 100", 20)//2, cubeScreenPosition.y//1, 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()
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
----------------------------------------------------------------------------------------
|
@@ -26,20 +26,17 @@ int main()
|
|||||||
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
|
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
|
||||||
Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
|
Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
|
||||||
|
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
|
||||||
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
62
examples/models_billboard.lua
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [models] example - Drawing billboards
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(5.0, 4.0, 5.0), Vector3(0.0, 2.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local bill = LoadTexture("resources/billboard.png") -- Our texture billboard
|
||||||
|
local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard
|
||||||
|
|
||||||
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawBillboard(camera, bill, billPosition, 2.0, WHITE)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadTexture(bill) -- Unload texture
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
115
examples/models_box_collisions.lua
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [models] example - Detect basic 3d collisions (box vs sphere vs box)
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local playerPosition = Vector3(0.0, 1.0, 2.0)
|
||||||
|
local playerSize = Vector3(1.0, 2.0, 1.0)
|
||||||
|
local playerColor = GREEN
|
||||||
|
|
||||||
|
local enemyBoxPos = Vector3(-4.0, 1.0, 0.0)
|
||||||
|
local enemyBoxSize = Vector3(2.0, 2.0, 2.0)
|
||||||
|
|
||||||
|
local enemySpherePos = Vector3(4.0, 0.0, 0.0)
|
||||||
|
local enemySphereSize = 1.5
|
||||||
|
|
||||||
|
local collision = false
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Move player
|
||||||
|
if (IsKeyDown(KEY.RIGHT)) then playerPosition.x = playerPosition.x + 0.2
|
||||||
|
elseif (IsKeyDown(KEY.LEFT)) then playerPosition.x = playerPosition.x - 0.2
|
||||||
|
elseif (IsKeyDown(KEY.DOWN)) then playerPosition.z = playerPosition.z + 0.2
|
||||||
|
elseif (IsKeyDown(KEY.UP)) then playerPosition.z = playerPosition.z - 0.2 end
|
||||||
|
|
||||||
|
collision = false
|
||||||
|
|
||||||
|
-- Check collisions player vs enemy-box
|
||||||
|
if (CheckCollisionBoxes(
|
||||||
|
BoundingBox(Vector3(playerPosition.x - playerSize.x/2,
|
||||||
|
playerPosition.y - playerSize.y/2,
|
||||||
|
playerPosition.z - playerSize.z/2),
|
||||||
|
Vector3(playerPosition.x + playerSize.x/2,
|
||||||
|
playerPosition.y + playerSize.y/2,
|
||||||
|
playerPosition.z + playerSize.z/2)),
|
||||||
|
BoundingBox(Vector3(enemyBoxPos.x - enemyBoxSize.x/2,
|
||||||
|
enemyBoxPos.y - enemyBoxSize.y/2,
|
||||||
|
enemyBoxPos.z - enemyBoxSize.z/2),
|
||||||
|
Vector3(enemyBoxPos.x + enemyBoxSize.x/2,
|
||||||
|
enemyBoxPos.y + enemyBoxSize.y/2,
|
||||||
|
enemyBoxPos.z + enemyBoxSize.z/2)))) then collision = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check collisions player vs enemy-sphere
|
||||||
|
if (CheckCollisionBoxSphere(
|
||||||
|
BoundingBox(Vector3(playerPosition.x - playerSize.x/2,
|
||||||
|
playerPosition.y - playerSize.y/2,
|
||||||
|
playerPosition.z - playerSize.z/2),
|
||||||
|
Vector3(playerPosition.x + playerSize.x/2,
|
||||||
|
playerPosition.y + playerSize.y/2,
|
||||||
|
playerPosition.z + playerSize.z/2)),
|
||||||
|
enemySpherePos, enemySphereSize)) then collision = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if (collision) then playerColor = RED
|
||||||
|
else playerColor = GREEN end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
-- Draw enemy-box
|
||||||
|
DrawCube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, GRAY)
|
||||||
|
DrawCubeWires(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, DARKGRAY)
|
||||||
|
|
||||||
|
-- Draw enemy-sphere
|
||||||
|
DrawSphere(enemySpherePos, enemySphereSize, GRAY)
|
||||||
|
DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, DARKGRAY)
|
||||||
|
|
||||||
|
-- Draw player
|
||||||
|
DrawCubeV(playerPosition, playerSize, playerColor)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("Move player with cursors to collide", 220, 40, 20, GRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -35,19 +35,17 @@ int main()
|
|||||||
|
|
||||||
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position
|
|
||||||
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
77
examples/models_cubicmap.lua
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [models] example - Cubicmap loading and drawing
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(16.0, 14.0, 16.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local image = LoadImage("resources/cubicmap.png") -- Load cubicmap image (RAM)
|
||||||
|
local cubicmap = LoadTextureFromImage(image) -- Convert image to texture to display (VRAM)
|
||||||
|
local map = LoadCubicmap(image) -- Load cubicmap model (generate model from image)
|
||||||
|
|
||||||
|
-- NOTE: By default each cube is mapped to one part of texture atlas
|
||||||
|
local texture = LoadTexture("resources/cubicmap_atlas.png") -- Load map texture
|
||||||
|
map.material.texDiffuse = texture -- Set map diffuse texture
|
||||||
|
|
||||||
|
local mapPosition = Vector3(-16.0, 0.0, -8.0) -- Set model position
|
||||||
|
|
||||||
|
UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawModel(map, mapPosition, 1.0, WHITE)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawTextureEx(cubicmap, (Vector2)(screenWidth - cubicmap.width*4 - 20, 20), 0.0, 4.0, WHITE)
|
||||||
|
DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN)
|
||||||
|
|
||||||
|
DrawText("cubicmap image used to", 658, 90, 10, GRAY)
|
||||||
|
DrawText("generate map 3d model", 658, 104, 10, GRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadTexture(cubicmap) -- Unload cubicmap texture
|
||||||
|
UnloadTexture(texture) -- Unload map texture
|
||||||
|
UnloadModel(map) -- Unload map model
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
67
examples/models_geometric_shapes.lua
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [models] example - Draw some basic geometric shapes (cube, sphere, cylinder...)
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update your variables here
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera) -- ERROR: Lua Error: attempt to index a number value
|
||||||
|
|
||||||
|
DrawCube(Vector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, RED)
|
||||||
|
DrawCubeWires(Vector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, GOLD)
|
||||||
|
DrawCubeWires(Vector3(-4.0, 0.0, -2.0), 3.0, 6.0, 2.0, MAROON)
|
||||||
|
|
||||||
|
DrawSphere(Vector3(-1.0, 0.0, -2.0), 1.0, GREEN)
|
||||||
|
DrawSphereWires(Vector3(1.0, 0.0, 2.0), 2.0, 16, 16, LIME)
|
||||||
|
|
||||||
|
DrawCylinder(Vector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, SKYBLUE)
|
||||||
|
DrawCylinderWires(Vector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, DARKBLUE)
|
||||||
|
DrawCylinderWires(Vector3(4.5, -1.0, 2.0), 1.0, 1.0, 2.0, 6, BROWN)
|
||||||
|
|
||||||
|
DrawCylinder(Vector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, GOLD)
|
||||||
|
DrawCylinderWires(Vector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, PINK)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -29,20 +29,19 @@ int main()
|
|||||||
map.material.texDiffuse = texture; // Set map diffuse texture
|
map.material.texDiffuse = texture; // Set map diffuse texture
|
||||||
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
|
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
|
||||||
|
|
||||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
72
examples/models_heightmap.lua
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [models] example - Heightmap loading and drawing
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
|
||||||
|
|
||||||
|
-- Define our custom camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(18.0, 16.0, 18.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local image = LoadImage("resources/heightmap.png") -- Load heightmap image (RAM)
|
||||||
|
local texture = LoadTextureFromImage(image) -- Convert image to texture (VRAM)
|
||||||
|
local map = LoadHeightmap(image, Vector3(16, 8, 16)) -- Load heightmap model with defined size
|
||||||
|
map.material.texDiffuse = texture -- Set map diffuse texture
|
||||||
|
local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (depends on model scaling!)
|
||||||
|
|
||||||
|
UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
-- NOTE: Model is scaled to 1/4 of its original size (128x128 units)
|
||||||
|
DrawModel(map, mapPosition, 1.0, RED)
|
||||||
|
|
||||||
|
DrawGrid(20, 1.0)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE)
|
||||||
|
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadTexture(texture) -- Unload texture
|
||||||
|
UnloadModel(map) -- Unload model
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
67
examples/models_obj_loading.lua
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [models] example - Load and draw a 3d model (OBJ)
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
|
||||||
|
local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture
|
||||||
|
dwarf.material.texDiffuse = texture -- Set dwarf model diffuse texture
|
||||||
|
local position = Vector3(0.0, 0.0, 0.0) -- Set model position
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- ...
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
|
DrawGizmo(position) -- Draw gizmo
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadTexture(texture) -- Unload texture
|
||||||
|
UnloadModel(dwarf) -- Unload model
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -1,128 +0,0 @@
|
|||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [physac] example - Basic rigidbody
|
|
||||||
*
|
|
||||||
* 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)
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Compile example using:
|
|
||||||
* cmd /c IF NOT EXIST pthreadGC2.dll copy C:\raylib\raylib\src\external\pthread\pthreadGC2.dll $(CURRENT_DIRECTORY) /Y
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
|
||||||
#include "physac.h"
|
|
||||||
|
|
||||||
#define MOVE_VELOCITY 5
|
|
||||||
#define JUMP_VELOCITY 30
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
int screenWidth = 800;
|
|
||||||
int screenHeight = 450;
|
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [physac] example - basic rigidbody");
|
|
||||||
InitPhysics((Vector2){ 0.0f, -9.81f/2 }); // Initialize physics module
|
|
||||||
|
|
||||||
// Debug variables
|
|
||||||
bool isDebug = false;
|
|
||||||
|
|
||||||
// Create rectangle physic object
|
|
||||||
PhysicBody rectangle = CreatePhysicBody((Vector2){ screenWidth*0.25f, screenHeight/2 }, 0.0f, (Vector2){ 75, 50 });
|
|
||||||
rectangle->rigidbody.enabled = true; // Enable physic object rigidbody behaviour
|
|
||||||
rectangle->rigidbody.applyGravity = true;
|
|
||||||
rectangle->rigidbody.friction = 0.1f;
|
|
||||||
rectangle->rigidbody.bounciness = 6.0f;
|
|
||||||
|
|
||||||
// Create square physic object
|
|
||||||
PhysicBody square = CreatePhysicBody((Vector2){ screenWidth*0.75f, screenHeight/2 }, 0.0f, (Vector2){ 50, 50 });
|
|
||||||
square->rigidbody.enabled = true; // Enable physic object rigidbody behaviour
|
|
||||||
square->rigidbody.applyGravity = true;
|
|
||||||
square->rigidbody.friction = 0.1f;
|
|
||||||
|
|
||||||
// Create walls physic objects
|
|
||||||
PhysicBody floor = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.95f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 });
|
|
||||||
PhysicBody leftWall = CreatePhysicBody((Vector2){ 0.0f, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight });
|
|
||||||
PhysicBody rightWall = CreatePhysicBody((Vector2){ screenWidth, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight });
|
|
||||||
PhysicBody roof = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.05f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 });
|
|
||||||
|
|
||||||
// Create pplatform physic object
|
|
||||||
PhysicBody platform = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.7f }, 0.0f, (Vector2){ screenWidth*0.25f, 20 });
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
||||||
{
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
// Check rectangle movement inputs
|
|
||||||
if (IsKeyPressed('W')) rectangle->rigidbody.velocity.y = JUMP_VELOCITY;
|
|
||||||
if (IsKeyDown('A')) rectangle->rigidbody.velocity.x = -MOVE_VELOCITY;
|
|
||||||
else if (IsKeyDown('D')) rectangle->rigidbody.velocity.x = MOVE_VELOCITY;
|
|
||||||
|
|
||||||
// Check square movement inputs
|
|
||||||
if (IsKeyDown(KEY_UP) && square->rigidbody.isGrounded) square->rigidbody.velocity.y = JUMP_VELOCITY;
|
|
||||||
if (IsKeyDown(KEY_LEFT)) square->rigidbody.velocity.x = -MOVE_VELOCITY;
|
|
||||||
else if (IsKeyDown(KEY_RIGHT)) square->rigidbody.velocity.x = MOVE_VELOCITY;
|
|
||||||
|
|
||||||
// Check debug switch input
|
|
||||||
if (IsKeyPressed('P')) isDebug = !isDebug;
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
BeginDrawing();
|
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
|
||||||
|
|
||||||
// Draw floor, roof and walls rectangles
|
|
||||||
DrawRectangleRec(TransformToRectangle(floor->transform), DARKGRAY); // Convert transform values to rectangle data type variable
|
|
||||||
DrawRectangleRec(TransformToRectangle(leftWall->transform), DARKGRAY);
|
|
||||||
DrawRectangleRec(TransformToRectangle(rightWall->transform), DARKGRAY);
|
|
||||||
DrawRectangleRec(TransformToRectangle(roof->transform), DARKGRAY);
|
|
||||||
|
|
||||||
// Draw middle platform rectangle
|
|
||||||
DrawRectangleRec(TransformToRectangle(platform->transform), DARKGRAY);
|
|
||||||
|
|
||||||
// Draw physic objects
|
|
||||||
DrawRectangleRec(TransformToRectangle(rectangle->transform), RED);
|
|
||||||
DrawRectangleRec(TransformToRectangle(square->transform), BLUE);
|
|
||||||
|
|
||||||
// Draw collider lines if debug is enabled
|
|
||||||
if (isDebug)
|
|
||||||
{
|
|
||||||
DrawRectangleLines(floor->collider.bounds.x, floor->collider.bounds.y, floor->collider.bounds.width, floor->collider.bounds.height, GREEN);
|
|
||||||
DrawRectangleLines(leftWall->collider.bounds.x, leftWall->collider.bounds.y, leftWall->collider.bounds.width, leftWall->collider.bounds.height, GREEN);
|
|
||||||
DrawRectangleLines(rightWall->collider.bounds.x, rightWall->collider.bounds.y, rightWall->collider.bounds.width, rightWall->collider.bounds.height, GREEN);
|
|
||||||
DrawRectangleLines(roof->collider.bounds.x, roof->collider.bounds.y, roof->collider.bounds.width, roof->collider.bounds.height, GREEN);
|
|
||||||
DrawRectangleLines(platform->collider.bounds.x, platform->collider.bounds.y, platform->collider.bounds.width, platform->collider.bounds.height, GREEN);
|
|
||||||
DrawRectangleLines(rectangle->collider.bounds.x, rectangle->collider.bounds.y, rectangle->collider.bounds.width, rectangle->collider.bounds.height, GREEN);
|
|
||||||
DrawRectangleLines(square->collider.bounds.x, square->collider.bounds.y, square->collider.bounds.width, square->collider.bounds.height, GREEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw help message
|
|
||||||
DrawText("Use WASD to move rectangle and ARROWS to move square", screenWidth/2 - MeasureText("Use WASD to move rectangle and ARROWS to move square", 20)/2, screenHeight*0.075f, 20, LIGHTGRAY);
|
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
|
||||||
|
|
||||||
EndDrawing();
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
ClosePhysics(); // Unitialize physics (including all loaded objects)
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Before Width: | Height: | Size: 15 KiB |
122
examples/physics_demo.c
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* Physac - Physics demo
|
||||||
|
*
|
||||||
|
* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations.
|
||||||
|
* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external'
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Victor Fisac
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define PHYSAC_IMPLEMENTATION
|
||||||
|
#include "..\src\physac.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics demo");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
// Physac logo drawing position
|
||||||
|
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||||
|
int logoY = 15;
|
||||||
|
|
||||||
|
// Initialize physics and default physics bodies
|
||||||
|
InitPhysics();
|
||||||
|
|
||||||
|
// Create floor rectangle physics body
|
||||||
|
PhysicsBody floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, 500, 100, 10);
|
||||||
|
floor->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
|
||||||
|
// Create obstacle circle physics body
|
||||||
|
PhysicsBody circle = CreatePhysicsBodyCircle((Vector2){ screenWidth/2, screenHeight/2 }, 45, 10);
|
||||||
|
circle->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed('R')) // Reset physics input
|
||||||
|
{
|
||||||
|
ResetPhysics();
|
||||||
|
|
||||||
|
floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, 500, 100, 10);
|
||||||
|
floor->enabled = false;
|
||||||
|
|
||||||
|
circle = CreatePhysicsBodyCircle((Vector2){ screenWidth/2, screenHeight/2 }, 45, 10);
|
||||||
|
circle->enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Physics body creation inputs
|
||||||
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10);
|
||||||
|
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10);
|
||||||
|
|
||||||
|
// Destroy falling physics bodies
|
||||||
|
int bodiesCount = GetPhysicsBodiesCount();
|
||||||
|
for (int i = bodiesCount - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
PhysicsBody body = GetPhysicsBody(i);
|
||||||
|
if (body != NULL && (body->position.y > screenHeight*2)) DestroyPhysicsBody(body);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
|
DrawFPS(screenWidth - 90, screenHeight - 30);
|
||||||
|
|
||||||
|
// Draw created physics bodies
|
||||||
|
bodiesCount = GetPhysicsBodiesCount();
|
||||||
|
for (int i = 0; i < bodiesCount; i++)
|
||||||
|
{
|
||||||
|
PhysicsBody body = GetPhysicsBody(i);
|
||||||
|
|
||||||
|
if (body != NULL)
|
||||||
|
{
|
||||||
|
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||||
|
for (int j = 0; j < vertexCount; j++)
|
||||||
|
{
|
||||||
|
// Get physics bodies shape vertices to draw lines
|
||||||
|
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||||
|
Vector2 vertexA = GetPhysicsShapeVertex(body, j);
|
||||||
|
|
||||||
|
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||||
|
Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
|
||||||
|
|
||||||
|
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE);
|
||||||
|
DrawText("Right mouse button to create a circle", 10, 25, 10, WHITE);
|
||||||
|
DrawText("Press 'R' to reset example", 10, 40, 10, WHITE);
|
||||||
|
|
||||||
|
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||||
|
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
ClosePhysics(); // Unitialize physics
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
examples/physics_demo.png
Normal file
After Width: | Height: | Size: 23 KiB |
@@ -1,187 +0,0 @@
|
|||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [physac] example - Forces
|
|
||||||
*
|
|
||||||
* 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)
|
|
||||||
*
|
|
||||||
* NOTE: This example requires raylib module [rlgl]
|
|
||||||
*
|
|
||||||
* Compile example using:
|
|
||||||
* cmd /c IF NOT EXIST pthreadGC2.dll copy C:\raylib\raylib\src\external\pthread\pthreadGC2.dll $(CURRENT_DIRECTORY) /Y
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
|
||||||
#include "physac.h"
|
|
||||||
|
|
||||||
#define FORCE_AMOUNT 5.0f
|
|
||||||
#define FORCE_RADIUS 150
|
|
||||||
#define LINE_LENGTH 75
|
|
||||||
#define TRIANGLE_LENGTH 12
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
int screenWidth = 800;
|
|
||||||
int screenHeight = 450;
|
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [physac] example - forces");
|
|
||||||
InitPhysics((Vector2){ 0.0f, -9.81f/2 }); // Initialize physics module
|
|
||||||
|
|
||||||
// Global variables
|
|
||||||
Vector2 mousePosition;
|
|
||||||
bool isDebug = false;
|
|
||||||
|
|
||||||
// Create rectangle physic objects
|
|
||||||
PhysicBody rectangles[3];
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
rectangles[i] = CreatePhysicBody((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/3) : (screenHeight/1.5f)) }, 0.0f, (Vector2){ 50, 50 });
|
|
||||||
rectangles[i]->rigidbody.enabled = true; // Enable physic object rigidbody behaviour
|
|
||||||
rectangles[i]->rigidbody.friction = 0.1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create circles physic objects
|
|
||||||
// NOTE: when creating circle physic objects, transform.scale must be { 0, 0 } and object radius must be defined in collider.radius and use this value to draw the circle.
|
|
||||||
PhysicBody circles[3];
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
circles[i] = CreatePhysicBody((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/1.5f) : (screenHeight/4)) }, 0.0f, (Vector2){ 0, 0 });
|
|
||||||
circles[i]->rigidbody.enabled = true; // Enable physic object rigidbody behaviour
|
|
||||||
circles[i]->rigidbody.friction = 0.1f;
|
|
||||||
circles[i]->collider.type = COLLIDER_CIRCLE;
|
|
||||||
circles[i]->collider.radius = 25;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create walls physic objects
|
|
||||||
PhysicBody leftWall = CreatePhysicBody((Vector2){ -25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight });
|
|
||||||
PhysicBody rightWall = CreatePhysicBody((Vector2){ screenWidth + 25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight });
|
|
||||||
PhysicBody topWall = CreatePhysicBody((Vector2){ screenWidth/2, -25 }, 0.0f, (Vector2){ screenWidth, 50 });
|
|
||||||
PhysicBody bottomWall = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight + 25 }, 0.0f, (Vector2){ screenWidth, 50 });
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
||||||
{
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Update mouse position value
|
|
||||||
mousePosition = GetMousePosition();
|
|
||||||
|
|
||||||
// Check force input
|
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ApplyForceAtPosition(mousePosition, FORCE_AMOUNT, FORCE_RADIUS);
|
|
||||||
|
|
||||||
// Check reset input
|
|
||||||
if (IsKeyPressed('R'))
|
|
||||||
{
|
|
||||||
// Reset rectangle physic objects positions
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
rectangles[i]->transform.position = (Vector2){ screenWidth/4*(i+1) - rectangles[i]->transform.scale.x/2, (((i % 2) == 0) ? (screenHeight/3) : (screenHeight/1.5f)) - rectangles[i]->transform.scale.y/2 };
|
|
||||||
rectangles[i]->rigidbody.velocity =(Vector2){ 0.0f, 0.0f };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset circles physic objects positions
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
circles[i]->transform.position = (Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/1.5f) : (screenHeight/4)) };
|
|
||||||
circles[i]->rigidbody.velocity =(Vector2){ 0.0f, 0.0f };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check debug switch input
|
|
||||||
if (IsKeyPressed('P')) isDebug = !isDebug;
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
BeginDrawing();
|
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
|
||||||
|
|
||||||
// Draw rectangles
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
// Convert transform values to rectangle data type variable
|
|
||||||
DrawRectangleRec(TransformToRectangle(rectangles[i]->transform), RED);
|
|
||||||
if (isDebug) DrawRectangleLines(rectangles[i]->collider.bounds.x, rectangles[i]->collider.bounds.y, rectangles[i]->collider.bounds.width, rectangles[i]->collider.bounds.height, GREEN);
|
|
||||||
|
|
||||||
// Draw force radius
|
|
||||||
DrawCircleLines(mousePosition.x, mousePosition.y, FORCE_RADIUS, BLACK);
|
|
||||||
|
|
||||||
// Draw direction lines
|
|
||||||
if (CheckCollisionPointCircle((Vector2){ rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 }, mousePosition, FORCE_RADIUS))
|
|
||||||
{
|
|
||||||
Vector2 direction = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2 - mousePosition.x, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 - mousePosition.y };
|
|
||||||
float angle = atan2l(direction.y, direction.x);
|
|
||||||
|
|
||||||
// Calculate arrow start and end positions
|
|
||||||
Vector2 startPosition = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 };
|
|
||||||
Vector2 endPosition = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2 + (cos(angle)*LINE_LENGTH), rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 + (sin(angle)*LINE_LENGTH) };
|
|
||||||
|
|
||||||
// Draw arrow line
|
|
||||||
DrawLineV(startPosition, endPosition, BLACK);
|
|
||||||
|
|
||||||
// Draw arrow triangle
|
|
||||||
DrawTriangleLines((Vector2){ endPosition.x - cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y - sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH },
|
|
||||||
(Vector2){ endPosition.x + cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y + sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH },
|
|
||||||
(Vector2){ endPosition.x + cos(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2, endPosition.y + sin(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2 }, BLACK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw circles
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
DrawCircleV(circles[i]->transform.position, circles[i]->collider.radius, BLUE);
|
|
||||||
if (isDebug) DrawCircleLines(circles[i]->transform.position.x, circles[i]->transform.position.y, circles[i]->collider.radius, GREEN);
|
|
||||||
|
|
||||||
// Draw force radius
|
|
||||||
DrawCircleLines(mousePosition.x, mousePosition.y, FORCE_RADIUS, BLACK);
|
|
||||||
|
|
||||||
// Draw direction lines
|
|
||||||
if (CheckCollisionPointCircle((Vector2){ circles[i]->transform.position.x, circles[i]->transform.position.y }, mousePosition, FORCE_RADIUS))
|
|
||||||
{
|
|
||||||
Vector2 direction = { circles[i]->transform.position.x - mousePosition.x, circles[i]->transform.position.y - mousePosition.y };
|
|
||||||
float angle = atan2l(direction.y, direction.x);
|
|
||||||
|
|
||||||
// Calculate arrow start and end positions
|
|
||||||
Vector2 startPosition = { circles[i]->transform.position.x, circles[i]->transform.position.y };
|
|
||||||
Vector2 endPosition = { circles[i]->transform.position.x + (cos(angle)*LINE_LENGTH), circles[i]->transform.position.y + (sin(angle)*LINE_LENGTH) };
|
|
||||||
|
|
||||||
// Draw arrow line
|
|
||||||
DrawLineV(startPosition, endPosition, BLACK);
|
|
||||||
|
|
||||||
// Draw arrow triangle
|
|
||||||
DrawTriangleLines((Vector2){ endPosition.x - cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y - sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH },
|
|
||||||
(Vector2){ endPosition.x + cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y + sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH },
|
|
||||||
(Vector2){ endPosition.x + cos(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2, endPosition.y + sin(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2 }, BLACK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw help messages
|
|
||||||
DrawText("Use LEFT MOUSE BUTTON to apply a force", screenWidth/2 - MeasureText("Use LEFT MOUSE BUTTON to apply a force", 20)/2, screenHeight*0.075f, 20, LIGHTGRAY);
|
|
||||||
DrawText("Use R to reset objects position", screenWidth/2 - MeasureText("Use R to reset objects position", 20)/2, screenHeight*0.875f, 20, GRAY);
|
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
|
||||||
|
|
||||||
EndDrawing();
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
ClosePhysics(); // Unitialize physics module
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Before Width: | Height: | Size: 18 KiB |
136
examples/physics_friction.c
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* Physac - Physics friction
|
||||||
|
*
|
||||||
|
* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations.
|
||||||
|
* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external'
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Victor Fisac
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define PHYSAC_IMPLEMENTATION
|
||||||
|
#include "..\src\physac.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics friction");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
// Physac logo drawing position
|
||||||
|
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||||
|
int logoY = 15;
|
||||||
|
|
||||||
|
// Initialize physics and default physics bodies
|
||||||
|
InitPhysics();
|
||||||
|
|
||||||
|
// Create floor rectangle physics body
|
||||||
|
PhysicsBody floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, screenWidth, 100, 10);
|
||||||
|
floor->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
PhysicsBody wall = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight*0.8f }, 10, 80, 10);
|
||||||
|
wall->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
|
||||||
|
// Create left ramp physics body
|
||||||
|
PhysicsBody rectLeft = CreatePhysicsBodyRectangle((Vector2){ 25, screenHeight - 5 }, 250, 250, 10);
|
||||||
|
rectLeft->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
SetPhysicsBodyRotation(rectLeft, 30*DEG2RAD);
|
||||||
|
|
||||||
|
// Create right ramp physics body
|
||||||
|
PhysicsBody rectRight = CreatePhysicsBodyRectangle((Vector2){ screenWidth - 25, screenHeight - 5 }, 250, 250, 10);
|
||||||
|
rectRight->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
SetPhysicsBodyRotation(rectRight, 330*DEG2RAD);
|
||||||
|
|
||||||
|
// Create dynamic physics bodies
|
||||||
|
PhysicsBody bodyA = CreatePhysicsBodyRectangle((Vector2){ 35, screenHeight*0.6f }, 40, 40, 10);
|
||||||
|
bodyA->staticFriction = 0.1f;
|
||||||
|
bodyA->dynamicFriction = 0.1f;
|
||||||
|
SetPhysicsBodyRotation(bodyA, 30*DEG2RAD);
|
||||||
|
|
||||||
|
PhysicsBody bodyB = CreatePhysicsBodyRectangle((Vector2){ screenWidth - 35, screenHeight*0.6f }, 40, 40, 10);
|
||||||
|
bodyB->staticFriction = 1;
|
||||||
|
bodyB->dynamicFriction = 1;
|
||||||
|
SetPhysicsBodyRotation(bodyB, 330*DEG2RAD);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed('R')) // Reset physics input
|
||||||
|
{
|
||||||
|
// Reset dynamic physics bodies position, velocity and rotation
|
||||||
|
bodyA->position = (Vector2){ 35, screenHeight*0.6f };
|
||||||
|
bodyA->velocity = (Vector2){ 0, 0 };
|
||||||
|
bodyA->angularVelocity = 0;
|
||||||
|
SetPhysicsBodyRotation(bodyA, 30*DEG2RAD);
|
||||||
|
|
||||||
|
bodyB->position = (Vector2){ screenWidth - 35, screenHeight*0.6f };
|
||||||
|
bodyB->velocity = (Vector2){ 0, 0 };
|
||||||
|
bodyB->angularVelocity = 0;
|
||||||
|
SetPhysicsBodyRotation(bodyB, 330*DEG2RAD);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
|
DrawFPS(screenWidth - 90, screenHeight - 30);
|
||||||
|
|
||||||
|
// Draw created physics bodies
|
||||||
|
int bodiesCount = GetPhysicsBodiesCount();
|
||||||
|
for (int i = 0; i < bodiesCount; i++)
|
||||||
|
{
|
||||||
|
PhysicsBody body = GetPhysicsBody(i);
|
||||||
|
|
||||||
|
if (body != NULL)
|
||||||
|
{
|
||||||
|
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||||
|
for (int j = 0; j < vertexCount; j++)
|
||||||
|
{
|
||||||
|
// Get physics bodies shape vertices to draw lines
|
||||||
|
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||||
|
Vector2 vertexA = GetPhysicsShapeVertex(body, j);
|
||||||
|
|
||||||
|
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||||
|
Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
|
||||||
|
|
||||||
|
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangle(0, screenHeight - 49, screenWidth, 49, BLACK);
|
||||||
|
|
||||||
|
DrawText("Friction amount", (screenWidth - MeasureText("Friction amount", 30))/2, 75, 30, WHITE);
|
||||||
|
DrawText("0.1", bodyA->position.x - MeasureText("0.1", 20)/2, bodyA->position.y - 7, 20, WHITE);
|
||||||
|
DrawText("1", bodyB->position.x - MeasureText("1", 20)/2, bodyB->position.y - 7, 20, WHITE);
|
||||||
|
|
||||||
|
DrawText("Press 'R' to reset example", 10, 10, 10, WHITE);
|
||||||
|
|
||||||
|
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||||
|
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
ClosePhysics(); // Unitialize physics
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
examples/physics_friction.png
Normal file
After Width: | Height: | Size: 18 KiB |
122
examples/physics_movement.c
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* Physac - Physics movement
|
||||||
|
*
|
||||||
|
* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations.
|
||||||
|
* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external'
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Victor Fisac
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define PHYSAC_IMPLEMENTATION
|
||||||
|
#include "..\src\physac.h"
|
||||||
|
|
||||||
|
#define VELOCITY 0.5f
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics movement");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
// Physac logo drawing position
|
||||||
|
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||||
|
int logoY = 15;
|
||||||
|
|
||||||
|
// Initialize physics and default physics bodies
|
||||||
|
InitPhysics();
|
||||||
|
|
||||||
|
// Create floor and walls rectangle physics body
|
||||||
|
PhysicsBody floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, screenWidth, 100, 10);
|
||||||
|
PhysicsBody platformLeft = CreatePhysicsBodyRectangle((Vector2){ screenWidth*0.25f, screenHeight*0.6f }, screenWidth*0.25f, 10, 10);
|
||||||
|
PhysicsBody platformRight = CreatePhysicsBodyRectangle((Vector2){ screenWidth*0.75f, screenHeight*0.6f }, screenWidth*0.25f, 10, 10);
|
||||||
|
PhysicsBody wallLeft = CreatePhysicsBodyRectangle((Vector2){ -5, screenHeight/2 }, 10, screenHeight, 10);
|
||||||
|
PhysicsBody wallRight = CreatePhysicsBodyRectangle((Vector2){ screenWidth + 5, screenHeight/2 }, 10, screenHeight, 10);
|
||||||
|
|
||||||
|
// Disable dynamics to floor and walls physics bodies
|
||||||
|
floor->enabled = false;
|
||||||
|
platformLeft->enabled = false;
|
||||||
|
platformRight->enabled = false;
|
||||||
|
wallLeft->enabled = false;
|
||||||
|
wallRight->enabled = false;
|
||||||
|
|
||||||
|
// Create movement physics body
|
||||||
|
PhysicsBody body = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight/2 }, 50, 50, 1);
|
||||||
|
body->freezeOrient = true; // Constrain body rotation to avoid little collision torque amounts
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed('R')) // Reset physics input
|
||||||
|
{
|
||||||
|
// Reset movement physics body position, velocity and rotation
|
||||||
|
body->position = (Vector2){ screenWidth/2, screenHeight/2 };
|
||||||
|
body->velocity = (Vector2){ 0, 0 };
|
||||||
|
SetPhysicsBodyRotation(body, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Horizontal movement input
|
||||||
|
if (IsKeyDown(KEY_RIGHT)) body->velocity.x = VELOCITY;
|
||||||
|
else if (IsKeyDown(KEY_LEFT)) body->velocity.x = -VELOCITY;
|
||||||
|
|
||||||
|
// Vertical movement input checking if player physics body is grounded
|
||||||
|
if (IsKeyDown(KEY_UP) && body->isGrounded) body->velocity.y = -VELOCITY*4;
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
|
DrawFPS(screenWidth - 90, screenHeight - 30);
|
||||||
|
|
||||||
|
// Draw created physics bodies
|
||||||
|
int bodiesCount = GetPhysicsBodiesCount();
|
||||||
|
for (int i = 0; i < bodiesCount; i++)
|
||||||
|
{
|
||||||
|
PhysicsBody body = GetPhysicsBody(i);
|
||||||
|
|
||||||
|
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||||
|
for (int j = 0; j < vertexCount; j++)
|
||||||
|
{
|
||||||
|
// Get physics bodies shape vertices to draw lines
|
||||||
|
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||||
|
Vector2 vertexA = GetPhysicsShapeVertex(body, j);
|
||||||
|
|
||||||
|
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||||
|
Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
|
||||||
|
|
||||||
|
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText("Use 'ARROWS' to move player", 10, 10, 10, WHITE);
|
||||||
|
DrawText("Press 'R' to reset example", 10, 30, 10, WHITE);
|
||||||
|
|
||||||
|
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||||
|
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
ClosePhysics(); // Unitialize physics
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
examples/physics_movement.png
Normal file
After Width: | Height: | Size: 16 KiB |
115
examples/physics_restitution.c
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* Physac - Physics restitution
|
||||||
|
*
|
||||||
|
* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations.
|
||||||
|
* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external'
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Victor Fisac
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define PHYSAC_IMPLEMENTATION
|
||||||
|
#include "..\src\physac.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics restitution");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
// Physac logo drawing position
|
||||||
|
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||||
|
int logoY = 15;
|
||||||
|
|
||||||
|
// Initialize physics and default physics bodies
|
||||||
|
InitPhysics();
|
||||||
|
|
||||||
|
// Create floor rectangle physics body
|
||||||
|
PhysicsBody floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, screenWidth, 100, 10);
|
||||||
|
floor->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
floor->restitution = 1;
|
||||||
|
|
||||||
|
// Create circles physics body
|
||||||
|
PhysicsBody circleA = CreatePhysicsBodyCircle((Vector2){ screenWidth*0.25f, screenHeight/2 }, 30, 10);
|
||||||
|
circleA->restitution = 0;
|
||||||
|
PhysicsBody circleB = CreatePhysicsBodyCircle((Vector2){ screenWidth*0.5f, screenHeight/2 }, 30, 10);
|
||||||
|
circleB->restitution = 0.5f;
|
||||||
|
PhysicsBody circleC = CreatePhysicsBodyCircle((Vector2){ screenWidth*0.75f, screenHeight/2 }, 30, 10);
|
||||||
|
circleC->restitution = 1;
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed('R')) // Reset physics input
|
||||||
|
{
|
||||||
|
// Reset circles physics bodies position and velocity
|
||||||
|
circleA->position = (Vector2){ screenWidth*0.25f, screenHeight/2 };
|
||||||
|
circleA->velocity = (Vector2){ 0, 0 };
|
||||||
|
circleB->position = (Vector2){ screenWidth*0.5f, screenHeight/2 };
|
||||||
|
circleB->velocity = (Vector2){ 0, 0 };
|
||||||
|
circleC->position = (Vector2){ screenWidth*0.75f, screenHeight/2 };
|
||||||
|
circleC->velocity = (Vector2){ 0, 0 };
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
|
DrawFPS(screenWidth - 90, screenHeight - 30);
|
||||||
|
|
||||||
|
// Draw created physics bodies
|
||||||
|
int bodiesCount = GetPhysicsBodiesCount();
|
||||||
|
for (int i = 0; i < bodiesCount; i++)
|
||||||
|
{
|
||||||
|
PhysicsBody body = GetPhysicsBody(i);
|
||||||
|
|
||||||
|
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||||
|
for (int j = 0; j < vertexCount; j++)
|
||||||
|
{
|
||||||
|
// Get physics bodies shape vertices to draw lines
|
||||||
|
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||||
|
Vector2 vertexA = GetPhysicsShapeVertex(body, j);
|
||||||
|
|
||||||
|
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||||
|
Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
|
||||||
|
|
||||||
|
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText("Restitution amount", (screenWidth - MeasureText("Restitution amount", 30))/2, 75, 30, WHITE);
|
||||||
|
DrawText("0", circleA->position.x - MeasureText("0", 20)/2, circleA->position.y - 7, 20, WHITE);
|
||||||
|
DrawText("0.5", circleB->position.x - MeasureText("0.5", 20)/2, circleB->position.y - 7, 20, WHITE);
|
||||||
|
DrawText("1", circleC->position.x - MeasureText("1", 20)/2, circleC->position.y - 7, 20, WHITE);
|
||||||
|
|
||||||
|
DrawText("Press 'R' to reset example", 10, 10, 10, WHITE);
|
||||||
|
|
||||||
|
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||||
|
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
ClosePhysics(); // Unitialize physics
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
examples/physics_restitution.png
Normal file
After Width: | Height: | Size: 17 KiB |
107
examples/physics_shatter.c
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* Physac - Body shatter
|
||||||
|
*
|
||||||
|
* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations.
|
||||||
|
* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external'
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Victor Fisac
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define PHYSAC_IMPLEMENTATION
|
||||||
|
#include "..\src\physac.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Body shatter");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
// Physac logo drawing position
|
||||||
|
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||||
|
int logoY = 15;
|
||||||
|
|
||||||
|
// Initialize physics and default physics bodies
|
||||||
|
InitPhysics();
|
||||||
|
SetPhysicsGravity(0, 0);
|
||||||
|
|
||||||
|
// Create random polygon physics body to shatter
|
||||||
|
PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed('R')) // Reset physics input
|
||||||
|
{
|
||||||
|
ResetPhysics();
|
||||||
|
|
||||||
|
// Create random polygon physics body to shatter
|
||||||
|
body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input
|
||||||
|
{
|
||||||
|
// Note: some values need to be stored in variables due to asynchronous changes during main thread
|
||||||
|
int count = GetPhysicsBodiesCount();
|
||||||
|
for (int i = count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
PhysicsBody currentBody = GetPhysicsBody(i);
|
||||||
|
if (currentBody != NULL) PhysicsShatter(currentBody, GetMousePosition(), 10/currentBody->inverseMass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
|
// Draw created physics bodies
|
||||||
|
int bodiesCount = GetPhysicsBodiesCount();
|
||||||
|
for (int i = 0; i < bodiesCount; i++)
|
||||||
|
{
|
||||||
|
PhysicsBody currentBody = GetPhysicsBody(i);
|
||||||
|
|
||||||
|
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||||
|
for (int j = 0; j < vertexCount; j++)
|
||||||
|
{
|
||||||
|
// Get physics bodies shape vertices to draw lines
|
||||||
|
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||||
|
Vector2 vertexA = GetPhysicsShapeVertex(currentBody, j);
|
||||||
|
|
||||||
|
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||||
|
Vector2 vertexB = GetPhysicsShapeVertex(currentBody, jj);
|
||||||
|
|
||||||
|
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText("Left mouse button in polygon area to shatter body\nPress 'R' to reset example", 10, 10, 10, WHITE);
|
||||||
|
|
||||||
|
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||||
|
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
ClosePhysics(); // Unitialize physics
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
examples/physics_shatter.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
examples/resources/audio/chiptun1.mod
Normal file
BIN
examples/resources/audio/mini1111.xm
Normal file
BIN
examples/resources/fonts/KAISG.ttf
Normal file
188
examples/resources/fonts/pixantiqua.fnt
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
info face="PixAntiqua" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=2,2,2,2 spacing=2,2 outline=0
|
||||||
|
common lineHeight=32 base=27 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||||
|
page id=0 file="pixantiqua_0.png"
|
||||||
|
chars count=184
|
||||||
|
char id=32 x=9 y=304 width=7 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=33 x=391 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=34 x=240 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=35 x=468 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=36 x=152 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=37 x=176 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=38 x=303 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=39 x=495 y=266 width=8 height=36 xoffset=-3 yoffset=-2 xadvance=5 page=0 chnl=15
|
||||||
|
char id=40 x=256 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=199 x=432 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=200 x=126 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=201 x=147 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=202 x=288 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=203 x=189 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=204 x=468 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=205 x=486 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=206 x=0 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=207 x=72 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=208 x=329 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=209 x=277 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=210 x=182 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=211 x=26 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=41 x=272 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=42 x=288 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=43 x=414 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=44 x=378 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=45 x=414 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=46 x=443 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=47 x=392 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=48 x=485 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=49 x=450 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=50 x=21 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=51 x=42 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=59 x=456 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=60 x=168 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=61 x=309 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=62 x=336 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=63 x=315 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=64 x=364 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=65 x=390 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=66 x=120 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=67 x=144 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=68 x=168 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=69 x=294 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=52 x=488 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=53 x=63 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=54 x=24 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=55 x=48 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=56 x=72 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=57 x=96 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=58 x=404 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=70 x=252 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=71 x=192 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=72 x=78 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=78 x=78 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=79 x=355 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=80 x=264 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=81 x=381 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=82 x=288 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=83 x=312 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=91 x=144 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=92 x=108 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=93 x=304 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=94 x=34 y=0 width=32 height=36 xoffset=-3 yoffset=-2 xadvance=29 page=0 chnl=15
|
||||||
|
char id=95 x=231 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=96 x=442 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=97 x=408 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=98 x=432 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=99 x=210 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=84 x=336 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=85 x=360 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=86 x=0 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=87 x=68 y=0 width=30 height=36 xoffset=-3 yoffset=-2 xadvance=27 page=0 chnl=15
|
||||||
|
char id=88 x=26 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=89 x=384 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=90 x=84 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=100 x=456 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=101 x=480 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=102 x=54 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=103 x=0 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=104 x=24 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=105 x=469 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=106 x=18 y=266 width=16 height=36 xoffset=-8 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=107 x=48 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=108 x=417 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=109 x=161 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15
|
||||||
|
char id=110 x=72 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=111 x=96 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=117 x=192 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=118 x=216 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=119 x=248 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15
|
||||||
|
char id=120 x=240 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=121 x=264 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=122 x=288 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=123 x=432 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=124 x=365 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=125 x=378 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=126 x=393 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=127 x=132 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15
|
||||||
|
char id=160 x=0 y=304 width=7 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=161 x=352 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=162 x=351 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=163 x=336 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=165 x=360 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=167 x=384 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=169 x=433 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=170 x=224 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=171 x=105 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=172 x=0 y=0 width=32 height=36 xoffset=-3 yoffset=-2 xadvance=29 page=0 chnl=15
|
||||||
|
char id=173 x=494 y=38 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=174 x=52 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=175 x=52 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=176 x=126 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=177 x=435 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=178 x=320 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=179 x=336 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=181 x=459 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=112 x=120 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=113 x=144 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=114 x=396 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=115 x=168 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=116 x=36 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=182 x=408 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=183 x=498 y=190 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=185 x=192 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=186 x=208 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=187 x=477 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=191 x=456 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=192 x=407 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=193 x=234 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=194 x=416 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=195 x=156 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=196 x=130 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=197 x=104 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=198 x=190 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15
|
||||||
|
char id=212 x=0 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=213 x=338 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=214 x=312 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=215 x=357 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=216 x=286 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=217 x=456 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=218 x=480 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=219 x=0 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=220 x=24 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=221 x=48 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=222 x=260 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=223 x=72 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=224 x=96 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=225 x=120 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=226 x=144 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=227 x=168 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=228 x=192 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=229 x=216 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=230 x=219 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15
|
||||||
|
char id=231 x=372 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=73 x=90 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15
|
||||||
|
char id=74 x=216 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=75 x=240 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=76 x=273 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=77 x=100 y=0 width=30 height=36 xoffset=-3 yoffset=-2 xadvance=27 page=0 chnl=15
|
||||||
|
char id=232 x=312 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=233 x=240 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=234 x=264 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=235 x=104 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=236 x=430 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=237 x=482 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=238 x=160 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15
|
||||||
|
char id=239 x=176 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15
|
||||||
|
char id=240 x=128 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=241 x=200 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=242 x=224 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=243 x=248 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=244 x=272 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=245 x=296 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=246 x=320 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=247 x=330 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=248 x=208 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15
|
||||||
|
char id=249 x=344 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=250 x=368 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=251 x=416 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=252 x=440 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=253 x=464 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
||||||
|
char id=254 x=0 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15
|
||||||
|
char id=255 x=0 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15
|
BIN
examples/resources/fonts/pixantiqua_0.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
examples/resources/ps3.png
Normal file
After Width: | Height: | Size: 19 KiB |
@@ -8,30 +8,32 @@ varying vec4 fragColor;
|
|||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 fragTintColor;
|
uniform vec4 colDiffuse;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
const vec2 size = vec2(800, 450); // render size
|
||||||
|
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||||
|
const float quality = 2.5; // lower = smaller glow, better quality
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 sum = vec4(0);
|
vec4 sum = vec4(0);
|
||||||
vec4 tc = vec4(0);
|
vec2 sizeFactor = vec2(1)/size*quality;
|
||||||
|
|
||||||
for (int i = -4; i < 4; i++)
|
// Texel color fetching from texture sampler
|
||||||
|
vec4 source = texture2D(texture0, fragTexCoord);
|
||||||
|
|
||||||
|
const int range = 2; // should be = (samples - 1)/2;
|
||||||
|
|
||||||
|
for (int x = -range; x <= range; x++)
|
||||||
{
|
{
|
||||||
for (int j = -3; j < 3; j++)
|
for (int y = -range; y <= range; y++)
|
||||||
{
|
{
|
||||||
sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25;
|
sum += texture2D(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texel color fetching from texture sampler
|
|
||||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
|
||||||
|
|
||||||
// Calculate final fragment color
|
// Calculate final fragment color
|
||||||
if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor;
|
gl_FragColor = ((sum/(samples*samples)) + source)*colDiffuse;
|
||||||
else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor;
|
|
||||||
else tc = sum*sum*0.0075 + texelColor;
|
|
||||||
|
|
||||||
gl_FragColor = tc;
|
|
||||||
}
|
}
|
152
examples/resources/shaders/glsl100/standard.fs
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
#version 100
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform sampler2D texture1;
|
||||||
|
uniform sampler2D texture2;
|
||||||
|
|
||||||
|
uniform vec4 colAmbient;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec4 colSpecular;
|
||||||
|
uniform float glossiness;
|
||||||
|
|
||||||
|
uniform int useNormal;
|
||||||
|
uniform int useSpecular;
|
||||||
|
|
||||||
|
uniform mat4 modelMatrix;
|
||||||
|
uniform vec3 viewDir;
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
vec4 diffuse;
|
||||||
|
float intensity;
|
||||||
|
float radius;
|
||||||
|
float coneAngle;
|
||||||
|
};
|
||||||
|
|
||||||
|
const int maxLights = 8;
|
||||||
|
uniform Light lights[maxLights];
|
||||||
|
|
||||||
|
vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s)
|
||||||
|
{
|
||||||
|
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1.0));
|
||||||
|
vec3 surfaceToLight = l.position - surfacePos;
|
||||||
|
|
||||||
|
// Diffuse shading
|
||||||
|
float brightness = clamp(float(dot(n, surfaceToLight)/(length(surfaceToLight)*length(n))), 0.0, 1.0);
|
||||||
|
float diff = 1.0/dot(surfaceToLight/l.radius, surfaceToLight/l.radius)*brightness*l.intensity;
|
||||||
|
|
||||||
|
// Specular shading
|
||||||
|
float spec = 0.0;
|
||||||
|
if (diff > 0.0)
|
||||||
|
{
|
||||||
|
vec3 h = normalize(-l.direction + v);
|
||||||
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (diff*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s)
|
||||||
|
{
|
||||||
|
vec3 lightDir = normalize(-l.direction);
|
||||||
|
|
||||||
|
// Diffuse shading
|
||||||
|
float diff = clamp(float(dot(n, lightDir)), 0.0, 1.0)*l.intensity;
|
||||||
|
|
||||||
|
// Specular shading
|
||||||
|
float spec = 0.0;
|
||||||
|
if (diff > 0.0)
|
||||||
|
{
|
||||||
|
vec3 h = normalize(lightDir + v);
|
||||||
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine results
|
||||||
|
return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s)
|
||||||
|
{
|
||||||
|
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
|
||||||
|
vec3 lightToSurface = normalize(surfacePos - l.position);
|
||||||
|
vec3 lightDir = normalize(-l.direction);
|
||||||
|
|
||||||
|
// Diffuse shading
|
||||||
|
float diff = clamp(float(dot(n, lightDir)), 0.0, 1.0)*l.intensity;
|
||||||
|
|
||||||
|
// Spot attenuation
|
||||||
|
float attenuation = clamp(float(dot(n, lightToSurface)), 0.0, 1.0);
|
||||||
|
attenuation = dot(lightToSurface, -lightDir);
|
||||||
|
|
||||||
|
float lightToSurfaceAngle = degrees(acos(attenuation));
|
||||||
|
if (lightToSurfaceAngle > l.coneAngle) attenuation = 0.0;
|
||||||
|
|
||||||
|
float falloff = (l.coneAngle - lightToSurfaceAngle)/l.coneAngle;
|
||||||
|
|
||||||
|
// Combine diffuse and attenuation
|
||||||
|
float diffAttenuation = diff*attenuation;
|
||||||
|
|
||||||
|
// Specular shading
|
||||||
|
float spec = 0.0;
|
||||||
|
if (diffAttenuation > 0.0)
|
||||||
|
{
|
||||||
|
vec3 h = normalize(lightDir + v);
|
||||||
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Calculate fragment normal in screen space
|
||||||
|
// NOTE: important to multiply model matrix by fragment normal to apply model transformation (rotation and scale)
|
||||||
|
mat3 normalMatrix = mat3(modelMatrix);
|
||||||
|
vec3 normal = normalize(normalMatrix*fragNormal);
|
||||||
|
|
||||||
|
// Normalize normal and view direction vectors
|
||||||
|
vec3 n = normalize(normal);
|
||||||
|
vec3 v = normalize(viewDir);
|
||||||
|
|
||||||
|
// Calculate diffuse texture color fetching
|
||||||
|
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||||
|
vec3 lighting = colAmbient.rgb;
|
||||||
|
|
||||||
|
// Calculate normal texture color fetching or set to maximum normal value by default
|
||||||
|
if (useNormal == 1)
|
||||||
|
{
|
||||||
|
n *= texture2D(texture1, fragTexCoord).rgb;
|
||||||
|
n = normalize(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate specular texture color fetching or set to maximum specular value by default
|
||||||
|
float spec = 1.0;
|
||||||
|
if (useSpecular == 1) spec = texture2D(texture2, fragTexCoord).r;
|
||||||
|
|
||||||
|
for (int i = 0; i < maxLights; i++)
|
||||||
|
{
|
||||||
|
// Check if light is enabled
|
||||||
|
if (lights[i].enabled == 1)
|
||||||
|
{
|
||||||
|
// Calculate lighting based on light type
|
||||||
|
if(lights[i].type == 0) lighting += ComputeLightPoint(lights[i], n, v, spec);
|
||||||
|
else if(lights[i].type == 1) lighting += ComputeLightDirectional(lights[i], n, v, spec);
|
||||||
|
else if(lights[i].type == 2) lighting += ComputeLightSpot(lights[i], n, v, spec);
|
||||||
|
|
||||||
|
// NOTE: It seems that too many ComputeLight*() operations inside for loop breaks the shader on RPI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate final fragment color
|
||||||
|
gl_FragColor = vec4(texelColor.rgb*lighting*colDiffuse.rgb, texelColor.a*colDiffuse.a);
|
||||||
|
}
|
23
examples/resources/shaders/glsl100/standard.vs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#version 100
|
||||||
|
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec2 vertexTexCoord;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
uniform mat4 mvpMatrix;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragPosition = vertexPosition;
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
fragColor = vertexColor;
|
||||||
|
fragNormal = vertexNormal;
|
||||||
|
|
||||||
|
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||||
|
}
|
@@ -6,33 +6,35 @@ in vec4 fragColor;
|
|||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 fragTintColor;
|
uniform vec4 colDiffuse;
|
||||||
|
|
||||||
// Output fragment color
|
// Output fragment color
|
||||||
out vec4 finalColor;
|
out vec4 finalColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
const vec2 size = vec2(800, 450); // render size
|
||||||
|
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||||
|
const float quality = 2.5; // lower = smaller glow, better quality
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 sum = vec4(0);
|
vec4 sum = vec4(0);
|
||||||
vec4 tc = vec4(0);
|
vec2 sizeFactor = vec2(1)/size*quality;
|
||||||
|
|
||||||
for (int i = -4; i < 4; i++)
|
// Texel color fetching from texture sampler
|
||||||
|
vec4 source = texture(texture0, fragTexCoord);
|
||||||
|
|
||||||
|
const int range = 2; // should be = (samples - 1)/2;
|
||||||
|
|
||||||
|
for (int x = -range; x <= range; x++)
|
||||||
{
|
{
|
||||||
for (int j = -3; j < 3; j++)
|
for (int y = -range; y <= range; y++)
|
||||||
{
|
{
|
||||||
sum += texture(texture0, fragTexCoord + vec2(j, i)*0.004)*0.25;
|
sum += texture(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texel color fetching from texture sampler
|
|
||||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
|
||||||
|
|
||||||
// Calculate final fragment color
|
|
||||||
if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor;
|
|
||||||
else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor;
|
|
||||||
else tc = sum*sum*0.0075 + texelColor;
|
|
||||||
|
|
||||||
finalColor = tc;
|
// Calculate final fragment color
|
||||||
|
finalColor = ((sum/(samples*samples)) + source)*colDiffuse;
|
||||||
}
|
}
|
150
examples/resources/shaders/glsl330/standard.fs
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
in vec3 fragPosition;
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec4 fragColor;
|
||||||
|
in vec3 fragNormal;
|
||||||
|
|
||||||
|
out vec4 finalColor;
|
||||||
|
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform sampler2D texture1;
|
||||||
|
uniform sampler2D texture2;
|
||||||
|
|
||||||
|
uniform vec4 colAmbient;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec4 colSpecular;
|
||||||
|
uniform float glossiness;
|
||||||
|
|
||||||
|
uniform int useNormal;
|
||||||
|
uniform int useSpecular;
|
||||||
|
|
||||||
|
uniform mat4 modelMatrix;
|
||||||
|
uniform vec3 viewDir;
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
vec4 diffuse;
|
||||||
|
float intensity;
|
||||||
|
float radius;
|
||||||
|
float coneAngle;
|
||||||
|
};
|
||||||
|
|
||||||
|
const int maxLights = 8;
|
||||||
|
uniform Light lights[maxLights];
|
||||||
|
|
||||||
|
vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s)
|
||||||
|
{
|
||||||
|
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
|
||||||
|
vec3 surfaceToLight = l.position - surfacePos;
|
||||||
|
|
||||||
|
// Diffuse shading
|
||||||
|
float brightness = clamp(float(dot(n, surfaceToLight)/(length(surfaceToLight)*length(n))), 0.0, 1.0);
|
||||||
|
float diff = 1.0/dot(surfaceToLight/l.radius, surfaceToLight/l.radius)*brightness*l.intensity;
|
||||||
|
|
||||||
|
// Specular shading
|
||||||
|
float spec = 0.0;
|
||||||
|
if (diff > 0.0)
|
||||||
|
{
|
||||||
|
vec3 h = normalize(-l.direction + v);
|
||||||
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (diff*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s)
|
||||||
|
{
|
||||||
|
vec3 lightDir = normalize(-l.direction);
|
||||||
|
|
||||||
|
// Diffuse shading
|
||||||
|
float diff = clamp(float(dot(n, lightDir)), 0.0, 1.0)*l.intensity;
|
||||||
|
|
||||||
|
// Specular shading
|
||||||
|
float spec = 0.0;
|
||||||
|
if (diff > 0.0)
|
||||||
|
{
|
||||||
|
vec3 h = normalize(lightDir + v);
|
||||||
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine results
|
||||||
|
return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s)
|
||||||
|
{
|
||||||
|
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
|
||||||
|
vec3 lightToSurface = normalize(surfacePos - l.position);
|
||||||
|
vec3 lightDir = normalize(-l.direction);
|
||||||
|
|
||||||
|
// Diffuse shading
|
||||||
|
float diff = clamp(float(dot(n, lightDir)), 0.0, 1.0)*l.intensity;
|
||||||
|
|
||||||
|
// Spot attenuation
|
||||||
|
float attenuation = clamp(float(dot(n, lightToSurface)), 0.0, 1.0);
|
||||||
|
attenuation = dot(lightToSurface, -lightDir);
|
||||||
|
|
||||||
|
float lightToSurfaceAngle = degrees(acos(attenuation));
|
||||||
|
if (lightToSurfaceAngle > l.coneAngle) attenuation = 0.0;
|
||||||
|
|
||||||
|
float falloff = (l.coneAngle - lightToSurfaceAngle)/l.coneAngle;
|
||||||
|
|
||||||
|
// Combine diffuse and attenuation
|
||||||
|
float diffAttenuation = diff*attenuation;
|
||||||
|
|
||||||
|
// Specular shading
|
||||||
|
float spec = 0.0;
|
||||||
|
if (diffAttenuation > 0.0)
|
||||||
|
{
|
||||||
|
vec3 h = normalize(lightDir + v);
|
||||||
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Calculate fragment normal in screen space
|
||||||
|
// NOTE: important to multiply model matrix by fragment normal to apply model transformation (rotation and scale)
|
||||||
|
mat3 normalMatrix = mat3(modelMatrix);
|
||||||
|
vec3 normal = normalize(normalMatrix*fragNormal);
|
||||||
|
|
||||||
|
// Normalize normal and view direction vectors
|
||||||
|
vec3 n = normalize(normal);
|
||||||
|
vec3 v = normalize(viewDir);
|
||||||
|
|
||||||
|
// Calculate diffuse texture color fetching
|
||||||
|
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||||
|
vec3 lighting = colAmbient.rgb;
|
||||||
|
|
||||||
|
// Calculate normal texture color fetching or set to maximum normal value by default
|
||||||
|
if (useNormal == 1)
|
||||||
|
{
|
||||||
|
n *= texture(texture1, fragTexCoord).rgb;
|
||||||
|
n = normalize(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate specular texture color fetching or set to maximum specular value by default
|
||||||
|
float spec = 1.0;
|
||||||
|
if (useSpecular == 1) spec = texture(texture2, fragTexCoord).r;
|
||||||
|
|
||||||
|
for (int i = 0; i < maxLights; i++)
|
||||||
|
{
|
||||||
|
// Check if light is enabled
|
||||||
|
if (lights[i].enabled == 1)
|
||||||
|
{
|
||||||
|
// Calculate lighting based on light type
|
||||||
|
if (lights[i].type == 0) lighting += ComputeLightPoint(lights[i], n, v, spec);
|
||||||
|
else if (lights[i].type == 1) lighting += ComputeLightDirectional(lights[i], n, v, spec);
|
||||||
|
else if (lights[i].type == 2) lighting += ComputeLightSpot(lights[i], n, v, spec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate final fragment color
|
||||||
|
finalColor = vec4(texelColor.rgb*lighting*colDiffuse.rgb, texelColor.a*colDiffuse.a);
|
||||||
|
}
|
23
examples/resources/shaders/glsl330/standard.vs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
in vec3 vertexPosition;
|
||||||
|
in vec3 vertexNormal;
|
||||||
|
in vec2 vertexTexCoord;
|
||||||
|
in vec4 vertexColor;
|
||||||
|
|
||||||
|
out vec3 fragPosition;
|
||||||
|
out vec2 fragTexCoord;
|
||||||
|
out vec4 fragColor;
|
||||||
|
out vec3 fragNormal;
|
||||||
|
|
||||||
|
uniform mat4 mvpMatrix;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragPosition = vertexPosition;
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
fragColor = vertexColor;
|
||||||
|
fragNormal = vertexNormal;
|
||||||
|
|
||||||
|
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||||
|
}
|
BIN
examples/resources/xbox.png
Normal file
After Width: | Height: | Size: 16 KiB |
93
examples/rlua_execute_file.c
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [rlua] example - Lua file execution
|
||||||
|
*
|
||||||
|
* NOTE: This example requires Lua library (http://luabinaries.sourceforge.net/download.html)
|
||||||
|
*
|
||||||
|
* Compile example using:
|
||||||
|
* gcc -o $(NAME_PART).exe $(FILE_NAME) $(RAYLIB_DIR)\raylib_icon /
|
||||||
|
* -I../src -I../src/external/lua/include -L../src/external/lua/lib /
|
||||||
|
* -lraylib -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -llua53 /
|
||||||
|
* -std=c99 -Wl,-allow-multiple-definition -Wl,--subsystem,windows
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define RLUA_IMPLEMENTATION
|
||||||
|
#include "rlua.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
InitLuaDevice();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ExecuteLuaFile("core_basic_window.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_input_keys.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_input_mouse.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_mouse_wheel.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_input_gamepad.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_random_values.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_color_select.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_drop_files.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_storage_values.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_gestures_detection.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_3d_mode.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_3d_picking.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_3d_camera_free.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_3d_camera_first_person.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_2d_camera.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_world_screen.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("core_oculus_rift.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shapes_logo_raylib.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shapes_basic_shapes.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shapes_colors_palette.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shapes_logo_raylib_anim.lua"); // OK! NOTE: Use lua string.sub() instead of raylib SubText()
|
||||||
|
// ExecuteLuaFile("textures_logo_raylib.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("textures_image_loading.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("textures_rectangle.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("textures_srcrec_dstrec.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("textures_to_image.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("textures_raw_data.lua"); // ERROR: LoadImageEx()
|
||||||
|
// ExecuteLuaFile("textures_formats_loading.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("textures_particles_trail_blending.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("textures_image_processing.lua"); // ERROR: GetImageData() --> UpdateTexture()
|
||||||
|
// ExecuteLuaFile("textures_image_drawing.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("text_sprite_fonts.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("text_bmfont_ttf.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("text_rbmf_fonts.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("text_format_text.lua"); // OK! NOTE: Use lua string.format() instead of raylib FormatText()
|
||||||
|
// ExecuteLuaFile("text_font_select.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("text_writing_anim.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("text_ttf_loading.lua"); // ISSUE: Attempt to index a SpriteFont value (local 'font')
|
||||||
|
// ExecuteLuaFile("text_bmfont_unordered.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("models_geometric_shapes.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("models_box_collisions.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("models_billboard.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("models_obj_loading.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("models_heightmap.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("models_cubicmap.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shaders_model_shader.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shaders_shapes_textures.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shaders_custom_uniform.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shaders_postprocessing.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("shaders_standard_lighting.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("audio_sound_loading.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("audio_music_stream.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("audio_module_playing.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("audio_raw_stream.lua"); // ERROR: UpdateAudioStream()
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseLuaDevice(); // Close Lua device and free resources
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@@ -51,9 +51,7 @@ int main()
|
|||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
// Setup orbital camera
|
// Setup orbital camera
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -71,7 +69,7 @@ int main()
|
|||||||
// Send new value to the shader to be used on drawing
|
// Send new value to the shader to be used on drawing
|
||||||
SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
|
SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
|
||||||
|
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
113
examples/shaders_custom_uniform.lua
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shaders] example - Apply a postprocessing shader and connect a custom uniform variable
|
||||||
|
--
|
||||||
|
-- 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), to test this example
|
||||||
|
-- on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
-- raylib comes with shaders ready for both versions, check raylib/shaders install folder
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG.MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
|
||||||
|
local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture (diffuse map)
|
||||||
|
dwarf.material.texDiffuse = texture -- Set dwarf model diffuse texture
|
||||||
|
|
||||||
|
local position = Vector3(0.0, 0.0, 0.0) -- Set model position
|
||||||
|
|
||||||
|
local shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||||
|
"resources/shaders/glsl330/swirl.fs") -- Load postpro shader
|
||||||
|
|
||||||
|
-- Get variable (uniform) location on the shader to connect with the program
|
||||||
|
-- NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||||
|
local swirlCenterLoc = GetShaderLocation(shader, "center")
|
||||||
|
|
||||||
|
local swirlCenter = { screenWidth/2, screenHeight/2 }
|
||||||
|
|
||||||
|
-- Create a RenderTexture2D to be used for render to texture
|
||||||
|
local target = LoadRenderTexture(screenWidth, screenHeight)
|
||||||
|
|
||||||
|
-- Setup orbital camera
|
||||||
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
local mousePosition = GetMousePosition()
|
||||||
|
|
||||||
|
swirlCenter[1] = mousePosition.x
|
||||||
|
swirlCenter[2] = screenHeight - mousePosition.y
|
||||||
|
|
||||||
|
-- Send new value to the shader to be used on drawing
|
||||||
|
SetShaderValue(shader, swirlCenterLoc, swirlCenter)
|
||||||
|
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
BeginTextureMode(target) -- Enable drawing to texture
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, RED)
|
||||||
|
|
||||||
|
EndTextureMode() -- End drawing to texture (now we have a texture available for next passes)
|
||||||
|
|
||||||
|
BeginShaderMode(shader)
|
||||||
|
|
||||||
|
-- NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||||
|
DrawTextureRec(target.texture, Rectangle(0, 0, target.texture.width, -target.texture.height), Vector2(0, 0), WHITE)
|
||||||
|
|
||||||
|
EndShaderMode()
|
||||||
|
|
||||||
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadShader(shader) -- Unload shader
|
||||||
|
UnloadTexture(texture) -- Unload texture
|
||||||
|
UnloadModel(dwarf) -- Unload model
|
||||||
|
UnloadRenderTexture(target) -- Unload render texture
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -37,25 +37,22 @@ int main()
|
|||||||
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||||
"resources/shaders/glsl330/grayscale.fs"); // Load model shader
|
"resources/shaders/glsl330/grayscale.fs"); // Load model shader
|
||||||
|
|
||||||
dwarf.material.shader = shader; // Set shader effect to 3d model
|
dwarf.material.shader = shader; // Set shader effect to 3d model
|
||||||
dwarf.material.texDiffuse = texture; // Bind texture to model
|
dwarf.material.texDiffuse = texture; // Bind texture to model
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
// Setup orbital camera
|
SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@@ -73,6 +70,9 @@ int main()
|
|||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||||
|
|
||||||
|
DrawText(FormatText("Camera position: (%.2f, %.2f, %.2f)", camera.position.x, camera.position.y, camera.position.z), 600, 20, 10, BLACK);
|
||||||
|
DrawText(FormatText("Camera target: (%.2f, %.2f, %.2f)", camera.target.x, camera.target.y, camera.target.z), 600, 40, 10, GRAY);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
83
examples/shaders_model_shader.lua
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shaders] example - Apply a shader to a 3d model
|
||||||
|
--
|
||||||
|
-- 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), to test this example
|
||||||
|
-- on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
-- raylib comes with shaders ready for both versions, check raylib/shaders install folder
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG.MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
|
||||||
|
local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture
|
||||||
|
local shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||||
|
"resources/shaders/glsl330/grayscale.fs") -- Load model shader
|
||||||
|
|
||||||
|
dwarf.material.shader = shader -- Set shader effect to 3d model
|
||||||
|
dwarf.material.texDiffuse = texture -- Bind texture to model
|
||||||
|
|
||||||
|
local position = Vector3(0.0, 0.0, 0.0) -- Set model position
|
||||||
|
|
||||||
|
-- Setup orbital camera
|
||||||
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadShader(shader) -- Unload shader
|
||||||
|
UnloadTexture(texture) -- Unload texture
|
||||||
|
UnloadModel(dwarf) -- Unload model
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -45,9 +45,7 @@ int main()
|
|||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
// Setup orbital camera
|
// Setup orbital camera
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -57,7 +55,7 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@@ -67,7 +65,7 @@ int main()
|
|||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginTextureMode(target); // Enable drawing to texture
|
BeginTextureMode(target); // Enable drawing to texture
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
||||||
|
99
examples/shaders_postprocessing.lua
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shaders] example - Apply a postprocessing shader to a scene
|
||||||
|
--
|
||||||
|
-- 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), to test this example
|
||||||
|
-- on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
-- raylib comes with shaders ready for both versions, check raylib/shaders install folder
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG.MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
|
||||||
|
local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture (diffuse map)
|
||||||
|
dwarf.material.texDiffuse = texture -- Set dwarf model diffuse texture
|
||||||
|
|
||||||
|
local position = Vector3(0.0, 0.0, 0.0) -- Set model position
|
||||||
|
|
||||||
|
local shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||||
|
"resources/shaders/glsl330/bloom.fs") -- Load postpro shader
|
||||||
|
|
||||||
|
-- Create a RenderTexture2D to be used for render to texture
|
||||||
|
local target = LoadRenderTexture(screenWidth, screenHeight)
|
||||||
|
|
||||||
|
-- Setup orbital camera
|
||||||
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
BeginTextureMode(target) -- Enable drawing to texture
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("HELLO POSTPROCESSING!", 70, 190, 50, RED)
|
||||||
|
|
||||||
|
EndTextureMode() -- End drawing to texture (now we have a texture available for next passes)
|
||||||
|
|
||||||
|
BeginShaderMode(shader)
|
||||||
|
|
||||||
|
-- NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||||
|
DrawTextureRec(target.texture, Rectangle(0, 0, target.texture.width, -target.texture.height), Vector2(0, 0), WHITE)
|
||||||
|
|
||||||
|
EndShaderMode()
|
||||||
|
|
||||||
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, DARKGRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadShader(shader) -- Unload shader
|
||||||
|
UnloadTexture(texture) -- Unload texture
|
||||||
|
UnloadModel(dwarf) -- Unload model
|
||||||
|
UnloadRenderTexture(target) -- Unload render texture
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
101
examples/shaders_shapes_textures.lua
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shaders] example - Apply a shader to some shape or texture
|
||||||
|
--
|
||||||
|
-- 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), to test this example
|
||||||
|
-- on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
-- raylib comes with shaders ready for both versions, check raylib/shaders install folder
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders")
|
||||||
|
|
||||||
|
local sonic = LoadTexture("resources/texture_formats/sonic.png")
|
||||||
|
|
||||||
|
-- NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||||
|
local shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||||
|
"resources/shaders/glsl330/grayscale.fs")
|
||||||
|
|
||||||
|
-- Shader usage is also different than models/postprocessing, shader is just activated when required
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update your variables here
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
-- Start drawing with default shader
|
||||||
|
|
||||||
|
DrawText("USING DEFAULT SHADER", 20, 40, 10, RED)
|
||||||
|
|
||||||
|
DrawCircle(80, 120, 35, DARKBLUE)
|
||||||
|
DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE)
|
||||||
|
DrawCircleLines(80, 340, 80, DARKBLUE)
|
||||||
|
|
||||||
|
|
||||||
|
-- Activate our custom shader to be applied on next shapes/textures drawings
|
||||||
|
BeginShaderMode(shader)
|
||||||
|
|
||||||
|
DrawText("USING CUSTOM SHADER", 190, 40, 10, RED)
|
||||||
|
|
||||||
|
DrawRectangle(250 - 60, 90, 120, 60, RED)
|
||||||
|
DrawRectangleGradient(250 - 90, 170, 180, 130, MAROON, GOLD)
|
||||||
|
DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE)
|
||||||
|
|
||||||
|
-- Activate our default shader for next drawings
|
||||||
|
EndShaderMode()
|
||||||
|
|
||||||
|
DrawText("USING DEFAULT SHADER", 370, 40, 10, RED)
|
||||||
|
|
||||||
|
DrawTriangle(Vector2(430, 80),
|
||||||
|
Vector2(430 - 60, 150),
|
||||||
|
Vector2(430 + 60, 150), VIOLET)
|
||||||
|
|
||||||
|
DrawTriangleLines(Vector2(430, 160),
|
||||||
|
Vector2(430 - 20, 230),
|
||||||
|
Vector2(430 + 20, 230), DARKBLUE)
|
||||||
|
|
||||||
|
DrawPoly(Vector2(430, 320), 6, 80, 0, BROWN)
|
||||||
|
|
||||||
|
-- Activate our custom shader to be applied on next shapes/textures drawings
|
||||||
|
BeginShaderMode(shader)
|
||||||
|
|
||||||
|
DrawTexture(sonic, 380, -10, WHITE) -- Using custom shader
|
||||||
|
|
||||||
|
-- Activate our default shader for next drawings
|
||||||
|
EndShaderMode()
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadShader(shader) -- Unload shader
|
||||||
|
UnloadTexture(sonic) -- Unload texture
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@@ -64,9 +64,7 @@ int main()
|
|||||||
pointLight->radius = 3.0f;
|
pointLight->radius = 3.0f;
|
||||||
|
|
||||||
// Setup orbital camera
|
// Setup orbital camera
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@@ -76,7 +74,7 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
112
examples/shaders_standard_lighting.lua
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shaders] example - Standard lighting (materials and lights)
|
||||||
|
--
|
||||||
|
-- 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), to test this example
|
||||||
|
-- on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
-- raylib comes with shaders ready for both versions, check raylib/shaders install folder
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG.MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = Camera(Vector3(4.0, 4.0, 4.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
|
||||||
|
|
||||||
|
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
|
||||||
|
local position = Vector3(0.0, 0.0, 0.0) -- Set model position
|
||||||
|
|
||||||
|
local material = LoadStandardMaterial()
|
||||||
|
|
||||||
|
material.texDiffuse = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model diffuse texture
|
||||||
|
material.texNormal = LoadTexture("resources/model/dwarf_normal.png") -- Load model normal texture
|
||||||
|
material.texSpecular = LoadTexture("resources/model/dwarf_specular.png") -- Load model specular texture
|
||||||
|
material.colDiffuse = WHITE
|
||||||
|
material.colAmbient = Color(0, 0, 10, 255)
|
||||||
|
material.colSpecular = WHITE
|
||||||
|
material.glossiness = 50.0
|
||||||
|
|
||||||
|
dwarf.material = material -- Apply material to model
|
||||||
|
|
||||||
|
local spotLight = CreateLight(LightType.SPOT, Vector3(3.0, 5.0, 2.0), Color(255, 255, 255, 255))
|
||||||
|
spotLight.target = Vector3(0.0, 0.0, 0.0)
|
||||||
|
spotLight.intensity = 2.0
|
||||||
|
spotLight.diffuse = Color(255, 100, 100, 255)
|
||||||
|
spotLight.coneAngle = 60.0
|
||||||
|
|
||||||
|
local dirLight = CreateLight(LightType.DIRECTIONAL, Vector3(0.0, -3.0, -3.0), Color(255, 255, 255, 255))
|
||||||
|
dirLight.target = Vector3(1.0, -2.0, -2.0)
|
||||||
|
dirLight.intensity = 2.0
|
||||||
|
dirLight.diffuse = Color(100, 255, 100, 255)
|
||||||
|
|
||||||
|
local pointLight = CreateLight(LightType.POINT, Vector3(0.0, 4.0, 5.0), Color(255, 255, 255, 255))
|
||||||
|
pointLight.intensity = 2.0
|
||||||
|
pointLight.diffuse = Color(100, 100, 255, 255)
|
||||||
|
pointLight.radius = 3.0
|
||||||
|
|
||||||
|
-- Setup orbital camera
|
||||||
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture
|
||||||
|
|
||||||
|
DrawLight(spotLight) -- Draw spot light
|
||||||
|
DrawLight(dirLight) -- Draw directional light
|
||||||
|
DrawLight(pointLight) -- Draw point light
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadMaterial(material) -- Unload material and assigned textures
|
||||||
|
UnloadModel(dwarf) -- Unload model
|
||||||
|
|
||||||
|
-- Destroy all created lights
|
||||||
|
DestroyLight(pointLight)
|
||||||
|
DestroyLight(dirLight)
|
||||||
|
DestroyLight(spotLight)
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
64
examples/shapes_basic_shapes.lua
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...)
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing")
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update your variables here
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY)
|
||||||
|
|
||||||
|
DrawLine(18, 42, screenWidth - 18, 42, BLACK)
|
||||||
|
|
||||||
|
DrawCircle(screenWidth/4, 120, 35, DARKBLUE)
|
||||||
|
DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE)
|
||||||
|
DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE)
|
||||||
|
|
||||||
|
DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED)
|
||||||
|
DrawRectangleGradient(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD)
|
||||||
|
DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE)
|
||||||
|
|
||||||
|
DrawTriangle(Vector2(screenWidth/4*3, 80),
|
||||||
|
Vector2(screenWidth/4*3 - 60, 150),
|
||||||
|
Vector2(screenWidth/4*3 + 60, 150), VIOLET)
|
||||||
|
|
||||||
|
DrawTriangleLines(Vector2(screenWidth/4*3, 160),
|
||||||
|
Vector2(screenWidth/4*3 - 20, 230),
|
||||||
|
Vector2(screenWidth/4*3 + 20, 230), DARKBLUE)
|
||||||
|
|
||||||
|
DrawPoly(Vector2(screenWidth/4*3, 320), 6, 80, 0, BROWN)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
89
examples/shapes_colors_palette.lua
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shapes] example - Draw raylib custom color palette
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette")
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update your variables here
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("raylib color palette", 28, 42, 20, BLACK)
|
||||||
|
|
||||||
|
DrawRectangle(26, 80, 100, 100, DARKGRAY)
|
||||||
|
DrawRectangle(26, 188, 100, 100, GRAY)
|
||||||
|
DrawRectangle(26, 296, 100, 100, LIGHTGRAY)
|
||||||
|
DrawRectangle(134, 80, 100, 100, MAROON)
|
||||||
|
DrawRectangle(134, 188, 100, 100, RED)
|
||||||
|
DrawRectangle(134, 296, 100, 100, PINK)
|
||||||
|
DrawRectangle(242, 80, 100, 100, ORANGE)
|
||||||
|
DrawRectangle(242, 188, 100, 100, GOLD)
|
||||||
|
DrawRectangle(242, 296, 100, 100, YELLOW)
|
||||||
|
DrawRectangle(350, 80, 100, 100, DARKGREEN)
|
||||||
|
DrawRectangle(350, 188, 100, 100, LIME)
|
||||||
|
DrawRectangle(350, 296, 100, 100, GREEN)
|
||||||
|
DrawRectangle(458, 80, 100, 100, DARKBLUE)
|
||||||
|
DrawRectangle(458, 188, 100, 100, BLUE)
|
||||||
|
DrawRectangle(458, 296, 100, 100, SKYBLUE)
|
||||||
|
DrawRectangle(566, 80, 100, 100, DARKPURPLE)
|
||||||
|
DrawRectangle(566, 188, 100, 100, VIOLET)
|
||||||
|
DrawRectangle(566, 296, 100, 100, PURPLE)
|
||||||
|
DrawRectangle(674, 80, 100, 100, DARKBROWN)
|
||||||
|
DrawRectangle(674, 188, 100, 100, BROWN)
|
||||||
|
DrawRectangle(674, 296, 100, 100, BEIGE)
|
||||||
|
|
||||||
|
|
||||||
|
DrawText("DARKGRAY", 65, 166, 10, BLACK)
|
||||||
|
DrawText("GRAY", 93, 274, 10, BLACK)
|
||||||
|
DrawText("LIGHTGRAY", 61, 382, 10, BLACK)
|
||||||
|
DrawText("MAROON", 186, 166, 10, BLACK)
|
||||||
|
DrawText("RED", 208, 274, 10, BLACK)
|
||||||
|
DrawText("PINK", 204, 382, 10, BLACK)
|
||||||
|
DrawText("ORANGE", 295, 166, 10, BLACK)
|
||||||
|
DrawText("GOLD", 310, 274, 10, BLACK)
|
||||||
|
DrawText("YELLOW", 300, 382, 10, BLACK)
|
||||||
|
DrawText("DARKGREEN", 382, 166, 10, BLACK)
|
||||||
|
DrawText("LIME", 420, 274, 10, BLACK)
|
||||||
|
DrawText("GREEN", 410, 382, 10, BLACK)
|
||||||
|
DrawText("DARKBLUE", 498, 166, 10, BLACK)
|
||||||
|
DrawText("BLUE", 526, 274, 10, BLACK)
|
||||||
|
DrawText("SKYBLUE", 505, 382, 10, BLACK)
|
||||||
|
DrawText("DARKPURPLE", 592, 166, 10, BLACK)
|
||||||
|
DrawText("VIOLET", 621, 274, 10, BLACK)
|
||||||
|
DrawText("PURPLE", 620, 382, 10, BLACK)
|
||||||
|
DrawText("DARKBROWN", 705, 166, 10, BLACK)
|
||||||
|
DrawText("BROWN", 733, 274, 10, BLACK)
|
||||||
|
DrawText("BEIGE", 737, 382, 10, BLACK)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
48
examples/shapes_logo_raylib.lua
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shapes] example - Draw raylib logo using basic shapes
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes")
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update your variables here
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawRectangle(screenWidth/2 - 128, screenHeight/2 - 128, 256, 256, BLACK)
|
||||||
|
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, RAYWHITE)
|
||||||
|
DrawText("raylib", screenWidth/2 - 44, screenHeight/2 + 48, 50, BLACK)
|
||||||
|
|
||||||
|
DrawText("this is NOT a texture!", 350, 370, 10, GRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
127
examples/shapes_logo_raylib_anim.lua
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [shapes] example - raylib logo animation
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation")
|
||||||
|
|
||||||
|
local logoPositionX = screenWidth/2 - 128
|
||||||
|
local logoPositionY = screenHeight/2 - 128
|
||||||
|
|
||||||
|
local framesCounter = 0
|
||||||
|
local lettersCount = 0
|
||||||
|
|
||||||
|
local topSideRecWidth = 16
|
||||||
|
local leftSideRecHeight = 16
|
||||||
|
|
||||||
|
local bottomSideRecWidth = 16
|
||||||
|
local rightSideRecHeight = 16
|
||||||
|
|
||||||
|
local state = 0 -- Tracking animation states (State Machine)
|
||||||
|
local alpha = 1.0 -- Useful for fading
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
if (state == 0) then -- State 0: Small box blinking
|
||||||
|
framesCounter = framesCounter + 1
|
||||||
|
|
||||||
|
if (framesCounter == 120) then
|
||||||
|
state = 1
|
||||||
|
framesCounter = 0 -- Reset counter... will be used later...
|
||||||
|
end
|
||||||
|
elseif (state == 1) then -- State 1: Top and left bars growing
|
||||||
|
topSideRecWidth = topSideRecWidth + 4
|
||||||
|
leftSideRecHeight = leftSideRecHeight + 4
|
||||||
|
|
||||||
|
if (topSideRecWidth == 256) then state = 2 end
|
||||||
|
elseif (state == 2) then -- State 2: Bottom and right bars growing
|
||||||
|
bottomSideRecWidth = bottomSideRecWidth + 4
|
||||||
|
rightSideRecHeight = rightSideRecHeight + 4
|
||||||
|
|
||||||
|
if (bottomSideRecWidth == 256) then state = 3 end
|
||||||
|
elseif (state == 3) then -- State 3: Letters appearing (one by one)
|
||||||
|
framesCounter = framesCounter + 1
|
||||||
|
|
||||||
|
if (framesCounter//12 == 1) then -- Every 12 frames, one more letter!
|
||||||
|
lettersCount = lettersCount + 1
|
||||||
|
framesCounter = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if (lettersCount >= 10) then -- When all letters have appeared, just fade out everything
|
||||||
|
alpha = alpha - 0.02
|
||||||
|
|
||||||
|
if (alpha <= 0.0) then
|
||||||
|
alpha = 0.0
|
||||||
|
state = 4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif (state == 4) then -- State 4: Reset and Replay
|
||||||
|
if (IsKeyPressed(KEY.R)) then
|
||||||
|
framesCounter = 0
|
||||||
|
lettersCount = 0
|
||||||
|
|
||||||
|
topSideRecWidth = 16
|
||||||
|
leftSideRecHeight = 16
|
||||||
|
|
||||||
|
bottomSideRecWidth = 16
|
||||||
|
rightSideRecHeight = 16
|
||||||
|
|
||||||
|
alpha = 1.0
|
||||||
|
state = 0 -- Return to State 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
if (state == 0) then
|
||||||
|
if ((framesCounter//15)%2 == 1) then DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK) end
|
||||||
|
elseif (state == 1) then
|
||||||
|
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK)
|
||||||
|
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK)
|
||||||
|
elseif (state == 2) then
|
||||||
|
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK)
|
||||||
|
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK)
|
||||||
|
|
||||||
|
DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK)
|
||||||
|
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK)
|
||||||
|
elseif (state == 3) then
|
||||||
|
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha))
|
||||||
|
DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha))
|
||||||
|
|
||||||
|
DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha))
|
||||||
|
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha))
|
||||||
|
|
||||||
|
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha))
|
||||||
|
|
||||||
|
DrawText(string.sub("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha))
|
||||||
|
elseif (state == 4) then DrawText("[R] REPLAY", 340, 200, 20, GRAY) end
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
59
examples/text_bmfont_ttf.lua
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [text] example - BMFont and TTF SpriteFonts loading
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading")
|
||||||
|
|
||||||
|
local msgBm = "THIS IS AN AngelCode SPRITE FONT"
|
||||||
|
local msgTtf = "THIS FONT has been GENERATED from TTF"
|
||||||
|
|
||||||
|
-- NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
|
local fontBm = LoadSpriteFont("resources/fonts/bmfont.fnt") -- BMFont (AngelCode)
|
||||||
|
local fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf") -- TTF font
|
||||||
|
|
||||||
|
local fontPosition = Vector2(0, 0)
|
||||||
|
fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2
|
||||||
|
fontPosition.y = screenHeight/2 - fontBm.size/2 - 80
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update variables here...
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON)
|
||||||
|
DrawTextEx(fontTtf, msgTtf, Vector2(60.0, 240.0), fontTtf.size, 2, LIME)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadSpriteFont(fontBm) -- AngelCode SpriteFont unloading
|
||||||
|
UnloadSpriteFont(fontTtf) -- TTF SpriteFont unloading
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
65
examples/text_bmfont_unordered.c
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [text] example - BMFont unordered chars loading and drawing
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.4 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing");
|
||||||
|
|
||||||
|
// NOTE: Using chars outside the [32..127] limits!
|
||||||
|
// NOTE: If a character is not found in the font, it just renders a space
|
||||||
|
const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
|
||||||
|
|
||||||
|
// NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
|
||||||
|
SpriteFont font = LoadSpriteFont("resources/fonts/pixantiqua.fnt"); // BMFont (AngelCode)
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// TODO: Update variables here...
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY);
|
||||||
|
DrawText(FormatText("Font base size: %i", font.size), 40, 80, 20, GRAY);
|
||||||
|
DrawText(FormatText("Font chars number: %i", font.numChars), 40, 110, 20, GRAY);
|
||||||
|
|
||||||
|
DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.size, 0, MAROON);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadSpriteFont(font); // AngelCode SpriteFont unloading
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
57
examples/text_bmfont_unordered.lua
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [text] example - BMFont unordered chars loading and drawing
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing")
|
||||||
|
|
||||||
|
-- NOTE: Using chars outside the [32..127] limits!
|
||||||
|
-- NOTE: If a character is not found in the font, it just renders a space
|
||||||
|
local msg = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
|
||||||
|
|
||||||
|
-- NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
|
||||||
|
local font = LoadSpriteFont("resources/fonts/pixantiqua.fnt") -- BMFont (AngelCode)
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update variables here...
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY)
|
||||||
|
DrawText(string.format("Font base size: %i", font.size), 40, 80, 20, GRAY)
|
||||||
|
DrawText(string.format("Font chars number: %i", font.numChars), 40, 110, 20, GRAY)
|
||||||
|
|
||||||
|
DrawTextEx(font, msg, Vector2(40, 180), font.size, 0, MAROON)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadSpriteFont(font) -- AngelCode SpriteFont unloading
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
BIN
examples/text_bmfont_unordered.png
Normal file
After Width: | Height: | Size: 18 KiB |
143
examples/text_font_select.lua
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [text] example - Font selector
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - font selector")
|
||||||
|
|
||||||
|
-- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
|
local fonts = {} -- SpriteFont array
|
||||||
|
|
||||||
|
fonts[1] = LoadSpriteFont("resources/fonts/alagard.rbmf") -- SpriteFont loading
|
||||||
|
fonts[2] = LoadSpriteFont("resources/fonts/pixelplay.rbmf") -- SpriteFont loading
|
||||||
|
fonts[3] = LoadSpriteFont("resources/fonts/mecha.rbmf") -- SpriteFont loading
|
||||||
|
fonts[4] = LoadSpriteFont("resources/fonts/setback.rbmf") -- SpriteFont loading
|
||||||
|
fonts[5] = LoadSpriteFont("resources/fonts/romulus.rbmf") -- SpriteFont loading
|
||||||
|
fonts[6] = LoadSpriteFont("resources/fonts/pixantiqua.rbmf") -- SpriteFont loading
|
||||||
|
fonts[7] = LoadSpriteFont("resources/fonts/alpha_beta.rbmf") -- SpriteFont loading
|
||||||
|
fonts[8] = LoadSpriteFont("resources/fonts/jupiter_crash.rbmf") -- SpriteFont loading
|
||||||
|
|
||||||
|
local currentFont = 1 -- Selected font
|
||||||
|
|
||||||
|
local colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED }
|
||||||
|
|
||||||
|
local fontNames = { "[1] Alagard", "[2] PixelPlay", "[3] MECHA", "[4] Setback",
|
||||||
|
"[5] Romulus", "[6] PixAntiqua", "[7] Alpha Beta", "[8] Jupiter Crash" }
|
||||||
|
|
||||||
|
local text = "THIS is THE FONT you SELECTED!" -- Main text
|
||||||
|
|
||||||
|
local textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1)
|
||||||
|
|
||||||
|
local mousePoint
|
||||||
|
|
||||||
|
local btnNextOutColor = DARKBLUE -- Button color (outside line)
|
||||||
|
local btnNextInColor = SKYBLUE -- Button color (inside)
|
||||||
|
|
||||||
|
local framesCounter = 0 -- Useful to count frames button is 'active' = clicked
|
||||||
|
|
||||||
|
local positionY = 180 -- Text selector and button Y position
|
||||||
|
|
||||||
|
local btnNextRec = Rectangle(673, positionY, 109, 44) -- Button rectangle (useful for collision)
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Keyboard-based font selection (easy)
|
||||||
|
if (IsKeyPressed(KEY.RIGHT)) then
|
||||||
|
if (currentFont < 8) then currentFont = currentFont + 1 end
|
||||||
|
end
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY.LEFT)) then
|
||||||
|
if (currentFont > 1) then currentFont = currentFont - 1 end
|
||||||
|
end
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY.ZERO)) then currentFont = 0
|
||||||
|
elseif (IsKeyPressed(KEY.ONE)) then currentFont = 1
|
||||||
|
elseif (IsKeyPressed(KEY.TWO)) then currentFont = 2
|
||||||
|
elseif (IsKeyPressed(KEY.THREE)) then currentFont = 3
|
||||||
|
elseif (IsKeyPressed(KEY.FOUR)) then currentFont = 4
|
||||||
|
elseif (IsKeyPressed(KEY.FIVE)) then currentFont = 5
|
||||||
|
elseif (IsKeyPressed(KEY.SIX)) then currentFont = 6
|
||||||
|
elseif (IsKeyPressed(KEY.SEVEN)) then currentFont = 7
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Mouse-based font selection (NEXT button logic)
|
||||||
|
mousePoint = GetMousePosition()
|
||||||
|
|
||||||
|
if (CheckCollisionPointRec(mousePoint, btnNextRec)) then
|
||||||
|
-- Mouse hover button logic
|
||||||
|
if (framesCounter == 0) then
|
||||||
|
btnNextOutColor = DARKPURPLE
|
||||||
|
btnNextInColor = PURPLE
|
||||||
|
end
|
||||||
|
|
||||||
|
if (IsMouseButtonDown(MOUSE.LEFT_BUTTON)) then
|
||||||
|
framesCounter = 20 -- Frames button is 'active'
|
||||||
|
btnNextOutColor = MAROON
|
||||||
|
btnNextInColor = RED
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Mouse not hover button
|
||||||
|
btnNextOutColor = DARKBLUE
|
||||||
|
btnNextInColor = SKYBLUE
|
||||||
|
end
|
||||||
|
|
||||||
|
if (framesCounter > 0) then framesCounter = framesCounter - 1 end
|
||||||
|
|
||||||
|
if (framesCounter == 1) then -- We change font on frame 1
|
||||||
|
currentFont = currentFont + 1
|
||||||
|
if (currentFont > 7) then currentFont = 0 end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Text measurement for better positioning on screen
|
||||||
|
textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1)
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("font selector - use arroys, button or numbers", 160, 80, 20, DARKGRAY)
|
||||||
|
DrawLine(120, 120, 680, 120, DARKGRAY)
|
||||||
|
|
||||||
|
DrawRectangle(18, positionY, 644, 44, DARKGRAY)
|
||||||
|
DrawRectangle(20, positionY + 2, 640, 40, LIGHTGRAY)
|
||||||
|
DrawText(fontNames[currentFont], 30, positionY + 13, 20, BLACK)
|
||||||
|
DrawText("< >", 610, positionY + 8, 30, BLACK)
|
||||||
|
|
||||||
|
DrawRectangleRec(btnNextRec, btnNextOutColor)
|
||||||
|
DrawRectangle(675, positionY + 2, 105, 40, btnNextInColor)
|
||||||
|
DrawText("NEXT", 700, positionY + 13, 20, btnNextOutColor)
|
||||||
|
|
||||||
|
DrawTextEx(fonts[currentFont], text, Vector2(screenWidth/2 - textSize.x/2,
|
||||||
|
260 + (70 - textSize.y)/2), fonts[currentFont].size*3,
|
||||||
|
1, colors[currentFont])
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
for i = 1, 8 do UnloadSpriteFont(fonts[i]) end -- SpriteFont(s) unloading
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|