-
Notifications
You must be signed in to change notification settings - Fork 301
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
base: main
Are you sure you want to change the base?
Conversation
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.
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") |
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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:
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 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. |
e4a8abe
to
818a7de
Compare
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. |
Another recommendation: I'd switch SDL3's tag to |
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.