Files
raylib/examples
Le Juez Victor 584bc14929 [rlgl] Add Software Rendering Support (#4832)
* add base of rlsw.h

* implement state support
Also replace the triangle rasterization functions with macros that generate specific functions for each state of the rendering system.
Also, add the OpenGL definitions in order to add a binding for rlgl.

* branchless float saturation

* apply perspective correction to colors

* impl line clipping and rasterization
+ tweak function names

* impl face culling

* impl color blending

* fixes and tweaks

* add clear buffer bitmasks

* small optimizations / tweaks

* review ndc to screen projection

* avoid to recalculate MVP when its not needed + tweaks

* review the loading and management of textures
to be closer to the OpenGL API

* texture sampling optimization

* review get pixel functions
+ review unorm/float conversion

* add several buffer format support
Several depth and color formats have been added for the framebuffer.

8-bit, 16-bit, and 24-bit formats are now available for depth.

RGB 8-bit (332), RGB 16-bit (565), and RGB 24-bit (888) formats are now available for color.

Alpha support is no longer present for the framebuffer at the moment, but it can easily be restored by adding the formats and reinterpolating the alpha in the areas that do not perform color blending.

Additionally, this commit brings performance improvements.

* tweaks

* impl line width

* impl points + point size

* fix and improve polygon clipping functions

* impl polygone modes

* add some not planned functions
- `glDepthMask`
- `glColorMask`

* framebuffer resizing + handle init failure

* add quick notes about line clipping algorithms used

* start to impl scissor test + review line clipping
The support for the scissor test has been implemented for clearing as well as for triangle clipping.
The implementation for lines and points is still missing.

I also removed the 2D clipping of lines that used the Cohen-Sutherland algorithm, opting instead to always use the Liang-Barsky algorithm in all cases.
This simplifies the implementation, and the 2D version would have caused issues when interpolating vertices in the future if we want to implement additional features.

* review scissor clear

* review `swScissor`

* impl line scissor clipping

* round screen coordinate (line rasterization)

* impl point scissor clipping

* remove unused defs

* add getter functions

* gl binding

* add `glHint` and `glShadeModel` macros (not implmented)

* binding tweaks

* impl copy framebuffer function + glReadPixels

* review `swCopyFramebuffer`

* update rlgl.h

* update rlgl.h

* texture copy support

* fix typo..

* add get error function

* def sw alloc macros

* reimpl get color buffer func
just in case

* remove normal interpolation

* review texture wrap

* fix ndc projection (viewport/scissor)

* impl framebuffer blit function

* reduce matrix compuations and memory usage

* swBegin tweaks

* preventing a possible division by zero

* remove useless scissor related data

* review color blending system

* greatly improve float saturation

* tweak lerp vertex function

* use opitmized fract function in sw_texture_map

* tweak framebuffer functions for better readability

* optimized copy/blit functions for each dst format

* review framebuffer filling functions

* impl specific quad rendering func

* use of a single global vertex buffer

* fix 'sw_poly_point_render'

* added `SW_RESTRICT` and redesigned `sw_lerp_vertex_PNCTH`

* tweak the pipeline flow regarding the face culling
avoids misprediction, improves vectorization if possible

* new rendering path for axis aligned quads

* oops, translating some comments

* use of `restrict` for blending function parameters

* update rlgl.h

* adding `GRAPHICS_API_OPENGL_11_SOFTWARE` in `DrawMesh`

* add `RL_OPENGL_11_SOFTWARE` enum

* temp tweak

* build fixes

* fix DrawMesh for GL 1.1

* update swClose

* review texture format + fix copy

* set minimum req vertices to 3 (quads)

* check swInit

* review pixelformat

* tweaks

* fix animNormals (DrawMesh)

* fallback color/texcoord (swDrawArrays)

* review swMultMatrixf

* fix texture pool alloc..

* review triangle scanlines
increment all data

* fix `sw_quad_sort_cw`

* impl sdl platform

* rm def

* increase max clipped polygon vertices

* improve triangle rasterization along Y axis
improved robustness against numerical errors
incremental interpolation along Y
simplified function, fewer jumps

* review current vertex data
+ increase max clipped polygon vertices (for extreme cases)

* fix and improve polygon clipping
Sets the vertex count to zero when the polygon is invalid
Stops clipping when the vertex count drops below 3

* fix gradient calculation

* cache texture size minus one + comments

* tweaks

* BGRA copy support

* adding software backend option (cmake)

* update Makefile

* fix face culling

* excluse some exemple with the software backend

* review SW_CLAMP case in sw_texture_map

* review sw_saturate

* review line raster

* fix sw_quad_is_aligned

* review sw_raster_quad_axis_aligned

* tweaks

* codepoint fix (?)

* fix var name...

* rcore_drm software renderering

* cleanup and tweaks

* adding support for `GL_POINT_SIZE` and `GL_LINE_WIDTH` get

* fix sampling issue

* fix swBlendFunc

---------

Co-authored-by: Ray <raysan5@gmail.com>
2025-09-29 10:28:20 +02:00
..
2025-09-26 20:56:54 +02:00
2025-09-14 10:22:56 +02:00
2025-01-01 00:02:52 +01:00

Building the Examples

The examples assume you have already built the raylib library in ../src.

With GNU make

  • make builds all examples
  • make [module] builds all examples for a particular module (e.g make core)
  • make [module]/[name] builds one examples for a particular module (e.g make core/core_basic_window)

With Zig

The Zig toolchain can compile C and C++ in addition to Zig. You may find it easier to use than other toolchains, especially when it comes to cross-compiling.

  • zig build to compile all examples
  • zig build [module] to compile all examples for a module (e.g. zig build core)
  • zig build [example] to compile and run a particular example (e.g. zig build core_basic_window)

EXAMPLES COLLECTION [TOTAL: 164]

category: core [38]

Examples using raylibcore platform functionality like window creation, inputs, drawing modes and system functionality.

example image difficulty
level
version
created
last version
updated
original
developer
core_basic_window core_basic_window ☆☆☆ 1.0 1.0 Ramon Santamaria
core_input_keys core_input_keys ☆☆☆ 1.0 1.0 Ramon Santamaria
core_input_mouse core_input_mouse ☆☆☆ 1.0 5.5 Ramon Santamaria
core_input_mouse_wheel core_input_mouse_wheel ☆☆☆ 1.1 1.3 Ramon Santamaria
core_input_gamepad core_input_gamepad ☆☆☆ 1.1 4.2 Ramon Santamaria
core_input_multitouch core_input_multitouch ☆☆☆ 2.1 2.5 Berni
core_input_gestures core_input_gestures ☆☆ 1.4 4.2 Ramon Santamaria
core_input_gestures_testbed core_input_gestures_testbed 5.0 5.6-dev ubkp
core_input_virtual_controls core_input_virtual_controls ☆☆ 5.0 5.0 GreenSnakeLinux
core_2d_camera core_2d_camera ☆☆ 1.5 3.0 Ramon Santamaria
core_2d_camera_mouse_zoom core_2d_camera_mouse_zoom ☆☆ 4.2 4.2 Jeffery Myers
core_2d_camera_platformer core_2d_camera_platformer 2.5 3.0 arvyy
core_2d_camera_split_screen core_2d_camera_split_screen 4.5 4.5 Gabriel dos Santos Sanches
core_3d_camera_mode core_3d_camera_mode ☆☆☆ 1.0 1.0 Ramon Santamaria
core_3d_camera_free core_3d_camera_free ☆☆☆ 1.3 1.3 Ramon Santamaria
core_3d_camera_first_person core_3d_camera_first_person ☆☆ 1.3 1.3 Ramon Santamaria
core_3d_camera_split_screen core_3d_camera_split_screen 3.7 4.0 Jeffery Myers
core_3d_camera_fps core_3d_camera_fps 5.5 5.5 Agnis Aldins
core_3d_picking core_3d_picking ☆☆ 1.3 4.0 Ramon Santamaria
core_world_screen core_world_screen ☆☆ 1.3 1.4 Ramon Santamaria
core_window_flags core_window_flags 3.5 3.5 Ramon Santamaria
core_window_letterbox core_window_letterbox ☆☆ 2.5 4.0 Anata
core_window_should_close core_window_should_close ☆☆☆ 4.2 4.2 Ramon Santamaria
core_custom_logging core_custom_logging 2.5 2.5 Pablo Marcos Oltra
core_drop_files core_drop_files ☆☆ 1.3 4.2 Ramon Santamaria
core_random_values core_random_values ☆☆☆ 1.1 1.1 Ramon Santamaria
core_storage_values core_storage_values ☆☆ 1.4 4.2 Ramon Santamaria
core_vr_simulator core_vr_simulator 2.5 4.0 Ramon Santamaria
core_scissor_test core_scissor_test ☆☆☆ 2.5 3.0 Chris Dill
core_basic_screen_manager core_basic_screen_manager ☆☆☆ 4.0 4.0 Ramon Santamaria
core_custom_frame_control core_custom_frame_control 4.0 4.0 Ramon Santamaria
core_smooth_pixelperfect core_smooth_pixelperfect 3.7 4.0 Giancamillo Alessandroni
core_random_sequence core_random_sequence ☆☆☆ 5.0 5.0 Dalton Overmyer
core_automation_events core_automation_events 5.0 5.0 Ramon Santamaria
core_high_dpi core_high_dpi ☆☆ 5.0 5.5 Jonathan Marler
core_render_texture core_render_texture ☆☆☆ 5.6-dev 5.6-dev Ramon Santamaria
core_undo_redo core_undo_redo 5.5 5.6 Ramon Santamaria
core_input_actions core_input_actions ☆☆ 5.5 5.6 Jett

category: shapes [20]

Examples using raylib shapes drawing functionality, provided by raylib shapes module.

example image difficulty
level
version
created
last version
updated
original
developer
shapes_basic_shapes shapes_basic_shapes ☆☆☆ 1.0 4.2 Ramon Santamaria
shapes_bouncing_ball shapes_bouncing_ball ☆☆☆ 2.5 2.5 Ramon Santamaria
shapes_colors_palette shapes_colors_palette ☆☆ 1.0 2.5 Ramon Santamaria
shapes_logo_raylib shapes_logo_raylib ☆☆☆ 1.0 1.0 Ramon Santamaria
shapes_logo_raylib_anim shapes_logo_raylib_anim ☆☆ 2.5 4.0 Ramon Santamaria
shapes_rectangle_scaling shapes_rectangle_scaling ☆☆ 2.5 2.5 Vlad Adrian
shapes_lines_bezier shapes_lines_bezier ☆☆☆ 1.7 1.7 Ramon Santamaria
shapes_collision_area shapes_collision_area ☆☆ 2.5 2.5 Ramon Santamaria
shapes_following_eyes shapes_following_eyes ☆☆ 2.5 2.5 Ramon Santamaria
shapes_easings_ball shapes_easings_ball ☆☆ 2.5 2.5 Ramon Santamaria
shapes_easings_box shapes_easings_box ☆☆ 2.5 2.5 Ramon Santamaria
shapes_easings_rectangles shapes_easings_rectangles 2.0 2.5 Ramon Santamaria
shapes_ring_drawing shapes_ring_drawing 2.5 2.5 Vlad Adrian
shapes_circle_sector_drawing shapes_circle_sector_drawing 2.5 2.5 Vlad Adrian
shapes_rounded_rectangle_drawing shapes_rounded_rectangle_drawing 2.5 2.5 Vlad Adrian
shapes_top_down_lights shapes_top_down_lights 4.2 4.2 Jeffery Myers
shapes_rectangle_advanced shapes_rectangle_advanced 5.5 5.5 Everton Jr.
shapes_splines_drawing shapes_splines_drawing 5.0 5.0 Ramon Santamaria
shapes_digital_clock shapes_digital_clock 5.5 5.6 Hamza RAHAL
shapes_double_pendulum shapes_double_pendulum ☆☆ 5.5 5.5 JoeCheong

category: textures [26]

Examples using raylib textures functionality, including image/textures loading/generation and drawing, provided by raylib textures module.

example image difficulty
level
version
created
last version
updated
original
developer
textures_logo_raylib textures_logo_raylib ☆☆☆ 1.0 1.0 Ramon Santamaria
textures_srcrec_dstrec textures_srcrec_dstrec 1.3 1.3 Ramon Santamaria
textures_image_drawing textures_image_drawing ☆☆ 1.4 1.4 Ramon Santamaria
textures_image_generation textures_image_generation ☆☆ 1.8 1.8 Wilhem Barbier
textures_image_loading textures_image_loading ☆☆☆ 1.3 1.3 Ramon Santamaria
textures_image_processing textures_image_processing 1.4 3.5 Ramon Santamaria
textures_image_text textures_image_text ☆☆ 1.8 4.0 Ramon Santamaria
textures_to_image textures_to_image ☆☆☆ 1.3 4.0 Ramon Santamaria
textures_raw_data textures_raw_data 1.3 3.5 Ramon Santamaria
textures_particles_blending textures_particles_blending ☆☆☆ 1.7 3.5 Ramon Santamaria
textures_npatch_drawing textures_npatch_drawing 2.0 2.5 Jorge A. Gomes
textures_background_scrolling textures_background_scrolling ☆☆☆ 2.0 2.5 Ramon Santamaria
textures_sprite_animation textures_sprite_animation ☆☆ 1.3 1.3 Ramon Santamaria
textures_sprite_button textures_sprite_button ☆☆ 2.5 2.5 Ramon Santamaria
textures_sprite_explosion textures_sprite_explosion ☆☆ 2.5 3.5 Ramon Santamaria
textures_bunnymark textures_bunnymark 1.6 2.5 Ramon Santamaria
textures_mouse_painting textures_mouse_painting 3.0 3.0 Chris Dill
textures_blend_modes textures_blend_modes ☆☆☆ 3.5 3.5 Karlo Licudine
textures_tiled_drawing textures_tiled_drawing 3.0 4.2 Vlad Adrian
textures_polygon_drawing textures_polygon_drawing ☆☆☆ 3.7 3.7 Chris Camacho
textures_fog_of_war textures_fog_of_war 4.2 4.2 Ramon Santamaria
textures_gif_player textures_gif_player 4.2 4.2 Ramon Santamaria
textures_image_kernel textures_image_kernel 1.3 1.3 Karim Salem
textures_image_channel textures_image_channel ☆☆ 5.5 5.5 Bruno Cabral
textures_image_rotate textures_image_rotate ☆☆ 1.0 1.0 Ramon Santamaria
textures_textured_curve textures_textured_curve 4.5 4.5 Jeffery Myers

category: text [14]

Examples using raylib text functionality, including sprite fonts loading/generation and text drawing, provided by raylib text module.

example image difficulty
level
version
created
last version
updated
original
developer
text_sprite_fonts text_sprite_fonts ☆☆☆ 1.7 3.7 Ramon Santamaria
text_font_spritefont text_font_spritefont ☆☆☆ 1.0 1.0 Ramon Santamaria
text_font_filters text_font_filters ☆☆ 1.3 4.2 Ramon Santamaria
text_font_loading text_font_loading ☆☆☆ 1.4 3.0 Ramon Santamaria
text_font_sdf text_font_sdf 1.3 4.0 Ramon Santamaria
text_format_text text_format_text ☆☆☆ 1.1 3.0 Ramon Santamaria
text_input_box text_input_box ☆☆ 1.7 3.5 Ramon Santamaria
text_writing_anim text_writing_anim ☆☆ 1.4 1.4 Ramon Santamaria
text_rectangle_bounds text_rectangle_bounds 2.5 4.0 Vlad Adrian
text_unicode_emojis text_unicode_emojis 2.5 4.0 Vlad Adrian
text_unicode_ranges text_unicode_ranges 5.5 5.6 Vlad Adrian
text_3d_drawing text_3d_drawing 3.5 4.0 Vlad Adrian
text_codepoints_loading text_codepoints_loading 4.2 4.2 Ramon Santamaria
text_inline_styling text_inline_styling 5.6-dev 5.6-dev Wagner Barongello

category: models [24]

Examples using raylib models functionality, including models loading/generation and drawing, provided by raylib models module.

example image difficulty
level
version
created
last version
updated
original
developer
models_animation_playing models_animation_playing ☆☆ 2.5 3.5 Culacant
models_billboard_rendering models_billboard_rendering 1.3 3.5 Ramon Santamaria
models_box_collisions models_box_collisions ☆☆☆ 1.3 3.5 Ramon Santamaria
models_cubicmap_rendering models_cubicmap_rendering ☆☆ 1.8 3.5 Ramon Santamaria
models_first_person_maze models_first_person_maze ☆☆ 2.5 3.5 Ramon Santamaria
models_geometric_shapes models_geometric_shapes ☆☆☆ 1.0 3.5 Ramon Santamaria
models_mesh_generation models_mesh_generation ☆☆ 1.8 4.0 Ramon Santamaria
models_mesh_picking models_mesh_picking 1.7 4.0 Joel Davis
models_loading models_loading ☆☆☆ 2.0 4.2 Ramon Santamaria
models_loading_gltf models_loading_gltf ☆☆☆ 3.7 4.2 Ramon Santamaria
models_loading_vox models_loading_vox ☆☆☆ 4.0 4.0 Johann Nadalutti
models_loading_m3d models_loading_m3d ☆☆ 4.5 4.5 bzt
models_orthographic_projection models_orthographic_projection ☆☆☆ 2.0 3.7 Max Danielsson
models_point_rendering models_point_rendering 5.0 5.0 Reese Gallagher
models_rlgl_solar_system models_rlgl_solar_system 2.5 4.0 Ramon Santamaria
models_yaw_pitch_roll models_yaw_pitch_roll ☆☆ 1.8 4.0 Berni
models_waving_cubes models_waving_cubes 2.5 3.7 Codecat
models_heightmap_rendering models_heightmap_rendering ☆☆☆ 1.8 3.5 Ramon Santamaria
models_skybox_rendering models_skybox_rendering ☆☆ 1.8 4.0 Ramon Santamaria
models_textured_cube models_textured_cube ☆☆ 4.5 4.5 Ramon Santamaria
models_animation_gpu_skinning models_animation_gpu_skinning 4.5 4.5 Daniel Holden
models_bone_socket models_bone_socket 4.5 4.5 iP
models_tesseract_view models_tesseract_view ☆☆ 5.6-dev 5.6-dev Timothy van der Valk
models_basic_voxel models_basic_voxel ☆☆ 5.5 5.5 Tim Little

category: shaders [29]

Examples using raylib shaders functionality, including shaders loading, parameters configuration and drawing using them (model shaders and postprocessing shaders). This functionality is directly provided by raylib rlgl module.

example image difficulty
level
version
created
last version
updated
original
developer
shaders_basic_lighting shaders_basic_lighting 3.0 4.2 Chris Camacho
shaders_model_shader shaders_model_shader ☆☆ 1.3 3.7 Ramon Santamaria
shaders_shapes_textures shaders_shapes_textures ☆☆ 1.7 3.7 Ramon Santamaria
shaders_custom_uniform shaders_custom_uniform ☆☆ 1.3 4.0 Ramon Santamaria
shaders_postprocessing shaders_postprocessing 1.3 4.0 Ramon Santamaria
shaders_palette_switch shaders_palette_switch 2.5 3.7 Marco Lizza
shaders_raymarching_rendering shaders_raymarching_rendering 2.0 4.2 Ramon Santamaria
shaders_texture_rendering shaders_texture_rendering ☆☆ 2.0 3.7 Michał Ciesielski
shaders_texture_outline shaders_texture_outline 4.0 4.0 Serenity Skiff
shaders_texture_waves shaders_texture_waves ☆☆ 2.5 3.7 Anata
shaders_julia_set shaders_julia_set 2.5 4.0 Josh Colclough
shaders_eratosthenes_sieve shaders_eratosthenes_sieve 2.5 4.0 ProfJski
shaders_fog_rendering shaders_fog_rendering 2.5 3.7 Chris Camacho
shaders_simple_mask shaders_simple_mask ☆☆ 2.5 3.7 Chris Camacho
shaders_hot_reloading shaders_hot_reloading 3.0 3.5 Ramon Santamaria
shaders_mesh_instancing shaders_mesh_instancing 3.7 4.2 seanpringle
shaders_multi_sample2d shaders_multi_sample2d ☆☆ 3.5 3.5 Ramon Santamaria
shaders_normalmap_rendering shaders_normalmap_rendering 5.6 5.6 Jeremy Montgomery
shaders_spotlight_rendering shaders_spotlight_rendering ☆☆ 2.5 3.7 Chris Camacho
shaders_deferred_rendering shaders_deferred_rendering 4.5 4.5 Justin Andreas Lacoste
shaders_hybrid_rendering shaders_hybrid_rendering 4.2 4.2 Buğra Alptekin Sarı
shaders_texture_tiling shaders_texture_tiling ☆☆ 4.5 4.5 Luis Almeida
shaders_shadowmap_rendering shaders_shadowmap_rendering 5.0 5.0 TheManTheMythTheGameDev
shaders_vertex_displacement shaders_vertex_displacement 5.0 4.5 Alex ZH
shaders_depth_writing shaders_depth_writing ☆☆ 4.2 4.2 Buğra Alptekin Sarı
shaders_basic_pbr shaders_basic_pbr 5.0 5.5 Afan OLOVCIC
shaders_lightmap_rendering shaders_lightmap_rendering 4.5 4.5 Jussi Viitala
shaders_rounded_rectangle shaders_rounded_rectangle 5.5 5.5 Anstro Pleuton
shaders_depth_rendering shaders_depth_rendering 5.6-dev 5.6-dev Luís Almeida

category: audio [8]

Examples using raylib audio functionality, including sound/music loading and playing. This functionality is provided by raylib raudio module. Note this module can be used standalone independently of raylib.

example image difficulty
level
version
created
last version
updated
original
developer
audio_module_playing audio_module_playing ☆☆☆ 1.5 3.5 Ramon Santamaria
audio_music_stream audio_music_stream ☆☆☆ 1.3 4.2 Ramon Santamaria
audio_raw_stream audio_raw_stream 1.6 4.2 Ramon Santamaria
audio_sound_loading audio_sound_loading ☆☆☆ 1.1 3.5 Ramon Santamaria
audio_mixed_processor audio_mixed_processor 4.2 4.2 hkc
audio_stream_effects audio_stream_effects 4.2 5.0 Ramon Santamaria
audio_sound_multi audio_sound_multi ☆☆ 5.0 5.0 Jeffery Myers
audio_sound_positioning audio_sound_positioning ☆☆ 5.5 5.5 Le Juez Victor

category: others [6]

Examples showing raylib misc functionality that does not fit in other categories, like standalone modules usage or examples integrating external libraries.

example image difficulty
level
version
created
last version
updated
original
developer
rlgl_standalone rlgl_standalone 1.6 4.0 Ramon Santamaria
rlgl_compute_shader rlgl_compute_shader 4.0 4.0 Teddy Astie
easings_testbed easings_testbed 2.5 3.0 Juan Miguel López
raylib_opengl_interop raylib_opengl_interop 3.8 4.0 Stephan Soller
embedded_files_loading embedded_files_loading ☆☆ 3.0 3.5 Kristian Holmgren
raymath_vector_angle raymath_vector_angle ☆☆ 1.0 5.0 Ramon Santamaria

Some example missing? As always, contributions are welcome, feel free to send new examples! Here is anexamples template with instructions to start with!