Przeglądaj źródła

New examples added (with some resources)

pull/26/head
raysan5 9 lat temu
rodzic
commit
ca402e9d36
22 zmienionych plików z 184 dodań i 76 usunięć
  1. +75
    -0
      examples/core_3d_camera_free.c
  2. BIN
      examples/core_3d_camera_free.png
  3. +20
    -11
      examples/core_3d_picking.c
  4. BIN
      examples/core_3d_picking.png
  5. +24
    -18
      examples/models_cubicmap.c
  6. BIN
      examples/models_cubicmap.png
  7. +16
    -13
      examples/models_heightmap.c
  8. BIN
      examples/models_heightmap.png
  9. +1
    -1
      examples/models_obj_loading.c
  10. BIN
      examples/models_obj_loading.png
  11. BIN
      examples/resources/cubicmap.png
  12. BIN
      examples/resources/cubicmap_atlas.png
  13. BIN
      examples/resources/guybrush.png
  14. BIN
      examples/resources/heightmap.png
  15. BIN
      examples/text_font_select.png
  16. +1
    -1
      examples/text_format_text.c
  17. +1
    -1
      examples/text_rbmf_fonts.c
  18. BIN
      examples/text_rbmf_fonts.png
  19. +27
    -19
      examples/textures_rectangle.c
  20. BIN
      examples/textures_rectangle.png
  21. +19
    -12
      examples/textures_srcrec_dstrec.c
  22. BIN
      examples/textures_srcrec_dstrec.png

+ 75
- 0
examples/core_3d_camera_free.c Wyświetl plik

@ -0,0 +1,75 @@
/*******************************************************************************************
*
* raylib [core] example - Initialize 3d camera free
*
* 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)
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
SetCameraMode(CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
camera = UpdateCamera(0); // Update internal camera and our camera
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(WHITE);
Begin3dMode(camera);
DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawGrid(10.0, 1.0);
End3dMode();
DrawText("Free camera default controls:", 20, 20, 10, GRAY);
DrawText("- Mouse Wheel to Zoom in-out", 40, 50, 10, DARKGRAY);
DrawText("- Mouse Wheel Pressed to Pan", 40, 70, 10, DARKGRAY);
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 90, 10, DARKGRAY);
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 110, 10, DARKGRAY);
DrawText("- Z to zoom to (0, 0, 0)", 40, 130, 10, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

BIN
examples/core_3d_camera_free.png Wyświetl plik

Przed Po
Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 24 KiB

+ 20
- 11
examples/core_3d_picking.c Wyświetl plik

@ -2,7 +2,7 @@
*
* raylib [core] example - Picking in 3d mode
*
* This example has been created using raylib 1.0 (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)
@ -23,23 +23,30 @@ int main()
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
Vector3 cubePosition = { 0.0, 1.0, 0.0 };
Ray pickingLine;
Ray ray; // Picking line ray
SetCameraMode(CAMERA_FREE);
SetCameraMode(CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetTargetFPS(60);
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
//----------------------------------------------------------------------------------
camera = UpdateCamera(0);
camera = UpdateCamera(0); // Update internal camera and our camera
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pickingLine = GetMouseRay(GetMousePosition(), camera);
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
// NOTE: This function is NOT WORKING properly!
ray = GetMouseRay(GetMousePosition(), camera);
// TODO: Check collision between ray and box
}
//----------------------------------------------------------------------------------
// Draw
@ -50,14 +57,16 @@ int main()
Begin3dMode(camera);
DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawCube(cubePosition, 2, 2, 2, GRAY);
DrawCubeWires(cubePosition, 2, 2, 2, DARKGRAY);
DrawGrid(10.0, 1.0);
DrawRay(pickingLine, MAROON);
DrawRay(ray, MAROON);
End3dMode();
DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY);
DrawFPS(10, 10);

BIN
examples/core_3d_picking.png Wyświetl plik

Przed Po
Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 23 KiB

+ 24
- 18
examples/models_cubicmap.c Wyświetl plik

@ -2,7 +2,7 @@
*
* raylib [models] example - Cubicmap loading and drawing
*
* 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)
@ -21,15 +21,22 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
// Define the camera to look into our 3d world
Camera camera = {{ 7.0, 7.0, 7.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 16.0, 14.0, 16.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Image image = LoadImage("resources/cubicmap.png"); // Load cubesmap image (RAM)
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image)
SetModelTexture(&map, texture); // Bind texture to model
Vector3 mapPosition = { -1, 0.0, -1 }; // Set model position
// NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
SetModelTexture(&map, texture); // Bind texture to map model
Vector3 mapPosition = { -16, 0.0, -8 }; // Set model position
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -39,11 +46,7 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyDown(KEY_UP)) camera.position.y += 0.2f;
else if (IsKeyDown(KEY_DOWN)) camera.position.y -= 0.2f;
if (IsKeyDown(KEY_RIGHT)) camera.position.z += 0.2f;
else if (IsKeyDown(KEY_LEFT)) camera.position.z -= 0.2f;
camera = UpdateCamera(0); // Update internal camera and our camera
//----------------------------------------------------------------------------------
// Draw
@ -54,13 +57,15 @@ int main()
Begin3dMode(camera);
DrawModel(map, mapPosition, 1.0f, MAROON);
DrawGrid(10.0, 1.0);
DrawGizmo(mapPosition);
DrawModel(map, mapPosition, 1.0f, WHITE);
End3dMode();
DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE);
DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
DrawText("cubicmap image used to", 658, 90, 10, GRAY);
DrawText("generate map 3d model", 658, 104, 10, GRAY);
DrawFPS(10, 10);
@ -70,8 +75,9 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture
UnloadModel(map); // Unload model
UnloadTexture(cubicmap); // Unload cubicmap texture
UnloadTexture(texture); // Unload map texture
UnloadModel(map); // Unload map model
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

BIN
examples/models_cubicmap.png Wyświetl plik

Przed Po
Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 27 KiB Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 403 KiB

+ 16
- 13
examples/models_heightmap.c Wyświetl plik

@ -2,10 +2,10 @@
*
* raylib [models] example - Heightmap loading and drawing
*
* This example has been created using raylib 1.1 (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 (n">Ray San - raysan@raysanweb.com)
* Copyright (c) 2014 Ramon Santamaria (err">@raysan5)
*
********************************************************************************************/
@ -20,16 +20,19 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
// Define the camera to look into our 3d world
Camera camera = {{ 10.0, 12.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
// Define our custom camera to look into our 3d world
Camera camera = {{ 24.0, 18.0, 24.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
Model map = LoadHeightmap(image, 4); // Load heightmap model
Model map = LoadHeightmap(image, 32); // Load heightmap model
SetModelTexture(&map, texture); // Bind texture to model
Vector3 mapPosition = { -4, 0.0, -4 }; // Set model position
Vector3 mapPosition = { -16, 0.0, -16 }; // Set model position (depends on model scaling!)
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -39,7 +42,7 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
o">// ...
n">camera = UpdateCamera(0); // Update internal camera and our camera
//----------------------------------------------------------------------------------
// Draw
@ -50,13 +53,13 @@ int main()
Begin3dMode(camera);
DrawModel(map, mapPosition, 0.5f, MAROON);
DrawGrid(10.0, 1.0);
DrawGizmo(mapPosition);
// NOTE: Model is scaled to 1/4 of its original size (128x128 units)
DrawModel(map, mapPosition, 1/4.0f, RED);
End3dMode();
DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE);
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN);
DrawFPS(10, 10);

BIN
examples/models_heightmap.png Wyświetl plik

Przed Po
Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 31 KiB Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 121 KiB

+ 1
- 1
examples/models_obj_loading.c Wyświetl plik

@ -2,7 +2,7 @@
*
* raylib [models] example - Load and draw a 3d model (OBJ)
*
* This example has been created using raylib 1.0 (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 (@raysan5)

BIN
examples/models_obj_loading.png Wyświetl plik

Przed Po
Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 60 KiB Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 125 KiB

BIN
examples/resources/cubicmap.png Wyświetl plik

Przed Po
Szerokość: 4  |  Wysokość: 4  |  Rozmiar: 173 B Szerokość: 32  |  Wysokość: 16  |  Rozmiar: 201 B

BIN
examples/resources/cubicmap_atlas.png Wyświetl plik

Przed Po
Szerokość: 256  |  Wysokość: 256  |  Rozmiar: 36 KiB

BIN
examples/resources/guybrush.png Wyświetl plik

Przed Po
Szerokość: 728  |  Wysokość: 150  |  Rozmiar: 83 KiB

BIN
examples/resources/heightmap.png Wyświetl plik

Przed Po
Szerokość: 16  |  Wysokość: 16  |  Rozmiar: 1.3 KiB Szerokość: 128  |  Wysokość: 128  |  Rozmiar: 11 KiB

BIN
examples/text_font_select.png Wyświetl plik

Przed Po
Szerokość: 800  |  Wysokość: 150  |  Rozmiar: 3.0 KiB Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 16 KiB

+ 1
- 1
examples/text_format_text.c Wyświetl plik

@ -5,7 +5,7 @@
* 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 (n">Ray San - raysan@raysanweb.com)
* Copyright (c) 2014 Ramon Santamaria (err">@raysan5)
*
********************************************************************************************/

+ 1
- 1
examples/text_rbmf_fonts.c Wyświetl plik

@ -8,7 +8,7 @@
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (n">Ray San - raysan@raysanweb.com)
* Copyright (c) 2014 Ramon Santamaria (err">@raysan5)
*
********************************************************************************************/

BIN
examples/text_rbmf_fonts.png Wyświetl plik

Przed Po
Szerokość: 560  |  Wysokość: 800  |  Rozmiar: 14 KiB Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 19 KiB

+ 27
- 19
examples/textures_rectangle.c Wyświetl plik

@ -5,7 +5,7 @@
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (n">Ray San - raysan@raysanweb.com)
* Copyright (c) 2014 Ramon Santamaria (err">@raysan5)
*
********************************************************************************************/
@ -20,15 +20,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle");
const char textLine1[] = "Lena image is a standard test image which has been in use since 1973.";
const char textLine2[] = "It comprises 512x512 pixels, and it is probably the most widely used";
const char textLine3[] = "test image for all sorts of image processing algorithms.";
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D texture = LoadTexture("resources/lena.png"); // Texture loading
Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
Rectangle eyesRec = { 225, 240, 155, 50 }; // Part of the texture to draw
Vector2 position = { 369, 241 };
Vector2 position = { 350, 240 };
Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height };
int currentFrame = 0;
//--------------------------------------------------------------------------------------
// Main game loop
@ -36,7 +33,14 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
if (IsKeyPressed(KEY_RIGHT))
{
currentFrame++;
if (currentFrame > 6) currentFrame = 0;
frameRec.x = currentFrame*guybrush.width/7;
}
//----------------------------------------------------------------------------------
// Draw
@ -45,15 +49,19 @@ int main()
ClearBackground(RAYWHITE);
DrawText("LENA", 220, 100, 20, PINK);
DrawTexture(texture, screenWidth/2 - 256, 0, Fade(WHITE, 0.1f)); // Draw background image
DrawTextureRec(texture, eyesRec, position, WHITE); // Draw eyes part of image
DrawText(textLine1, 220, 140, 10, DARKGRAY);
DrawText(textLine2, 220, 160, 10, DARKGRAY);
DrawText(textLine3, 220, 180, 10, DARKGRAY);
DrawTexture(guybrush, 35, 40, WHITE);
DrawRectangleLines(35, 40, guybrush.width, guybrush.height, LIME);
DrawTextureRec(guybrush, frameRec, position, WHITE); // Draw part of the texture
DrawRectangleLines(35 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED);
DrawText("PRESS RIGHT KEY to", 540, 310, 10, GRAY);
DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, GRAY);
DrawText("Guybrush Ulysses Threepwood,", 100, 300, 10, GRAY);
DrawText("main character of the Monkey Island series", 80, 320, 10, GRAY);
DrawText("of computer adventure games by LucasArts.", 80, 340, 10, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
@ -61,7 +69,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading
UnloadTexture(guybrush); // Texture unloading
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

BIN
examples/textures_rectangle.png Wyświetl plik

Przed Po
Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 75 KiB Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 107 KiB

+ 19
- 12
examples/textures_srcrec_dstrec.c Wyświetl plik

@ -5,7 +5,7 @@
* 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 (n">Ray San - raysan@raysanweb.com)
* Copyright (c) 2014 Ramon Santamaria (err">@raysan5)
*
********************************************************************************************/
@ -21,16 +21,23 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading
Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
int frameWidth = guybrush.width/7;
int frameHeight = guybrush.height;
// NOTE: Source rectangle (part of the texture to use for drawing)
Rectangle sourceRec = { 128, 128, 128, 128 };
Rectangle sourceRec = { 0, 0, frameWidth, frameHeight };
// NOTE: Destination rectangle (screen rectangle where drawing part of texture)
Rectangle destRec = { screenWidth/2, screenHeight/2, 256, 256 };
// NOTE: Origin of the texture in case of rotation, it's relative to destination rectangle size
Vector2 origin = { 128, 128 };
Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 };
// NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
Vector2 origin = { frameWidth, frameHeight };
int rotation = 0;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
@ -38,7 +45,7 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
o">// TODO: Update your variables here
n">rotation++;
//----------------------------------------------------------------------------------
// Draw
@ -48,10 +55,10 @@ int main()
ClearBackground(RAYWHITE);
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
DrawTexturePro(texture, sourceRec, destRec, origin, mi">45, LIGHTGRAY);
DrawTexturePro(guybrush, sourceRec, destRec, origin, n">rotation, WHITE);
DrawLine(destRec.x, 0, destRec.x, screenHeight, RED);
DrawLine(0, destRec.y, screenWidth, destRec.y, RED);
DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY);
DrawLine(0, destRec.y, screenWidth, destRec.y, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
@ -59,7 +66,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading
UnloadTexture(guybrush); // Texture unloading
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

BIN
examples/textures_srcrec_dstrec.png Wyświetl plik

Przed Po
Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 19 KiB Szerokość: 800  |  Wysokość: 450  |  Rozmiar: 47 KiB

Ładowanie…
Anuluj
Zapisz