nuklear icon indicating copy to clipboard operation
nuklear copied to clipboard

Custom rendering inside windows

Open Nuk510 opened this issue 8 years ago • 2 comments

Hello! I've been messing around with Nuklear, and I have to say, this is very cool library you have here, and also very well-organized!

The only real roadblock I have hit with it is that I can't do any custom rendering inside the windows. Custom OpenGL code inside a window, for example.

I've tried callbacks so far, thinking that any rendering within them would be called on top of the window that they belong to. As it turns out, the callbacks get processed/executed inside nk_convert, before any window drawing happens, so my triangle test gets covered up with the window I'm trying to target. The SDL2 OpenGL ES 2 demo has been my testbed, so I commented out the line glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset); to see what the result would be. As expected, the windows are no longer rendered, and the triangle test is drawn exactly where it should be.

Another thing I have tried was hackishly setting up the triangle test to render based on userdata. It almost worked, but userdata doesn't seem to work per-window, so windows dragged over it render behind it, while the window borders/buttons are in front of it.

The last thing I tried was using widgets to get the job done, but once again, no dice. Like the other two solutions, widgets don't seem geared toward plugging custom rendering routines into specific parts of windows.

Of all three attempts, the callback method with nk_push_custom has been the cleanest and most favorable, except all the windows draw on top of it.

Is there something I'm missing? I've been scouring the source code and demos to no avail. Is there any function that can be called similarly to nk_push_custom (nk_push_custom(nk_window_get_canvas(ctx),nk_window_get_content_region(ctx),triangle_test,nk_handle_ptr(NULL));) which will do exactly the same thing, but on top of the window it belongs to instead of behind it? Or is this currently impossible in Nuklear?

Any suggestions would be nice, thank you!

Nuk510 avatar Nov 13 '17 21:11 Nuk510

Hm..., I am still not sure what exactly you mean with custom rendering. Do you mean custom 2D drawing using nuklears internal drawing features. If so look inside the example/canvas example to see how to do it. On the other hand if you mean custom 3D elements like a 3D scene what you can do is draw your scene into a texture and just draw it inside a window using nk_image passing in your rendered texture as ID.

vurtun avatar Nov 16 '17 12:11 vurtun

As I've understood it, the idea is to use a window (or any widget, the idea is the same), as a target of an opengl scene. If you look at this image https://i.imgur.com/3wRpijA.png?1 there is a window named "Game (Edit Mode) Paused" that contains the game scene embedded into a window.

I'm also kinda interested in that (even if my idea is to create a freetype-gl widget to display a complex text using shaders).

Is there any way we could achieve that?

aCorrado avatar Mar 19 '18 10:03 aCorrado