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

[Renderers/SDL3] Adds an example using SDL3 as a renderer #107

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LiquidityC
Copy link

This example is rather basic but it does provide an example how one could setup a rendering loop between clay and SDL3.

Although SDL3 is in its infancy and doesn't have an official stable release the API has been locked so there shouldn't be any code adaptations required for this example if one was to update to a more recent SDL3 release in the future.

This example is rather basic but it does provide an example how one
could setup a rendering loop between clay and SDL3.

Although SDL3 is in its infancy and doesn't have an official stable
release the API has been locked so there shouldn't be any code
adaptations required for this example if one was to update to a more
recent SDL3 release in the future.
@nicbarker nicbarker changed the title Adds an example using SDL3 as a renderer [Renderers/SDL3] Adds an example using SDL3 as a renderer Dec 26, 2024
@nicbarker
Copy link
Owner

Awesome, thank you for the contribution! I will take a proper look at this over the next week or so 👍


# Project setup
project(clay_sdl3_renderer C)
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Werror")

Choose a reason for hiding this comment

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

Small remark here, which was already present in the other examples: you're replacing the flags here instead of adding them. Ideally, you'd write something like

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Wall -Werror")

Copy link
Author

Choose a reason for hiding this comment

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

Done

)
message(STATUS "Using SDL via FetchContent")
FetchContent_MakeAvailable(SDL)
set_property(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_deps/sdl-src" PROPERTY EXCLUDE_FROM_ALL TRUE)
Copy link

@SiebrenW SiebrenW Dec 29, 2024

Choose a reason for hiding this comment

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

You probably want to use <lowercaseName>_SOURCE_DIR instead of _debs/sdl-src https://cmake.org/cmake/help/latest/module/FetchContent.html

So that'd be:

set_property(DIRECTORY "${sdl_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL TRUE)

Copy link
Author

Choose a reason for hiding this comment

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

I did not know that this variable existed. Thanks. I'll need to revisit some of my projects now I think 😄

FetchContent_Declare(
SDL_ttf
GIT_REPOSITORY https://github.com/libsdl-org/SDL_ttf.git
GIT_TAG 40219a6

Choose a reason for hiding this comment

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

This tag failed for me when I tried to build your PR. I recommend changing the GIT_TAG to main until a proper SDL_ttf version is tagged and released for SDL3.

Copy link
Author

Choose a reason for hiding this comment

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

I'll swap it to main for now. Once there's an official stable SDL3 release i assume there'll be a related tag set in SDL_ttf. I think the risk of breakage should be rather low at this point even if we do point out main.

@kattkieru
Copy link

Tested as working on macOS 15.2 -- thanks for this! I appreciate that you took the time to wrap in SDL_ttf. I also like that you used the new callbacks method for integration. I'm all-in on SDL3 so it's nice to see others adopting it for new, useful frameworks like Clay.

I left one comment on the SDL_ttf version, above. Otherwise, the demo works a treat.

My thoughts:

  • Do you think it would be good to split this into a renderer that could be shared?
  • Should this be using dynamic libraries by default?

I'd also love to see the demo essentially replicate the Raylib scroller, which would involve adding SDL_image to the build. (I'm one of those weirdos who thinks SDL_image and SDL_ttf should be part of the base library, though. 🤣 )

@LiquidityC
Copy link
Author

Tested as working on macOS 15.2 -- thanks for this! I appreciate that you took the time to wrap in SDL_ttf. I also like that you used the new callbacks method for integration. I'm all-in on SDL3 so it's nice to see others adopting it for new, useful frameworks like Clay.

I left one comment on the SDL_ttf version, above. Otherwise, the demo works a treat.

My thoughts:

  • Do you think it would be good to split this into a renderer that could be shared?
  • Should this be using dynamic libraries by default?

I'd also love to see the demo essentially replicate the Raylib scroller, which would involve adding SDL_image to the build. (I'm one of those weirdos who thinks SDL_image and SDL_ttf should be part of the base library, though. 🤣 )

Nice that it worked.

Regarding extensions. There is one caveat with the builtin renderer in SDL. There's no ability to render circles out of the box. I didn't look into the "border" rendering commands from clay. But my best guess is that there might be some issues with this and the border radius. This will require bespoke solutions per project that does chose to utilize clay.

For me that's a reason to avoid providing a default SDL renderer within clay and instead leave that to the user to solve for their particular case.

Granted I'm not the maintainer of the repo and if there's an interest in extending this renderer to a provided solution I'm open to help out.

@kattkieru
Copy link

There is one caveat with the builtin renderer in SDL. There's no ability to render circles out of the box.

Yes, it's been a weird API hole for decades. That said, you could render circles using SDL_RenderGeometry (providing "circles" in the form of triangles). I know that SDL_RenderPoint has too much overhead for a circle rasterizer, but I haven't tested SDL_RenderPoints, which allows for passing a bunch of points at once-- perhaps the latter would be the easiest path? I might run a test.

@kattkieru
Copy link

Another recommendation: I'd switch SDL3's tag to main as well. They added live window resizing to macOS but it's only within the past week. When 3.2.0 hits I could see pinning to that version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants