summaryrefslogtreecommitdiffhomepage
path: root/examples/core
diff options
context:
space:
mode:
authorRay <[email protected]>2023-09-08 13:27:13 +0200
committerRay <[email protected]>2023-09-08 13:27:13 +0200
commit1896268775e59d00b2b4f3fea0bc244eee1a1cb4 (patch)
treedd695865a0545a29d08901563d1b96c578814564 /examples/core
parent2d5d0c2999717ea28924d6cdd47bab014478cc32 (diff)
downloadraylib-1896268775e59d00b2b4f3fea0bc244eee1a1cb4.tar.gz
raylib-1896268775e59d00b2b4f3fea0bc244eee1a1cb4.zip
Reviewed examples for consistency
Diffstat (limited to 'examples/core')
-rw-r--r--examples/core/core_2d_camera_split_screen.c167
-rw-r--r--examples/core/core_2d_camera_split_screen.pngbin0 -> 21543 bytes
-rw-r--r--examples/core/core_3d_camera_free.c2
-rw-r--r--examples/core/core_3d_camera_split_screen.c (renamed from examples/core/core_split_screen.c)87
-rw-r--r--examples/core/core_3d_camera_split_screen.pngbin0 -> 16165 bytes
-rw-r--r--examples/core/core_camera_2d_split_screen.c137
-rw-r--r--examples/core/core_camera_2d_split_screen.pngbin20010 -> 0 bytes
-rw-r--r--examples/core/core_split_screen.pngbin21609 -> 0 bytes
8 files changed, 223 insertions, 170 deletions
diff --git a/examples/core/core_2d_camera_split_screen.c b/examples/core/core_2d_camera_split_screen.c
new file mode 100644
index 00000000..57a0dfd3
--- /dev/null
+++ b/examples/core/core_2d_camera_split_screen.c
@@ -0,0 +1,167 @@
+/*******************************************************************************************
+*
+* raylib [core] example - 2d camera split screen
+*
+* Addapted from the core_3d_camera_split_screen example:
+* https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_split_screen.c
+*
+* Example originally created with raylib 4.5, last time updated with raylib 4.5
+*
+* Example contributed by Gabriel dos Santos Sanches (@gabrielssanches) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
+* BSD-like license that allows static linking with closed source software
+*
+* Copyright (c) 2023 Gabriel dos Santos Sanches (@gabrielssanches)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#define PLAYER_SIZE 40
+
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 440;
+
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera split screen");
+
+ Rectangle player1 = { 200, 200, PLAYER_SIZE, PLAYER_SIZE };
+ Rectangle player2 = { 250, 200, PLAYER_SIZE, PLAYER_SIZE };
+
+ Camera2D camera1 = { 0 };
+ camera1.target = (Vector2){ player1.x, player1.y };
+ camera1.offset = (Vector2){ 200.0f, 200.0f };
+ camera1.rotation = 0.0f;
+ camera1.zoom = 1.0f;
+
+ Camera2D camera2 = { 0 };
+ camera2.target = (Vector2){ player2.x, player2.y };
+ camera2.offset = (Vector2){ 200.0f, 200.0f };
+ camera2.rotation = 0.0f;
+ camera2.zoom = 1.0f;
+
+ RenderTexture screenCamera1 = LoadRenderTexture(screenWidth/2, screenHeight);
+ RenderTexture screenCamera2 = LoadRenderTexture(screenWidth/2, screenHeight);
+
+ // Build a flipped rectangle the size of the split view to use for drawing later
+ Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenCamera1.texture.width, (float)-screenCamera1.texture.height };
+
+ 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
+ //----------------------------------------------------------------------------------
+ if (IsKeyDown(KEY_S)) player1.y += 3.0f;
+ else if (IsKeyDown(KEY_W)) player1.y -= 3.0f;
+ if (IsKeyDown(KEY_D)) player1.x += 3.0f;
+ else if (IsKeyDown(KEY_A)) player1.x -= 3.0f;
+
+ if (IsKeyDown(KEY_UP)) player2.y -= 3.0f;
+ else if (IsKeyDown(KEY_DOWN)) player2.y += 3.0f;
+ if (IsKeyDown(KEY_RIGHT)) player2.x += 3.0f;
+ else if (IsKeyDown(KEY_LEFT)) player2.x -= 3.0f;
+
+ camera1.target = (Vector2){ player1.x, player1.y };
+ camera2.target = (Vector2){ player2.x, player2.y };
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginTextureMode(screenCamera1);
+ ClearBackground(RAYWHITE);
+
+ BeginMode2D(camera1);
+
+ // Draw full scene with first camera
+ for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
+ {
+ DrawLineV((Vector2){PLAYER_SIZE*i, 0}, (Vector2){PLAYER_SIZE*i, screenHeight}, LIGHTGRAY);
+ }
+
+ for (int i = 0; i < screenHeight/PLAYER_SIZE + 1; i++)
+ {
+ DrawLineV((Vector2){0, PLAYER_SIZE*i}, (Vector2){screenWidth, PLAYER_SIZE*i}, LIGHTGRAY);
+ }
+
+ for (int i = 0; i < screenWidth/PLAYER_SIZE; i++)
+ {
+ for (int j = 0; j < screenHeight/PLAYER_SIZE; j++)
+ {
+ DrawText(TextFormat("[%i,%i]", i, j), 10 + PLAYER_SIZE*i, 15 + PLAYER_SIZE*j, 10, LIGHTGRAY);
+ }
+ }
+
+ DrawRectangleRec(player1, RED);
+ DrawRectangleRec(player2, BLUE);
+ EndMode2D();
+
+ DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
+ DrawText("PLAYER1: W/S/A/D to move", 10, 10, 10, MAROON);
+
+ EndTextureMode();
+
+ BeginTextureMode(screenCamera2);
+ ClearBackground(RAYWHITE);
+
+ BeginMode2D(camera2);
+
+ // Draw full scene with second camera
+ for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
+ {
+ DrawLineV((Vector2){PLAYER_SIZE*i, 0}, (Vector2){PLAYER_SIZE*i, screenHeight}, LIGHTGRAY);
+ }
+
+ for (int i = 0; i < screenHeight/PLAYER_SIZE + 1; i++)
+ {
+ DrawLineV((Vector2){0, PLAYER_SIZE*i}, (Vector2){screenWidth, PLAYER_SIZE*i}, LIGHTGRAY);
+ }
+
+ for (int i = 0; i < screenWidth/PLAYER_SIZE; i++)
+ {
+ for (int j = 0; j < screenHeight/PLAYER_SIZE; j++)
+ {
+ DrawText(TextFormat("[%i,%i]", i, j), 10 + PLAYER_SIZE*i, 15 + PLAYER_SIZE*j, 10, LIGHTGRAY);
+ }
+ }
+
+ DrawRectangleRec(player1, RED);
+ DrawRectangleRec(player2, BLUE);
+
+ EndMode2D();
+
+ DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
+ DrawText("PLAYER2: UP/DOWN/LEFT/RIGHT to move", 10, 10, 10, DARKBLUE);
+
+ EndTextureMode();
+
+ // Draw both views render textures to the screen side by side
+ BeginDrawing();
+ ClearBackground(BLACK);
+
+ DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
+ DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
+
+ DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
+ EndDrawing();
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadRenderTexture(screenCamera1); // Unload render texture
+ UnloadRenderTexture(screenCamera2); // Unload render texture
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/core/core_2d_camera_split_screen.png b/examples/core/core_2d_camera_split_screen.png
new file mode 100644
index 00000000..a441e392
--- /dev/null
+++ b/examples/core/core_2d_camera_split_screen.png
Binary files differ
diff --git a/examples/core/core_3d_camera_free.c b/examples/core/core_3d_camera_free.c
index 59bd158a..78200a64 100644
--- a/examples/core/core_3d_camera_free.c
+++ b/examples/core/core_3d_camera_free.c
@@ -72,7 +72,7 @@ int main(void)
DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY);
DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY);
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY);
- DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY);
+ //DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY);
DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY);
EndDrawing();
diff --git a/examples/core/core_split_screen.c b/examples/core/core_3d_camera_split_screen.c
index 50cfcf7a..d625e1c0 100644
--- a/examples/core/core_split_screen.c
+++ b/examples/core/core_3d_camera_split_screen.c
@@ -1,6 +1,6 @@
/*******************************************************************************************
*
-* raylib [core] example - split screen
+* raylib [core] example - 3d cmaera split screen
*
* Example originally created with raylib 3.7, last time updated with raylib 4.0
*
@@ -15,32 +15,6 @@
#include "raylib.h"
-Camera cameraPlayer1 = { 0 };
-Camera cameraPlayer2 = { 0 };
-
-// Scene drawing
-void DrawScene(void)
-{
- int count = 5;
- float spacing = 4;
-
- // Grid of cube trees on a plane to make a "world"
- DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
-
- for (float x = -count*spacing; x <= count*spacing; x += spacing)
- {
- for (float z = -count*spacing; z <= count*spacing; z += spacing)
- {
- DrawCube((Vector3) { x, 1.5f, z }, 1, 1, 1, LIME);
- DrawCube((Vector3) { x, 0.5f, z }, 0.25f, 1, 0.25f, BROWN);
- }
- }
-
- // Draw a cube at each player's position
- DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
- DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
-}
-
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
@@ -51,9 +25,10 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib [core] example - split screen");
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera split screen");
// Setup player 1 camera and screen
+ Camera cameraPlayer1 = { 0 };
cameraPlayer1.fovy = 45.0f;
cameraPlayer1.up.y = 1.0f;
cameraPlayer1.target.y = 1.0f;
@@ -63,6 +38,7 @@ int main(void)
RenderTexture screenPlayer1 = LoadRenderTexture(screenWidth/2, screenHeight);
// Setup player two camera and screen
+ Camera cameraPlayer2 = { 0 };
cameraPlayer2.fovy = 45.0f;
cameraPlayer2.up.y = 1.0f;
cameraPlayer2.target.y = 3.0f;
@@ -73,6 +49,10 @@ int main(void)
// Build a flipped rectangle the size of the split view to use for drawing later
Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenPlayer1.texture.width, (float)-screenPlayer1.texture.height };
+
+ // Grid data
+ int count = 5;
+ float spacing = 4;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -116,26 +96,69 @@ int main(void)
// Draw Player1 view to the render texture
BeginTextureMode(screenPlayer1);
ClearBackground(SKYBLUE);
+
BeginMode3D(cameraPlayer1);
- DrawScene();
+
+ // Draw scene: grid of cube trees on a plane to make a "world"
+ DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
+
+ for (float x = -count*spacing; x <= count*spacing; x += spacing)
+ {
+ for (float z = -count*spacing; z <= count*spacing; z += spacing)
+ {
+ DrawCube((Vector3) { x, 1.5f, z }, 1, 1, 1, LIME);
+ DrawCube((Vector3) { x, 0.5f, z }, 0.25f, 1, 0.25f, BROWN);
+ }
+ }
+
+ // Draw a cube at each player's position
+ DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
+ DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
+
EndMode3D();
- DrawText("PLAYER1 W/S to move", 10, 10, 20, RED);
+
+ DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
+ DrawText("PLAYER1: W/S to move", 10, 10, 20, MAROON);
+
EndTextureMode();
// Draw Player2 view to the render texture
BeginTextureMode(screenPlayer2);
ClearBackground(SKYBLUE);
+
BeginMode3D(cameraPlayer2);
- DrawScene();
+
+ // Draw scene: grid of cube trees on a plane to make a "world"
+ DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
+
+ for (float x = -count*spacing; x <= count*spacing; x += spacing)
+ {
+ for (float z = -count*spacing; z <= count*spacing; z += spacing)
+ {
+ DrawCube((Vector3) { x, 1.5f, z }, 1, 1, 1, LIME);
+ DrawCube((Vector3) { x, 0.5f, z }, 0.25f, 1, 0.25f, BROWN);
+ }
+ }
+
+ // Draw a cube at each player's position
+ DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
+ DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
+
EndMode3D();
- DrawText("PLAYER2 UP/DOWN to move", 10, 10, 20, BLUE);
+
+ DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
+ DrawText("PLAYER2: UP/DOWN to move", 10, 10, 20, DARKBLUE);
+
EndTextureMode();
// Draw both views render textures to the screen side by side
BeginDrawing();
ClearBackground(BLACK);
+
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
+
+ DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
EndDrawing();
}
diff --git a/examples/core/core_3d_camera_split_screen.png b/examples/core/core_3d_camera_split_screen.png
new file mode 100644
index 00000000..bc323d6a
--- /dev/null
+++ b/examples/core/core_3d_camera_split_screen.png
Binary files differ
diff --git a/examples/core/core_camera_2d_split_screen.c b/examples/core/core_camera_2d_split_screen.c
deleted file mode 100644
index 5f505956..00000000
--- a/examples/core/core_camera_2d_split_screen.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************************
-*
-* raylib [core] example - split screen
-*
-* Addapted from the Split Screen example (https://github.com/raysan5/raylib/blob/master/examples/core/core_split_screen.c)
-*
-* Example originally created with raylib 4.5, last time updated with raylib 4.5
-*
-* Example contributed by Jeffery Myers (@JeffM2501) and reviewed by Ramon Santamaria (@raysan5)
-*
-* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
-* BSD-like license that allows static linking with closed source software
-*
-* Copyright (c) 2021-2023 Jeffery Myers (@JeffM2501)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include <stdio.h>
-
-#define PLAYER_SIZE 40
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main(void)
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- const int screenWidth = 800;
- const int screenHeight = 440;
-
- InitWindow(screenWidth, screenHeight, "raylib [core] example - camera 2D split screen");
-
- Rectangle player1 = { 200, 200, PLAYER_SIZE, PLAYER_SIZE };
- Rectangle player2 = { 250, 200, PLAYER_SIZE, PLAYER_SIZE };
-
- Camera2D camera1 = { 0 };
- camera1.target = (Vector2){ player1.x, player1.y };
- camera1.offset = (Vector2){ 200.0f, 200.0f };
- camera1.rotation = 0.0f;
- camera1.zoom = 1.0f;
-
- Camera2D camera2 = { 0 };
- camera2.target = (Vector2){ player2.x, player2.y };
- camera2.offset = (Vector2){ 200.0f, 200.0f };
- camera2.rotation = 0.0f;
- camera2.zoom = 1.0f;
-
- RenderTexture screenCamera1 = LoadRenderTexture(screenWidth / 2, screenHeight);
- RenderTexture screenCamera2 = LoadRenderTexture(screenWidth / 2, screenHeight);
-
- // Build a flipped rectangle the size of the split view to use for drawing later
- Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenCamera1.texture.width, (float)-screenCamera1.texture.height };
-
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
- //--------------------------------------------------------------------------------------
- void DrawScene(void) {
- for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
- {
- DrawLineV((Vector2){PLAYER_SIZE*i, 0}, (Vector2){PLAYER_SIZE*i, screenHeight}, LIGHTGRAY);
- }
-
- for (int i = 0; i < screenHeight/PLAYER_SIZE + 1; i++)
- {
- DrawLineV((Vector2){0, PLAYER_SIZE*i}, (Vector2){screenWidth, PLAYER_SIZE*i}, LIGHTGRAY);
- }
-
- for (int i = 0; i < screenWidth/PLAYER_SIZE; i++)
- {
- for (int j = 0; j < screenHeight/PLAYER_SIZE; j++)
- {
- char coordinate_str[8];
- snprintf(coordinate_str, sizeof(coordinate_str), "%d,%d", i, j);
- DrawText(coordinate_str, 10 + PLAYER_SIZE*i, 10 + PLAYER_SIZE*j, 10, LIGHTGRAY);
- }
- }
-
- DrawRectangleRec(player1, RED);
- DrawRectangleRec(player2, BLUE);
- }
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- if (IsKeyDown(KEY_S)) player1.y += 3;
- else if (IsKeyDown(KEY_W)) player1.y -= 3;
- if (IsKeyDown(KEY_D)) player1.x += 3;
- else if (IsKeyDown(KEY_A)) player1.x -= 3;
-
- if (IsKeyDown(KEY_UP)) player2.y += 3;
- else if (IsKeyDown(KEY_DOWN)) player2.y -= 3;
- if (IsKeyDown(KEY_RIGHT)) player2.x += 3;
- else if (IsKeyDown(KEY_LEFT)) player2.x -= 3;
-
- camera1.target = (Vector2){ player1.x, player1.y };
- camera2.target = (Vector2){ player2.x, player2.y };
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginTextureMode(screenCamera1);
- ClearBackground(RAYWHITE);
- BeginMode2D(camera1);
- DrawScene();
- EndMode2D();
- DrawText("PLAYER1 W/S/A/D to move", 10, 10, 15, RED);
- EndTextureMode();
-
- BeginTextureMode(screenCamera2);
- ClearBackground(RAYWHITE);
- BeginMode2D(camera2);
- DrawScene();
- EndMode2D();
- DrawText("PLAYER2 UP/DOWN/LEFT/RIGHT to move", 10, 10, 15, BLUE);
- EndTextureMode();
-
- // Draw both views render textures to the screen side by side
- BeginDrawing();
- ClearBackground(BLACK);
- DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
- DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
- EndDrawing();
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadRenderTexture(screenCamera1); // Unload render texture
- UnloadRenderTexture(screenCamera2); // Unload render texture
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
diff --git a/examples/core/core_camera_2d_split_screen.png b/examples/core/core_camera_2d_split_screen.png
deleted file mode 100644
index ed5aaa58..00000000
--- a/examples/core/core_camera_2d_split_screen.png
+++ /dev/null
Binary files differ
diff --git a/examples/core/core_split_screen.png b/examples/core/core_split_screen.png
deleted file mode 100644
index eace9027..00000000
--- a/examples/core/core_split_screen.png
+++ /dev/null
Binary files differ