Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: SDL2 SDL_Renderer #280

Closed
wants to merge 6 commits into from
Closed

Backend: SDL2 SDL_Renderer #280

wants to merge 6 commits into from

Conversation

1bsyl
Copy link
Contributor

@1bsyl 1bsyl commented Mar 26, 2021

Provide an example to build Nuklear using SDL2 / SDL_RenderGeometry (using this PR libsdl-org/SDL#4195)

Which makes Nuklear using the platform backend available (opengl, opengles2, Direct3D11, Metal, or software rendering).

@gabrielrad
Copy link

@1bsyl just a small curiosity..is this is meant to be working with the SDL_Renderer, why the need to specify those OpenGL attributes? Is there any limitation? I'm asking this because I use SDL and don't want to drop D3D11 :)

@1bsyl
Copy link
Contributor Author

1bsyl commented Mar 30, 2021

@gabrielrad
Sorry I forgot to remove them ! After I copy pasted the opengl example...
(though you may want maybe want to add some GL attribute if you use and want to configure the opengl backend specifically)

I'll clean up this example if the SDL branch is merged. (so please don't merge the branch right now).

This example should also run on with D3D11 / METAL / opengl / gles2 / and software.
Not running with native SDLdirect3d ( 9 ? ), because I haven't add the triangles function in it.
It also runs with the software renderer backend

@gabrielrad
Copy link

Thank you for being awesome @1bsyl ! Fingers crossed it gets merged in SDL2! I'm very happy on using SDL2 for everything especially the drawing aspect, and having also the ability to use something like dear imgui alongside would be a dream come true!

@gabrielrad
Copy link

@1bsyl undefined reference for SDL_RenderGeometryRaw

@1bsyl
Copy link
Contributor Author

1bsyl commented Apr 1, 2021

@gabrielrad
I haven't pushed everything into the SDL branch, but I've planned to do this today

@1bsyl
Copy link
Contributor Author

1bsyl commented Apr 1, 2021

@gabrielrad I have pushed so stuff to SDL branch (not yet the METAL nor the D3D11 implementation)

@1bsyl
Copy link
Contributor Author

1bsyl commented Apr 1, 2021

@gabrielrad : I've pushed METAL and D3D11 backend updates

@atticus5
Copy link

atticus5 commented Apr 3, 2021

@1bsyl In nk_sdl_render you should reset the clip rectangle back to default with SDL_RenderSetClipRect(sdl.renderer, NULL); otherwise it might mess with the drawing logic other people have..

Also did you figure out how to draw textures?

@1bsyl
Copy link
Contributor Author

1bsyl commented Apr 3, 2021

@gavriil07
added save&restore the clip rect.
About texture: the SDL api draws textures.
Not sure about Nuklear, I'm not familiar with it.

@atticus5
Copy link

atticus5 commented Apr 3, 2021

@1bsyl Not quite right..You should check SDL_RenderIsClipEnabled before saving the clip rectangle, because if clipping is disabled you don't want to activate it with an empty rectangle :

rect an SDL_Rect structure filled in with the current clipping area or an empty rectangle if clipping is disabled

(https://wiki.libsdl.org/SDL_RenderGetClipRect)

This seems to work nice:
SDL_Rect *saved_clip = NULL; if (SDL_RenderIsClipEnabled(sdl.renderer)) SDL_RenderGetClipRect(sdl.renderer, saved_clip);

I know SDL has support for drawing textures, that is why it would be nice that your example would include some image buttons also, because nuklear supports this. I for myself could not get it working..

@1bsyl
Copy link
Contributor Author

1bsyl commented Apr 3, 2021

@gavriil07 yes you're right you need to check if clipping was enabled
but you're example is wrong. you've no storage for saved_clip, only null ptr.

Sorry I don't know the Nuklear API, I modified the existing example to test SDL_RenderGeometry.
But for sure it works with texture. It actually use the g_fonttexture.

@1bsyl
Copy link
Contributor Author

1bsyl commented Apr 4, 2021 via email

@jwurzer
Copy link

jwurzer commented Dec 11, 2021

SDL 2.0.18 was released on 30. Nov 2021 with official Support for SDL_RenderGeometry() and SDL_RenderGeometryRaw() :-)
Is there any stopper with this pull request to support Nuklear with SDL renderer? I think it would be great if Nuklear official include this pull request to support a demo with SDL renderer.

Comment on lines +42 to +47
#ifdef INCLUDE_ALL
#define INCLUDE_STYLE
#define INCLUDE_CALCULATOR
#define INCLUDE_OVERVIEW
#define INCLUDE_NODE_EDITOR
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding the Canvas demo too?

#include <limits.h>
#include <time.h>

#include <SDL.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHould this be #include <SDL2/SDL.h> instead?

Comment on lines +11 to +12
#ifndef NK_SDL_GL2_H_
#define NK_SDL_GL2_H_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect header define.

#ifndef NK_SDL_GL2_H_
#define NK_SDL_GL2_H_

#include <SDL.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <SDL2/SDL.h>?

*
* ===============================================================
*/
#ifdef NK_SDL_GL2_IMPLEMENTATION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect define.

@RobLoach RobLoach changed the title Add example to use Nuklear with SDL2 SDL_Renderer and SDL_RenderGeome… Backend: SDL2 SDL_Renderer Dec 22, 2021
@RobLoach RobLoach added the Backend Any discussion about a certain binding implementation label Dec 22, 2021
@RobLoach RobLoach marked this pull request as draft December 27, 2021 02:19
@RobLoach
Copy link
Contributor

RobLoach commented Jan 7, 2022

Brought over to #396 ... Thanks so much!

@RobLoach RobLoach closed this Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Any discussion about a certain binding implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants