Skip to content

Commit 3cbe911

Browse files
committed
REXM: RENAME: example: models_billboard --> models_billboard_rendering
1 parent b17936d commit 3cbe911

File tree

8 files changed

+690
-6
lines changed

8 files changed

+690
-6
lines changed

examples/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ TEXT = \
603603

604604
MODELS = \
605605
models/models_animation \
606-
models/models_billboard_rendering_rendering \
606+
models/models_billboard_rendering \
607607
models/models_bone_socket \
608608
models/models_box_collisions \
609609
models/models_cubicmap \

examples/Makefile.Web

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ TEXT = \
603603

604604
MODELS = \
605605
models/models_animation \
606-
models/models_billboard_rendering_rendering \
606+
models/models_billboard_rendering \
607607
models/models_bone_socket \
608608
models/models_box_collisions \
609609
models/models_cubicmap \
@@ -1028,7 +1028,7 @@ models/models_animation: models/models_animation.c
10281028
--preload-file models/resources/models/iqm/guytex.png@resources/models/iqm/guytex.png \
10291029
--preload-file models/resources/models/iqm/guyanim.iqm@resources/models/iqm/guyanim.iqm
10301030

1031-
models/models_billboard_rendering_rendering: models/models_billboard_rendering_rendering.c
1031+
models/models_billboard_rendering: models/models_billboard_rendering.c
10321032
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
10331033
--preload-file models/resources/billboard.png@resources/billboard.png
10341034

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Examples using raylib models functionality, including models loading/generation
148148
| example | image | difficulty<br>level | version<br>created | last version<br>updated | original<br>developer |
149149
|-----------|--------|:-------------------:|:------------------:|:-----------------------:|:----------------------|
150150
| [models_animation](models/models_animation.c) | <img src="models/models_animation.png" alt="models_animation" width="80"> | ⭐⭐☆☆ | 2.5 | 3.5 | [Culacant](https://github.com/culacant) |
151-
| [models_billboard_rendering_rendering](models/models_billboard_rendering_rendering.c) | <img src="models/models_billboard_rendering_rendering.png" alt="models_billboard_rendering_rendering" width="80"> | ⭐⭐⭐☆ | 1.3 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |
151+
| [models_billboard_rendering](models/models_billboard_rendering.c) | <img src="models/models_billboard_rendering.png" alt="models_billboard_rendering" width="80"> | ⭐⭐⭐☆ | 1.3 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |
152152
| [models_box_collisions](models/models_box_collisions.c) | <img src="models/models_box_collisions.png" alt="models_box_collisions" width="80"> | ⭐☆☆☆ | 1.3 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |
153153
| [models_cubicmap](models/models_cubicmap.c) | <img src="models/models_cubicmap.png" alt="models_cubicmap" width="80"> | ⭐⭐☆☆ | 1.8 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |
154154
| [models_first_person_maze](models/models_first_person_maze.c) | <img src="models/models_first_person_maze.png" alt="models_first_person_maze" width="80"> | ⭐⭐☆☆ | 2.5 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |

examples/examples_list.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ text;text_unicode_ranges;⭐️⭐️⭐️⭐️;5.5;5.6;"Vlad Adrian";@demizdo
103103
text;text_3d_drawing;⭐️⭐️⭐️⭐️;3.5;4.0;"Vlad Adrian";@demizdor
104104
text;text_codepoints_loading;⭐️⭐️⭐️☆;4.2;4.2;"Ramon Santamaria";@raysan5
105105
models;models_animation;⭐️⭐️☆☆;2.5;3.5;"Culacant";@culacant
106-
models;models_billboard_rendering_rendering;⭐️⭐️⭐️☆;1.3;3.5;"Ramon Santamaria";@raysan5
106+
models;models_billboard_rendering;⭐️⭐️⭐️☆;1.3;3.5;"Ramon Santamaria";@raysan5
107107
models;models_box_collisions;⭐️☆☆☆;1.3;3.5;"Ramon Santamaria";@raysan5
108108
models;models_cubicmap;⭐️⭐️☆☆;1.8;3.5;"Ramon Santamaria";@raysan5
109109
models;models_first_person_maze;⭐️⭐️☆☆;2.5;3.5;"Ramon Santamaria";@raysan5
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*******************************************************************************************
2+
*
3+
* raylib [models] example - billboard render
4+
*
5+
* Example complexity rating: [★★★☆] 3/4
6+
*
7+
* Example originally created with raylib 1.3, last time updated with raylib 3.5
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) 2015-2025 Ramon Santamaria (@raysan5)
13+
*
14+
********************************************************************************************/
15+
16+
#include "raylib.h"
17+
#include "raymath.h"
18+
19+
//------------------------------------------------------------------------------------
20+
// Program main entry point
21+
//------------------------------------------------------------------------------------
22+
int main(void)
23+
{
24+
// Initialization
25+
//--------------------------------------------------------------------------------------
26+
const int screenWidth = 800;
27+
const int screenHeight = 450;
28+
29+
InitWindow(screenWidth, screenHeight, "raylib [models] example - billboard render");
30+
31+
// Define the camera to look into our 3d world
32+
Camera camera = { 0 };
33+
camera.position = (Vector3){ 5.0f, 4.0f, 5.0f }; // Camera position
34+
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
35+
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
36+
camera.fovy = 45.0f; // Camera field-of-view Y
37+
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
38+
39+
Texture2D bill = LoadTexture("resources/billboard.png"); // Our billboard texture
40+
Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard
41+
Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard
42+
43+
// Entire billboard texture, source is used to take a segment from a larger texture
44+
Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height };
45+
46+
// NOTE: Billboard locked on axis-Y
47+
Vector3 billUp = { 0.0f, 1.0f, 0.0f };
48+
49+
// Set the height of the rotating billboard to 1.0 with the aspect ratio fixed
50+
Vector2 size = { source.width/source.height, 1.0f };
51+
52+
// Rotate around origin
53+
// Here we choose to rotate around the image center
54+
Vector2 origin = Vector2Scale(size, 0.5f);
55+
56+
// Distance is needed for the correct billboard draw order
57+
// Larger distance (further away from the camera) should be drawn prior to smaller distance
58+
float distanceStatic;
59+
float distanceRotating;
60+
float rotation = 0.0f;
61+
62+
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
63+
//--------------------------------------------------------------------------------------
64+
65+
// Main game loop
66+
while (!WindowShouldClose()) // Detect window close button or ESC key
67+
{
68+
// Update
69+
//----------------------------------------------------------------------------------
70+
UpdateCamera(&camera, CAMERA_ORBITAL);
71+
72+
rotation += 0.4f;
73+
distanceStatic = Vector3Distance(camera.position, billPositionStatic);
74+
distanceRotating = Vector3Distance(camera.position, billPositionRotating);
75+
//----------------------------------------------------------------------------------
76+
77+
// Draw
78+
//----------------------------------------------------------------------------------
79+
BeginDrawing();
80+
81+
ClearBackground(RAYWHITE);
82+
83+
BeginMode3D(camera);
84+
85+
DrawGrid(10, 1.0f); // Draw a grid
86+
87+
// Draw order matters!
88+
if (distanceStatic > distanceRotating)
89+
{
90+
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
91+
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
92+
}
93+
else
94+
{
95+
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
96+
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
97+
}
98+
99+
EndMode3D();
100+
101+
DrawFPS(10, 10);
102+
103+
EndDrawing();
104+
//----------------------------------------------------------------------------------
105+
}
106+
107+
// De-Initialization
108+
//--------------------------------------------------------------------------------------
109+
UnloadTexture(bill); // Unload texture
110+
111+
CloseWindow(); // Close window and OpenGL context
112+
//--------------------------------------------------------------------------------------
113+
114+
return 0;
115+
}
53.6 KB
Loading

0 commit comments

Comments
 (0)