#872

demos do not handle NK_UINT_DRAW_INDEX flag, resulting in broken rendering

OpensleeptightAnsiCopened 10mo ago

Most of the demos do not handle NK_UINT_DRAW_INDEX in any way, which means that whenever said flag is defined, either the vertex data or the draw calls will break, which results in broken rendering like so:

This was found by @Xeverous and mentioned on Nuklear discord server https://discord.com/channels/922234432071548968/922234432071548973/1456733473355206666

Xeverous — Yesterday at 8:38 PM
I have found an issue where defining NK_UINT_DRAW_INDEX completely destroys the rendering, I see shaded rectangles, no UI or any text. Happens with SDL backend. Will try to reproduce on pure C and minimal code.
I confirm. This is completely broken. Add -DNK_UINT_DRAW_INDEX to demo/sdl_opengl2/Makefile and see yourself.

sleeptightAnsiC — 12:40 PM
This is probably also broken with most other demos. Only two demos (d3d11 and d3d12) have a condition related to this flag. I suspect you could take a look at how d3d11 solves it, and try applying the same. https://github.com/Immediate-Mode-UI/Nuklear/blob/9afb3dd6d14fba0c5e62f08809b494b6d580b9b1/demo/d3d11/nuklear_d3d11.h#L89-L93

sleeptightAnsiC — 12:44 PM
Does this patch fixes the issue for you?
[see patch below]
^ This should work. I just tested it on my side.

[patch from above]

diff --git a/demo/sdl_opengl2/nuklear_sdl_gl2.h b/demo/sdl_opengl2/nuklear_sdl_gl2.h
index 18509f1..f9a0144 100644
--- a/demo/sdl_opengl2/nuklear_sdl_gl2.h
+++ b/demo/sdl_opengl2/nuklear_sdl_gl2.h
@@ -158,7 +158,11 @@ nk_sdl_render(enum nk_anti_aliasing AA)
                 (GLint)((height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y),
                 (GLint)(cmd->clip_rect.w * scale.x),
                 (GLint)(cmd->clip_rect.h * scale.y));
+        #ifdef NK_UINT_DRAW_INDEX
+            glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_INT, offset);
+        #else
             glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
+        #endif
             offset += cmd->elem_count;
         }
         nk_clear(&sdl.ctx);

As you can see, this was trivial to fix for demo/sdl_opengl2 and it should be easy to fix for other demos.

The problem is that since every demo is affected by this, we need to fix and test all of them separately...

This was reported before as https://github.com/Immediate-Mode-UI/Nuklear/issues/659 but since there was not much info there, I decided to enter new Issue.

Activity

5
Xeverous9mo ago

I confirm the patch fixes the issue for me.

Xeverous9mo ago

I confirm the patch fixes the issue for me.

Xeverous9mo ago

I confirm the patch fixes the issue for me.

sleeptightAnsiC5mo ago

Small note: some demos have this hardcoded to literal value - 2 - and those values can be replaced with sizeof(nk_draw_index) https://github.com/Immediate-Mode-UI/Nuklear/blob/859d17b71a6c44836d0dc1ced897ec41707ac670/demo/sdl_renderer/nuklear_sdl_renderer.h#L184

sleeptightAnsiC5mo ago

Small note: some demos have this hardcoded to literal value - 2 - and those values can be replaced with sizeof(nk_draw_index) https://github.com/Immediate-Mode-UI/Nuklear/blob/859d17b71a6c44836d0dc1ced897ec41707ac670/demo/sdl_renderer/nuklear_sdl_renderer.h#L184