SDL_gpu_examples icon indicating copy to clipboard operation
SDL_gpu_examples copied to clipboard

Could you provide a demo of using a set of basic shader effects?

Open jcy1001 opened this issue 1 year ago • 2 comments
trafficstars

Thanks, buddy. Could you provide a demo of using a set of basic shader effects? It would be really useful for us ordinary developers.

jcy1001 avatar Oct 12 '24 06:10 jcy1001

"Basic shader effects" can mean a lot of different things. The repo already has a bunch of shaders for different purposes. Was there something specific you had in mind?

TheSpydog avatar Oct 12 '24 17:10 TheSpydog

static SDL_Window window; static SDL_Renderer renderer; static SDL_Texture display_buffer;

renderer = SDL_CreateRenderer( window, renderer_id, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE ); SDL_Surface * surface= IMG_Load( path ) ;

SDL_Texture* pic= SDL_CreateTextureFromSurface( renderer, surface ) ;

SDL_SetRenderDrawBlendMode( renderer, SDL_BLENDMODE_NONE ); display_buffer.reset( SDL_CreateTexture( renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, 1280, 720) );

SDL_SetRenderTarget( renderer, display_buffer);

RenderCopy( renderer, display_buffer, nullptr, nullptr ); SDL_RenderPresent( renderer );

Here is the code from my game that uses SDL2 to render my images. I want to add a white shader effect when the monster is hit on this basis. I'm considering migrating to SDL3. How should I use the new API or GPU API for this?

jcy1001 avatar Oct 14 '24 09:10 jcy1001

Sounds like what you want is demonstrated in this demo: https://github.com/TheSpydog/SDL_gpu_examples/blob/main/Examples/TexturedAnimatedQuad.c

FunByJohn avatar Oct 16 '24 08:10 FunByJohn

In order to use shaders, you'll need to migrate from SDL_Render to the GPU API. As FunByJohn said, you can see what that might look like in some of the examples here. Especially check out ComputeSpriteBatch as that's designed to demonstrate how to efficiently draw a large number of sprites.

Since shader setup is heavily dependent on your overall rendering infrastructure, I don't think having a collection of 2D sprite effects would be particularly useful, so I'm going to close this as Not Planned. There are plenty of example shaders across the web you can look at and adapt to your needs if you do decide to switch to SDL_GPU!

TheSpydog avatar Oct 17 '24 14:10 TheSpydog