Immediate-Mode-UI / Immediate-Mode-UI/Nuklear

demos do not handle NK_UINT_DRAW_INDEX flag, resulting in broken rendering

Open
#872 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
11.4k
Forks
686
Avg merge
4d 1h
Merged PRs (30d)
3

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start with demo/sdl_opengl2/nuklear_sdl_gl2.h and the NK_UINT_DRAW_INDEX handling in demo/d3d11/nuklear_d3d11.h. Search the other demo backend headers for draw calls that assume 16-bit indices, then build each affected demo with the flag enabled. Done means the demos render their UI and text correctly with both index-width configurations.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.