The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Fastest Method To Modify Pixels In SDL2 Texture?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Fastest Method To Modify Pixels In SDL2 Texture?

Hi,

We are working on a Wolfenstein 3D styled game SDL2 game now.
What would be the best and fastest method to modify pixels in an SDL2 texture?
We want to draw the 3d game off screen to an SDL2 texture and then render that SDL2 texture once to the screen.
Any advice would be appreciated!

You can download a clean and stable version of our work in progress game below:
http://16bitsoft.com/files/ThreeDimensional/Alpha/3D-WinLinux-Alpha02.zip
(game is 100% open-source cross-platform and has been tested on both Windows and Linux)

Thanks in advance!
Fastest Method To Modify Pixels In SDL2 Texture?
Travis McKinney
Guest

I've had success using SDL_LockTexture and SDL_UpdateTexture for software rendering. According to the wiki, SDL_LockTexture is faster but there are a few anecdotes online where SDL_UpdateTexture has been faster. In the case of SDL_UpdateTexture, I'm creating an RGBA/ABGR8888 pixel array with Uint8_T *pixels = new [width * height *4]; Using SDL_LockTexture, it may be possible to use SDL to allocate the memory
Uint8_T *pixels = SDL_LockTexture(tex);
//Modify pixels
pixels = NULL;
SDL_UnlockTexture(tex); On May 25, 2015 4:41 PM, "JeZ-l-Lee" wrote:
Quote:
Fastest Method To Modify Pixels In SDL2 Texture?

Hi,

We are working on a Wolfenstein 3D styled game SDL2 game now.
What would be the best and fastest method to modify pixels in an SDL2 texture?
We want to draw the 3d game off screen to an SDL2 texture and then render that SDL2 texture once to the screen.
Any advice would be appreciated!

You can download a clean and stable version of our work in progress game below:
http://16bitsoft.com/files/ThreeDimensional/Alpha/3D-WinLinux-Alpha02.zip
(game is 100% open-source cross-platform and has been tested on both Windows and Linux)

Thanks in advance!



JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Fastest Method To Modify Pixels In SDL2 Texture?
Eric Wing
Guest

On 5/25/15, JeZ-l-Lee wrote:
Quote:
Fastest Method To Modify Pixels In SDL2 Texture?

Hi,

We are working on a Wolfenstein 3D styled game SDL2 game now.
What would be the best and fastest method to modify pixels in an SDL2
texture?
We want to draw the 3d game off screen to an SDL2 texture and then render
that SDL2 texture once to the screen.
Any advice would be appreciated!


Maybe you can avoid modifying individual pixels altogether and avoid
the CPU in your path? By your description, at the core, it sounds
simply like a render-to-texture scenario.

I think the trick is getting the 3D scene to render to an SDL_texture
so you can just call SDL_RenderCopy on it for the final screen draw. I
haven't looked into how to do that, but I think this technique is what
you are kind of after.
https://wiki.libsdl.org/SDL_GL_BindTexture

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Fastest Method To Modify Pixels In SDL2 Texture?
Ryan C. Gordon
Guest

Quote:
We want to draw the 3d game off screen to an SDL2 texture and then
render that SDL2 texture once to the screen.
Any advice would be appreciated!

Just to be clear: if you want to render individual pixels, render them
to a memory buffer and upload them all to the texture when you're ready
to put them to the screen, once, at the end of the frame.

(You can get away with doing this if you SDL_LockTexture() once at the
start of the frame, do whatever you want to the pixels, and Unlock right
before SDL_RenderCopy'ing the texture to the screen, but that's because
streaming SDL_Textures keep a copy of themselves in RAM to make this
scenario faster.)

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org