raylib: [examples] Review some examples not working properly on several platforms

Issues on multiple platforms

  • REVIEW: core_3d_camera_free. Displayed controls do not match and camera behaves strangely.

Issues on PLATFORM_DESKTOP, macOS (and maybe other platforms/OSs)

  • REVIEW: custom_frame_control --> Requires raylib built with SUPPORT_CUSTOM_FRAME_CONTROL.
  • REVIEW: models_loading. It seems to be buggy at selecting the model, needs some review
  • REVIEW: skybox_loading. Doesn’t fill the entire window, only the bottom-left quadrant --> Probably related to HighDPI.
  • REVIEW: shader_hot_reloading, shader_spotlight. Scaling issue between the mouse and circle positions --> Probably related to HighDPI.
  • REVIEW: top_down_lights. Fully illuminated (no shadows are drawn) until light is moved

Issues on PLATFORM_WEB

  • REVIEW: models_skybox. WebGL: INVALID_VALUE: disableVertexAttribArray: index out of range _glDisableVertexAttribArray.
  • REVIEW: core_custom_frame_control --> Requires raylib built with SUPPORT_CUSTOM_FRAME_CONTROL.
  • REVIEW: core_loading_thread --> Threading support depends on the browser and security reasons.
  • REVIEW: core_window_flags --> Most window flags are intended for a window, not a canvas.
  • REVIEW: raylib_opengl_interop --> Example intended for OpenGL desktop, not OpenGL ES.
  • REVIEW: rlgl_standalone --> PLATFORM_DESKTOP exclusively
  • REVIEW: models_mesh_instancing. Not working properly on web, issues with the shader but ONLY when uploade to GitHub, it works as expected locally.

Issues on PLATFORM_DRM

  • REVIEW: Examples with 3D cameras (e.g.: models_first_person_maze, core_3d_camera_free). Camera moving uncontrollably.
  • REVIEW: Examples with visible cursors (e.g.: shapes_draw_circle_sector, shapes_draw_ring). Cursor not showing.
  • REVIEW: Examples with type inputs (e.g.: text_draw_3d, text_input_box). Can’t type.
  • REVIEW: audio_module_playing. Crashing the Raspberry Pi after a few seconds.
  • REVIEW: core_custom_frame_control. Flickering and not working. --> Requires raylib built with SUPPORT_CUSTOM_FRAME_CONTROL.
  • REVIEW: core_vr_simulator. Not rendering.
  • REVIEW: models_skybox. Not rendering. --> Requires enabling HDR loading but maybe not supported by OpenGL ES.
  • REVIEW: shaders_raymarching. Not rendering. --> Shader not adapted for GLSL100.
  • REVIEW: shaders_mesh_instancing. Segmentation fault. --> Not supported by OpenGL ES.
  • REVIEW: rlgl_compute_shader. Not working. --> Not supported by OpenGL ES.
  • REVIEW: raylib_opengl_interop. Not compiling. --> Example intended for OpenGL desktop, not OpenGL ES.
  • REVIEW: rlgl_standalone. Not compiling. --> PLATFORM_DESKTOP exclusively

Note that some of the issues seem related to platform/OpenGL limitations.

In any case, any help with those examples is really welcome.

About this issue

  • Original URL
  • State: open
  • Created 8 months ago
  • Reactions: 2
  • Comments: 42 (18 by maintainers)

Commits related to this issue

Most upvoted comments

@ubkp @erikyuzwa the gamejam template actually belongs to a previous gamejam that required a 32x32 pixels game and it included code to scale that game x4, so I kept the RenderTexture for convenience, also useful to deal with fixed game sizes/screen-ratios that need to be scaled to screen later on.

About the log output to file, afair, in Windows CMD, core_3d_camera_first_person > mylog.txt should work. But you also have SetTraceLogCallback(TraceLogCallback callback) to output the log messages wherever you want.

I think we can continue with the raylib 5.0 release despite some issues with the examples, they can be reviewed in the future as required.

Agreed. I think the major problems were solved or documented. The examples issues left don’t appear to be super critical.

As a side note, today I implemented a tool to update examples open-graph metada, so examples can be shared on multiple social networks (X, Mastodon, LinkedIn, Discord…) with a fancy visual card showing each example details. I will provide more info asap.

That’s awesome! 👍

Most of the example after adjusting the size, I made it global:

find . -type f -name "*.c" -print0 | xargs -0 sed -i -e 's/screenHeight = 450/screenHeight =
1280/g'

and

find . -type f -name "*.c" -print0 | xargs -0 sed -i -e 's/screenWidth = 800/screenWidth = 400
g'

from folder examples work without problems.

This applies to RayGUI as well.

@colesnicov Just note that I’m planning to remove glad from raylib dependencies and just load required extensions manually. It would reduce initialization times and memory required… as well as an external dependency.

I found this https://gen.glad.sh/, and I’m a deer for it 😄 .

@colesnicov this is a special example to illustrate raylib interoperatibility with OpenGL, it requires including OpenGL libraries.

appreciate the followup and insight there @raysan5 🙇

@erikyuzwa No problem, glad it worked. 😃

I think the problem was that the gamejam template basic structure, for some reason, opts to render to a texture (L79-L82, L124-L130) and them render that texture to screen (L133-L141).

Most of the examples use a far simpler method of just rendering things directly to screen (e.g.: L144-L196), which is probably what I would recommend using while you’re getting used to raylib.

Regarding the log, on Linux it’s usually just a matter of piping the log to a file (e.g.: ./core_3d_camera_first_person > LOG). Windows probably have something similar to that, although I don’t know the syntax.

Edit: typo.

@ubkp - that worked! Thanks so much. Not sure why the same code dropped into the rendering in the game template didn’t but I’ll leave that until I work more with textures - thank you SO much and apologies for polluting the OG issue with this.

Here’s the log just in case it helps. I will also go through the source to see if I can pipe the log to a file (for eventual testers).

INFO: Initializing raylib 5.1-dev
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 1920 x 1080
INFO:     > Screen size:  800 x 450
INFO:     > Render size:  800 x 450
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 400
INFO: GL: OpenGL device information:
INFO:     > Vendor:   NVIDIA Corporation
INFO:     > Renderer: NVIDIA GeForce RTX 2070 SUPER/PCIe/SSE2
INFO:     > Version:  3.3.0 NVIDIA 546.33
INFO:     > GLSL:     3.30 NVIDIA via Cg compiler
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: PLATFORM: DESKTOP (GLFW): Initialized successfully
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TIMER: Target time per frame: 16.667 milliseconds
INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
INFO: SHADER: [ID 3] Default shader unloaded successfully
INFO: TEXTURE: [ID 1] Default texture unloaded successfully
INFO: Window closed successfully

@erikyuzwa You mentioned you’re using the gamejam template, right? By any chance are you testing using this structure? If so, please test using just this (exactly as is) instead.

@ubkp @Bigfoot71 I reviewed rlgl_standalone example, I’m afraid it is PLATFORM_DESKTOP exclusive and supporting other platforms would require some redesign. I just added a note explaining this. The examples uses GLFW to initialize the platform layer and the OpenGL 3.3 Core profile context. It could work on web with OpenGL ES 2.0 but it would need a redesign, I think it’s out-of-scope for the moment for this example.

Actually, all examples in others are somewhat special and are not intended to work on all platforms or under “all scenarios”.

I think we can continue with the raylib 5.0 release despite some issues with the examples, they can be reviewed in the future as required.

As a side note, today I implemented a tool to update examples open-graph metada, so examples can be shared on multiple social networks (X, Mastodon, LinkedIn, Discord…) with a fancy visual card showing each example details. I will provide more info asap.

This issue with mediump and Z-Fighting only occurs on certain devices and under certain conditions. I hadn’t even noticed it on my device during “normal” use.

@Bigfoot71 I really think it’s platform/drivers-dependant and there is not a good solution to cover most use case. Better leave it as it is. In any case, advance users can change it for their needs depending on their target audience and development process.

@Bigfoot71 Perhaps an #ifdef there could solve that for both?

#if defined(PLATFORM_WEB)
   "precision mediump float;           \n"     // Precision required for OpenGL ES2 (WebGL) (on some browsers)
#elif defined(PLATFORM_ANDROID)
   "precision highp float;             \n"
#endif

@Bigfoot71 Related: #3260, #3261.

@raysan5 I found how to resolve the Z-Fighting issue I mentioned earlier. (on Android)

You need to modify the floating-point precision of the default shader as follows:

#if defined(GRAPHICS_API_OPENGL_ES2)
    "#version 100                       \n"
-   "precision mediump float;           \n"     // Precision required for OpenGL ES2 (WebGL) (on some browsers)
+   "precision highp float;             \n"     // Precision required for OpenGL ES2 (WebGL) (on some browsers)
    "attribute vec3 vertexPosition;     \n"
    "attribute vec2 vertexTexCoord;     \n"
    "attribute vec4 vertexColor;        \n"
    "varying vec2 fragTexCoord;         \n"
    "varying vec4 fragColor;            \n"
#endif

However, after some research, it seems that this Z-Fighting issue, which can be resolved by modifying the floating-point precision in the shader, only occurs on certain devices (not high-end or older ones).

@Bigfoot71 I just meant as a reference. Those were just the ones I couldn’t get to work completely here. I think most of those marked with 2 are indeed not meant to run on Android.

@Bigfoot71 not sure if you tested all the examples on PLATFORM_ANDROID and you also found some issues there…

No, from memory, the few issues I had noticed last time have been fixed, and even GetMouseDelta() was implemented as a bonus. I had tried an example in each category on the site, including several from CORE.

I will try all of them tomorrow and provide a brief report. Normally, except for some shader examples, I believe they should all be able to run without any problems.

Edit: I had already mentioned it, but unfortunately, I won’t be able to try the example for the gamepad.

Platftorm Example Status Comment
Desktop core_3d_camera_free ✔️ Fixes on #3240 and #3488.
Web models_skybox ✔️ It’s working, but requires SUPPORT_FILEFORMAT_HDR to be enabled on config.h.
Web core_loading_thread IMHO, I don’t think this example should work (at least for now) on PLATFORM_WEB. See the warning on L602-L605, which I think is warranted (check this and this). I don’t think this feature is mature enough yet.

Note: There was a recent PR related to this example: #3449
Web rlgl_standalone I think this should/could work. I’ve added the necessary lines to the Makefile.Web but for some reason it just refuses to link to the GLES2/gl2.h inside emscripten’s upstream/emscripten/cache/sysroot/include.

At the moment I’m still unable to make it compile for web.
Web shaders_mesh_instancing I believe the example itself is working. Compiled and uploaded it to Github at https://ubkp.github.io/shaders_mesh_instancing.html and it’s working correctly.

Testing it on https://www.raylib.com/examples.html I get the errors from the screenshot on Note 1.

My best guess is that the problem could be related to the way the example gets built and/or run on raylib.com.
DRM Examples with 3D cameras:
models_first_person_maze
core_3d_camera_free
etc
✔️ Fix on #3492.
DRM Examples with visible cursors:
shapes_draw_circle_sector
shapes_draw_ring
etc
Although the examples are working, I think that the cursor is not showing because it’s not implemented for DRM (L490-L494).

Not sure how to handle it in this case. I’m assuming that in this platform the cursor would be rendered by the user on the Drawing step of the application.

References: core_input_mouse (L56) and https://github.com/raysan5/raylib/discussions/2952#discussioncomment-7172966.
Platftorm Example Status Comment
DRM Examples with type inputs:
text_draw_3d
text_input_box
etc
✔️ Fix on #3498.
DRM audio_module_playing I have no idea why this is crashing the Raspberry Pi. All I could find was that it happens after restarting the music a few times and then trying to exit the example hitting ESC.
DRM core_vr_simulator The only thing I could find was WARNING: FBO: [ID 1] Framebuffer has incomplete attachment.
DRM models_skybox Got these errors: IMAGE: Data format not supported IMAGE: Failed to load image data.

Looks like the Raspberry Pi 3B doesn’t support HDR, perhaps the newer ones do.
DRM shaders_raymarching Issue with the fragment shader: extension GL_OES_standard_derivates unsupported in fragment shader.

Not sure if this example can run on the Raspberry Pi 3B, perhaps the newer ones can.
DRM rlgl_standalone Looks like it’s possible that this could be compiled. Just need to add the -L../examples/others/external/lib and -lglfw3. However, it returns an error libglfw3.a: file not recognized: file format not recognized.. Which leads me to believe that .a (file) was compiled for x86 and not ARM.

IMHO, the easiest (and safest) solution would be the user compiling/providing his own libglfw3.a for the Raspberry Pi. Would just be the case of adding that information to the source instructions (L16).

Notes

  1. Screenshot of shaders_mesh_instancing error on raylib.com/examples.html:

img

Edits

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11. updates.

@ubkp @michaelfiber Just opened this issue for further discussion on the examples not working properly that you reported. Actually some of them are not intended to work on the target platform while others have specific concerns.

@Bigfoot71 not sure if you tested all the examples on PLATFORM_ANDROID and you also found some issues there…