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
Simple Directmedia Layer Forums
Problem with SDL_UpdateTexture when altering surface pixels
dandago
Joined: 30 Aug 2013
Posts: 34
Posted: Fri Aug 30, 2013 8:29 pm
Hi,
I'm having a bit of a problem with SDL_UpdateTexture() - I'm using SDL2 on Windows 7.
Basically I'm developing a simple image viewer to get used to the new API. I first load the image to a surface (IMG_Load()), and then use SDL_CreateTextureFromSurface(). So far so good.
The problem arises when I alter the SDL_Surface's pixels directly and then call SDL_UpdateTexture(). The window is 640x480 but the image is 476x334 pixels. SDL automatically scales this. But with SDL_UpdateTexture(), I have two courses of action.
1. If I set the second parameter (rect) to NULL, the image doesn't scale, and looks a bit messed up. It still fills the area of the window, but it's kind of tiled.
2. If I set the second parameter to a rect with width 640 and height 480, the image in the window just doesn't get updated at all.
Is there any way that I can alter pixels, update the texture, and get scaling for free as well?
Thanks,
Daniel
dandago
Joined: 30 Aug 2013
Posts: 34
Posted: Sat Aug 31, 2013 12:31 pm
Here's example code to replicate the problem. I removed the code that would mess with the pixels; just using SDL_UpdateTexture() is enough.