summaryrefslogtreecommitdiffhomepage
path: root/examples/core
diff options
context:
space:
mode:
authorRay <[email protected]>2021-06-23 01:25:09 +0200
committerRay <[email protected]>2021-06-23 01:25:09 +0200
commit716e26aa37e352f0188824bc2de7dd3035f7413c (patch)
tree6239af3f4c247e30932b32c884baafb8b2eba8eb /examples/core
parentf989048bda60aeb74111ec687cd44ec92deacfe3 (diff)
downloadraylib-716e26aa37e352f0188824bc2de7dd3035f7413c.tar.gz
raylib-716e26aa37e352f0188824bc2de7dd3035f7413c.zip
Review BeginTextureMode() usage
Moved outside BeginDrawing()/EndDrawing() to illustrate drawing is happening to an external texture (not screen)
Diffstat (limited to 'examples/core')
-rw-r--r--examples/core/core_split_screen.c22
-rw-r--r--examples/core/core_vr_simulator.c28
-rw-r--r--examples/core/core_window_letterbox.c36
3 files changed, 39 insertions, 47 deletions
diff --git a/examples/core/core_split_screen.c b/examples/core/core_split_screen.c
index 0bfdb84a..31c3fb4b 100644
--- a/examples/core/core_split_screen.c
+++ b/examples/core/core_split_screen.c
@@ -89,7 +89,7 @@ int main(void)
// this moves thigns at 10 world units per second, regardless of the actual FPS
float offsetThisFrame = 10.0f*GetFrameTime();
- // Move player 1 forward and backwards (no turning)
+ // Move Player1 forward and backwards (no turning)
if (IsKeyDown(KEY_W))
{
cameraPlayer1.position.z += offsetThisFrame;
@@ -101,7 +101,7 @@ int main(void)
cameraPlayer1.target.z -= offsetThisFrame;
}
- // Move player 2 forward and backwards (no turning)
+ // Move Player2 forward and backwards (no turning)
if (IsKeyDown(KEY_UP))
{
cameraPlayer2.position.x += offsetThisFrame;
@@ -116,7 +116,7 @@ int main(void)
// Draw
//----------------------------------------------------------------------------------
- // Draw player 1's view to the render texture
+ // Draw Player1 view to the render texture
BeginTextureMode(screenPlayer1);
ClearBackground(SKYBLUE);
BeginMode3D(cameraPlayer1);
@@ -125,7 +125,7 @@ int main(void)
DrawText("PLAYER1 W/S to move", 0, 0, 20, RED);
EndTextureMode();
- // Draw player 2's view to the render texture
+ // Draw Player2 view to the render texture
BeginTextureMode(screenPlayer2);
ClearBackground(SKYBLUE);
BeginMode3D(cameraPlayer2);
@@ -134,21 +134,21 @@ int main(void)
DrawText("PLAYER2 UP/DOWN to move", 0, 0, 20, BLUE);
EndTextureMode();
- // Draw both view render textures to the screen side by side
+ // 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);
+ DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
+ DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
EndDrawing();
}
// De-Initialization
//--------------------------------------------------------------------------------------
- UnloadRenderTexture(screenPlayer1);
- UnloadRenderTexture(screenPlayer2);
- UnloadTexture(textureGrid);
+ UnloadRenderTexture(screenPlayer1); // Unload render texture
+ UnloadRenderTexture(screenPlayer2); // Unload render texture
+ UnloadTexture(textureGrid); // Unload texture
- CloseWindow(); // Close window and OpenGL context
+ CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
diff --git a/examples/core/core_vr_simulator.c b/examples/core/core_vr_simulator.c
index bba90b82..65f0dec6 100644
--- a/examples/core/core_vr_simulator.c
+++ b/examples/core/core_vr_simulator.c
@@ -105,30 +105,26 @@ int main(void)
// Draw
//----------------------------------------------------------------------------------
- BeginDrawing();
-
+ BeginTextureMode(target);
ClearBackground(RAYWHITE);
+ BeginVrStereoMode(config);
+ BeginMode3D(camera);
- BeginTextureMode(target);
- ClearBackground(RAYWHITE);
- BeginVrStereoMode(config);
- BeginMode3D(camera);
-
- DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
- DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
- DrawGrid(40, 1.0f);
-
- EndMode3D();
- EndVrStereoMode();
- EndTextureMode();
+ DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
+ DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
+ DrawGrid(40, 1.0f);
+ EndMode3D();
+ EndVrStereoMode();
+ EndTextureMode();
+
+ BeginDrawing();
+ ClearBackground(RAYWHITE);
BeginShaderMode(distortion);
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width,
(float)-target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE);
EndShaderMode();
-
DrawFPS(10, 10);
-
EndDrawing();
//----------------------------------------------------------------------------------
}
diff --git a/examples/core/core_window_letterbox.c b/examples/core/core_window_letterbox.c
index 2c3af6df..2933ca42 100644
--- a/examples/core/core_window_letterbox.c
+++ b/examples/core/core_window_letterbox.c
@@ -48,11 +48,11 @@ int main(void)
Color colors[10] = { 0 };
for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 };
- 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
//----------------------------------------------------------------------------------
@@ -79,37 +79,33 @@ int main(void)
// Draw
//----------------------------------------------------------------------------------
- BeginDrawing();
- ClearBackground(BLACK);
-
- // Draw everything in the render texture, note this will not be rendered on screen, yet
- BeginTextureMode(target);
-
- ClearBackground(RAYWHITE); // Clear render texture background color
-
- for (int i = 0; i < 10; i++) DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i]);
+ // Draw everything in the render texture, note this will not be rendered on screen, yet
+ BeginTextureMode(target);
+ ClearBackground(RAYWHITE); // Clear render texture background color
- DrawText("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
+ for (int i = 0; i < 10; i++) DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i]);
- DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 350, 25, 20, GREEN);
- DrawText(TextFormat("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
-
- EndTextureMode();
+ DrawText("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
+ DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 350, 25, 20, GREEN);
+ DrawText(TextFormat("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
+ EndTextureMode();
+
+ BeginDrawing();
+ ClearBackground(BLACK); // Clear screen background
- // Draw RenderTexture2D to window, properly scaled
+ // Draw render texture to screen, properly scaled
DrawTexturePro(target.texture, (Rectangle){ 0.0f, 0.0f, (float)target.texture.width, (float)-target.texture.height },
(Rectangle){ (GetScreenWidth() - ((float)gameScreenWidth*scale))*0.5f, (GetScreenHeight() - ((float)gameScreenHeight*scale))*0.5f,
(float)gameScreenWidth*scale, (float)gameScreenHeight*scale }, (Vector2){ 0, 0 }, 0.0f, WHITE);
-
EndDrawing();
//--------------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
- UnloadRenderTexture(target); // Unload render texture
+ UnloadRenderTexture(target); // Unload render texture
- CloseWindow(); // Close window and OpenGL context
+ CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;