Multiple rendering questions

Hello, I am currently developing a raycasting engine much like Doom and HeXen. I have been using SFML 2 so far but it proved lacking and unworthy so I decided to switch to SDL 2. Has all the functionality and works faster, which I really like since raycasting is time heavy. Current setup is to use streaming SDL_Texture and “default” SDL_Renderer for sending prerendered frames to the GPU. Having said that I have a couple of questions:

  1. Is there a fast way to multiply (or any other operation) a uint32_t pixel (all components packed into one number) with a modifier? For example I need to render one sector with redish lighting - with my old codebase where colors were separate uint8_t for each component I would do: r * 1, g * .2, b * .1 or so but here I have no idea what to do. SDL_GetRGB and SDL_MapRGB is out of question since it is too slow when done ScreenWidth*ScreenHeight times.

  2. Can I use shaders with SDL_Renderer and how? Or do I need to resort to “basic” OpenGL setup i.e. no renderer? Question No. 1 could be easily solved (and would be faster I guess) by a post-effect combining framebuffer and a color map.

Indorile wrote:

Hello, I am currently developing a raycasting engine much like Doom and HeXen. I have been using SFML 2 so far but it proved lacking and unworthy so I decided to switch to SDL 2. Has all the functionality and works faster, which I really like since raycasting is time heavy. Current setup is to use streaming SDL_Texture and “default” SDL_Renderer for sending prerendered frames to the GPU. Having said that I have a couple of questions:

  1. Is there a fast way to multiply (or any other operation) a uint32_t pixel (all components packed into one number) with a modifier? For example I need to render one sector with redish lighting - with my old codebase where colors were separate uint8_t for each component I would do: r * 1, g * .2, b * .1 or so but here I have no idea what to do. SDL_GetRGB and SDL_MapRGB is out of question since it is too slow when done ScreenWidth*ScreenHeight times.

  2. Can I use shaders with SDL_Renderer and how? Or do I need to resort to “basic” OpenGL setup i.e. no renderer? Question No. 1 could be easily solved (and would be faster I guess) by a post-effect combining framebuffer and a color map.

  1. Have you looked at the SDL_SetTextureColorMod() function? Using this, you can set some fixed color mods which will automatically be applied whenever that texture is used in a RenderCopy() operation. Assuming you’re using an accelerated renderer, this will be handled by the GPU, and so it is quite fast compared to doing it yourself in the CPU.

  2. I believe that using shaders does require using OpenGL along with SDL2. I’m not very experienced with this, so hopefully someone else will wander by with more info on the subject.

Thank you lloyd_b, although your answer wasn’t “valid” since I weren’t clear enough it did help me reach a working solution which is SDL_SetTextureBlendMode(m_ColorTexture, SDL_BLENDMODE_MOD); Thing about raycasting is that you are drawing vertical stripe by vertical stripe into your framebuffer, and during those draws i need to multiply parts of the stripe (since I can draw multiple sectors at one) with a color mod, so setting the whole texture with a color mod is not a good option (its more like overall brightness). But my shader idea came in nicely with discovery of SDL_SetTextureBlendMode. What I’m doing is that is I’m having another texture with SDL_BLENDMODE_MOD on which for every vertical stripe part I paint the color of the rendered sector, then I render copy it after the actual frame is render copied and voila! Same scene as before only rendering much faster - before I had average FPS of ~82 now its ~135. You can see on screenshots below what I mean.

[Image: http://i41.tinypic.com/xlfsl5.png ] [Image: http://i42.tinypic.com/sl1u0x.png ] [Image: http://i42.tinypic.com/24mdkqt.png ]

That’s a really nice effect!

Jonny D