Merge branch 'raysan5:master' into master

This commit is contained in:
Tushar Singh 2022-01-29 11:41:24 +05:30 committed by GitHub
commit 5c514b24b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 197 additions and 102 deletions

View File

@ -36,7 +36,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to
| raylib_odin_bindings | 4.0-dev | [Odin](https://odin-lang.org/) | MIT | https://github.com/Deathbat2190/raylib_odin_bindings | | raylib_odin_bindings | 4.0-dev | [Odin](https://odin-lang.org/) | MIT | https://github.com/Deathbat2190/raylib_odin_bindings |
| raylib-odin | **4.0** | [Odin](https://odin-lang.org/) | BSD-3Clause | https://github.com/odin-lang/Odin/tree/master/vendor/raylib | | raylib-odin | **4.0** | [Odin](https://odin-lang.org/) | BSD-3Clause | https://github.com/odin-lang/Odin/tree/master/vendor/raylib |
| raylib.v | **4.0** | [V](https://vlang.io/) | Zlib | https://github.com/irishgreencitrus/raylib.v | | raylib.v | **4.0** | [V](https://vlang.io/) | Zlib | https://github.com/irishgreencitrus/raylib.v |
| raylib-ocaml | 3.7 | [OCaml](https://ocaml.org/) | MIT | https://github.com/tjammer/raylib-ocaml | | raylib-ocaml | **4.0** | [OCaml](https://ocaml.org/) | MIT | https://github.com/tjammer/raylib-ocaml |
| raylib-swift | 3.7 | [Swift](https://swift.org/) | MIT | https://github.com/STREGAsGate/Raylib | | raylib-swift | 3.7 | [Swift](https://swift.org/) | MIT | https://github.com/STREGAsGate/Raylib |
| hb-raylib | 3.5 | [Harbour](https://harbour.github.io) | MIT | https://github.com/MarcosLeonardoMendezGerencir/hb-raylib | | hb-raylib | 3.5 | [Harbour](https://harbour.github.io) | MIT | https://github.com/MarcosLeonardoMendezGerencir/hb-raylib |
| Relib | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | ? | https://github.com/RedCubeDev-ByteSpace/Relib | | Relib | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | ? | https://github.com/RedCubeDev-ByteSpace/Relib |

View File

@ -117,13 +117,12 @@ endif
ifeq ($(PLATFORM),PLATFORM_WEB) ifeq ($(PLATFORM),PLATFORM_WEB)
# Emscripten required variables # Emscripten required variables
EMSDK_PATH ?= C:/emsdk EMSDK_PATH ?= C:/emsdk
EMSCRIPTEN_VERSION ?= 1.38.31 EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten
CLANG_VERSION = e$(EMSCRIPTEN_VERSION)_64bit CLANG_PATH = $(EMSDK_PATH)/upstream/bin
PYTHON_VERSION = 2.7.13.1_64bit\python-2.7.13.amd64 PYTHON_PATH = $(EMSDK_PATH)/python/3.9.2-1_64bit
NODE_VERSION = 8.9.1_64bit NODE_PATH = $(EMSDK_PATH)/node/14.18.2_64bit/bin
export PATH = $(EMSDK_PATH);$(EMSDK_PATH)\clang\$(CLANG_VERSION);$(EMSDK_PATH)\node\$(NODE_VERSION)\bin;$(EMSDK_PATH)\python\$(PYTHON_VERSION);$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION);C:\raylib\MinGW\bin:$$(PATH) export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH):$$(PATH)
EMSCRIPTEN = $(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION)
endif endif
# Define raylib release directory for compiled library. # Define raylib release directory for compiled library.
@ -344,7 +343,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
endif endif
ifeq ($(PLATFORM),PLATFORM_WEB) ifeq ($(PLATFORM),PLATFORM_WEB)
# Libraries for web (HTML5) compiling # Libraries for web (HTML5) compiling
LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.a
endif endif
# Define a recursive wildcard function # Define a recursive wildcard function

View File

@ -15,12 +15,30 @@
* This example has been created using raylib 1.0 (www.raylib.com) * 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) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2013-2020 Ramon Santamaria (@raysan5) * Copyright (c) 2013-2022 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
#include "raylib.h" #include "raylib.h"
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
//----------------------------------------------------------------------------------
// Local Variables Definition (local to this module)
//----------------------------------------------------------------------------------
Camera camera = { 0 };
Vector3 cubePosition = { 0 };
//----------------------------------------------------------------------------------
// Local Functions Declaration
//----------------------------------------------------------------------------------
static void UpdateDrawFrame(void); // Update and draw one frame
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main() int main()
{ {
// Initialization // Initialization
@ -30,7 +48,6 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib"); InitWindow(screenWidth, screenHeight, "raylib");
Camera camera = { 0 };
camera.position = (Vector3){ 10.0f, 10.0f, 8.0f }; camera.position = (Vector3){ 10.0f, 10.0f, 8.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
@ -39,45 +56,55 @@ int main()
SetCameraMode(camera, CAMERA_ORBITAL); SetCameraMode(camera, CAMERA_ORBITAL);
Vector3 cubePosition = { 0 }; //--------------------------------------------------------------------------------------
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
#else
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 UpdateDrawFrame();
//----------------------------------------------------------------------------------
UpdateCamera(&camera);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10, 1.0f);
EndMode3D();
DrawText("This is a raylib example", 10, 40, 20, DARKGRAY);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
} }
#endif
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
}
// Update and draw game frame
static void UpdateDrawFrame(void)
{
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10, 1.0f);
EndMode3D();
DrawText("This is a raylib example", 10, 40, 20, DARKGRAY);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
} }

View File

@ -0,0 +1 @@
Assets license.

114
src/external/qoi.h vendored
View File

@ -28,8 +28,8 @@ SOFTWARE.
-- About -- About
QOI encodes and decodes images in a lossless format. Compared to stb_image and QOI encodes and decodes images in a lossless format. Compared to stb_image and
stb_image_write QOI offers 20x-50x faster encoding, 3x-4x faster decoding and stb_image_write QOI offers 20x-50x faster encoding, 3x-4x faster decoding and
20% better compression. 20% better compression.
@ -45,7 +45,7 @@ stb_image_write QOI offers 20x-50x faster encoding, 3x-4x faster decoding and
// the input pixel data. // the input pixel data.
qoi_write("image_new.qoi", rgba_pixels, &(qoi_desc){ qoi_write("image_new.qoi", rgba_pixels, &(qoi_desc){
.width = 1920, .width = 1920,
.height = 1080, .height = 1080,
.channels = 4, .channels = 4,
.colorspace = QOI_SRGB .colorspace = QOI_SRGB
}); });
@ -74,7 +74,7 @@ QOI_NO_STDIO before including this library.
This library uses malloc() and free(). To supply your own malloc implementation This library uses malloc() and free(). To supply your own malloc implementation
you can define QOI_MALLOC and QOI_FREE before including this library. you can define QOI_MALLOC and QOI_FREE before including this library.
This library uses memset() to zero-initialize the index. To supply your own This library uses memset() to zero-initialize the index. To supply your own
implementation you can define QOI_ZEROARR before including this library. implementation you can define QOI_ZEROARR before including this library.
@ -91,9 +91,9 @@ struct qoi_header_t {
uint8_t colorspace; // 0 = sRGB with linear alpha, 1 = all channels linear uint8_t colorspace; // 0 = sRGB with linear alpha, 1 = all channels linear
}; };
Images are encoded from top to bottom, left to right. The decoder and encoder Images are encoded row by row, left to right, top to bottom. The decoder and
start with {r: 0, g: 0, b: 0, a: 255} as the previous pixel value. An image is encoder start with {r: 0, g: 0, b: 0, a: 255} as the previous pixel value. An
complete when all pixels specified by width * height have been covered. image is complete when all pixels specified by width * height have been covered.
Pixels are encoded as Pixels are encoded as
- a run of the previous pixel - a run of the previous pixel
@ -101,20 +101,20 @@ Pixels are encoded as
- a difference to the previous pixel value in r,g,b - a difference to the previous pixel value in r,g,b
- full r,g,b or r,g,b,a values - full r,g,b or r,g,b,a values
The color channels are assumed to not be premultiplied with the alpha channel The color channels are assumed to not be premultiplied with the alpha channel
("un-premultiplied alpha"). ("un-premultiplied alpha").
A running array[64] (zero-initialized) of previously seen pixel values is A running array[64] (zero-initialized) of previously seen pixel values is
maintained by the encoder and decoder. Each pixel that is seen by the encoder maintained by the encoder and decoder. Each pixel that is seen by the encoder
and decoder is put into this array at the position formed by a hash function of and decoder is put into this array at the position formed by a hash function of
the color value. In the encoder, if the pixel value at the index matches the the color value. In the encoder, if the pixel value at the index matches the
current pixel, this index position is written to the stream as QOI_OP_INDEX. current pixel, this index position is written to the stream as QOI_OP_INDEX.
The hash function for the index is: The hash function for the index is:
index_position = (r * 3 + g * 5 + b * 7 + a * 11) % 64 index_position = (r * 3 + g * 5 + b * 7 + a * 11) % 64
Each chunk starts with a 2- or 8-bit tag, followed by a number of data bits. The Each chunk starts with a 2- or 8-bit tag, followed by a number of data bits. The
bit length of chunks is divisible by 8 - i.e. all chunks are byte aligned. All bit length of chunks is divisible by 8 - i.e. all chunks are byte aligned. All
values encoded in these data bits have the most significant bit on the left. values encoded in these data bits have the most significant bit on the left.
The 8-bit tags have precedence over the 2-bit tags. A decoder must check for the The 8-bit tags have precedence over the 2-bit tags. A decoder must check for the
@ -135,11 +135,11 @@ The possible chunks are:
2-bit tag b00 2-bit tag b00
6-bit index into the color index array: 0..63 6-bit index into the color index array: 0..63
A valid encoder must not issue 7 or more consecutive QOI_OP_INDEX chunks to the A valid encoder must not issue 2 or more consecutive QOI_OP_INDEX chunks to the
index 0, to avoid confusion with the 8 byte end marker. same index. QOI_OP_RUN should be used instead.
.- QOI_OP_DIFF -----------. .- QOI_OP_DIFF -----------.
| Byte[0] | | Byte[0] |
| 7 6 5 4 3 2 1 0 | | 7 6 5 4 3 2 1 0 |
|-------+-----+-----+-----| |-------+-----+-----+-----|
@ -150,14 +150,16 @@ index 0, to avoid confusion with the 8 byte end marker.
2-bit green channel difference from the previous pixel between -2..1 2-bit green channel difference from the previous pixel between -2..1
2-bit blue channel difference from the previous pixel between -2..1 2-bit blue channel difference from the previous pixel between -2..1
The difference to the current channel values are using a wraparound operation, The difference to the current channel values are using a wraparound operation,
so "1 - 2" will result in 255, while "255 + 1" will result in 0. so "1 - 2" will result in 255, while "255 + 1" will result in 0.
Values are stored as unsigned integers with a bias of 2. E.g. -2 is stored as Values are stored as unsigned integers with a bias of 2. E.g. -2 is stored as
0 (b00). 1 is stored as 3 (b11). 0 (b00). 1 is stored as 3 (b11).
The alpha value remains unchanged from the previous pixel.
.- QOI_OP_LUMA -------------------------------------.
.- QOI_OP_LUMA -------------------------------------.
| Byte[0] | Byte[1] | | Byte[0] | Byte[1] |
| 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 | | 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 |
|-------+-----------------+-------------+-----------| |-------+-----------------+-------------+-----------|
@ -168,18 +170,20 @@ Values are stored as unsigned integers with a bias of 2. E.g. -2 is stored as
4-bit red channel difference minus green channel difference -8..7 4-bit red channel difference minus green channel difference -8..7
4-bit blue channel difference minus green channel difference -8..7 4-bit blue channel difference minus green channel difference -8..7
The green channel is used to indicate the general direction of change and is The green channel is used to indicate the general direction of change and is
encoded in 6 bits. The red and blue channels (dr and db) base their diffs off encoded in 6 bits. The red and blue channels (dr and db) base their diffs off
of the green channel difference and are encoded in 4 bits. I.e.: of the green channel difference and are encoded in 4 bits. I.e.:
dr_dg = (last_px.r - cur_px.r) - (last_px.g - cur_px.g) dr_dg = (cur_px.r - prev_px.r) - (cur_px.g - prev_px.g)
db_dg = (last_px.b - cur_px.b) - (last_px.g - cur_px.g) db_dg = (cur_px.b - prev_px.b) - (cur_px.g - prev_px.g)
The difference to the current channel values are using a wraparound operation, The difference to the current channel values are using a wraparound operation,
so "10 - 13" will result in 253, while "250 + 7" will result in 1. so "10 - 13" will result in 253, while "250 + 7" will result in 1.
Values are stored as unsigned integers with a bias of 32 for the green channel Values are stored as unsigned integers with a bias of 32 for the green channel
and a bias of 8 for the red and blue channel. and a bias of 8 for the red and blue channel.
The alpha value remains unchanged from the previous pixel.
.- QOI_OP_RUN ------------. .- QOI_OP_RUN ------------.
| Byte[0] | | Byte[0] |
@ -190,8 +194,8 @@ and a bias of 8 for the red and blue channel.
2-bit tag b11 2-bit tag b11
6-bit run-length repeating the previous pixel: 1..62 6-bit run-length repeating the previous pixel: 1..62
The run-length is stored with a bias of -1. Note that the run-lengths 63 and 64 The run-length is stored with a bias of -1. Note that the run-lengths 63 and 64
(b111110 and b111111) are illegal as they are occupied by the QOI_OP_RGB and (b111110 and b111111) are illegal as they are occupied by the QOI_OP_RGB and
QOI_OP_RGBA tags. QOI_OP_RGBA tags.
@ -206,6 +210,8 @@ QOI_OP_RGBA tags.
8-bit green channel value 8-bit green channel value
8-bit blue channel value 8-bit blue channel value
The alpha value remains unchanged from the previous pixel.
.- QOI_OP_RGBA ---------------------------------------------------. .- QOI_OP_RGBA ---------------------------------------------------.
| Byte[0] | Byte[1] | Byte[2] | Byte[3] | Byte[4] | | Byte[0] | Byte[1] | Byte[2] | Byte[3] | Byte[4] |
@ -232,17 +238,17 @@ Header - Public functions */
extern "C" { extern "C" {
#endif #endif
/* A pointer to a qoi_desc struct has to be supplied to all of qoi's functions. /* A pointer to a qoi_desc struct has to be supplied to all of qoi's functions.
It describes either the input format (for qoi_write and qoi_encode), or is It describes either the input format (for qoi_write and qoi_encode), or is
filled with the description read from the file header (for qoi_read and filled with the description read from the file header (for qoi_read and
qoi_decode). qoi_decode).
The colorspace in this qoi_desc is an enum where The colorspace in this qoi_desc is an enum where
0 = sRGB, i.e. gamma scaled RGB channels and a linear alpha channel 0 = sRGB, i.e. gamma scaled RGB channels and a linear alpha channel
1 = all channels are linear 1 = all channels are linear
You may use the constants QOI_SRGB or QOI_LINEAR. The colorspace is purely You may use the constants QOI_SRGB or QOI_LINEAR. The colorspace is purely
informative. It will be saved to the file header, but does not affect informative. It will be saved to the file header, but does not affect
en-/decoding in any way. */ how chunks are en-/decoded. */
#define QOI_SRGB 0 #define QOI_SRGB 0
#define QOI_LINEAR 1 #define QOI_LINEAR 1
@ -256,11 +262,11 @@ typedef struct {
#ifndef QOI_NO_STDIO #ifndef QOI_NO_STDIO
/* Encode raw RGB or RGBA pixels into a QOI image and write it to the file /* Encode raw RGB or RGBA pixels into a QOI image and write it to the file
system. The qoi_desc struct must be filled with the image width, height, system. The qoi_desc struct must be filled with the image width, height,
number of channels (3 = RGB, 4 = RGBA) and the colorspace. number of channels (3 = RGB, 4 = RGBA) and the colorspace.
The function returns 0 on failure (invalid parameters, or fopen or malloc The function returns 0 on failure (invalid parameters, or fopen or malloc
failed) or the number of bytes written on success. */ failed) or the number of bytes written on success. */
int qoi_write(const char *filename, const void *data, const qoi_desc *desc); int qoi_write(const char *filename, const void *data, const qoi_desc *desc);
@ -271,7 +277,7 @@ number of channels from the file header is used. If channels is 3 or 4 the
output format will be forced into this number of channels. output format will be forced into this number of channels.
The function either returns NULL on failure (invalid data, or malloc or fopen The function either returns NULL on failure (invalid data, or malloc or fopen
failed) or a pointer to the decoded pixels. On success, the qoi_desc struct failed) or a pointer to the decoded pixels. On success, the qoi_desc struct
will be filled with the description from the file header. will be filled with the description from the file header.
The returned pixel data should be free()d after use. */ The returned pixel data should be free()d after use. */
@ -283,8 +289,8 @@ void *qoi_read(const char *filename, qoi_desc *desc, int channels);
/* Encode raw RGB or RGBA pixels into a QOI image in memory. /* Encode raw RGB or RGBA pixels into a QOI image in memory.
The function either returns NULL on failure (invalid parameters or malloc The function either returns NULL on failure (invalid parameters or malloc
failed) or a pointer to the encoded data on success. On success the out_len failed) or a pointer to the encoded data on success. On success the out_len
is set to the size in bytes of the encoded data. is set to the size in bytes of the encoded data.
The returned qoi data should be free()d after use. */ The returned qoi data should be free()d after use. */
@ -294,8 +300,8 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len);
/* Decode a QOI image from memory. /* Decode a QOI image from memory.
The function either returns NULL on failure (invalid parameters or malloc The function either returns NULL on failure (invalid parameters or malloc
failed) or a pointer to the decoded pixels. On success, the qoi_desc struct failed) or a pointer to the decoded pixels. On success, the qoi_desc struct
is filled with the description from the file header. is filled with the description from the file header.
The returned pixel data should be free()d after use. */ The returned pixel data should be free()d after use. */
@ -340,8 +346,8 @@ Implementation */
#define QOI_HEADER_SIZE 14 #define QOI_HEADER_SIZE 14
/* 2GB is the max file size that this implementation can safely handle. We guard /* 2GB is the max file size that this implementation can safely handle. We guard
against anything larger than that, assuming the worst case with 5 bytes per against anything larger than that, assuming the worst case with 5 bytes per
pixel, rounded down to a nice clean value. 400 million pixels ought to be pixel, rounded down to a nice clean value. 400 million pixels ought to be
enough for anybody. */ enough for anybody. */
#define QOI_PIXELS_MAX ((unsigned int)400000000) #define QOI_PIXELS_MAX ((unsigned int)400000000)
@ -352,14 +358,14 @@ typedef union {
static const unsigned char qoi_padding[8] = {0,0,0,0,0,0,0,1}; static const unsigned char qoi_padding[8] = {0,0,0,0,0,0,0,1};
void qoi_write_32(unsigned char *bytes, int *p, unsigned int v) { static void qoi_write_32(unsigned char *bytes, int *p, unsigned int v) {
bytes[(*p)++] = (0xff000000 & v) >> 24; bytes[(*p)++] = (0xff000000 & v) >> 24;
bytes[(*p)++] = (0x00ff0000 & v) >> 16; bytes[(*p)++] = (0x00ff0000 & v) >> 16;
bytes[(*p)++] = (0x0000ff00 & v) >> 8; bytes[(*p)++] = (0x0000ff00 & v) >> 8;
bytes[(*p)++] = (0x000000ff & v); bytes[(*p)++] = (0x000000ff & v);
} }
unsigned int qoi_read_32(const unsigned char *bytes, int *p) { static unsigned int qoi_read_32(const unsigned char *bytes, int *p) {
unsigned int a = bytes[(*p)++]; unsigned int a = bytes[(*p)++];
unsigned int b = bytes[(*p)++]; unsigned int b = bytes[(*p)++];
unsigned int c = bytes[(*p)++]; unsigned int c = bytes[(*p)++];
@ -385,8 +391,8 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) {
return NULL; return NULL;
} }
max_size = max_size =
desc->width * desc->height * (desc->channels + 1) + desc->width * desc->height * (desc->channels + 1) +
QOI_HEADER_SIZE + sizeof(qoi_padding); QOI_HEADER_SIZE + sizeof(qoi_padding);
p = 0; p = 0;
@ -412,7 +418,7 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) {
px_prev.rgba.b = 0; px_prev.rgba.b = 0;
px_prev.rgba.a = 255; px_prev.rgba.a = 255;
px = px_prev; px = px_prev;
px_len = desc->width * desc->height * desc->channels; px_len = desc->width * desc->height * desc->channels;
px_end = px_len - desc->channels; px_end = px_len - desc->channels;
channels = desc->channels; channels = desc->channels;
@ -460,14 +466,14 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) {
if ( if (
vr > -3 && vr < 2 && vr > -3 && vr < 2 &&
vg > -3 && vg < 2 && vg > -3 && vg < 2 &&
vb > -3 && vb < 2 vb > -3 && vb < 2
) { ) {
bytes[p++] = QOI_OP_DIFF | (vr + 2) << 4 | (vg + 2) << 2 | (vb + 2); bytes[p++] = QOI_OP_DIFF | (vr + 2) << 4 | (vg + 2) << 2 | (vb + 2);
} }
else if ( else if (
vg_r > -9 && vg_r < 8 && vg_r > -9 && vg_r < 8 &&
vg > -33 && vg < 32 && vg > -33 && vg < 32 &&
vg_b > -9 && vg_b < 8 vg_b > -9 && vg_b < 8
) { ) {
bytes[p++] = QOI_OP_LUMA | (vg + 32); bytes[p++] = QOI_OP_LUMA | (vg + 32);
@ -526,7 +532,7 @@ void *qoi_decode(const void *data, int size, qoi_desc *desc, int channels) {
desc->colorspace = bytes[p++]; desc->colorspace = bytes[p++];
if ( if (
desc->width == 0 || desc->height == 0 || desc->width == 0 || desc->height == 0 ||
desc->channels < 3 || desc->channels > 4 || desc->channels < 3 || desc->channels > 4 ||
desc->colorspace > 1 || desc->colorspace > 1 ||
header_magic != QOI_MAGIC || header_magic != QOI_MAGIC ||
@ -592,7 +598,7 @@ void *qoi_decode(const void *data, int size, qoi_desc *desc, int channels) {
index[QOI_COLOR_HASH(px) % 64] = px; index[QOI_COLOR_HASH(px) % 64] = px;
} }
if (channels == 4) { if (channels == 4) {
*(qoi_rgba_t*)(pixels + px_pos) = px; *(qoi_rgba_t*)(pixels + px_pos) = px;
} }
else { else {
@ -621,11 +627,11 @@ int qoi_write(const char *filename, const void *data, const qoi_desc *desc) {
if (!encoded) { if (!encoded) {
fclose(f); fclose(f);
return 0; return 0;
} }
fwrite(encoded, 1, size, f); fwrite(encoded, 1, size, f);
fclose(f); fclose(f);
QOI_FREE(encoded); QOI_FREE(encoded);
return size; return size;
} }

View File

@ -31,6 +31,7 @@
<link rel="shortcut icon" href="https://www.raylib.com/favicon.ico"> <link rel="shortcut icon" href="https://www.raylib.com/favicon.ico">
<style> <style>
body { margin: 0px; }
canvas.emscripten { border: 0px none; background-color: black; } canvas.emscripten { border: 0px none; background-color: black; }
</style> </style>
<script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js"> </script> <script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js"> </script>

View File

@ -839,7 +839,7 @@ typedef enum {
BLEND_MULTIPLIED, // Blend textures multiplying colors BLEND_MULTIPLIED, // Blend textures multiplying colors
BLEND_ADD_COLORS, // Blend textures adding colors (alternative) BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative) BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
BLEND_CUSTOM // Belnd textures using custom src/dst factors (use rlSetBlendMode()) BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendMode())
} BlendMode; } BlendMode;
// Gesture // Gesture
@ -1041,6 +1041,7 @@ RLAPI bool SaveFileText(const char *fileName, char *text); // Save text d
RLAPI bool FileExists(const char *fileName); // Check if file exists RLAPI bool FileExists(const char *fileName); // Check if file exists
RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists
RLAPI bool IsFileExtension(const char *fileName, const char *ext); // Check file extension (including point: .png, .wav) RLAPI bool IsFileExtension(const char *fileName, const char *ext); // Check file extension (including point: .png, .wav)
RLAPI int GetFileLength(const char *fileName); // Get file length in bytes (NOTE: GetFileSize() conflicts with windows.h)
RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: '.png') RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: '.png')
RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string
RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string) RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string)
@ -1336,6 +1337,7 @@ RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color co
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
RLAPI void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); // Draw text using Font and pro parameters (rotation) RLAPI void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); // Draw text using Font and pro parameters (rotation)
RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint); // Draw one character (codepoint) RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint); // Draw one character (codepoint)
RLAPI void DrawTextCodepoints(Font font, int *codepoints, int count, Vector2 position, float fontSize, float spacing, Color tint); // Draw multiple character (codepoint)
// Text font info functions // Text font info functions
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font

View File

@ -173,6 +173,7 @@
#include <unistd.h> #include <unistd.h>
#elif defined(__APPLE__) #elif defined(__APPLE__)
#include <sys/syslimits.h> #include <sys/syslimits.h>
#include <mach-o/dyld.h>
#endif // OSs #endif // OSs
#endif // PLATFORM_DESKTOP #endif // PLATFORM_DESKTOP
@ -2850,6 +2851,24 @@ bool DirectoryExists(const char *dirPath)
return result; return result;
} }
// Get file length in bytes
// NOTE: GetFileSize() conflicts with windows.h
int GetFileLength(const char *fileName)
{
int size = 0;
FILE *file = fopen(fileName, "rb");
if (file != NULL)
{
fseek(file, 0L, SEEK_END);
size = (int)ftell(file);
fclose(file);
}
return size;
}
// Get pointer to extension for a filename string (includes the dot: .png) // Get pointer to extension for a filename string (includes the dot: .png)
const char *GetFileExtension(const char *fileName) const char *GetFileExtension(const char *fileName)
{ {

View File

@ -1778,7 +1778,11 @@ void rlSetBlendMode(int mode)
case RL_BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break; case RL_BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_ADD_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); break; case RL_BLEND_ADD_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_SUBTRACT_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_SUBTRACT); break; case RL_BLEND_SUBTRACT_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_SUBTRACT); break;
case RL_BLEND_CUSTOM: glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation); break; case RL_BLEND_CUSTOM:
{
// NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()
glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation);
} break;
default: break; default: break;
} }

View File

@ -4692,13 +4692,12 @@ static Model LoadGLTF(const char *fileName)
model.materials[j].maps[MATERIAL_MAP_ALBEDO].texture = LoadTextureFromImage(imAlbedo); model.materials[j].maps[MATERIAL_MAP_ALBEDO].texture = LoadTextureFromImage(imAlbedo);
UnloadImage(imAlbedo); UnloadImage(imAlbedo);
} }
// Load base color factor (tint)
model.materials[j].maps[MATERIAL_MAP_ALBEDO].color.r = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[0]*255);
model.materials[j].maps[MATERIAL_MAP_ALBEDO].color.g = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[1]*255);
model.materials[j].maps[MATERIAL_MAP_ALBEDO].color.b = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[2]*255);
model.materials[j].maps[MATERIAL_MAP_ALBEDO].color.a = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[3]*255);
} }
// Load base color factor (tint)
model.materials[j].maps[MATERIAL_MAP_ALBEDO].color.r = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[0]*255);
model.materials[j].maps[MATERIAL_MAP_ALBEDO].color.g = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[1]*255);
model.materials[j].maps[MATERIAL_MAP_ALBEDO].color.b = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[2]*255);
model.materials[j].maps[MATERIAL_MAP_ALBEDO].color.a = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[3]*255);
// Load metallic/roughness texture // Load metallic/roughness texture
if (data->materials[i].pbr_metallic_roughness.metallic_roughness_texture.texture) if (data->materials[i].pbr_metallic_roughness.metallic_roughness_texture.texture)

View File

@ -1091,6 +1091,38 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSiz
DrawTexturePro(font.texture, srcRec, dstRec, (Vector2){ 0, 0 }, 0.0f, tint); DrawTexturePro(font.texture, srcRec, dstRec, (Vector2){ 0, 0 }, 0.0f, tint);
} }
// Draw multiple character (codepoints)
void DrawTextCodepoints(Font font, int *codepoints, int count, Vector2 position, float fontSize, float spacing, Color tint)
{
int textOffsetY = 0; // Offset between lines (on line break '\n')
float textOffsetX = 0.0f; // Offset X to next character to draw
float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor
for (int i = 0; i < count; i++)
{
int index = GetGlyphIndex(font, codepoints[i]);
if (codepoints[i] == '\n')
{
// NOTE: Fixed line spacing of 1.5 line-height
// TODO: Support custom line spacing defined by user
textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor);
textOffsetX = 0.0f;
}
else
{
if ((codepoints[i] != ' ') && (codepoints[i] != '\t'))
{
DrawTextCodepoint(font, codepoints[i], (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, tint);
}
if (font.glyphs[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width*scaleFactor + spacing);
else textOffsetX += ((float)font.glyphs[index].advanceX*scaleFactor + spacing);
}
}
}
// Measure string width for default font // Measure string width for default font
int MeasureText(const char *text, int fontSize) int MeasureText(const char *text, int fontSize)
{ {

View File

@ -500,7 +500,8 @@ bool ExportImage(Image image, const char *fileName)
else if (IsFileExtension(fileName, ".tga")) success = stbi_write_tga(fileName, image.width, image.height, channels, imgData); else if (IsFileExtension(fileName, ".tga")) success = stbi_write_tga(fileName, image.width, image.height, channels, imgData);
#endif #endif
#if defined(SUPPORT_FILEFORMAT_JPG) #if defined(SUPPORT_FILEFORMAT_JPG)
else if (IsFileExtension(fileName, ".jpg")) success = stbi_write_jpg(fileName, image.width, image.height, channels, imgData, 90); // JPG quality: between 1 and 100 else if (IsFileExtension(fileName, ".jpg") ||
IsFileExtension(fileName, ".jpeg")) success = stbi_write_jpg(fileName, image.width, image.height, channels, imgData, 90); // JPG quality: between 1 and 100
#endif #endif
#if defined(SUPPORT_FILEFORMAT_QOI) #if defined(SUPPORT_FILEFORMAT_QOI)
else if (IsFileExtension(fileName, ".qoi")) else if (IsFileExtension(fileName, ".qoi"))
@ -4324,6 +4325,7 @@ static Image LoadPKM(const unsigned char *fileData, unsigned int fileSize)
#if defined(SUPPORT_FILEFORMAT_KTX) #if defined(SUPPORT_FILEFORMAT_KTX)
// Load KTX compressed image data (ETC1/ETC2 compression) // Load KTX compressed image data (ETC1/ETC2 compression)
// TODO: Review KTX loading, many things changed!
static Image LoadKTX(const unsigned char *fileData, unsigned int fileSize) static Image LoadKTX(const unsigned char *fileData, unsigned int fileSize)
{ {
unsigned char *fileDataPtr = (unsigned char *)fileData; unsigned char *fileDataPtr = (unsigned char *)fileData;
@ -4398,6 +4400,8 @@ static Image LoadKTX(const unsigned char *fileData, unsigned int fileSize)
if (ktxHeader->glInternalFormat == 0x8D64) image.format = PIXELFORMAT_COMPRESSED_ETC1_RGB; if (ktxHeader->glInternalFormat == 0x8D64) image.format = PIXELFORMAT_COMPRESSED_ETC1_RGB;
else if (ktxHeader->glInternalFormat == 0x9274) image.format = PIXELFORMAT_COMPRESSED_ETC2_RGB; else if (ktxHeader->glInternalFormat == 0x9274) image.format = PIXELFORMAT_COMPRESSED_ETC2_RGB;
else if (ktxHeader->glInternalFormat == 0x9278) image.format = PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA; else if (ktxHeader->glInternalFormat == 0x9278) image.format = PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA;
// TODO: Support uncompressed data formats? Right now it returns format = 0!
} }
} }
@ -4406,11 +4410,12 @@ static Image LoadKTX(const unsigned char *fileData, unsigned int fileSize)
// Save image data as KTX file // Save image data as KTX file
// NOTE: By default KTX 1.1 spec is used, 2.0 is still on draft (01Oct2018) // NOTE: By default KTX 1.1 spec is used, 2.0 is still on draft (01Oct2018)
// TODO: Review KTX saving, many things changed!
static int SaveKTX(Image image, const char *fileName) static int SaveKTX(Image image, const char *fileName)
{ {
// KTX file Header (64 bytes) // KTX file Header (64 bytes)
// v1.1 - https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/ // v1.1 - https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/
// v2.0 - http://github.khronos.org/KTX-Specification/ - still on draft, not ready for implementation // v2.0 - http://github.khronos.org/KTX-Specification/ - Final specs by 2021-04-18
typedef struct { typedef struct {
char id[12]; // Identifier: "«KTX 11»\r\n\x1A\n" // KTX 2.0: "«KTX 22»\r\n\x1A\n" char id[12]; // Identifier: "«KTX 11»\r\n\x1A\n" // KTX 2.0: "«KTX 22»\r\n\x1A\n"
unsigned int endianness; // Little endian: 0x01 0x02 0x03 0x04 unsigned int endianness; // Little endian: 0x01 0x02 0x03 0x04