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] Add image rendering and scissor support to SDL3 renderer #246

Merged
merged 4 commits into from
Feb 12, 2025

Conversation

steviegt6
Copy link
Contributor

@steviegt6 steviegt6 commented Jan 31, 2025

Implements CLAY_RENDER_COMMAND_TYPE_IMAGE for the SDL3 renderer using SDL_image essentially identically to how it's done in SDL2 (see #208).

Also implements CLAY_RENDER_COMMAND_TYPE_SCISSOR_START/CLAY_RENDER_COMMAND_TYPE_SCISSOR_END based on the similar implementation in the SDL2 renderer.

@steviegt6 steviegt6 changed the title add image rendering support to SDL3 renderer add image rendering support to sdl3 renderer Jan 31, 2025
@steviegt6 steviegt6 changed the title add image rendering support to sdl3 renderer [Renderers/SDL3] Add image rendering and scissor support to SDL3 renderer Feb 7, 2025
@steviegt6
Copy link
Contributor Author

When I first implemented images, the example was split and I just inserted an image to render. Now the SDL3 example uses the video demo and the image example in the SDL2 example also goes unused, I'll leave the loading there as an example but I'm not sure what the ideal change to make it.

const SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, config->imageData);
const SDL_FRect dest = { rect.x, rect.y, rect.w, rect.h };

SDL_RenderTexture(renderer, texture, NULL, &dest);
Copy link
Contributor

@ernestoyaquello ernestoyaquello Feb 9, 2025

Choose a reason for hiding this comment

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

After it's rendered, the texture should be destroyed here:

Suggested change
SDL_RenderTexture(renderer, texture, NULL, &dest);
SDL_RenderTexture(renderer, texture, NULL, &dest);
SDL_DestroyTexture(texture);

@ernestoyaquello
Copy link
Contributor

ernestoyaquello commented Feb 9, 2025

Is there a reason why we pass a surface and then convert it into a texture? The SDL_image library allows us to get a texture directly for any image (IMG_LoadTexture, etc), so that seems much more efficient. 🤔

@nicbarker
Copy link
Owner

Thank you for the great work here, we just get the DestroyTexture in to prevent the memory getting leaked, then we can merge it 😁

@nicbarker nicbarker force-pushed the feature/sdl3-image-rendering branch from 69e0839 to 1848f1f Compare February 12, 2025 21:01
@nicbarker nicbarker merged commit bc2548e into nicbarker:main Feb 12, 2025
3 checks passed
@steviegt6
Copy link
Contributor Author

Thanks for merging; sorry I didn't get to the additional changes myself! I've been busy with work.

@nicbarker
Copy link
Owner

That's totally fine, thank you for the good work!

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.

3 participants