aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2015-08-28 18:07:39 +0200
committerraysan5 <raysan5@gmail.com>2015-08-28 18:07:39 +0200
commitea45223f1ff0f0f3ebe7535548829681d2a7fa7d (patch)
treed00e009d9222003df69e83fa9740047dd43fcdb3
parent12581c1721a3cbca990766cb98b78211b59074be (diff)
downloadraylib-ea45223f1ff0f0f3ebe7535548829681d2a7fa7d.tar.gz
raylib-ea45223f1ff0f0f3ebe7535548829681d2a7fa7d.zip
New examples added
-rw-r--r--examples/core_3d_camera_free.c2
-rw-r--r--examples/core_3d_picking.c2
-rw-r--r--examples/core_drop_files.c74
-rw-r--r--examples/core_drop_files.pngbin0 -> 4682 bytes
-rw-r--r--examples/models_billboard.c29
-rw-r--r--examples/models_billboard.pngbin0 -> 53998 bytes
-rw-r--r--examples/models_cubicmap.c2
-rw-r--r--examples/models_heightmap.c2
-rw-r--r--examples/resources/billboard.pngbin0 -> 22439 bytes
-rw-r--r--examples/resources/smoke.pngbin0 -> 15427 bytes
-rw-r--r--examples/textures_particles_trail_blending.c132
-rw-r--r--examples/textures_particles_trail_blending.pngbin0 -> 358260 bytes
-rw-r--r--examples/textures_to_image.c68
-rw-r--r--examples/textures_to_image.pngbin0 -> 17200 bytes
14 files changed, 292 insertions, 19 deletions
diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c
index 9e123b04..b54a99c1 100644
--- a/examples/core_3d_camera_free.c
+++ b/examples/core_3d_camera_free.c
@@ -5,7 +5,7 @@
* This example has been created using raylib 1.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c
index 056dcd65..28503570 100644
--- a/examples/core_3d_picking.c
+++ b/examples/core_3d_picking.c
@@ -5,7 +5,7 @@
* This example has been created using raylib 1.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
diff --git a/examples/core_drop_files.c b/examples/core_drop_files.c
new file mode 100644
index 00000000..5802e48f
--- /dev/null
+++ b/examples/core_drop_files.c
@@ -0,0 +1,74 @@
+/*******************************************************************************************
+*
+* raylib [core] example - Windows drop files
+*
+* This example has been created using raylib 1.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
+
+ int count = 0;
+ char **droppedFiles;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (IsFileDropped())
+ {
+ droppedFiles = GetDroppedFiles(&count);
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ if (count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY);
+ else
+ {
+ DrawText("Dropped files:", 100, 40, 20, DARKGRAY);
+
+ for (int i = 0; i < count; i++)
+ {
+ if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f));
+ else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f));
+
+ DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY);
+ }
+
+ DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY);
+ }
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ ClearDroppedFiles(); // Clear internal buffers
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/core_drop_files.png b/examples/core_drop_files.png
new file mode 100644
index 00000000..d46c44cf
--- /dev/null
+++ b/examples/core_drop_files.png
Binary files differ
diff --git a/examples/models_billboard.c b/examples/models_billboard.c
index a58ec7d7..511d61ce 100644
--- a/examples/models_billboard.c
+++ b/examples/models_billboard.c
@@ -2,10 +2,10 @@
*
* raylib [models] example - Drawing billboards
*
-* This example has been created using raylib 1.2 (www.raylib.com)
+* This example has been created using raylib 1.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -21,24 +21,24 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
// Define the camera to look into our 3d world
- Camera camera = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
+ Camera camera = {{ 5.0, 4.0, 5.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 1.0, 0.0 }};
- Texture2D lena = LoadTexture("resources/lena.png"); // Our texture for billboard
- Rectangle eyesRec = { 225, 240, 155, 50 }; // Part of the texture to draw
- Vector3 billPosition = { 0.0, 0.0, 0.0 }; // Position where draw billboard
+ Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
+ Vector3 billPosition = { 0.0, 2.0, 0.0 }; // Position where draw billboard
+
+ SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
+ SetCameraPosition(camera.position); // Set internal camera position to match our camera position
+ SetCameraTarget(camera.target); // Set internal camera target to match our camera target
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
+ while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
- if (IsKeyDown(KEY_LEFT)) camera.position.x -= 0.2;
- if (IsKeyDown(KEY_RIGHT)) camera.position.x += 0.2;
- if (IsKeyDown(KEY_UP)) camera.position.y -= 0.2;
- if (IsKeyDown(KEY_DOWN)) camera.position.y += 0.2;
+ camera = UpdateCamera(0); // Update internal camera and our camera
//----------------------------------------------------------------------------------
// Draw
@@ -49,8 +49,7 @@ int main()
Begin3dMode(camera);
- //DrawBillboard(camera, lena, billPosition, 1.0, WHITE);
- DrawBillboardRec(camera, lena, eyesRec, billPosition, 4.0, WHITE);
+ DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
DrawGrid(10.0, 1.0); // Draw a grid
@@ -64,7 +63,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- UnloadTexture(lena); // Unload texture
+ UnloadTexture(bill); // Unload texture
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/examples/models_billboard.png b/examples/models_billboard.png
new file mode 100644
index 00000000..f1ed9239
--- /dev/null
+++ b/examples/models_billboard.png
Binary files differ
diff --git a/examples/models_cubicmap.c b/examples/models_cubicmap.c
index e1f2e7df..3b20907b 100644
--- a/examples/models_cubicmap.c
+++ b/examples/models_cubicmap.c
@@ -5,7 +5,7 @@
* This example has been created using raylib 1.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
diff --git a/examples/models_heightmap.c b/examples/models_heightmap.c
index 297ada32..7de31a8e 100644
--- a/examples/models_heightmap.c
+++ b/examples/models_heightmap.c
@@ -5,7 +5,7 @@
* This example has been created using raylib 1.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/resources/billboard.png b/examples/resources/billboard.png
new file mode 100644
index 00000000..e2fe398d
--- /dev/null
+++ b/examples/resources/billboard.png
Binary files differ
diff --git a/examples/resources/smoke.png b/examples/resources/smoke.png
new file mode 100644
index 00000000..7bad8c68
--- /dev/null
+++ b/examples/resources/smoke.png
Binary files differ
diff --git a/examples/textures_particles_trail_blending.c b/examples/textures_particles_trail_blending.c
new file mode 100644
index 00000000..1e7abf7e
--- /dev/null
+++ b/examples/textures_particles_trail_blending.c
@@ -0,0 +1,132 @@
+/*******************************************************************************************
+*
+* raylib example - particles trail blending
+*
+* This example has been created using raylib 1.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#define MAX_PARTICLES 200
+
+typedef struct {
+ Vector2 position;
+ Color color;
+ float alpha;
+ float size;
+ float rotation;
+ bool active; // NOTE: Use it to activate/deactive particle
+} Particle;
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles trail blending");
+
+ // Particles pool, reuse them!
+ Particle mouseTail[MAX_PARTICLES];
+
+ // 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;
+ mouseTail[i].rotation = GetRandomValue(0, 360);
+ mouseTail[i].active = false;
+ }
+
+ float gravity = 3;
+
+ Texture2D smoke = LoadTexture("resources/smoke.png");
+
+ int blending = BLEND_ALPHA;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // 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;
+ }
+ }
+
+ if (IsKeyPressed(KEY_SPACE))
+ {
+ if (blending == BLEND_ALPHA) blending = BLEND_ADDITIVE;
+ else blending = BLEND_ALPHA;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(DARKGRAY);
+
+ SetBlendMode(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));
+ }
+
+ DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, RAYWHITE);
+
+ if (blending == BLEND_ALPHA) DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, RAYWHITE);
+ else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(smoke);
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/textures_particles_trail_blending.png b/examples/textures_particles_trail_blending.png
new file mode 100644
index 00000000..b0c40fd2
--- /dev/null
+++ b/examples/textures_particles_trail_blending.png
Binary files differ
diff --git a/examples/textures_to_image.c b/examples/textures_to_image.c
new file mode 100644
index 00000000..3ea8e017
--- /dev/null
+++ b/examples/textures_to_image.c
@@ -0,0 +1,68 @@
+/*******************************************************************************************
+*
+* raylib [textures] example - Retrieve image data from texture: GetTextureData()
+*
+* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
+*
+* This example has been created using raylib 1.1 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image");
+
+ // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
+
+ Image image = LoadImage("resources/raylib_logo.png"); // Load image data into CPU memory (RAM)
+ Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM)
+ UnloadImage(image); // Unload image data from CPU memory (RAM)
+
+ image = GetTextureData(texture); // Retrieve image data from GPU memory (VRAM -> RAM)
+ UnloadTexture(texture); // Unload texture from GPU memory (VRAM)
+
+ texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM)
+ UnloadImage(image); // Unload retrieved image data from CPU memory (RAM)
+ //---------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // TODO: Update your variables here
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
+
+ DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(texture); // Texture unloading
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/textures_to_image.png b/examples/textures_to_image.png
new file mode 100644
index 00000000..410103a5
--- /dev/null
+++ b/examples/textures_to_image.png
Binary files differ