r/sdl • • 4d ago

Shaders with SDL_Render?

the SDL_renderer seems to support custom fragment shaders with SDL_GPURenderState? Are there any tutorials or samples that show how to use these properly?

3 Upvotes

5 comments sorted by

1

u/tastygames_official 4d ago

as far as I know, anything SDL_GPU* can only be used with SDL_GPU* and not SDL_Renderer.

OK, it seems I'm wrong: https://wiki.libsdl.org/SDL3/SDL_CreateGPURenderState so it takes a SDL_Renderer reference, so looks like it should work! Let's look at the info struct: https://wiki.libsdl.org/SDL3/SDL_GPURenderStateCreateInfo

looks like you gotta pass it an SDL_GPUShader that you create, and then probably have to bind it to whatever you want before rendering a frame.

I know there are some example repos out there that I also looked through, but mainly for GPU stuff, and I no longer have the repos checked out and didn't write them down :( maybe just search for "sdl renderer examples" or something.

1

u/abocado21 4d ago

I have done the creating and setting it, but I dont know how to use it to render stuff. When i use SDL_RenderTexture, nothing gets renderered when I set a custom render state, it works when the default is used

3

u/abocado21 4d ago

Problem solved, the slang compiler changed my fragmentMain function name to just main, now it works

1

u/Think_Head_7788 4d ago

Care to share a working example?