You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

854 lines
50 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib 1.4.0 (www.raylib.com)
  4. *
  5. * A simple and easy-to-use library to learn videogames programming
  6. *
  7. * Features:
  8. * Library written in plain C code (C99)
  9. * Uses C# PascalCase/camelCase notation
  10. * Hardware accelerated with OpenGL (1.1, 3.3 or ES2)
  11. * Unique OpenGL abstraction layer [rlgl]
  12. * Powerful fonts module with SpriteFonts support (including AngelCode fonts and TTF)
  13. * Multiple textures support, including compressed formats and mipmaps generation
  14. * Basic 3d support for Shapes, Models, Heightmaps and Billboards
  15. * Powerful math module for Vector and Matrix operations [raymath]
  16. * Audio loading and playing with streaming support (WAV and OGG)
  17. * Multiplatform support, including Android devices, Raspberry Pi and HTML5
  18. *
  19. * Used external libs:
  20. * GLFW3 (www.glfw.org) for window/context management and input
  21. * GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP)
  22. * stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC)
  23. * stb_image_write (Sean Barret) for image writting (PNG)
  24. * stb_vorbis (Sean Barret) for ogg audio loading
  25. * stb_truetype (Sean Barret) for ttf fonts loading
  26. * OpenAL Soft for audio device/context management
  27. * tinfl for data decompression (DEFLATE algorithm)
  28. *
  29. * Some design decisions:
  30. * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte)
  31. * One custom default font is loaded automatically when InitWindow()
  32. * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads
  33. * If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined)
  34. *
  35. * -- LICENSE --
  36. *
  37. * raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  38. * BSD-like license that allows static linking with closed source software:
  39. *
  40. * Copyright (c) 2013 Ramon Santamaria (@raysan5)
  41. *
  42. * This software is provided "as-is", without any express or implied warranty. In no event
  43. * will the authors be held liable for any damages arising from the use of this software.
  44. *
  45. * Permission is granted to anyone to use this software for any purpose, including commercial
  46. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  47. *
  48. * 1. The origin of this software must not be misrepresented; you must not claim that you
  49. * wrote the original software. If you use this software in a product, an acknowledgment
  50. * in the product documentation would be appreciated but is not required.
  51. *
  52. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  53. * as being the original software.
  54. *
  55. * 3. This notice may not be removed or altered from any source distribution.
  56. *
  57. **********************************************************************************************/
  58. #ifndef RAYLIB_H
  59. #define RAYLIB_H
  60. // Choose your platform here or just define it at compile time: -DPLATFORM_DESKTOP
  61. //#define PLATFORM_DESKTOP // Windows, Linux or OSX
  62. //#define PLATFORM_ANDROID // Android device
  63. //#define PLATFORM_RPI // Raspberry Pi
  64. //#define PLATFORM_WEB // HTML5 (emscripten, asm.js)
  65. // Security check in case no PLATFORM_* defined
  66. #if !defined(PLATFORM_DESKTOP) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_RPI) && !defined(PLATFORM_WEB)
  67. #define PLATFORM_DESKTOP
  68. #endif
  69. #if defined(PLATFORM_ANDROID)
  70. typedef struct android_app; // Define android_app struct (android_native_app_glue.h)
  71. #endif
  72. //----------------------------------------------------------------------------------
  73. // Some basic Defines
  74. //----------------------------------------------------------------------------------
  75. #ifndef PI
  76. #define PI 3.14159265358979323846
  77. #endif
  78. #define DEG2RAD (PI/180.0f)
  79. #define RAD2DEG (180.0f/PI)
  80. // raylib Config Flags
  81. #define FLAG_FULLSCREEN_MODE 1
  82. #define FLAG_SHOW_LOGO 2
  83. #define FLAG_SHOW_MOUSE_CURSOR 4
  84. #define FLAG_CENTERED_MODE 8
  85. #define FLAG_MSAA_4X_HINT 16
  86. #define FLAG_VSYNC_HINT 32
  87. // Keyboard Function Keys
  88. #define KEY_SPACE 32
  89. #define KEY_ESCAPE 256
  90. #define KEY_ENTER 257
  91. #define KEY_BACKSPACE 259
  92. #define KEY_RIGHT 262
  93. #define KEY_LEFT 263
  94. #define KEY_DOWN 264
  95. #define KEY_UP 265
  96. #define KEY_F1 290
  97. #define KEY_F2 291
  98. #define KEY_F3 292
  99. #define KEY_F4 293
  100. #define KEY_F5 294
  101. #define KEY_F6 295
  102. #define KEY_F7 296
  103. #define KEY_F8 297
  104. #define KEY_F9 298
  105. #define KEY_F10 299
  106. #define KEY_F11 300
  107. #define KEY_F12 301
  108. #define KEY_LEFT_SHIFT 340
  109. #define KEY_LEFT_CONTROL 341
  110. #define KEY_LEFT_ALT 342
  111. #define KEY_RIGHT_SHIFT 344
  112. #define KEY_RIGHT_CONTROL 345
  113. #define KEY_RIGHT_ALT 346
  114. // Keyboard Alpha Numeric Keys
  115. #define KEY_ZERO 48
  116. #define KEY_ONE 49
  117. #define KEY_TWO 50
  118. #define KEY_THREE 51
  119. #define KEY_FOUR 52
  120. #define KEY_FIVE 53
  121. #define KEY_SIX 54
  122. #define KEY_SEVEN 55
  123. #define KEY_EIGHT 56
  124. #define KEY_NINE 57
  125. #define KEY_A 65
  126. #define KEY_B 66
  127. #define KEY_C 67
  128. #define KEY_D 68
  129. #define KEY_E 69
  130. #define KEY_F 70
  131. #define KEY_G 71
  132. #define KEY_H 72
  133. #define KEY_I 73
  134. #define KEY_J 74
  135. #define KEY_K 75
  136. #define KEY_L 76
  137. #define KEY_M 77
  138. #define KEY_N 78
  139. #define KEY_O 79
  140. #define KEY_P 80
  141. #define KEY_Q 81
  142. #define KEY_R 82
  143. #define KEY_S 83
  144. #define KEY_T 84
  145. #define KEY_U 85
  146. #define KEY_V 86
  147. #define KEY_W 87
  148. #define KEY_X 88
  149. #define KEY_Y 89
  150. #define KEY_Z 90
  151. // Mouse Buttons
  152. #define MOUSE_LEFT_BUTTON 0
  153. #if defined(PLATFORM_WEB)
  154. #define MOUSE_RIGHT_BUTTON 2
  155. #define MOUSE_MIDDLE_BUTTON 1
  156. #else
  157. #define MOUSE_RIGHT_BUTTON 1
  158. #define MOUSE_MIDDLE_BUTTON 2
  159. #endif
  160. // Touch points registered
  161. #define MAX_TOUCH_POINTS 2
  162. // Gamepad Number
  163. #define GAMEPAD_PLAYER1 0
  164. #define GAMEPAD_PLAYER2 1
  165. #define GAMEPAD_PLAYER3 2
  166. #define GAMEPAD_PLAYER4 3
  167. // Gamepad Buttons
  168. // NOTE: Adjusted for a PS3 USB Controller
  169. #define GAMEPAD_BUTTON_A 2
  170. #define GAMEPAD_BUTTON_B 1
  171. #define GAMEPAD_BUTTON_X 3
  172. #define GAMEPAD_BUTTON_Y 4
  173. #define GAMEPAD_BUTTON_R1 7
  174. #define GAMEPAD_BUTTON_R2 5
  175. #define GAMEPAD_BUTTON_L1 6
  176. #define GAMEPAD_BUTTON_L2 8
  177. #define GAMEPAD_BUTTON_SELECT 9
  178. #define GAMEPAD_BUTTON_START 10
  179. // TODO: Review Xbox360 USB Controller Buttons
  180. // Android Physic Buttons
  181. #define ANDROID_BACK 4
  182. #define ANDROID_MENU 82
  183. #define ANDROID_VOLUME_UP 24
  184. #define ANDROID_VOLUME_DOWN 25
  185. // Some Basic Colors
  186. // NOTE: Custom raylib color palette for amazing visuals on WHITE background
  187. #define LIGHTGRAY (Color){ 200, 200, 200, 255 } // Light Gray
  188. #define GRAY (Color){ 130, 130, 130, 255 } // Gray
  189. #define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray
  190. #define YELLOW (Color){ 253, 249, 0, 255 } // Yellow
  191. #define GOLD (Color){ 255, 203, 0, 255 } // Gold
  192. #define ORANGE (Color){ 255, 161, 0, 255 } // Orange
  193. #define PINK (Color){ 255, 109, 194, 255 } // Pink
  194. #define RED (Color){ 230, 41, 55, 255 } // Red
  195. #define MAROON (Color){ 190, 33, 55, 255 } // Maroon
  196. #define GREEN (Color){ 0, 228, 48, 255 } // Green
  197. #define LIME (Color){ 0, 158, 47, 255 } // Lime
  198. #define DARKGREEN (Color){ 0, 117, 44, 255 } // Dark Green
  199. #define SKYBLUE (Color){ 102, 191, 255, 255 } // Sky Blue
  200. #define BLUE (Color){ 0, 121, 241, 255 } // Blue
  201. #define DARKBLUE (Color){ 0, 82, 172, 255 } // Dark Blue
  202. #define PURPLE (Color){ 200, 122, 255, 255 } // Purple
  203. #define VIOLET (Color){ 135, 60, 190, 255 } // Violet
  204. #define DARKPURPLE (Color){ 112, 31, 126, 255 } // Dark Purple
  205. #define BEIGE (Color){ 211, 176, 131, 255 } // Beige
  206. #define BROWN (Color){ 127, 106, 79, 255 } // Brown
  207. #define DARKBROWN (Color){ 76, 63, 47, 255 } // Dark Brown
  208. #define WHITE (Color){ 255, 255, 255, 255 } // White
  209. #define BLACK (Color){ 0, 0, 0, 255 } // Black
  210. #define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent)
  211. #define MAGENTA (Color){ 255, 0, 255, 255 } // Magenta
  212. #define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo)
  213. //----------------------------------------------------------------------------------
  214. // Types and Structures Definition
  215. //----------------------------------------------------------------------------------
  216. #ifndef __cplusplus
  217. // Boolean type
  218. typedef enum { false, true } bool;
  219. #endif
  220. // byte type
  221. typedef unsigned char byte;
  222. // Vector2 type
  223. typedef struct Vector2 {
  224. float x;
  225. float y;
  226. } Vector2;
  227. // Vector3 type
  228. typedef struct Vector3 {
  229. float x;
  230. float y;
  231. float z;
  232. } Vector3;
  233. // Matrix type (OpenGL style 4x4 - right handed, column major)
  234. typedef struct Matrix {
  235. float m0, m4, m8, m12;
  236. float m1, m5, m9, m13;
  237. float m2, m6, m10, m14;
  238. float m3, m7, m11, m15;
  239. } Matrix;
  240. // Color type, RGBA (32bit)
  241. typedef struct Color {
  242. unsigned char r;
  243. unsigned char g;
  244. unsigned char b;
  245. unsigned char a;
  246. } Color;
  247. // Rectangle type
  248. typedef struct Rectangle {
  249. int x;
  250. int y;
  251. int width;
  252. int height;
  253. } Rectangle;
  254. // Image type, bpp always RGBA (32bit)
  255. // NOTE: Data stored in CPU memory (RAM)
  256. typedef struct Image {
  257. void *data; // Image raw data
  258. int width; // Image base width
  259. int height; // Image base height
  260. int mipmaps; // Mipmap levels, 1 by default
  261. int format; // Data format (TextureFormat)
  262. } Image;
  263. // Texture2D type, bpp always RGBA (32bit)
  264. // NOTE: Data stored in GPU memory
  265. typedef struct Texture2D {
  266. unsigned int id; // OpenGL texture id
  267. int width; // Texture base width
  268. int height; // Texture base height
  269. int mipmaps; // Mipmap levels, 1 by default
  270. int format; // Data format (TextureFormat)
  271. } Texture2D;
  272. // SpriteFont type, includes texture and charSet array data
  273. typedef struct SpriteFont {
  274. Texture2D texture; // Font texture
  275. int size; // Base size (default chars height)
  276. int numChars; // Number of characters
  277. int *charValues; // Characters values array
  278. Rectangle *charRecs; // Characters rectangles within the texture
  279. Vector2 *charOffsets; // Characters offsets (on drawing)
  280. int *charAdvanceX; // Characters x advance (on drawing)
  281. } SpriteFont;
  282. // Camera type, defines a camera position/orientation in 3d space
  283. typedef struct Camera {
  284. Vector3 position;
  285. Vector3 target;
  286. Vector3 up;
  287. } Camera;
  288. // Bounding box type
  289. typedef struct BoundingBox {
  290. Vector3 min;
  291. Vector3 max;
  292. } BoundingBox;
  293. // Vertex data definning a mesh
  294. typedef struct Mesh {
  295. int vertexCount; // num vertices
  296. float *vertices; // vertex position (XYZ - 3 components per vertex)
  297. float *texcoords; // vertex texture coordinates (UV - 2 components per vertex)
  298. float *texcoords2; // vertex second texture coordinates (useful for lightmaps)
  299. float *normals; // vertex normals (XYZ - 3 components per vertex)
  300. float *tangents; // vertex tangents (XYZ - 3 components per vertex)
  301. unsigned char *colors; // vertex colors (RGBA - 4 components per vertex)
  302. BoundingBox bounds; // mesh limits defined by min and max points
  303. unsigned int vaoId; // OpenGL Vertex Array Object id
  304. unsigned int vboId[6]; // OpenGL Vertex Buffer Objects id (6 types of vertex data)
  305. } Mesh;
  306. // Shader type (generic shader)
  307. typedef struct Shader {
  308. unsigned int id; // Shader program id
  309. // TODO: This should be Texture2D objects
  310. unsigned int texDiffuseId; // Diffuse texture id
  311. unsigned int texNormalId; // Normal texture id
  312. unsigned int texSpecularId; // Specular texture id
  313. // Variable attributes
  314. int vertexLoc; // Vertex attribute location point (vertex shader)
  315. int texcoordLoc; // Texcoord attribute location point (vertex shader)
  316. int normalLoc; // Normal attribute location point (vertex shader)
  317. int colorLoc; // Color attibute location point (vertex shader)
  318. // Uniforms
  319. int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
  320. int tintColorLoc; // Color uniform location point (fragment shader)
  321. int mapDiffuseLoc; // Diffuse map texture uniform location point (fragment shader)
  322. int mapNormalLoc; // Normal map texture uniform location point (fragment shader)
  323. int mapSpecularLoc; // Specular map texture uniform location point (fragment shader)
  324. } Shader;
  325. // Material type
  326. // TODO: Redesign material-shaders-textures system
  327. typedef struct Material {
  328. //Shader shader;
  329. //Texture2D texDiffuse; // Diffuse texture
  330. //Texture2D texNormal; // Normal texture
  331. //Texture2D texSpecular; // Specular texture
  332. Color colDiffuse;
  333. Color colAmbient;
  334. Color colSpecular;
  335. float glossiness;
  336. float normalDepth;
  337. } Material;
  338. // 3d Model type
  339. // TODO: Replace shader/testure by material
  340. typedef struct Model {
  341. Mesh mesh;
  342. Matrix transform;
  343. Texture2D texture; // Only for OpenGL 1.1, on newer versions this should be in the shader
  344. Shader shader;
  345. //Material material;
  346. } Model;
  347. // Ray type (useful for raycast)
  348. typedef struct Ray {
  349. Vector3 position;
  350. Vector3 direction;
  351. } Ray;
  352. // Sound source type
  353. typedef struct Sound {
  354. unsigned int source;
  355. unsigned int buffer;
  356. } Sound;
  357. // Wave type, defines audio wave data
  358. typedef struct Wave {
  359. void *data; // Buffer data pointer
  360. unsigned int dataSize; // Data size in bytes
  361. unsigned int sampleRate;
  362. short bitsPerSample;
  363. short channels;
  364. } Wave;
  365. // Texture formats
  366. // NOTE: Support depends on OpenGL version and platform
  367. typedef enum {
  368. UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
  369. UNCOMPRESSED_GRAY_ALPHA, // 16 bpp (2 channels)
  370. UNCOMPRESSED_R5G6B5, // 16 bpp
  371. UNCOMPRESSED_R8G8B8, // 24 bpp
  372. UNCOMPRESSED_R5G5B5A1, // 16 bpp (1 bit alpha)
  373. UNCOMPRESSED_R4G4B4A4, // 16 bpp (4 bit alpha)
  374. UNCOMPRESSED_R8G8B8A8, // 32 bpp
  375. COMPRESSED_DXT1_RGB, // 4 bpp (no alpha)
  376. COMPRESSED_DXT1_RGBA, // 4 bpp (1 bit alpha)
  377. COMPRESSED_DXT3_RGBA, // 8 bpp
  378. COMPRESSED_DXT5_RGBA, // 8 bpp
  379. COMPRESSED_ETC1_RGB, // 4 bpp
  380. COMPRESSED_ETC2_RGB, // 4 bpp
  381. COMPRESSED_ETC2_EAC_RGBA, // 8 bpp
  382. COMPRESSED_PVRT_RGB, // 4 bpp
  383. COMPRESSED_PVRT_RGBA, // 4 bpp
  384. COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
  385. COMPRESSED_ASTC_8x8_RGBA // 2 bpp
  386. } TextureFormat;
  387. // Color blending modes (pre-defined)
  388. typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode;
  389. // Gestures type
  390. // NOTE: It could be used as flags to enable only some gestures
  391. typedef enum {
  392. GESTURE_NONE = 0,
  393. GESTURE_TAP = 1,
  394. GESTURE_DOUBLETAP = 2,
  395. GESTURE_HOLD = 4,
  396. GESTURE_DRAG = 8,
  397. GESTURE_SWIPE_RIGHT = 16,
  398. GESTURE_SWIPE_LEFT = 32,
  399. GESTURE_SWIPE_UP = 64,
  400. GESTURE_SWIPE_DOWN = 128,
  401. GESTURE_PINCH_IN = 256,
  402. GESTURE_PINCH_OUT = 512
  403. } Gestures;
  404. // Touch action (fingers or mouse)
  405. typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction;
  406. // Gesture events
  407. // NOTE: MAX_TOUCH_POINTS fixed to 2
  408. typedef struct {
  409. int touchAction;
  410. int pointCount;
  411. int pointerId[MAX_TOUCH_POINTS];
  412. Vector2 position[MAX_TOUCH_POINTS];
  413. } GestureEvent;
  414. // Camera system modes
  415. typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode;
  416. // Collider types
  417. typedef enum { COLLIDER_CIRCLE, COLLIDER_RECTANGLE, COLLIDER_CAPSULE } ColliderType;
  418. // Transform struct
  419. typedef struct Transform {
  420. Vector2 position;
  421. float rotation;
  422. Vector2 scale;
  423. } Transform;
  424. // Rigidbody struct
  425. typedef struct Rigidbody {
  426. bool enabled;
  427. float mass;
  428. Vector2 acceleration;
  429. Vector2 velocity;
  430. bool isGrounded;
  431. bool isContact; // Avoid freeze player when touching floor
  432. bool applyGravity;
  433. float friction; // 0.0f to 1.0f
  434. float bounciness; // 0.0f to 1.0f
  435. } Rigidbody;
  436. // Collider struct
  437. typedef struct Collider {
  438. bool enabled;
  439. ColliderType type;
  440. Rectangle bounds; // Used for COLLIDER_RECTANGLE and COLLIDER_CAPSULE
  441. int radius; // Used for COLLIDER_CIRCLE and COLLIDER_CAPSULE
  442. } Collider;
  443. #ifdef __cplusplus
  444. extern "C" { // Prevents name mangling of functions
  445. #endif
  446. //------------------------------------------------------------------------------------
  447. // Global Variables Definition
  448. //------------------------------------------------------------------------------------
  449. // It's lonely here...
  450. //------------------------------------------------------------------------------------
  451. // Window and Graphics Device Functions (Module: core)
  452. //------------------------------------------------------------------------------------
  453. #if defined(PLATFORM_ANDROID)
  454. void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics
  455. #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
  456. void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics
  457. #endif
  458. void CloseWindow(void); // Close Window and Terminate Context
  459. bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed
  460. bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus)
  461. void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP)
  462. #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
  463. void SetCustomCursor(const char *cursorImage); // Set a custom cursor icon/image
  464. void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
  465. #endif
  466. int GetScreenWidth(void); // Get current screen width
  467. int GetScreenHeight(void); // Get current screen height
  468. void ClearBackground(Color color); // Sets Background Color
  469. void BeginDrawing(void); // Setup drawing canvas to start drawing
  470. void BeginDrawingEx(int blendMode, Shader shader, Matrix transform); // Setup drawing canvas with extended parameters
  471. void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering)
  472. void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup)
  473. void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode
  474. Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position
  475. Vector2 WorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position
  476. Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix)
  477. void SetTargetFPS(int fps); // Set target FPS (maximum)
  478. float GetFPS(void); // Returns current FPS
  479. float GetFrameTime(void); // Returns time in seconds for one frame
  480. Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value
  481. int GetHexValue(Color color); // Returns hexadecimal value for a Color
  482. float *ColorToFloat(Color color); // Converts Color to float array and normalizes
  483. float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array
  484. float *MatrixToFloat(Matrix mat); // Converts Matrix to float array
  485. int GetRandomValue(int min, int max); // Returns a random value between min and max (both included)
  486. Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
  487. void SetConfigFlags(char flags); // Setup some window configuration flags
  488. void ShowLogo(void); // Activates raylib logo at startup (can be done with flags)
  489. bool IsFileDropped(void); // Check if a file have been dropped into window
  490. char **GetDroppedFiles(int *count); // Retrieve dropped files into window
  491. void ClearDroppedFiles(void); // Clear dropped files paths buffer
  492. void StorageSaveValue(int position, int value); // Storage save integer value (to defined position)
  493. int StorageLoadValue(int position); // Storage load integer value (from defined position)
  494. //------------------------------------------------------------------------------------
  495. // Input Handling Functions (Module: core)
  496. //------------------------------------------------------------------------------------
  497. #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
  498. bool IsKeyPressed(int key); // Detect if a key has been pressed once
  499. bool IsKeyDown(int key); // Detect if a key is being pressed
  500. bool IsKeyReleased(int key); // Detect if a key has been released once
  501. bool IsKeyUp(int key); // Detect if a key is NOT being pressed
  502. int GetKeyPressed(void); // Get latest key pressed
  503. bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once
  504. bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed
  505. bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once
  506. bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed
  507. int GetMouseX(void); // Returns mouse position X
  508. int GetMouseY(void); // Returns mouse position Y
  509. Vector2 GetMousePosition(void); // Returns mouse position XY
  510. void SetMousePosition(Vector2 position); // Set mouse position XY
  511. int GetMouseWheelMove(void); // Returns mouse wheel movement Y
  512. void ShowCursor(void); // Shows cursor
  513. void HideCursor(void); // Hides cursor
  514. void EnableCursor(void); // Enables cursor
  515. void DisableCursor(void); // Disables cursor
  516. bool IsCursorHidden(void); // Returns true if cursor is not visible
  517. bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available
  518. Vector2 GetGamepadMovement(int gamepad); // Return axis movement vector for a gamepad
  519. bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once
  520. bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed
  521. bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once
  522. bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed
  523. #endif
  524. int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size)
  525. int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size)
  526. Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size)
  527. #if defined(PLATFORM_ANDROID)
  528. bool IsButtonPressed(int button); // Detect if an android physic button has been pressed
  529. bool IsButtonDown(int button); // Detect if an android physic button is being pressed
  530. bool IsButtonReleased(int button); // Detect if an android physic button has been released
  531. #endif
  532. //------------------------------------------------------------------------------------
  533. // Gestures and Touch Handling Functions (Module: gestures)
  534. //------------------------------------------------------------------------------------
  535. void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
  536. void UpdateGestures(void); // Update gestures detected (must be called every frame)
  537. bool IsGestureDetected(void); // Check if a gesture have been detected
  538. int GetGestureType(void); // Get latest detected gesture
  539. void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags
  540. int GetTouchPointsCount(void); // Get touch points count
  541. float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds
  542. Vector2 GetGestureDragVector(void); // Get gesture drag vector
  543. float GetGestureDragAngle(void); // Get gesture drag angle
  544. Vector2 GetGesturePinchVector(void); // Get gesture pinch delta
  545. float GetGesturePinchAngle(void); // Get gesture pinch angle
  546. //------------------------------------------------------------------------------------
  547. // Camera System Functions (Module: camera)
  548. //------------------------------------------------------------------------------------
  549. void SetCameraMode(int mode); // Set camera mode (multiple camera modes available)
  550. void UpdateCamera(Camera *camera); // Update camera (player position is ignored)
  551. void UpdateCameraPlayer(Camera *camera, Vector3 *position); // Update camera and player position (1st person and 3rd person cameras)
  552. void SetCameraPosition(Vector3 position); // Set internal camera position
  553. void SetCameraTarget(Vector3 target); // Set internal camera target
  554. void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera)
  555. void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera)
  556. void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera)
  557. void SetCameraMoveControls(int frontKey, int backKey,
  558. int leftKey, int rightKey,
  559. int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras)
  560. void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras)
  561. //------------------------------------------------------------------------------------
  562. // Basic Shapes Drawing Functions (Module: shapes)
  563. //------------------------------------------------------------------------------------
  564. void DrawPixel(int posX, int posY, Color color); // Draw a pixel
  565. void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version)
  566. void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line
  567. void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version)
  568. void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle
  569. void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle
  570. void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version)
  571. void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline
  572. void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle
  573. void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle
  574. void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle
  575. void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version)
  576. void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline
  577. void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle
  578. void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline
  579. void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version)
  580. void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points
  581. void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines
  582. bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles
  583. bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles
  584. bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle
  585. Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision
  586. bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle
  587. bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle
  588. bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle
  589. //------------------------------------------------------------------------------------
  590. // Texture Loading and Drawing Functions (Module: textures)
  591. //------------------------------------------------------------------------------------
  592. Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM)
  593. Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit)
  594. Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file
  595. Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource)
  596. Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory
  597. Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory
  598. Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource)
  599. Texture2D LoadTextureFromImage(Image image); // Load a texture from image data
  600. void UnloadImage(Image image); // Unload image from CPU memory (RAM)
  601. void UnloadTexture(Texture2D texture); // Unload texture from GPU memory
  602. Color *GetImageData(Image image); // Get pixel data from image as a Color struct array
  603. Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image
  604. void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two)
  605. void ImageFormat(Image *image, int newFormat); // Convert image data to desired format
  606. void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
  607. Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)
  608. void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle
  609. void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering)
  610. void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image
  611. Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font)
  612. Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint); // Create an image from text (custom sprite font)
  613. void ImageFlipVertical(Image *image); // Flip image vertically
  614. void ImageFlipHorizontal(Image *image); // Flip image horizontally
  615. void ImageColorTint(Image *image, Color color); // Modify image color: tint
  616. void ImageColorInvert(Image *image); // Modify image color: invert
  617. void ImageColorGrayscale(Image *image); // Modify bimage color: grayscale
  618. void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100)
  619. void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255)
  620. void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture
  621. void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data
  622. void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D
  623. void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2
  624. void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters
  625. void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle
  626. void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters
  627. float rotation, Color tint);
  628. //------------------------------------------------------------------------------------
  629. // Font Loading and Text Drawing Functions (Module: text)
  630. //------------------------------------------------------------------------------------
  631. SpriteFont GetDefaultFont(void); // Get the default SpriteFont
  632. SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory
  633. void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory
  634. void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
  635. void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters
  636. int fontSize, int spacing, Color tint);
  637. int MeasureText(const char *text, int fontSize); // Measure string width for default font
  638. Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont
  639. void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner
  640. const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
  641. const char *SubText(const char *text, int position, int length); // Get a piece of a text string
  642. //------------------------------------------------------------------------------------
  643. // Basic 3d Shapes Drawing Functions (Module: models)
  644. //------------------------------------------------------------------------------------
  645. void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube
  646. void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version)
  647. void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires
  648. void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float lenght, Color color); // Draw cube textured
  649. void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere
  650. void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters
  651. void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires
  652. void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone
  653. void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires
  654. void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ
  655. void DrawQuad(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Color color); // Draw a quad
  656. void DrawRay(Ray ray, Color color); // Draw a ray line
  657. void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0))
  658. void DrawGizmo(Vector3 position); // Draw simple gizmo
  659. //DrawTorus(), DrawTeapot() are useless...
  660. //------------------------------------------------------------------------------------
  661. // Model 3d Loading and Drawing Functions (Module: models)
  662. //------------------------------------------------------------------------------------
  663. Model LoadModel(const char *fileName); // Load a 3d model (.OBJ)
  664. Model LoadModelEx(Mesh data); // Load a 3d model (from vertex data)
  665. //Model LoadModelFromRES(const char *rresName, int resId); // TODO: Load a 3d model from rRES file (raylib Resource)
  666. Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model
  667. Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based)
  668. void UnloadModel(Model model); // Unload 3d model from memory
  669. void SetModelTexture(Model *model, Texture2D texture); // Link a texture to a model
  670. void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
  671. void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters
  672. void DrawModelWires(Model model, Vector3 position, float scale, Color color); // Draw a model wires (with texture if set)
  673. void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
  674. void DrawBoundingBox(BoundingBox box); // Draw bounding box (wires)
  675. void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture
  676. void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec
  677. BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits
  678. bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres
  679. bool CheckCollisionBoxes(Vector3 minBBox1, Vector3 maxBBox1, Vector3 minBBox2, Vector3 maxBBox2); // Detect collision between two boxes
  680. bool CheckCollisionBoxSphere(Vector3 minBBox, Vector3 maxBBox, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere
  681. bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere
  682. bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection
  683. bool CheckCollisionRayBox(Ray ray, Vector3 minBBox, Vector3 maxBBox); // Detect collision between ray and box
  684. Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap
  685. // NOTE: Return the normal vector of the impacted surface
  686. //------------------------------------------------------------------------------------
  687. // Shaders System Functions (Module: rlgl)
  688. // NOTE: This functions are useless when using OpenGL 1.1
  689. //------------------------------------------------------------------------------------
  690. Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
  691. unsigned int LoadShaderProgram(char *vShaderStr, char *fShaderStr); // Load custom shaders strings and return program id
  692. void UnloadShader(Shader shader); // Unload a custom shader from memory
  693. void SetPostproShader(Shader shader); // Set fullscreen postproduction shader
  694. void SetCustomShader(Shader shader); // Set custom shader to be used in batch draw
  695. void SetDefaultShader(void); // Set default shader to be used in batch draw
  696. void SetModelShader(Model *model, Shader shader); // Link a shader to a model
  697. bool IsPosproShaderEnabled(void); // Check if postprocessing shader is enabled
  698. int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
  699. void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float)
  700. void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
  701. void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
  702. void SetShaderMapDiffuse(Shader *shader, Texture2D texture); // Default diffuse shader map texture assignment
  703. void SetShaderMapNormal(Shader *shader, const char *uniformName, Texture2D texture); // Normal map texture shader assignment
  704. void SetShaderMapSpecular(Shader *shader, const char *uniformName, Texture2D texture); // Specular map texture shader assignment
  705. void SetShaderMap(Shader *shader, int mapLocation, Texture2D texture, int textureUnit); // TODO: Generic shader map assignment
  706. void SetBlendMode(int mode); // Set blending mode (alpha, additive, multiplied)
  707. //----------------------------------------------------------------------------------
  708. // Physics System Functions (engine-module: physac)
  709. //----------------------------------------------------------------------------------
  710. void InitPhysics(int maxPhysicElements); // Initialize all internal physics values
  711. void UnloadPhysics(); // Unload physic elements arrays
  712. void AddRigidbody(int index, Rigidbody rigidbody); // Initialize a new rigidbody with parameters to internal index slot
  713. void AddCollider(int index, Collider collider); // Initialize a new Collider with parameters to internal index slot
  714. void ApplyPhysics(int index, Vector2 *position); // Apply physics to internal rigidbody, physics calculations are applied to position pointer parameter
  715. void SetRigidbodyEnabled(int index, bool state); // Set enabled state to a defined rigidbody
  716. void SetRigidbodyVelocity(int index, Vector2 velocity); // Set velocity of rigidbody (without considering of mass value)
  717. void SetRigidbodyAcceleration(int index, Vector2 acceleration); // Set acceleration of rigidbody (without considering of mass value)
  718. void AddRigidbodyForce(int index, Vector2 force); // Set rigidbody force (considering mass value)
  719. void AddForceAtPosition(Vector2 position, float intensity, float radius); // Add a force to all enabled rigidbodies at a position
  720. void SetColliderEnabled(int index, bool state); // Set enabled state to a defined collider
  721. Rigidbody GetRigidbody(int index); // Returns the internal rigidbody data defined by index parameter
  722. Collider GetCollider(int index); // Returns the internal collider data defined by index parameter
  723. //------------------------------------------------------------------------------------
  724. // Audio Loading and Playing Functions (Module: audio)
  725. //------------------------------------------------------------------------------------
  726. void InitAudioDevice(void); // Initialize audio device and context
  727. void CloseAudioDevice(void); // Close the audio device and context (and music stream)
  728. Sound LoadSound(char *fileName); // Load sound to memory
  729. Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
  730. Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource)
  731. void UnloadSound(Sound sound); // Unload sound
  732. void PlaySound(Sound sound); // Play a sound
  733. void PauseSound(Sound sound); // Pause a sound
  734. void StopSound(Sound sound); // Stop playing a sound
  735. bool SoundIsPlaying(Sound sound); // Check if a sound is currently playing
  736. void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
  737. void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
  738. void PlayMusicStream(char *fileName); // Start music playing (open stream)
  739. void UpdateMusicStream(void); // Updates buffers for music streaming
  740. void StopMusicStream(void); // Stop music playing (close stream)
  741. void PauseMusicStream(void); // Pause music playing
  742. void ResumeMusicStream(void); // Resume playing paused music
  743. bool MusicIsPlaying(void); // Check if music is playing
  744. void SetMusicVolume(float volume); // Set volume for music (1.0 is max level)
  745. float GetMusicTimeLength(void); // Get current music time length (in seconds)
  746. float GetMusicTimePlayed(void); // Get current music time played (in seconds)
  747. #ifdef __cplusplus
  748. }
  749. #endif
  750. #endif // RAYLIB_H