Skip to content

Commit ffe7465

Browse files
committed
REXM: ADDED: example: core_render_texture
1 parent 84e2cbc commit ffe7465

File tree

8 files changed

+705
-3
lines changed

8 files changed

+705
-3
lines changed

examples/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ CORE = \
526526
core/core_input_virtual_controls \
527527
core/core_random_sequence \
528528
core/core_random_values \
529+
core/core_render_texture \
529530
core/core_scissor_test \
530531
core/core_smooth_pixelperfect \
531532
core/core_storage_values \

examples/Makefile.Web

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ CORE = \
526526
core/core_input_virtual_controls \
527527
core/core_random_sequence \
528528
core/core_random_values \
529+
core/core_render_texture \
529530
core/core_scissor_test \
530531
core/core_smooth_pixelperfect \
531532
core/core_storage_values \
@@ -761,6 +762,9 @@ core/core_random_sequence: core/core_random_sequence.c
761762
core/core_random_values: core/core_random_values.c
762763
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
763764

765+
core/core_render_texture: core/core_render_texture.c
766+
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
767+
764768
core/core_scissor_test: core/core_scissor_test.c
765769
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
766770

examples/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ You may find it easier to use than other toolchains, especially when it comes to
1717
- `zig build [module]` to compile all examples for a module (e.g. `zig build core`)
1818
- `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`)
1919

20-
## EXAMPLES COLLECTION [TOTAL: 160]
20+
## EXAMPLES COLLECTION [TOTAL: 161]
2121

22-
### category: core [35]
22+
### category: core [36]
2323

2424
Examples using raylib[core](../src/rcore.c) platform functionality like window creation, inputs, drawing modes and system functionality.
2525

@@ -60,6 +60,7 @@ Examples using raylib[core](../src/rcore.c) platform functionality like window c
6060
| [core_random_sequence](core/core_random_sequence.c) | <img src="core/core_random_sequence.png" alt="core_random_sequence" width="80"> | ⭐☆☆☆ | 5.0 | 5.0 | [Dalton Overmyer](https://github.com/REDl3east) |
6161
| [core_automation_events](core/core_automation_events.c) | <img src="core/core_automation_events.png" alt="core_automation_events" width="80"> | ⭐⭐⭐☆ | 5.0 | 5.0 | [Ramon Santamaria](https://github.com/raysan5) |
6262
| [core_high_dpi](core/core_high_dpi.c) | <img src="core/core_high_dpi.png" alt="core_high_dpi" width="80"> | ⭐⭐☆☆ | 5.0 | 5.5 | [Jonathan Marler](https://github.com/marler8997) |
63+
| [core_render_texture](core/core_render_texture.c) | <img src="core/core_render_texture.png" alt="core_render_texture" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [@raysan5](https://github.com/ Santamaria") |
6364

6465
### category: shapes [20]
6566

@@ -85,7 +86,7 @@ Examples using raylib shapes drawing functionality, provided by raylib [shapes](
8586
| [shapes_top_down_lights](shapes/shapes_top_down_lights.c) | <img src="shapes/shapes_top_down_lights.png" alt="shapes_top_down_lights" width="80"> | ⭐⭐⭐⭐️ | 4.2 | 4.2 | [Jeffery Myers](https://github.com/JeffM2501) |
8687
| [shapes_rectangle_advanced](shapes/shapes_rectangle_advanced.c) | <img src="shapes/shapes_rectangle_advanced.png" alt="shapes_rectangle_advanced" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.5 | [Everton Jr.](https://github.com/evertonse) |
8788
| [shapes_splines_drawing](shapes/shapes_splines_drawing.c) | <img src="shapes/shapes_splines_drawing.png" alt="shapes_splines_drawing" width="80"> | ⭐⭐⭐☆ | 5.0 | 5.0 | [Ramon Santamaria](https://github.com/raysan5) |
88-
| [shapes_digital_clock](shapes/shapes_digital_clock.c) | <img src="shapes/shapes_digital_clock.png" alt="shapes_digital_clock" width="80"> | ⭐⭐☆☆ | 5.5 | 5.6 | [Hamza RAHAL](https://github.com/hmz-rhl) |
89+
| [shapes_digital_clock](shapes/shapes_digital_clock.c) | <img src="shapes/shapes_digital_clock.png" alt="shapes_digital_clock" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.6 | [Hamza RAHAL](https://github.com/hmz-rhl) |
8990
| [shapes_double_pendulum](shapes/shapes_double_pendulum.c) | <img src="shapes/shapes_double_pendulum.png" alt="shapes_double_pendulum" width="80"> | ⭐⭐☆☆ | 5.5 | 5.5 | [JoeCheong](https://github.com/Joecheong2006) |
9091

9192
### category: textures [26]
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*******************************************************************************************
2+
*
3+
* raylib [core] example - render texture
4+
*
5+
* Example complexity rating: [★☆☆☆] 1/4
6+
*
7+
* Example originally created with raylib 5.6-dev, last time updated with raylib 5.6-dev
8+
*
9+
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
10+
* BSD-like license that allows static linking with closed source software
11+
*
12+
* Copyright (c) 2025 @raysan5 (@ Santamaria")
13+
*
14+
********************************************************************************************/
15+
16+
#include "raylib.h"
17+
18+
//------------------------------------------------------------------------------------
19+
// Program main entry point
20+
//------------------------------------------------------------------------------------
21+
int main(void)
22+
{
23+
// Initialization
24+
//---------------------------------------------------------
25+
const int screenWidth = 800;
26+
const int screenHeight = 450;
27+
28+
InitWindow(screenWidth, screenHeight, "raylib [core] example - render texture");
29+
30+
// Define a render texture to render
31+
int renderTextureWidth = 300;
32+
int renderTextureHeight = 300;
33+
RenderTexture2D target = LoadRenderTexture(renderTextureWidth, renderTextureHeight);
34+
35+
Vector2 ballPosition = { renderTextureWidth/2.0f, renderTextureHeight/2.0f };
36+
Vector2 ballSpeed = { 5.0f, 4.0f };
37+
int ballRadius = 20;
38+
39+
float rotation = 0.0f;
40+
41+
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
42+
//----------------------------------------------------------
43+
44+
// Main game loop
45+
while (!WindowShouldClose()) // Detect window close button or ESC key
46+
{
47+
// Update
48+
//-----------------------------------------------------
49+
// Ball movement logic
50+
ballPosition.x += ballSpeed.x;
51+
ballPosition.y += ballSpeed.y;
52+
53+
// Check walls collision for bouncing
54+
if ((ballPosition.x >= (renderTextureWidth - ballRadius)) || (ballPosition.x <= ballRadius)) ballSpeed.x *= -1.0f;
55+
if ((ballPosition.y >= (renderTextureHeight - ballRadius)) || (ballPosition.y <= ballRadius)) ballSpeed.y *= -1.0f;
56+
57+
// Render texture rotation
58+
rotation += 0.5f;
59+
//-----------------------------------------------------
60+
61+
// Draw
62+
//-----------------------------------------------------
63+
// Draw our scene to the render texture
64+
BeginTextureMode(target);
65+
66+
ClearBackground(SKYBLUE);
67+
68+
DrawCircleV(ballPosition, (float)ballRadius, MAROON);
69+
70+
EndTextureMode();
71+
72+
// Draw render texture to main framebuffer
73+
BeginDrawing();
74+
75+
ClearBackground(RAYWHITE);
76+
77+
// Draw our render texture with rotation applied
78+
// NOTE: We set the origin of the texture to the center of the render texture
79+
DrawTexturePro(target.texture,
80+
(Rectangle){ 0, 0, target.texture.width, -target.texture.height },
81+
(Rectangle){ screenWidth/2, screenHeight/2, target.texture.width, -target.texture.height },
82+
(Vector2){ target.texture.width/2, target.texture.height/2 }, rotation, WHITE);
83+
84+
DrawText("DRAWING BOUNCING BALL INSIDE RENDER TEXTURE!", 10, screenHeight - 40, 20, BLACK);
85+
86+
87+
DrawFPS(10, 10);
88+
89+
EndDrawing();
90+
//-----------------------------------------------------
91+
}
92+
93+
// De-Initialization
94+
//---------------------------------------------------------
95+
CloseWindow(); // Close window and OpenGL context
96+
//----------------------------------------------------------
97+
98+
return 0;
99+
}
16.9 KB
Loading

examples/examples_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ core;core_smooth_pixelperfect;★★★☆;3.7;4.0;2021;2025;"Giancamillo Alessa
4242
core;core_random_sequence;★☆☆☆;5.0;5.0;2023;2025;"Dalton Overmyer";@REDl3east
4343
core;core_automation_events;★★★☆;5.0;5.0;2023;2025;"Ramon Santamaria";@raysan5
4444
core;core_high_dpi;★★☆☆;5.0;5.5;2025;2025;"Jonathan Marler";@marler8997
45+
core;core_render_texture;★☆☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santamaria";@raysan5
4546
shapes;shapes_basic_shapes;★☆☆☆;1.0;4.2;2014;2025;"Ramon Santamaria";@raysan5
4647
shapes;shapes_bouncing_ball;★☆☆☆;2.5;2.5;2013;2025;"Ramon Santamaria";@raysan5
4748
shapes;shapes_colors_palette;★★☆☆;1.0;2.5;2014;2025;"Ramon Santamaria";@raysan5

0 commit comments

Comments
 (0)