Skip to content

Commit 1cdf1dc

Browse files
authored
[examples] Add models_geometry_textures_cube (#5221)
* ADDED: example: models_geometry_textures_cube * FIXED: example: models_geometry_textures_cube - removed leftover TODO and aligned title with header
1 parent 452cac3 commit 1cdf1dc

File tree

6 files changed

+98
-2
lines changed

6 files changed

+98
-2
lines changed

examples/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ MODELS = \
616616
models/models_cubicmap_rendering \
617617
models/models_first_person_maze \
618618
models/models_geometric_shapes \
619+
models/models_geometry_textures_cube \
619620
models/models_heightmap_rendering \
620621
models/models_loading \
621622
models/models_loading_gltf \

examples/Makefile.Web

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ MODELS = \
616616
models/models_cubicmap_rendering \
617617
models/models_first_person_maze \
618618
models/models_geometric_shapes \
619+
models/models_geometry_textures_cube \
619620
models/models_heightmap_rendering \
620621
models/models_loading \
621622
models/models_loading_gltf \
@@ -1085,6 +1086,10 @@ models/models_first_person_maze: models/models_first_person_maze.c
10851086
models/models_geometric_shapes: models/models_geometric_shapes.c
10861087
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
10871088

1089+
models/models_geometry_textures_cube: models/models_geometry_textures_cube.c
1090+
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
1091+
--preload-file models/resources/cubicmap_atlas.png@resources/cubicmap_atlas.png
1092+
10881093
models/models_heightmap_rendering: models/models_heightmap_rendering.c
10891094
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
10901095
--preload-file models/resources/heightmap.png@resources/heightmap.png

examples/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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: 165]
20+
## EXAMPLES COLLECTION [TOTAL: 166]
2121

2222
### category: core [38]
2323

@@ -147,7 +147,7 @@ Examples using raylib text functionality, including sprite fonts loading/generat
147147
| [text_codepoints_loading](text/text_codepoints_loading.c) | <img src="text/text_codepoints_loading.png" alt="text_codepoints_loading" width="80"> | ⭐⭐⭐☆ | 4.2 | 4.2 | [Ramon Santamaria](https://github.com/raysan5) |
148148
| [text_inline_styling](text/text_inline_styling.c) | <img src="text/text_inline_styling.png" alt="text_inline_styling" width="80"> | ⭐⭐⭐☆ | 5.6-dev | 5.6-dev | [Wagner Barongello](https://github.com/SultansOfCode) |
149149

150-
### category: models [24]
150+
### category: models [25]
151151

152152
Examples using raylib models functionality, including models loading/generation and drawing, provided by raylib [models](../src/rmodels.c) module.
153153

@@ -177,6 +177,7 @@ Examples using raylib models functionality, including models loading/generation
177177
| [models_bone_socket](models/models_bone_socket.c) | <img src="models/models_bone_socket.png" alt="models_bone_socket" width="80"> | ⭐⭐⭐⭐️ | 4.5 | 4.5 | [iP](https://github.com/ipzaur) |
178178
| [models_tesseract_view](models/models_tesseract_view.c) | <img src="models/models_tesseract_view.png" alt="models_tesseract_view" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Timothy van der Valk](https://github.com/arceryz) |
179179
| [models_basic_voxel](models/models_basic_voxel.c) | <img src="models/models_basic_voxel.png" alt="models_basic_voxel" width="80"> | ⭐⭐☆☆ | 5.5 | 5.5 | [Tim Little](https://github.com/timlittle) |
180+
| [models_geometry_textures_cube](models/models_geometry_textures_cube.c) | <img src="models/models_geometry_textures_cube.png" alt="models_geometry_textures_cube" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Jopestpe](https://github.com/jopestpe) |
180181

181182
### category: shaders [29]
182183

examples/examples_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ models;models_animation_gpu_skinning;★★★☆;4.5;4.5;2024;2025;"Daniel Hold
131131
models;models_bone_socket;★★★★;4.5;4.5;2024;2025;"iP";@ipzaur
132132
models;models_tesseract_view;★★☆☆;5.6-dev;5.6-dev;2024;2025;"Timothy van der Valk";@arceryz
133133
models;models_basic_voxel;★★☆☆;5.5;5.5;2025;2025;"Tim Little";@timlittle
134+
models;models_geometry_textures_cube;★☆☆☆;5.6-dev;5.6-dev;2025;2025;"Jopestpe";@jopestpe
134135
shaders;shaders_basic_lighting;★★★★;3.0;4.2;2019;2025;"Chris Camacho";@chriscamacho
135136
shaders;shaders_model_shader;★★☆☆;1.3;3.7;2014;2025;"Ramon Santamaria";@raysan5
136137
shaders;shaders_shapes_textures;★★☆☆;1.7;3.7;2015;2025;"Ramon Santamaria";@raysan5
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*******************************************************************************************
2+
*
3+
* raylib [models] example - geometry textures cube
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 contributed by Jopestpe (@jopestpe)
10+
*
11+
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
12+
* BSD-like license that allows static linking with closed source software
13+
*
14+
* Copyright (c) 2025-2025 Jopestpe (@jopestpe)
15+
*
16+
********************************************************************************************/
17+
18+
#include "raylib.h"
19+
20+
//------------------------------------------------------------------------------------
21+
// Program main entry point
22+
//------------------------------------------------------------------------------------
23+
int main(void)
24+
{
25+
// Initialization
26+
//--------------------------------------------------------------------------------------
27+
const int screenWidth = 800;
28+
const int screenHeight = 450;
29+
30+
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometry textures cube");
31+
32+
// Define the camera to look into our 3d world
33+
Camera camera = { 0 };
34+
camera.position = (Vector3){ 0.0f, 0.0f, 4.0f };
35+
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
36+
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
37+
camera.fovy = 45.0f;
38+
camera.projection = CAMERA_PERSPECTIVE;
39+
40+
// Load image to create texture for the cube
41+
Model model = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
42+
Image img = LoadImage("resources/cubicmap_atlas.png");
43+
Image crop = ImageFromImage(img, (Rectangle){0, img.height/2, img.width/2, img.height/2});
44+
Texture2D texture = LoadTextureFromImage(crop);
45+
UnloadImage(img);
46+
UnloadImage(crop);
47+
48+
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
49+
50+
float rotation = 0.0f;
51+
52+
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
53+
//--------------------------------------------------------------------------------------
54+
55+
// Main game loop
56+
while (!WindowShouldClose()) // Detect window close button or ESC key
57+
{
58+
// Update
59+
//----------------------------------------------------------------------------------
60+
rotation += 1.0f;
61+
62+
// Draw
63+
//----------------------------------------------------------------------------------
64+
BeginDrawing();
65+
66+
ClearBackground(RAYWHITE);
67+
68+
BeginMode3D(camera);
69+
70+
DrawModelEx(model, (Vector3){0,0,0}, (Vector3){0.5f,1,0}, rotation, (Vector3){1,1,1}, WHITE);
71+
72+
EndMode3D();
73+
74+
DrawFPS(10, 10);
75+
76+
EndDrawing();
77+
//----------------------------------------------------------------------------------
78+
}
79+
80+
// De-Initialization
81+
//--------------------------------------------------------------------------------------
82+
UnloadTexture(texture); // Unload texture
83+
UnloadModel(model); // Unload model
84+
CloseWindow(); // Close window and OpenGL context
85+
//--------------------------------------------------------------------------------------
86+
87+
return 0;
88+
}
48.3 KB
Loading

0 commit comments

Comments
 (0)