Review and recompile web examples
BIN
docs/examples/web/textures/resources/fudesumi.png
Normal file
After Width: | Height: | Size: 214 KiB |
BIN
docs/examples/web/textures/resources/fudesumi.raw
Normal file
BIN
docs/examples/web/textures/textures_image_drawing.png
Normal file
After Width: | Height: | Size: 410 KiB |
BIN
docs/examples/web/textures/textures_image_loading.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/examples/web/textures/textures_image_processing.png
Normal file
After Width: | Height: | Size: 253 KiB |
BIN
docs/examples/web/textures/textures_logo_raylib.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
docs/examples/web/textures/textures_particles__blending.png
Normal file
After Width: | Height: | Size: 350 KiB |
163
docs/examples/web/textures/textures_particles_blending.c
Normal file
|
@ -0,0 +1,163 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib example - particles blending
|
||||
*
|
||||
* This example has been created using raylib 1.7 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#define MAX_PARTICLES 200
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
// Particle structure with basic data
|
||||
typedef struct {
|
||||
Vector2 position;
|
||||
Color color;
|
||||
float alpha;
|
||||
float size;
|
||||
float rotation;
|
||||
bool active; // NOTE: Use it to activate/deactive particle
|
||||
} Particle;
|
||||
|
||||
Particle mouseTail[MAX_PARTICLES];
|
||||
|
||||
float gravity = 3.0f;
|
||||
|
||||
Texture2D smoke;
|
||||
|
||||
int blending = BLEND_ALPHA;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
void UpdateDrawFrame(void); // Update and Draw one frame
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main Enry Point
|
||||
//----------------------------------------------------------------------------------
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending");
|
||||
|
||||
// Initialize particles
|
||||
for (int i = 0; i < MAX_PARTICLES; i++)
|
||||
{
|
||||
mouseTail[i].position = (Vector2){ 0, 0 };
|
||||
mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 };
|
||||
mouseTail[i].alpha = 1.0f;
|
||||
mouseTail[i].size = (float)GetRandomValue(1, 30)/20.0f;
|
||||
mouseTail[i].rotation = GetRandomValue(0, 360);
|
||||
mouseTail[i].active = false;
|
||||
}
|
||||
|
||||
smoke = LoadTexture("resources/smoke.png");
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
UpdateDrawFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(smoke); // Texture unloading
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
void UpdateDrawFrame(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// Activate one particle every frame and Update active particles
|
||||
// NOTE: Particles initial position should be mouse position when activated
|
||||
// NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0)
|
||||
// NOTE: When a particle disappears, active = false and it can be reused.
|
||||
for (int i = 0; i < MAX_PARTICLES; i++)
|
||||
{
|
||||
if (!mouseTail[i].active)
|
||||
{
|
||||
mouseTail[i].active = true;
|
||||
mouseTail[i].alpha = 1.0f;
|
||||
mouseTail[i].position = GetMousePosition();
|
||||
i = MAX_PARTICLES;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_PARTICLES; i++)
|
||||
{
|
||||
if (mouseTail[i].active)
|
||||
{
|
||||
mouseTail[i].position.y += gravity;
|
||||
mouseTail[i].alpha -= 0.01f;
|
||||
|
||||
if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false;
|
||||
|
||||
mouseTail[i].rotation += 5.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
if (blending == BLEND_ALPHA) blending = BLEND_ADDITIVE;
|
||||
else blending = BLEND_ALPHA;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(DARKGRAY);
|
||||
|
||||
BeginBlendMode(blending);
|
||||
|
||||
// Draw active particles
|
||||
for (int i = 0; i < MAX_PARTICLES; i++)
|
||||
{
|
||||
if (mouseTail[i].active) DrawTexturePro(smoke, (Rectangle){ 0, 0, smoke.width, smoke.height },
|
||||
(Rectangle){ mouseTail[i].position.x, mouseTail[i].position.y, smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size },
|
||||
(Vector2){ smoke.width*mouseTail[i].size/2, smoke.height*mouseTail[i].size/2 }, mouseTail[i].rotation,
|
||||
Fade(mouseTail[i].color, mouseTail[i].alpha));
|
||||
}
|
||||
|
||||
EndBlendMode();
|
||||
|
||||
DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK);
|
||||
|
||||
if (blending == BLEND_ALPHA) DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK);
|
||||
else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
BIN
docs/examples/web/textures/textures_particles_blending.data
Normal file
After Width: | Height: | Size: 15 KiB |
38697
docs/examples/web/textures/textures_particles_blending.js
Normal file
|
@ -25,7 +25,7 @@
|
|||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
Texture2D sonic;
|
||||
Texture2D fudesumi;
|
||||
Texture2D checked;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -43,9 +43,9 @@ int main()
|
|||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data");
|
||||
|
||||
// Load RAW image data (512x512, 32bit RGBA, no file header)
|
||||
Image sonicRaw = LoadImageRaw("resources/texture_formats/sonic_R8G8B8A8.raw", 512, 512, UNCOMPRESSED_R8G8B8A8, 0);
|
||||
sonic = LoadTextureFromImage(sonicRaw); // Upload CPU (RAM) image to GPU (VRAM)
|
||||
UnloadImage(sonicRaw); // Unload CPU (RAM) image data
|
||||
Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, UNCOMPRESSED_R8G8B8A8, 0);
|
||||
fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM)
|
||||
UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data
|
||||
|
||||
// Generate a checked texture by code (1024x1024 pixels)
|
||||
int width = 1024;
|
||||
|
@ -58,8 +58,8 @@ int main()
|
|||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
if (((x/32+y/32)/1)%2 == 0) pixels[y*height + x] = DARKBLUE;
|
||||
else pixels[y*height + x] = SKYBLUE;
|
||||
if (((x/32+y/32)/1)%2 == 0) pixels[y*height + x] = ORANGE;
|
||||
else pixels[y*height + x] = GOLD;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ int main()
|
|||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(sonic); // Texture unloading
|
||||
UnloadTexture(fudesumi); // Texture unloading
|
||||
UnloadTexture(checked); // Texture unloading
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
|
@ -111,12 +111,14 @@ void UpdateDrawFrame(void)
|
|||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.3f));
|
||||
DrawTexture(sonic, 330, -20, WHITE);
|
||||
DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, WHITE);
|
||||
DrawTexture(fudesumi, 430, -30, WHITE);
|
||||
|
||||
DrawText("CHECKED TEXTURE ", 84, 100, 30, DARKBLUE);
|
||||
DrawText("GENERATED by CODE", 72, 164, 30, DARKBLUE);
|
||||
DrawText("and RAW IMAGE LOADING", 46, 226, 30, DARKBLUE);
|
||||
DrawText("CHECKED TEXTURE ", 84, 100, 30, BROWN);
|
||||
DrawText("GENERATED by CODE", 72, 164, 30, BROWN);
|
||||
DrawText("and RAW IMAGE LOADING", 46, 226, 30, BROWN);
|
||||
|
||||
DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
BIN
docs/examples/web/textures/textures_raw_data.data
Normal file
BIN
docs/examples/web/textures/textures_raw_data.png
Normal file
After Width: | Height: | Size: 240 KiB |
BIN
docs/examples/web/textures/textures_rectangle.png
Normal file
After Width: | Height: | Size: 39 KiB |
|
@ -22,7 +22,7 @@ int screenWidth = 800;
|
|||
int screenHeight = 450;
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Texture2D guybrush;
|
||||
Texture2D scarfy;
|
||||
|
||||
int frameWidth;
|
||||
int frameHeight;
|
||||
|
@ -33,7 +33,6 @@ Vector2 origin;
|
|||
|
||||
int rotation = 0;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -48,10 +47,10 @@ int main()
|
|||
//--------------------------------------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles");
|
||||
|
||||
guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
|
||||
scarfy = LoadTexture("resources/scarfy.png"); // Texture loading
|
||||
|
||||
frameWidth = guybrush.width/7;
|
||||
frameHeight = guybrush.height;
|
||||
frameWidth = scarfy.width/6;
|
||||
frameHeight = scarfy.height;
|
||||
|
||||
// NOTE: On PLATFORM_WEB, NPOT textures support is limited
|
||||
|
||||
|
@ -79,9 +78,9 @@ int main()
|
|||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(guybrush); // Texture unloading
|
||||
UnloadTexture(scarfy); // Texture unloading
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
|
@ -108,10 +107,12 @@ void UpdateDrawFrame(void)
|
|||
// destRec defines the rectangle where our texture part will fit (scaling it to fit)
|
||||
// origin defines the point of the texture used as reference for rotation and scaling
|
||||
// rotation defines the texture rotation (using origin as rotation point)
|
||||
DrawTexturePro(guybrush, sourceRec, destRec, origin, rotation, WHITE);
|
||||
DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, WHITE);
|
||||
|
||||
DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY);
|
||||
DrawLine(0, destRec.y, screenWidth, destRec.y, GRAY);
|
||||
|
||||
DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
BIN
docs/examples/web/textures/textures_srcrec_dstrec.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
docs/examples/web/textures/textures_to_image.png
Normal file
After Width: | Height: | Size: 17 KiB |