aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2015-08-28 14:16:28 +0200
committerraysan5 <raysan5@gmail.com>2015-08-28 14:16:28 +0200
commitca402e9d360d519e37e2fb1d8073ebec56b0014c (patch)
treef5b0c858c49e794add2006a1cc8ec094f1a0a950
parent6ac5d3bc06913469f6e32f68a4c356e1c1da24b8 (diff)
downloadraylib-ca402e9d360d519e37e2fb1d8073ebec56b0014c.tar.gz
raylib-ca402e9d360d519e37e2fb1d8073ebec56b0014c.zip
New examples added (with some resources)
-rw-r--r--examples/core_3d_camera_free.c75
-rw-r--r--examples/core_3d_camera_free.pngbin0 -> 25106 bytes
-rw-r--r--examples/core_3d_picking.c31
-rw-r--r--examples/core_3d_picking.pngbin0 -> 23100 bytes
-rw-r--r--examples/models_cubicmap.c42
-rw-r--r--examples/models_cubicmap.pngbin27438 -> 412536 bytes
-rw-r--r--examples/models_heightmap.c29
-rw-r--r--examples/models_heightmap.pngbin31972 -> 123602 bytes
-rw-r--r--examples/models_obj_loading.c2
-rw-r--r--examples/models_obj_loading.pngbin61860 -> 127720 bytes
-rw-r--r--examples/resources/cubicmap.pngbin173 -> 201 bytes
-rw-r--r--examples/resources/cubicmap_atlas.pngbin0 -> 37225 bytes
-rw-r--r--examples/resources/guybrush.pngbin0 -> 85247 bytes
-rw-r--r--examples/resources/heightmap.pngbin1362 -> 10920 bytes
-rw-r--r--examples/text_font_select.pngbin3097 -> 16261 bytes
-rw-r--r--examples/text_format_text.c2
-rw-r--r--examples/text_rbmf_fonts.c2
-rw-r--r--examples/text_rbmf_fonts.pngbin14877 -> 19458 bytes
-rw-r--r--examples/textures_rectangle.c46
-rw-r--r--examples/textures_rectangle.pngbin76980 -> 109993 bytes
-rw-r--r--examples/textures_srcrec_dstrec.c31
-rw-r--r--examples/textures_srcrec_dstrec.pngbin19183 -> 48478 bytes
22 files changed, 184 insertions, 76 deletions
diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c
new file mode 100644
index 00000000..9e123b04
--- /dev/null
+++ b/examples/core_3d_camera_free.c
@@ -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;
+} \ No newline at end of file
diff --git a/examples/core_3d_camera_free.png b/examples/core_3d_camera_free.png
new file mode 100644
index 00000000..afb5a7c5
--- /dev/null
+++ b/examples/core_3d_camera_free.png
Binary files differ
diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c
index a7a96fa9..056dcd65 100644
--- a/examples/core_3d_picking.c
+++ b/examples/core_3d_picking.c
@@ -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);
diff --git a/examples/core_3d_picking.png b/examples/core_3d_picking.png
new file mode 100644
index 00000000..828c41a8
--- /dev/null
+++ b/examples/core_3d_picking.png
Binary files differ
diff --git a/examples/models_cubicmap.c b/examples/models_cubicmap.c
index 62f7b076..e1f2e7df 100644
--- a/examples/models_cubicmap.c
+++ b/examples/models_cubicmap.c
@@ -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
//--------------------------------------------------------------------------------------
diff --git a/examples/models_cubicmap.png b/examples/models_cubicmap.png
index f686ba21..9cb854cb 100644
--- a/examples/models_cubicmap.png
+++ b/examples/models_cubicmap.png
Binary files differ
diff --git a/examples/models_heightmap.c b/examples/models_heightmap.c
index a23656a5..297ada32 100644
--- a/examples/models_heightmap.c
+++ b/examples/models_heightmap.c
@@ -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 (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2014 Ramon Santamaria (@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
//----------------------------------------------------------------------------------
- // ...
+ 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);
diff --git a/examples/models_heightmap.png b/examples/models_heightmap.png
index a32ec954..9ed04586 100644
--- a/examples/models_heightmap.png
+++ b/examples/models_heightmap.png
Binary files differ
diff --git a/examples/models_obj_loading.c b/examples/models_obj_loading.c
index 55501f65..ef024356 100644
--- a/examples/models_obj_loading.c
+++ b/examples/models_obj_loading.c
@@ -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)
diff --git a/examples/models_obj_loading.png b/examples/models_obj_loading.png
index da49c457..560348b4 100644
--- a/examples/models_obj_loading.png
+++ b/examples/models_obj_loading.png
Binary files differ
diff --git a/examples/resources/cubicmap.png b/examples/resources/cubicmap.png
index 87b95d50..b361c018 100644
--- a/examples/resources/cubicmap.png
+++ b/examples/resources/cubicmap.png
Binary files differ
diff --git a/examples/resources/cubicmap_atlas.png b/examples/resources/cubicmap_atlas.png
new file mode 100644
index 00000000..7ddfc83a
--- /dev/null
+++ b/examples/resources/cubicmap_atlas.png
Binary files differ
diff --git a/examples/resources/guybrush.png b/examples/resources/guybrush.png
new file mode 100644
index 00000000..32c9dced
--- /dev/null
+++ b/examples/resources/guybrush.png
Binary files differ
diff --git a/examples/resources/heightmap.png b/examples/resources/heightmap.png
index c17050fc..fe30f679 100644
--- a/examples/resources/heightmap.png
+++ b/examples/resources/heightmap.png
Binary files differ
diff --git a/examples/text_font_select.png b/examples/text_font_select.png
index 27bf9432..65040df6 100644
--- a/examples/text_font_select.png
+++ b/examples/text_font_select.png
Binary files differ
diff --git a/examples/text_format_text.c b/examples/text_format_text.c
index 516e3ecf..ca28be74 100644
--- a/examples/text_format_text.c
+++ b/examples/text_format_text.c
@@ -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 (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/text_rbmf_fonts.c b/examples/text_rbmf_fonts.c
index a521862b..74e3da6b 100644
--- a/examples/text_rbmf_fonts.c
+++ b/examples/text_rbmf_fonts.c
@@ -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 (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/text_rbmf_fonts.png b/examples/text_rbmf_fonts.png
index 58f6d83f..c047c503 100644
--- a/examples/text_rbmf_fonts.png
+++ b/examples/text_rbmf_fonts.png
Binary files differ
diff --git a/examples/textures_rectangle.c b/examples/textures_rectangle.c
index c0fb0d97..61cce9fb 100644
--- a/examples/textures_rectangle.c
+++ b/examples/textures_rectangle.c
@@ -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 (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2014 Ramon Santamaria (@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
//--------------------------------------------------------------------------------------
diff --git a/examples/textures_rectangle.png b/examples/textures_rectangle.png
index fb434a8e..d89404ab 100644
--- a/examples/textures_rectangle.png
+++ b/examples/textures_rectangle.png
Binary files differ
diff --git a/examples/textures_srcrec_dstrec.c b/examples/textures_srcrec_dstrec.c
index 1f0b56e2..72a209fb 100644
--- a/examples/textures_srcrec_dstrec.c
+++ b/examples/textures_srcrec_dstrec.c
@@ -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 (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2014 Ramon Santamaria (@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
//----------------------------------------------------------------------------------
- // TODO: Update your variables here
+ 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, 45, LIGHTGRAY);
+ DrawTexturePro(guybrush, sourceRec, destRec, origin, 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
//--------------------------------------------------------------------------------------
diff --git a/examples/textures_srcrec_dstrec.png b/examples/textures_srcrec_dstrec.png
index 95b7130e..7459d6ec 100644
--- a/examples/textures_srcrec_dstrec.png
+++ b/examples/textures_srcrec_dstrec.png
Binary files differ