#872·Nuklear

demos do not handle NK_UINT_DRAW_INDEX flag, resulting in broken rendering

Author: sleeptightAnsiCCreated Jan 3, 2026Updated Jul 8, 2026

Most of the demos do not handle NK_UINT_DRAW_INDEX in any way, which means that whenever said flag is defined, there will be mismatch between vertex data and draw calls, which results in broken rendering like so:

Image

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
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.

Source: Immediate-Mode-UI/Nuklear